diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2004-02-16 21:44:28 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:32:28 -0700 |
commit | 50e5de03d16be3e35e65cdf65f552807ad24e996 (patch) | |
tree | 46c83042e99cf64eb308ac6bd47fab4f75525733 /udev-add.c | |
parent | bb7386472466e55f75df024d18e8da37a222bb41 (diff) |
[PATCH] udev - create all partitions of blockdevice
Here is the first try to create all partitons of a blockdevice, since
removable media devices may need to acces the expected partition to
revalidate the media.
It uses the attribute syntax introduced with the last %s{file} patch.
I'm using this with my multi-slot-flash-card-reader:
SYSFS{model}="USB Storage-SMC ", NAME{all_partitions}="smartmedia"
SYSFS{model}="USB Storage-CFC ", NAME{all_partitions}="compactflash"
SYSFS{model}="USB Storage-MSC ", NAME{all_partitions}="memorystick"
SYSFS{model}="USB Storage-MMC ", NAME{all_partitions}="multimedia"
and I get:
tree /udev/
/udev/
|-- memorystick
|-- memorystick1
|-- memorystick10
|-- memorystick11
|-- memorystick12
|-- memorystick13
|-- memorystick14
|-- memorystick15
|-- memorystick2
|-- memorystick3
|-- memorystick4
|-- memorystick5
|-- memorystick6
|-- memorystick7
|-- memorystick8
|-- memorystick9
|-- multimedia
|-- multimedia1
|-- multimedia10
|-- multimedia11
|-- multimedia12
|-- multimedia13
|-- multimedia14
|-- multimedia15
|-- multimedia2
|-- multimedia3
|-- multimedia4
|-- multimedia5
|-- multimedia6
|-- multimedia7
|-- multimedia8
|-- multimedia9
...
If needed, we can make the number of partions to create
adjustable with the attribute?
Diffstat (limited to 'udev-add.c')
-rw-r--r-- | udev-add.c | 71 |
1 files changed, 46 insertions, 25 deletions
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)) |