chiark / gitweb /
[PATCH] switch device type to enum
[elogind.git] / udev_remove.c
index e1af3dbef61cf3a0d34a67af13e972eb31dd5c2a..0ba6962cad660f481714d91ebb2c235a79e0b363 100644 (file)
@@ -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);