#define UDEV_H
#include "libsysfs/libsysfs.h"
+#include <stddef.h>
#include <sys/param.h>
#define COMMENT_CHARACTER '#'
#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];
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) \
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);
}
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;
}