Add prop_array_t support to prop_kern.

This commit is contained in:
thorpej 2006-10-26 18:51:21 +00:00
parent f31bc9e7e9
commit 1aea07a325
6 changed files with 223 additions and 60 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_array.h,v 1.3 2006/08/21 04:13:28 thorpej Exp $ */
/* $NetBSD: prop_array.h,v 1.4 2006/10/26 18:51:21 thorpej Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -71,6 +71,21 @@ prop_array_t prop_array_internalize(const char *);
boolean_t prop_array_externalize_to_file(prop_array_t, const char *);
prop_array_t prop_array_internalize_from_file(const char *);
#if defined(__NetBSD__)
#if !defined(_KERNEL) && !defined(_STANDALONE)
int prop_array_send_ioctl(prop_array_t, int, unsigned long);
int prop_array_recv_ioctl(int, unsigned long, prop_array_t *);
#elif defined(_KERNEL)
struct plistref;
int prop_array_copyin_ioctl(const struct plistref *, const u_long,
prop_array_t *);
int prop_array_copyout_ioctl(struct plistref *, const u_long,
prop_array_t);
#endif
#endif /* __NetBSD__ */
__END_DECLS
#endif /* _PROPLIB_PROP_ARRAY_H_ */

View File

@ -1,4 +1,4 @@
.\" $NetBSD: prop_dictionary_copyin_ioctl.9,v 1.4 2006/09/22 04:20:23 thorpej Exp $
.\" $NetBSD: prop_copyin_ioctl.9,v 1.1 2006/10/26 18:51:21 thorpej Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -34,16 +34,24 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 13, 2006
.Dt PROP_DICTIONARY_COPYIN_IOCTL 9
.Dd October 25, 2006
.Dt PROP_COPYIN_IOCTL 9
.Os
.Sh NAME
.Nm prop_array_copyin_ioctl ,
.Nm prop_array_copyout_ioctl ,
.Nm prop_dictionary_copyin_ioctl ,
.Nm prop_dictionary_copyout_ioctl
.Nd Copy property lists to and from kernel space
.Sh SYNOPSIS
.In prop/proplib.h
.Ft int
.Fn prop_array_copyin_ioctl "const struct plistref *pref" \
"const u_long cmd" "prop_array_t *arrayp"
.Ft int
.Fn prop_array_copyout_ioctl "struct plistref *pref" \
"const u_long cmd" "prop_array_t array"
.Ft int
.Fn prop_dictionary_copyin_ioctl "const struct plistref *pref" \
"const u_long cmd" "prop_dictionary_t *dictp"
.Ft int
@ -51,7 +59,9 @@
"const u_long cmd" "prop_dictionary_t dict"
.Sh DESCRIPTION
The
.Nm prop_dictionary_copyin_ioctl
.Nm prop_array_copyin ,
.Nm prop_array_copyout ,
.Nm prop_dictionary_copyin_ioctl ,
and
.Nm prop_dictionary_copyout_ioctl
functions implement the kernel side of a protocol for sending property lists
@ -105,8 +115,9 @@ fooioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l)
}
.Ed
.Sh SEE ALSO
.Xr prop_array 3 ,
.Xr prop_dictionary 3 ,
.Xr prop_dictionary_send_ioctl 3 ,
.Xr prop_send_ioctl 3 ,
.Xr proplib 3
.Sh HISTORY
The

View File

