int udev_node_remove(struct udev_device *dev) { struct udev *udev = udev_device_get_udev(dev); struct udev_list_entry *list_entry; const char *devnode; char partitionname[UTIL_PATH_SIZE]; struct stat stats; int err = 0; int num; /* remove,update symlinks, remove symlinks from name index */ udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) link_update(dev, udev_list_entry_get_name(list_entry), 0); devnode = udev_device_get_devnode(dev); if (devnode == NULL) return 0; if (stat(devnode, &stats) != 0) { info(udev, "device node '%s' not found\n", devnode); return 0; } if (stats.st_rdev != udev_device_get_devnum(dev)) { info(udev, "device node '%s' points to a different device, skip removal\n", devnode); return -1; } info(udev, "removing device node '%s'\n", devnode); err = util_unlink_secure(udev, devnode); if (err) return err; num = udev_device_get_num_fake_partitions(dev); if (num > 0) { int i; info(udev, "removing all_partitions '%s[1-%i]'\n", devnode, num); if (num > 255) return -1; for (i = 1; i <= num; i++) { snprintf(partitionname, sizeof(partitionname), "%s%d", devnode, i); partitionname[sizeof(partitionname)-1] = '\0'; util_unlink_secure(udev, partitionname); } } util_delete_path(udev, devnode); return err; }
int udev_node_remove(struct udev_device *dev) { struct udev *udev = udev_device_get_udev(dev); struct udev_list_entry *list_entry; const char *devnode; struct stat stats; struct udev_device *dev_check; char filename[UTIL_PATH_SIZE]; int err = 0; /* remove/update symlinks, remove symlinks from name index */ udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) link_update(dev, udev_list_entry_get_name(list_entry), 0); devnode = udev_device_get_devnode(dev); if (devnode == NULL) goto out; if (stat(devnode, &stats) != 0) { info(udev, "device node '%s' not found\n", devnode); goto out; } if (stats.st_rdev != udev_device_get_devnum(dev)) { info(udev, "device node '%s' points to a different device, skip removal\n", devnode); err = -1; goto out; } dev_check = udev_device_new_from_syspath(udev, udev_device_get_syspath(dev)); if (dev_check != NULL) { /* do not remove device node if the same sys-device is re-created in the meantime */ info(udev, "keeping device node of existing device'%s'\n", devnode); udev_device_unref(dev_check); goto out; } info(udev, "removing device node '%s'\n", devnode); err = util_unlink_secure(udev, devnode); if (err == 0) util_delete_path(udev, devnode); /* remove /dev/{block,char}/$major:$minor */ snprintf(filename, sizeof(filename), "%s/%s/%u:%u", udev_get_dev_path(udev), strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char", major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev))); unlink(filename); out: return err; }