summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--namedev.c2
-rw-r--r--namedev.h43
-rw-r--r--namedev_parse.c22
-rw-r--r--test/udev-test.pl11
-rw-r--r--udev-add.c71
-rw-r--r--udev-remove.c13
-rw-r--r--udev.h1
7 files changed, 108 insertions, 55 deletions
diff --git a/namedev.c b/namedev.c
index cd38f25cb0..942788b2a2 100644
--- a/namedev.c
+++ b/namedev.c
@@ -820,7 +820,7 @@ found:
/* substitute placeholder */
apply_format(udev, udev->name, class_dev, sysfs_device);
apply_format(udev, udev->symlink, class_dev, sysfs_device);
-
+ udev->partitions = dev->partitions;
done:
perm = find_perm(udev->name);
if (perm) {
diff --git a/namedev.h b/namedev.h
index e38c4f5257..10a5dcaf0c 100644
--- a/namedev.h
+++ b/namedev.h
@@ -28,25 +28,29 @@
struct sysfs_class_device;
-#define BUS_SIZE 30
-#define FILE_SIZE 50
-#define VALUE_SIZE 100
-#define ID_SIZE 50
-#define PLACE_SIZE 50
-#define PROGRAM_SIZE 100
-
-#define FIELD_BUS "BUS"
-#define FIELD_SYSFS "SYSFS"
-#define FIELD_ID "ID"
-#define FIELD_PLACE "PLACE"
-#define FIELD_PROGRAM "PROGRAM"
-#define FIELD_RESULT "RESULT"
-#define FIELD_KERNEL "KERNEL"
-#define FIELD_NAME "NAME"
-#define FIELD_SYMLINK "SYMLINK"
-
-#define PROGRAM_MAXARG 10
-#define MAX_SYSFS_PAIRS 5
+#define BUS_SIZE 30
+#define FILE_SIZE 50
+#define VALUE_SIZE 100
+#define ID_SIZE 50
+#define PLACE_SIZE 50
+#define PROGRAM_SIZE 100
+
+#define FIELD_BUS "BUS"
+#define FIELD_SYSFS "SYSFS"
+#define FIELD_ID "ID"
+#define FIELD_PLACE "PLACE"
+#define FIELD_PROGRAM "PROGRAM"
+#define FIELD_RESULT "RESULT"
+#define FIELD_KERNEL "KERNEL"
+#define FIELD_NAME "NAME"
+#define FIELD_SYMLINK "SYMLINK"
+
+#define ATTR_PARTITIONS "all_partitions"
+#define PARTITIONS_COUNT 15
+
+
+#define PROGRAM_MAXARG 10
+#define MAX_SYSFS_PAIRS 5
struct sysfs_pair {
char file[FILE_SIZE];
@@ -65,6 +69,7 @@ struct config_device {
char name[NAME_SIZE];
char symlink[NAME_SIZE];
struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
+ int partitions;
int config_line;
};
diff --git a/namedev_parse.c b/namedev_parse.c
index 20ff60d640..d5d2181cb6 100644
--- a/namedev_parse.c
+++ b/namedev_parse.c
@@ -91,13 +91,6 @@ static char *get_key_attribute(char *str)
char *pos;
char *attr;
- attr = strchr(str, '_');
- if (attr != NULL) {
- attr++;
- dbg("attribute='%s'", attr);
- return attr;
- }
-
attr = strchr(str, '{');
if (attr != NULL) {
attr++;
@@ -111,6 +104,13 @@ static char *get_key_attribute(char *str)
return attr;
}
+ attr = strchr(str, '_');
+ if (attr != NULL) {
+ attr++;
+ dbg("attribute='%s'", attr);
+ return attr;
+ }
+
return NULL;
}
@@ -221,7 +221,13 @@ int namedev_init_rules(void)
continue;
}
- if (strcasecmp(temp2, FIELD_NAME) == 0) {
+ if (strncasecmp(temp2, FIELD_NAME, sizeof(FIELD_NAME)-1) == 0) {
+ attr = get_key_attribute(temp2 + sizeof(FIELD_NAME)-1);
+ if (attr != NULL)
+ if (strcasecmp(attr, ATTR_PARTITIONS) == 0) {
+ dbg_parse("creation of partition nodes requested");
+ dev.partitions = PARTITIONS_COUNT;
+ }
strfieldcpy(dev.name, temp3);
continue;
}
diff --git a/test/udev-test.pl b/test/udev-test.pl
index abe622cf8a..258d5c9596 100644
--- a/test/udev-test.pl
+++ b/test/udev-test.pl
@@ -350,7 +350,16 @@ KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n"
EOF
},
{
- desc => "sysfs parent heirachy",
+ desc => "create all possible partitions",
+ subsys => "block",
+ devpath => "block/sda",
+ expected => "boot_disk15" ,
+ conf => <<EOF
+BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME{all_partitions}="boot_disk"
+EOF
+ },
+ {
+ desc => "sysfs parent hierarchy",
subsys => "tty",
devpath => "class/tty/ttyUSB0",
expected => "visor" ,
diff --git a/udev-add.c b/udev-add.c
index 8867c8f5af..3b3ebd5bbb 100644
--- a/udev-add.c
+++ b/udev-add.c
@@ -99,11 +99,44 @@ static int create_path(char *file)
return 0;
}
+static int make_node(char *filename, int major, int minor, unsigned int mode, uid_t uid, gid_t gid)
+{
+ int retval;
+
+ retval = mknod(filename, mode, makedev(major, minor));
+ if (retval != 0) {
+ dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
+ filename, mode, major, minor, strerror(errno));
+ return retval;
+ }
+
+ dbg("chmod(%s, %#o)", filename, mode);
+ retval = chmod(filename, mode);
+ if (retval != 0) {
+ dbg("chmod(%s, %#o) failed with error '%s'",
+ filename, mode, strerror(errno));
+ return retval;
+ }
+
+ if (uid != 0 || gid != 0) {
+ dbg("chown(%s, %u, %u)", filename, uid, gid);
+ retval = chown(filename, uid, gid);
+ if (retval != 0) {
+ dbg("chown(%s, %u, %u) failed with error '%s'",
+ filename, uid, gid, strerror(errno));
+ return retval;
+ }
+ }
+
+ return 0;
+}
+
static int create_node(struct udevice *dev, int fake)
{
struct stat stats;
char filename[255];
char linktarget[255];
+ char partitionname[255];
char *linkname;
char *symlinks;
int retval = 0;
@@ -135,23 +168,6 @@ static int create_node(struct udevice *dev, int fake)
if (strrchr(dev->name, '/'))
create_path(filename);
- info("creating device node '%s'", filename);
- dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
- if (!fake) {
- retval = mknod(filename, dev->mode, makedev(dev->major, dev->minor));
- if (retval != 0)
- dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
- filename, dev->mode, dev->major, dev->minor, strerror(errno));
- }
-
- dbg("chmod(%s, %#o)", filename, dev->mode);
- if (!fake) {
- retval = chmod(filename, dev->mode);
- if (retval != 0)
- dbg("chmod(%s, %#o) failed with error '%s'",
- filename, dev->mode, strerror(errno));
- }
-
if (dev->owner[0] != '\0') {
char *endptr;
unsigned long id = strtoul(dev->owner, &endptr, 10);
@@ -180,12 +196,18 @@ static int create_node(struct udevice *dev, int fake)
}
}
- if (uid != 0 || gid != 0) {
- dbg("chown(%s, %u, %u)", filename, uid, gid);
- retval = chown(filename, uid, gid);
- if (retval != 0)
- dbg("chown(%s, %u, %u) failed with error '%s'",
- filename, uid, gid, strerror(errno));
+ if (!fake)
+ info("creating device node '%s'", filename);
+ make_node(filename, dev->major, dev->minor, dev->mode, uid, gid);
+
+ /* create partitions if requested */
+ if (dev->partitions > 0) {
+ info("creating device partition nodes '%s[1-%i]'", filename, dev->partitions);
+ for (i = 1; i <= dev->partitions; i++) {
+ sprintf(partitionname, "%s%i", filename, i);
+ make_node(partitionname, dev->major, dev->minor + i,
+ dev->mode, uid, gid);
+ }
}
/* create symlink if requested */
@@ -222,8 +244,7 @@ static int create_node(struct udevice *dev, int fake)
strcpy(linktarget, "./");
strcat(linktarget, &dev->name[tail]);
- /* unlink existing non-directories to ensure that our symlink
- * is created */
+ /* unlink existing files to ensure that our symlink is created */
if (!fake && (lstat(filename, &stats) == 0)) {
if ((stats.st_mode & S_IFMT) != S_IFDIR) {
if (unlink(filename))
diff --git a/udev-remove.c b/udev-remove.c
index c21938fae7..c20c651dc5 100644
--- a/udev-remove.c
+++ b/udev-remove.c
@@ -66,9 +66,11 @@ static int delete_path(char *path)
static int delete_node(struct udevice *dev)
{
char filename[255];
+ char partitionname[255];
char *symlinks;
char *linkname;
int retval;
+ int i;
strncpy(filename, udev_root, sizeof(filename));
strncat(filename, dev->name, sizeof(filename));
@@ -81,11 +83,20 @@ static int delete_node(struct udevice *dev)
return retval;
}
+ /* remove partition nodes */
+ if (dev->partitions > 0) {
+ info("removing partitions '%s[1-%i]'", filename, dev->partitions);
+ for (i = 1; i <= dev->partitions; i++) {
+ sprintf(partitionname, "%s%i", filename, i);
+ unlink(partitionname);
+ }
+ }
+
/* remove subdirectories */
if (strchr(dev->name, '/'))
delete_path(filename);
- if (*dev->symlink) {
+ if (dev->symlink[0] != '\0') {
symlinks = dev->symlink;
while (1) {
linkname = strsep(&symlinks, " ");
diff --git a/udev.h b/udev.h
index e615b4c8bb..e8f93ad5ad 100644
--- a/udev.h
+++ b/udev.h
@@ -46,6 +46,7 @@ struct udevice {
int minor;
unsigned int mode; /* not mode_t due to conflicting definitions in different libcs */
char symlink[NAME_SIZE];
+ int partitions;
/* private data that help us in building strings */
char bus_id[SYSFS_NAME_LEN];