@ -1,4 +1,4 @@
/* $NetBSD: prop_kern.c,v 1.4 2006/09/22 23:58:36 dogcow Exp $ */
/* $NetBSD: prop_kern.c,v 1.5 2006/10/26 18:51:21 thorpej Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -51,12 +51,20 @@
#include <stdio.h>
static int
prop_dictionary_pack_pref(prop_dictionary_t dict, struct plistref *pref,
char **bufp)
_prop_object_pack_pref(prop_object_t obj, struct plistref *pref, char **bufp)
{
char *buf;
buf = prop_dictionary_externalize(dict);
switch (prop_object_type(obj)) {
case PROP_TYPE_DICTIONARY:
buf = prop_dictionary_externalize(obj);
break;
case PROP_TYPE_ARRAY:
buf = prop_array_externalize(obj);
break;
default:
return (ENOTSUP);
}
if (buf == NULL) {
/* Assume we ran out of memory. */
return (ENOMEM);
@ -69,18 +77,14 @@ prop_dictionary_pack_pref(prop_dictionary_t dict, struct plistref *pref,
return (0);
}
/*
* prop_dictionary_send_ioctl --
* Send a dictionary to the kernel using the specified ioctl.
*/
int
prop_dictionary_send_ioctl(prop_dictionary_t dict, int fd, unsigned long cmd)
static int
_prop_object_send_ioctl(prop_object_t obj, int fd, unsigned long cmd)
{
struct plistref pref;
char *buf;
int error;
error = prop_dictionary_pack_pref(dict, &pref, &buf);
error = _prop_object_pack_pref(obj, &pref, &buf);
if (error)
return (error);
@ -94,13 +98,35 @@ prop_dictionary_send_ioctl(prop_dictionary_t dict, int fd, unsigned long cmd)
return (error);
}
static int
prop_dictionary_unpack_pref(const struct plistref *pref,
prop_dictionary_t *dictp)
/*
* prop_array_send_ioctl --
* Send an array to the kernel using the specified ioctl.
*/
int
prop_array_send_ioctl(prop_array_t array, int fd, unsigned long cmd)
{
prop_dictionary_t dict;
return (_prop_object_send_ioctl(array, fd, cmd));
}
/*
* prop_dictionary_send_ioctl --
* Send a dictionary to the kernel using the specified ioctl.
*/
int
prop_dictionary_send_ioctl(prop_dictionary_t dict, int fd, unsigned long cmd)
{
return (_prop_object_send_ioctl(dict, fd, cmd));
}
static int
_prop_object_unpack_pref(const struct plistref *pref, prop_type_t type,
prop_object_t *objp)
{
prop_object_t obj = NULL;
char *buf;
int error;
int error = 0;
if (pref->pref_len == 0) {
/*
@ -112,20 +138,43 @@ prop_dictionary_unpack_pref(const struct plistref *pref,
} else {
buf = pref->pref_plist;
buf[pref->pref_len - 1] = '\0'; /* extra insurance */
dict = prop_dictionary_internalize(buf);
switch (type) {
case PROP_TYPE_DICTIONARY:
obj = prop_dictionary_internalize(buf);
break;
case PROP_TYPE_ARRAY:
obj = prop_array_internalize(buf);
break;
default:
error = ENOTSUP;
}
(void) munmap(buf, pref->pref_len);
if (dict == NULL)
if (obj == NULL && error == 0)
error = EIO;
else
error = 0;
}
out:
if (error == 0)
*dictp = dict;
*objp = obj;
return (error);
}
/*
* prop_array_recv_ioctl --
* Receive an array from the kernel using the specified ioctl.
*/
int
prop_array_recv_ioctl(int fd, unsigned long cmd, prop_array_t *arrayp)
{
struct plistref pref;
if (ioctl(fd, cmd, &pref) == -1)
return (errno);
return (_prop_object_unpack_pref(&pref, PROP_TYPE_ARRAY,
(prop_object_t *)arrayp));
}
/*
* prop_dictionary_recv_ioctl --
* Receive a dictionary from the kernel using the specified ioctl.
@ -138,7 +187,8 @@ prop_dictionary_recv_ioctl(int fd, unsigned long cmd, prop_dictionary_t *dictp)
if (ioctl(fd, cmd, &pref) == -1)
return (errno);
return (prop_dictionary_unpack_pref(&pref, dictp));
return (_prop_object_unpack_pref(&pref, PROP_TYPE_DICTIONARY,
(prop_object_t *)dictp));
}
/*
@ -154,7 +204,7 @@ prop_dictionary_sendrecv_ioctl(prop_dictionary_t dict, int fd,
char *buf;
int error;
error = prop_dictionary_pack_pref(dict, &pref, &buf);
error = _prop_object_pack_pref(dict, &pref, &buf);
if (error)
return (error);
@ -168,7 +218,8 @@ prop_dictionary_sendrecv_ioctl(prop_dictionary_t dict, int fd,
if (error)
return (error);
return (prop_dictionary_unpack_pref(&pref, dictp));
return (_prop_object_unpack_pref(&pref, PROP_TYPE_DICTIONARY,
(prop_object_t *)dictp));
}
#endif /* !_KERNEL && !_STANDALONE */
@ -183,15 +234,11 @@ prop_dictionary_sendrecv_ioctl(prop_dictionary_t dict, int fd,
#include <uvm/uvm.h>
/*
* prop_dictionary_copyin_ioctl --
* Copy in a dictionary sent with an ioctl.
*/
int
prop_dictionary_copyin_ioctl(const struct plistref *pref, const u_long cmd,
prop_dictionary_t *dictp)
static int
_prop_object_copyin_ioctl(const struct plistref *pref, const prop_type_t type,
const u_long cmd, prop_object_t *objp)
{
prop_dictionary_t dict;
prop_object_t obj = NULL;
char *buf;
int error;
@ -210,22 +257,54 @@ prop_dictionary_copyin_ioctl(const struct plistref *pref, const u_long cmd,
}
buf[pref->pref_len] = '\0';
dict = prop_dictionary_internalize(buf);
switch (type) {
case PROP_TYPE_ARRAY:
obj = prop_array_internalize(buf);
break;
case PROP_TYPE_DICTIONARY:
obj = prop_dictionary_internalize(buf);
break;
default:
error = ENOTSUP;
}
free(buf, M_TEMP);
if (dict == NULL)
return (EIO);
*dictp = dict;
return (0);
if (obj == NULL) {
if (error == 0)
error = EIO;
} else {
*objp = obj;
}
return (error);
}
/*
* prop_dictionary_copyout_ioctl --
* Copy out a dictionary being received with an ioctl.
* prop_array_copyin_ioctl --
* Copy in an array send with an ioctl.
*/
int
prop_dictionary_copyout_ioctl(struct plistref *pref, const u_long cmd,
prop_dictionary_t dict)
prop_array_copyin_ioctl(const struct plistref *pref, const u_long cmd,
prop_array_t *arrayp)
{
return (_prop_object_copyin_ioctl(pref, PROP_TYPE_ARRAY,
cmd, (prop_object_t *)arrayp));
}
/*
* prop_dictionary_copyin_ioctl --
* Copy in a dictionary sent with an ioctl.
*/
int
prop_dictionary_copyin_ioctl(const struct plistref *pref, const u_long cmd,
prop_dictionary_t *dictp)
{
return (_prop_object_copyin_ioctl(pref, PROP_TYPE_DICTIONARY,
cmd, (prop_object_t *)dictp));
}
static int
_prop_object_copyout_ioctl(struct plistref *pref, const u_long cmd,
prop_object_t obj)
{
struct lwp *l = curlwp; /* XXX */
struct proc *p = l->l_proc;
@ -237,7 +316,16 @@ prop_dictionary_copyout_ioctl(struct plistref *pref, const u_long cmd,
if ((cmd & IOC_OUT) == 0)
return (EFAULT);
buf = prop_dictionary_externalize(dict);
switch (prop_object_type(obj)) {
case PROP_TYPE_ARRAY:
buf = prop_array_externalize(obj);
break;
case PROP_TYPE_DICTIONARY:
buf = prop_dictionary_externalize(obj);
break;
default:
return (ENOTSUP);
}
if (buf == NULL)
return (ENOMEM);
@ -263,6 +351,28 @@ prop_dictionary_copyout_ioctl(struct plistref *pref, const u_long cmd,
return (error);
}
/*
* prop_array_copyout_ioctl --
* Copy out an array being received with an ioctl.
*/
int
prop_array_copyout_ioctl(struct plistref *pref, const u_long cmd,
prop_array_t array)
{
return (_prop_object_copyout_ioctl(pref, cmd, array));
}
/*
* prop_dictionary_copyout_ioctl --
* Copy out a dictionary being received with an ioctl.
*/
int
prop_dictionary_copyout_ioctl(struct plistref *pref, const u_long cmd,
prop_dictionary_t dict)
{
return (_prop_object_copyout_ioctl(pref, cmd, dict));
}
#endif /* _KERNEL */
#endif /* __NetBSD__ */

View File

@ -1,4 +1,4 @@
.\" $NetBSD: prop_dictionary_send_ioctl.3,v 1.4 2006/09/22 04:20:23 thorpej Exp $
.\" $NetBSD: prop_send_ioctl.3,v 1.1 2006/10/26 18:51:21 thorpej Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -34,10 +34,12 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 13, 2006
.Dt PROP_DICTIONARY_SEND_IOCTL 9
.Dd October 25, 2006
.Dt PROP_SEND_IOCTL 9
.Os
.Sh NAME
.Nm prop_array_send_ioctl ,
.Nm prop_array_recv_ioctl ,
.Nm prop_dictionary_send_ioctl ,
.Nm prop_dictionary_recv_ioctl ,
.Nm prop_dictionary_sendrecv_ioctl
@ -45,6 +47,10 @@
.Sh SYNOPSIS
.In prop/proplib.h
.Ft int
.Fn prop_array_send_ioctl "prop_array_t array" "int fd" "unsigned long cmd"
.Ft int
.Fn prop_array_recv_ioctl "int fd" "unsigned long cmd" "prop_array_t *arrayp"
.Ft int
.Fn prop_dictionary_send_ioctl "prop_dictionary_t dict" "int fd" \
"unsigned long cmd"
.Ft int
@ -54,6 +60,8 @@
"unsigned long cmd" "prop_dictionary_t *dictp"
.Sh DESCRIPTION
The
.Nm prop_array_send_ioctl ,
.Nm prop_array_recv_ioctl ,
.Nm prop_dictionary_send_ioctl ,
.Nm prop_dictionary_recv_ioctl ,
and
@ -109,9 +117,10 @@ function combines the send and receive functionality, allowing for
ioctls that require two-way communication
.Pq for example to specify arguments for the ioctl operation .
.Sh SEE ALSO
.Xr prop_array 3 ,
.Xr prop_dictionary 3 ,
.Xr proplib 3 ,
.Xr prop_dictionary_copyin_ioctl 9
.Xr prop_copyin_ioctl 9
.Sh HISTORY
The
.Nm proplib

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.956 2006/10/26 05:02:12 thorpej Exp $
# $NetBSD: mi,v 1.957 2006/10/26 18:51:21 thorpej Exp $
./etc/mtree/set.comp comp-sys-root
./usr/bin/addr2line comp-debug-bin bfd
./usr/bin/ar comp-util-bin bfd
@ -5408,7 +5408,9 @@
./usr/share/man/cat3/prop_array_iterator.0 comp-c-catman .cat
./usr/share/man/cat3/prop_array_make_immutable.0 comp-c-catman .cat
./usr/share/man/cat3/prop_array_mutable.0 comp-c-catman .cat
./usr/share/man/cat3/prop_array_recv_ioctl.0 comp-c-catman .cat
./usr/share/man/cat3/prop_array_remove.0 comp-c-catman .cat
./usr/share/man/cat3/prop_array_send_ioctl.0 comp-c-catman .cat
./usr/share/man/cat3/prop_array_set.0 comp-c-catman .cat
./usr/share/man/cat3/prop_bool.0 comp-c-catman .cat
./usr/share/man/cat3/prop_bool_copy.0 comp-c-catman .cat
@ -5500,6 +5502,7 @@
./usr/share/man/cat3/prop_object_release.0 comp-c-catman .cat
./usr/share/man/cat3/prop_object_retain.0 comp-c-catman .cat
./usr/share/man/cat3/prop_object_type.0 comp-c-catman .cat
./usr/share/man/cat3/prop_send_ioctl.0 comp-c-catman .cat
./usr/share/man/cat3/prop_string.0 comp-c-catman .cat
./usr/share/man/cat3/prop_string_append.0 comp-c-catman .cat
./usr/share/man/cat3/prop_string_append_cstring.0 comp-c-catman .cat
@ -7070,7 +7073,10 @@
./usr/share/man/cat9/printf.0 comp-sys-catman .cat
./usr/share/man/cat9/printf_nolog.0 comp-sys-catman .cat
./usr/share/man/cat9/proc_trampoline.0 comp-sys-catman .cat
./usr/share/man/cat9/prop_array_copyin_ioctl.0 comp-sys-catman .cat
./usr/share/man/cat9/prop_array_copyout_ioctl.0 comp-sys-catman .cat
./usr/share/man/cat9/prop_copy.0 comp-obsolete obsolete
./usr/share/man/cat9/prop_copyin_ioctl.0 comp-sys-catman .cat
./usr/share/man/cat9/prop_delete.0 comp-obsolete obsolete
./usr/share/man/cat9/prop_dictionary_copyin_ioctl.0 comp-sys-catman .cat
./usr/share/man/cat9/prop_dictionary_copyout_ioctl.0 comp-sys-catman .cat
@ -9651,7 +9657,9 @@
./usr/share/man/man3/prop_array_iterator.3 comp-c-man .man
./usr/share/man/man3/prop_array_make_immutable.3 comp-c-man .man
./usr/share/man/man3/prop_array_mutable.3 comp-c-man .man
./usr/share/man/man3/prop_array_recv_ioctl.3 comp-c-man .man
./usr/share/man/man3/prop_array_remove.3 comp-c-man .man
./usr/share/man/man3/prop_array_send_ioctl.3 comp-c-man .man
./usr/share/man/man3/prop_array_set.3 comp-c-man .man
./usr/share/man/man3/prop_bool.3 comp-c-man .man
./usr/share/man/man3/prop_bool_copy.3 comp-c-man .man
@ -9742,6 +9750,7 @@
./usr/share/man/man3/prop_object_release.3 comp-c-man .man
./usr/share/man/man3/prop_object_retain.3 comp-c-man .man
./usr/share/man/man3/prop_object_type.3 comp-c-man .man
./usr/share/man/man3/prop_send_ioctl.3 comp-c-man .cat
./usr/share/man/man3/prop_string.3 comp-c-man .man
./usr/share/man/man3/prop_string_append.3 comp-c-man .man
./usr/share/man/man3/prop_string_append_cstring.3 comp-c-man .man
@ -11306,7 +11315,10 @@
./usr/share/man/man9/printf.9 comp-sys-man .man
./usr/share/man/man9/printf_nolog.9 comp-sys-man .man
./usr/share/man/man9/proc_trampoline.9 comp-sys-man .man
./usr/share/man/man9/prop_array_copyin_ioctl.9 comp-sys-man .man
./usr/share/man/man9/prop_array_copyout_ioctl.9 comp-sys-man .man
./usr/share/man/man9/prop_copy.9 comp-obsolete obsolete
./usr/share/man/man9/prop_copyin_ioctl.9 comp-sys-man .man
./usr/share/man/man9/prop_delete.9 comp-obsolete obsolete
./usr/share/man/man9/prop_dictionary_copyin_ioctl.9 comp-sys-man .man
./usr/share/man/man9/prop_dictionary_copyout_ioctl.9 comp-sys-man .man

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.12 2006/10/26 05:02:12 thorpej Exp $
# $NetBSD: Makefile,v 1.13 2006/10/26 18:51:21 thorpej Exp $
.include <bsd.own.mk>
@ -17,12 +17,18 @@ LIB= prop
MAN= prop_array.3 prop_bool.3 prop_data.3 prop_dictionary.3 \
prop_ingest.3 prop_number.3 prop_object.3 prop_string.3 proplib.3
MAN+= prop_dictionary_copyin_ioctl.9
MLINKS+= prop_dictionary_copyin_ioctl.9 prop_dictionary_copyout_ioctl.9
MAN+= prop_copyin_ioctl.9
MLINKS+= prop_copyin_ioctl.9 prop_array_copyin_ioctl.9
MLINKS+= prop_copyin_ioctl.9 prop_array_copyout_ioctl.9
MLINKS+= prop_copyin_ioctl.9 prop_dictionary_copyin_ioctl.9
MLINKS+= prop_copyin_ioctl.9 prop_dictionary_copyout_ioctl.9
MAN+= prop_dictionary_send_ioctl.3
MLINKS+= prop_dictionary_send_ioctl.3 prop_dictionary_recv_ioctl.3
MLINKS+= prop_dictionary_send_ioctl.3 prop_dictionary_sendrecv_ioctl.3
MAN+= prop_send_ioctl.3
MLINKS+= prop_send_ioctl.3 prop_array_send_ioctl.3
MLINKS+= prop_send_ioctl.3 prop_array_recv_ioctl.3
MLINKS+= prop_send_ioctl.3 prop_dictionary_send_ioctl.3
MLINKS+= prop_send_ioctl.3 prop_dictionary_recv_ioctl.3
MLINKS+= prop_send_ioctl.3 prop_dictionary_sendrecv_ioctl.3
MAN+= prop_dictionary_util.3
MLINKS+= prop_dictionary_util.3 prop_dictionary_get_bool.3