X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_remove.c;h=0ba6962cad660f481714d91ebb2c235a79e0b363;hp=e1af3dbef61cf3a0d34a67af13e972eb31dd5c2a;hb=5ef42682053f57fc031d420f0a2ae3e204421b8d;hpb=c1ab046124ebef3c82950b91ccfd1678d9f7fe5b diff --git a/udev_remove.c b/udev_remove.c index e1af3dbef..0ba6962ca 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->devt && stats.st_rdev != udev->devt) { + 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) @@ -89,7 +99,7 @@ static int delete_node(struct udevice *udev) 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; } @@ -137,7 +147,7 @@ int udev_remove_device(struct udevice *udev) const char *temp; int retval; - if (udev->type != 'b' && udev->type != 'c') + if (udev->type != BLOCK && udev->type != CLASS) return 0; retval = udev_db_get_device(udev);