home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / modutils / kerneld / kerneld-persist-patch < prev    next >
Encoding:
Text File  |  1998-01-06  |  1.9 KB  |  77 lines

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