From 1cec1c241600fc11121f9504bc9e95836c03bd9c Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Fri, 18 Feb 2005 03:30:03 +0100 Subject: [PATCH] [PATCH] remove the device node only if the major/minor number matches --- test/udev-test.pl | 37 +++++++++++++++---------------------- udev_db.c | 9 +++++++++ udev_remove.c | 10 ++++++++++ 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/test/udev-test.pl b/test/udev-test.pl index 5f9c0cb9c..fe7b93266 100644 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -755,17 +755,6 @@ EOF BUS="scsi", KERNEL="sda", SYMLINK="symlink-only1" BUS="scsi", KERNEL="sda", SYMLINK="symlink-only2" BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0" -EOF - }, - { - desc => "symlink name empty", - subsys => "block", - devpath => "/block/sda", - exp_name => "", - exp_target => "link", - exp_error => "yes", - conf => < "/block/sda", exp_name => ".", exp_target => "link", - exp_error => "yes", + exp_add_error => "yes", + exp_rem_error => "yes", conf => < "/block/sda", exp_name => "symlink", exp_target => "", - exp_error => "yes", + exp_add_error => "yes", conf => < "/block/sda", exp_name => "", exp_target => "", - exp_error => "yes", + exp_add_error => "yes", + exp_rem_error => "yes", conf => < "/class/tty/tty0", exp_name => "link", exp_target => "link", + exp_rem_error => "yes", + option => "clear", conf => < "block", devpath => "/block/sda", exp_name => "node", - exp_error => "yes", + exp_add_error => "yes", conf => < "block", devpath => "/block/sda/sda1", exp_name => "node6", - exp_error => "yes", + exp_add_error => "yes", conf => < "block", devpath => "/block/sda", exp_name => "node", - exp_error => "yes", + exp_rem_error => "yes", conf => < "block", devpath => "/block/sda", exp_name => "node14", - exp_error => "yes", + exp_rem_error => "yes", option => "clear", conf => <{exp_name}\' to \'$config->{exp_target}\'\n"; print "created symlink from: \'$config->{exp_name}\' to \'$2\'\n"; - if ($config->{exp_error}) { + if ($config->{exp_add_error}) { print "as expected "; } else { $error++; @@ -1234,7 +1227,7 @@ sub symlink_test { } else { print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; print "symlink: not created "; - if ($config->{exp_error}) { + if ($config->{exp_add_error}) { print "as expected "; } else { $error++; @@ -1273,7 +1266,7 @@ sub run_test { print "add: ok "; } else { print "add: error "; - if ($config->{exp_error}) { + if ($config->{exp_add_error}) { print "as expected "; } else { print "\n\n"; @@ -1292,7 +1285,7 @@ sub run_test { if ((-e "$PWD/$udev_root$config->{exp_name}") || (-l "$PWD/$udev_root$config->{exp_name}")) { print "remove: error "; - if ($config->{exp_error}) { + if ($config->{exp_rem_error}) { print "as expected\n\n"; } else { print "\n\n"; diff --git a/udev_db.c b/udev_db.c index df7cfbb25..0be7620ad 100644 --- a/udev_db.c +++ b/udev_db.c @@ -79,6 +79,7 @@ int udev_db_add_device(struct udevice *udev) fprintf(f, "P:%s\n", udev->devpath); fprintf(f, "N:%s\n", udev->name); fprintf(f, "S:%s\n", udev->symlink); + fprintf(f, "M:%u:%u\n", udev->major, udev->minor); fprintf(f, "A:%u\n", udev->partitions); fprintf(f, "R:%u\n", udev->ignore_remove); @@ -90,6 +91,7 @@ int udev_db_add_device(struct udevice *udev) static int parse_db_file(struct udevice *udev, const char *filename) { char line[NAME_SIZE]; + char temp[NAME_SIZE]; char *bufline; char *buf; size_t bufsize; @@ -120,6 +122,13 @@ static int parse_db_file(struct udevice *udev, const char *filename) strncpy(udev->name, &bufline[2], count-2); udev->name[count-2] = '\0'; break; + case 'M': + if (count > NAME_SIZE) + count = NAME_SIZE-1; + strncpy(temp, &bufline[2], count-2); + temp[count-2] = '\0'; + sscanf(temp, "%u:%u", &udev->major, &udev->minor); + break; case 'S': if (count > NAME_SIZE) count = NAME_SIZE-1; diff --git a/udev_remove.c b/udev_remove.c index 172ec1269..baafdea51 100644 --- a/udev_remove.c +++ b/udev_remove.c @@ -71,6 +71,7 @@ static int delete_node(struct udevice *udev) { char filename[NAME_SIZE]; char partitionname[NAME_SIZE]; + struct stat stats; int retval; int i; char *pos; @@ -80,6 +81,15 @@ static int delete_node(struct udevice *udev) snprintf(filename, NAME_SIZE, "%s/%s", udev_root, udev->name); filename[NAME_SIZE-1] = '\0'; + dbg("checking major/minor of device node '%s'", filename); + if (stat(filename, &stats) != 0) + return -1; + + if (udev->major && stats.st_rdev != makedev(udev->major, udev->minor)) { + info("device node '%s' points to a different device, skip removal", filename); + return -1; + } + info("removing device node '%s'", filename); retval = unlink_secure(filename); if (retval) -- 2.30.2