#define ATTR_PARTITIONS "all_partitions"
#define ATTR_IGNORE_REMOVE "ignore_remove"
-#define PARTITIONS_COUNT 15
#define MAX_SYSFS_PAIRS 5
extern int namedev_init(void);
extern int namedev_name_device(struct udevice *udev, struct sysfs_class_device *class_dev);
+extern void namedev_close(void);
extern void dump_config_dev(struct config_device *dev);
extern void dump_config_dev_list(void);
if (attr != NULL) {
if (strstr(attr, ATTR_PARTITIONS) != NULL) {
dbg_parse("creation of partition nodes requested");
- dev.partitions = PARTITIONS_COUNT;
+ dev.partitions = DEFAULT_PARTITIONS_COUNT;
}
if (strstr(attr, ATTR_IGNORE_REMOVE) != NULL) {
dbg_parse("remove event should be ignored");
return retval;
}
+
+void namedev_close(void)
+{
+ struct config_device *dev;
+
+ list_for_each_entry(dev, &config_device_list, node) {
+ list_del(&dev->node);
+ free(dev);
+ }
+}
+
#define HOTPLUGD_DIR "/etc/hotplug.d"
#define HOTPLUG_SUFFIX ".hotplug"
+#define DEFAULT_PARTITIONS_COUNT 15
+
struct udevice {
char devpath[DEVPATH_SIZE];
char subsystem[SUBSYSTEM_SIZE];
return retval;
}
-static int create_node(struct udevice *udev)
+static int create_node(struct udevice *udev, struct sysfs_class_device *class_dev)
{
char filename[NAME_SIZE];
char partitionname[NAME_SIZE];
uid_t uid = 0;
gid_t gid = 0;
- int i;
int tail;
char *pos;
int len;
+ int i;
snprintf(filename, NAME_SIZE, "%s/%s", udev_root, udev->name);
filename[NAME_SIZE-1] = '\0';
if (udev->owner[0] != '\0') {
char *endptr;
unsigned long id = strtoul(udev->owner, &endptr, 10);
+
if (endptr[0] == '\0')
uid = (uid_t) id;
else {
if (udev->group[0] != '\0') {
char *endptr;
unsigned long id = strtoul(udev->group, &endptr, 10);
+
if (endptr[0] == '\0')
gid = (gid_t) id;
else {
/* create all_partitions if requested */
if (udev->partitions > 0) {
+ struct sysfs_attribute *attr;
+ int range;
+
+ /* take the maximum registered minor range */
+ attr = sysfs_get_classdev_attr(class_dev, "range");
+ if (attr) {
+ range = atoi(attr->value);
+ if (range > 1)
+ udev->partitions = range-1;
+ }
info("creating device partition nodes '%s[1-%i]'", filename, udev->partitions);
if (!udev->test_run) {
for (i = 1; i <= udev->partitions; i++) {
selinux_init();
if (udev->type == 'b' || udev->type == 'c') {
- retval = create_node(udev);
+ retval = create_node(udev, class_dev);
if (retval != 0)
goto exit;
num = udev->partitions;
if (num > 0) {
info("removing all_partitions '%s[1-%i]'", filename, num);
- if (num > PARTITIONS_COUNT) {
+ if (num > 255) {
info("garbage from udev database, skip all_partitions removal");
return -1;
}