chiark / gitweb /
[PATCH] udev - keep private data out of the database?
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Fri, 13 Feb 2004 06:51:44 +0000 (22:51 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:32:27 +0000 (21:32 -0700)
Shouldn't we keep the temporary strings out of the database,
or is this information useful for something?

It cuts the length of the data from 628 to 275 bytes.

udev.h
udevdb.c

diff --git a/udev.h b/udev.h
index 00f1361016d8e743d4503d8c5f08a677f7bdbf66..e615b4c8bb9e6a88b78d1e1ac72686ae349e3b73 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -24,6 +24,7 @@
 #define UDEV_H
 
 #include "libsysfs/libsysfs.h"
 #define UDEV_H
 
 #include "libsysfs/libsysfs.h"
+#include <stddef.h>
 #include <sys/param.h>
 
 #define COMMENT_CHARACTER              '#'
 #include <sys/param.h>
 
 #define COMMENT_CHARACTER              '#'
@@ -33,6 +34,9 @@
 #define GROUP_SIZE     30
 #define MODE_SIZE      8
 
 #define GROUP_SIZE     30
 #define MODE_SIZE      8
 
+/* length of public data */
+#define UDEVICE_LEN (offsetof(struct udevice, bus_id))
+
 struct udevice {
        char name[NAME_SIZE];
        char owner[OWNER_SIZE];
 struct udevice {
        char name[NAME_SIZE];
        char owner[OWNER_SIZE];
@@ -43,11 +47,11 @@ struct udevice {
        unsigned int mode;      /* not mode_t due to conflicting definitions in different libcs */
        char symlink[NAME_SIZE];
 
        unsigned int mode;      /* not mode_t due to conflicting definitions in different libcs */
        char symlink[NAME_SIZE];
 
-       /* fields that help us in building strings */
-       unsigned char bus_id[SYSFS_NAME_LEN];
-       unsigned char program_result[NAME_SIZE];
-       unsigned char kernel_number[NAME_SIZE];
-       unsigned char kernel_name[NAME_SIZE];
+       /* private data that help us in building strings */
+       char bus_id[SYSFS_NAME_LEN];
+       char program_result[NAME_SIZE];
+       char kernel_number[NAME_SIZE];
+       char kernel_name[NAME_SIZE];
 };
 
 #define strfieldcpy(to, from) \
 };
 
 #define strfieldcpy(to, from) \
index c4e064fc115d4414ef21cbbbc44403ed4570e7bc..e657fedcb2018ec8b67ac310f42ee85eb23f5482 100644 (file)
--- a/udevdb.c
+++ b/udevdb.c
@@ -58,8 +58,8 @@ int udevdb_add_dev(const char *path, const struct udevice *dev)
        key.dsize = strlen(keystr) + 1;
 
        data.dptr = (void *)dev;
        key.dsize = strlen(keystr) + 1;
 
        data.dptr = (void *)dev;
-       data.dsize = sizeof(*dev);
-       
+       data.dsize = UDEVICE_LEN;
+
        return tdb_store(udevdb, key, data, TDB_REPLACE); 
 }
 
        return tdb_store(udevdb, key, data, TDB_REPLACE); 
 }
 
@@ -77,7 +77,8 @@ int udevdb_get_dev(const char *path, struct udevice *dev)
        if (data.dptr == NULL || data.dsize == 0)
                return -ENODEV;
 
        if (data.dptr == NULL || data.dsize == 0)
                return -ENODEV;
 
-       memcpy(dev, data.dptr, sizeof(*dev));
+       memset(dev, 0, sizeof(struct udevice));
+       memcpy(dev, data.dptr, UDEVICE_LEN);
        return 0;
 }
 
        return 0;
 }