tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
factoring out prop_XXX_pack_pref() and prop_XXX_copyin_pref()
I am working on code that includes a system call where the arguments
are passed into the kernel as a plistref to a proplib dictionary.
To help with that I'd like to extend the userland and kernel API of
proplib with the following two functions each:
int prop_array_pack_pref(prop_array_t, struct plistref *);
int prop_dictionary_pack_pref(prop_dictionary_t, struct plistref *);
int prop_array_copyin(const struct plistref *, prop_array_t *);
int prop_dictionary_copyin(const struct plistref *, prop_dictionary_t *);
I intend to document prop_array_pack_pref() and
prop_dictionary_pack_pref() in the man-page prop_pack.3. And
prop_array_copyin() and prop_dictionary_copyin() in prop_copyin_ioctl.9.
While there I'll refactor a bit of common code like.
If no-one has technical objections I'd like to commit the changes soonish.
Comments?
--chris
Index: common/include/prop/prop_array.h
===================================================================
RCS file: /cvsroot/src/common/include/prop/prop_array.h,v
retrieving revision 1.8
diff -u -r1.8 prop_array.h
--- common/include/prop/prop_array.h 11 Sep 2008 13:15:13 -0000 1.8
+++ common/include/prop/prop_array.h 29 Jul 2009 22:29:29 -0000
@@ -66,12 +66,14 @@
prop_array_t prop_array_internalize_from_file(const char *);
#if defined(__NetBSD__)
+struct plistref;
+
#if !defined(_KERNEL) && !defined(_STANDALONE)
+int prop_array_pack_pref(prop_array_t, struct plistref *);
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(const struct plistref *, prop_array_t *);
int prop_array_copyin_ioctl(const struct plistref *, const u_long,
prop_array_t *);
int prop_array_copyout_ioctl(struct plistref *, const u_long,
Index: common/include/prop/prop_dictionary.h
===================================================================
RCS file: /cvsroot/src/common/include/prop/prop_dictionary.h,v
retrieving revision 1.9
diff -u -r1.9 prop_dictionary.h
--- common/include/prop/prop_dictionary.h 28 Apr 2008 20:22:51 -0000
1.9
+++ common/include/prop/prop_dictionary.h 29 Jul 2009 22:29:30 -0000
@@ -82,7 +82,10 @@
prop_dictionary_keysym_t);
#if defined(__NetBSD__)
+struct plistref;
+
#if !defined(_KERNEL) && !defined(_STANDALONE)
+int prop_dictionary_pack_pref(prop_dictionary_t, struct plistref *);
int prop_dictionary_send_ioctl(prop_dictionary_t, int,
unsigned long);
int prop_dictionary_recv_ioctl(int, unsigned long,
@@ -91,8 +94,8 @@
int, unsigned long,
prop_dictionary_t *);
#elif defined(_KERNEL)
-struct plistref;
-
+int prop_dictionary_copyin(const struct plistref *,
+ prop_dictionary_t *);
int prop_dictionary_copyin_ioctl(const struct plistref *,
const u_long,
prop_dictionary_t *);
Index: common/lib/libprop/prop_kern.c
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_kern.c,v
retrieving revision 1.9
diff -u -r1.9 prop_kern.c
--- common/lib/libprop/prop_kern.c 28 Apr 2008 20:22:53 -0000 1.9
+++ common/lib/libprop/prop_kern.c 29 Jul 2009 22:29:30 -0000
@@ -1,7 +1,7 @@
/* $NetBSD: prop_kern.c,v 1.9 2008/04/28 20:22:53 martin Exp $ */
/*-
- * Copyright (c) 2006 The NetBSD Foundation, Inc.
+ * Copyright (c) 2006, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -70,6 +70,30 @@
return (0);
}
+/*
+ * prop_array_pack_pref --
+ * Pack an array into a plistref for sending to the kernel.
+ */
+int
+prop_array_pack_pref(prop_array_t array, struct plistref *prefp)
+{
+ char *buf;
+
+ return _prop_object_pack_pref(array, prefp, &buf);
+}
+
+/*
+ * prop_dictionary_pack_pref --
+ * Pack an dictionary into a plistref for sending to the kernel.
+ */
+int
+prop_dictionary_pack_pref(prop_dictionary_t dict, struct plistref *prefp)
+{
+ char *buf;
+
+ return _prop_object_pack_pref(dict, prefp, &buf);
+}
+
static int
_prop_object_send_ioctl(prop_object_t obj, int fd, unsigned long cmd)
{
@@ -231,16 +255,13 @@
unsigned int prop_object_copyin_limit = 65536;
static int
-_prop_object_copyin_ioctl(const struct plistref *pref, const prop_type_t type,
- const u_long cmd, prop_object_t *objp)
+_prop_object_copyin(const struct plistref *pref, const prop_type_t type,
+ prop_object_t *objp)
{
prop_object_t obj = NULL;
char *buf;
int error;
- if ((cmd & IOC_IN) == 0)
- return (EFAULT);
-
/*
* Allocate an extra byte so we can guarantee NUL-termination.
*
@@ -277,6 +298,40 @@
return (error);
}
+
+static int
+_prop_object_copyin_ioctl(const struct plistref *pref, const prop_type_t type,
+ const u_long cmd, prop_object_t *objp)
+{
+ if ((cmd & IOC_IN) == 0)
+ return (EFAULT);
+
+ return _prop_object_copyin(pref, type, objp);
+}
+
+/*
+ * prop_array_copyin --
+ * Copy in an array passed as a syscall arg.
+ */
+int
+prop_array_copyin(const struct plistref *pref, prop_array_t *arrayp)
+{
+ return (_prop_object_copyin(pref, PROP_TYPE_ARRAY,
+ (prop_object_t *)arrayp));
+}
+
+/*
+ * prop_dictionary_copyin --
+ * Copy in a dictionary passed as a syscall arg.
+ */
+int
+prop_dictionary_copyin(const struct plistref *pref, prop_dictionary_t *dictp)
+{
+ return (_prop_object_copyin(pref, PROP_TYPE_DICTIONARY,
+ (prop_object_t *)dictp));
+}
+
+
/*
* prop_array_copyin_ioctl --
* Copy in an array send with an ioctl.
Home |
Main Index |
Thread Index |
Old Index