mirror of
https://github.com/systemd/systemd.git
synced 2025-01-21 16:03:42 +08:00
[PATCH] add support for subdirs
support subdirectory creation/removal for NAME="/devfs/is/crazy/video0" create parent subdirs for device node if needed remove subdirs when last node is removed
This commit is contained in:
parent
c19a6b304c
commit
218eae8727
26
udev-add.c
26
udev-add.c
@ -101,6 +101,32 @@ static int create_node(struct udevice *dev)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* create subdirectories if requested */
|
||||
if (strchr(dev->name, '/')) {
|
||||
char path[255];
|
||||
char *pos;
|
||||
struct stat stats;
|
||||
|
||||
strncpy(path, filename, sizeof(path));
|
||||
pos = strchr(path+1, '/');
|
||||
while (1) {
|
||||
pos = strchr(pos+1, '/');
|
||||
if (pos == NULL)
|
||||
break;
|
||||
*pos = 0x00;
|
||||
if (stat(path, &stats)) {
|
||||
retval = mkdir(path, 0755);
|
||||
if (retval) {
|
||||
dbg("mkdir(%s) failed with error '%s'",
|
||||
path, strerror(errno));
|
||||
return retval;
|
||||
}
|
||||
dbg("created %s", path);
|
||||
}
|
||||
*pos = '/';
|
||||
}
|
||||
}
|
||||
|
||||
dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
|
||||
retval = mknod(filename, dev->mode, res);
|
||||
if (retval)
|
||||
|
@ -69,12 +69,45 @@ exit:
|
||||
static int delete_node(char *name)
|
||||
{
|
||||
char filename[255];
|
||||
int retval;
|
||||
|
||||
strncpy(filename, udev_root, sizeof(filename));
|
||||
strncat(filename, name, sizeof(filename));
|
||||
|
||||
dbg("unlinking %s", filename);
|
||||
return unlink(filename);
|
||||
retval = unlink(filename);
|
||||
if (retval) {
|
||||
dbg("unlink(%s) failed with error '%s'",
|
||||
filename, strerror(errno));
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* remove subdirectories */
|
||||
if (strchr(name, '/')) {
|
||||
char *pos;
|
||||
|
||||
pos = strrchr(filename, '/');
|
||||
while (1) {
|
||||
*pos = 0x00;
|
||||
pos = strrchr(filename, '/');
|
||||
|
||||
/* don't remove the last one */
|
||||
if ((pos == filename) || (pos == NULL))
|
||||
break;
|
||||
|
||||
/* remove if empty */
|
||||
retval = rmdir(filename);
|
||||
if (retval) {
|
||||
if (errno == ENOTEMPTY)
|
||||
return 0;
|
||||
dbg("rmdir(%s) failed with error '%s'",
|
||||
filename, strerror(errno));
|
||||
break;
|
||||
}
|
||||
dbg("removed %s", filename);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int udev_remove_device(char *device, char *subsystem)
|
||||
|
Loading…
Reference in New Issue
Block a user