1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
--- kerneld.h.org Sat Nov 29 19:33:21 1997
+++ kerneld.h Tue Feb 17 17:31:11 1998
@@ -9,6 +9,8 @@
#define KERNELD_REQUEST_ROUTE 6 /* from net/ipv4/route.c */
#define KERNELD_BLANKER 7 /* from drivers/char/console.c */
#define KERNELD_PNP 8 /* from drivers/pnp/kerneld.c */
+#define KERNELD_GET_PERSIST 200 /* persistent module storage */
+#define KERNELD_SET_PERSIST 201 /* persistent module storage */
#define KERNELD_ARP 256 /* from net/ipv4/arp.c */
/*
@@ -47,7 +49,16 @@
#endif /* __KERNEL__ */
};
+struct __persist {
+ int keylen;
+ int arglen;
+ char arr[0];
+};
+
#ifdef __KERNEL__
+#include <linux/malloc.h>
+
extern int kerneld_send(int msgtype, int ret_size, int msgsz,
const char *text, const char *ret_val);
@@ -126,6 +137,49 @@
return kerneld_send(KERNELD_BLANKER,
0 | (on_off?KERNELD_NOWAIT:KERNELD_WAIT),
strlen(on_off?"on":"off"), on_off?"on":"off", NULL);
+}
+
+/*
+ * Persistent storage for modules
+ *
+ * Usage:
+ * int get_persist("a key", &value, sizeof(value));
+ * Returns > 0 on success (return value == returned size)
+ *
+ * int set_persist("a key", &value, sizeof(value));
+ * Returns < 0 on failure
+ *
+ * To remove an entry, use: "set_persist("a key", NULL, 0);"
+ */
+
+static inline int set_persist(char *key, void *value, size_t length)
+{
+ struct __persist *p;
+ int keylen = strlen(key) + 1;
+ int structsize = keylen + length + sizeof(struct __persist);
+ int status;
+
+ if ((p = (struct __persist *)kmalloc(structsize, GFP_ATOMIC)) == NULL)
+ return -ENOMEM;
+ strcpy(p->arr, key);
+ p->keylen = keylen;
+ p->arglen = length;
+ if (length)
+ memcpy(p->arr + keylen, value, length);
+
+ status = kerneld_send(KERNELD_SET_PERSIST,
+ 0 | KERNELD_NOWAIT,
+ structsize, (char *)p, NULL);
+
+ kfree(p);
+ return status;
+}
+
+static inline int get_persist(char *key, void *value, size_t length)
+{
+ return kerneld_send(KERNELD_GET_PERSIST,
+ length | KERNELD_WAIT,
+ strlen(key), key, value);
}
#endif /* __KERNEL__ */
|