4 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation version 2 of the License.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 static int delete_node(struct udevice *udev)
35 char filename[PATH_SIZE];
36 char devname[PATH_SIZE];
37 char partitionname[PATH_SIZE];
38 struct name_entry *name_loop;
44 list_for_each_entry(name_loop, &udev->symlink_list, node) {
45 snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name);
46 filename[sizeof(filename)-1] = '\0';
48 if (stat(filename, &stats) != 0) {
49 dbg("symlink '%s' not found", filename);
52 if (udev->devt && stats.st_rdev != udev->devt) {
53 info("symlink '%s' points to a different device, skip removal", filename);
57 info("removing symlink '%s'", filename);
60 if (strchr(filename, '/'))
61 delete_path(filename);
64 snprintf(filename, sizeof(filename), "%s/%s", udev_root, udev->name);
65 filename[sizeof(filename)-1] = '\0';
67 if (stat(filename, &stats) != 0) {
68 dbg("device node '%s' not found", filename);
71 if (udev->devt && stats.st_rdev != udev->devt) {
72 info("device node '%s' points to a different device, skip removal", filename);
76 info("removing device node '%s'", filename);
77 retval = unlink_secure(filename);
81 snprintf(devname, sizeof(devname), "%s/%s", udev_root, udev->name);
82 devname[sizeof(devname)-1] = '\0';
83 setenv("DEVNAME", devname, 1);
85 num = udev->partitions;
87 info("removing all_partitions '%s[1-%i]'", filename, num);
89 info("garbage from udev database, skip all_partitions removal");
92 for (i = 1; i <= num; i++) {
93 snprintf(partitionname, sizeof(partitionname), "%s%d", filename, i);
94 partitionname[sizeof(partitionname)-1] = '\0';
95 unlink_secure(partitionname);
99 if (strchr(udev->name, '/'))
100 delete_path(filename);
106 * look up the sysfs path in the database to get the node name to remove
107 * If we can't find it, use kernel name for lack of anything else to know to do
109 int udev_remove_device(struct udevice *udev)
111 if (major(udev->devt) == 0)
114 if (udev_db_get_device(udev, udev->dev->devpath) == 0) {
115 if (udev->ignore_remove) {
116 dbg("remove event for '%s' requested to be ignored by rule", udev->name);
119 dbg("remove name='%s'", udev->name);
120 udev_db_delete_device(udev);
122 dbg("'%s' not found in database, using kernel name '%s'", udev->dev->devpath, udev->dev->kernel_name);
123 strlcpy(udev->name, udev->dev->kernel_name, sizeof(udev->name));
126 return delete_node(udev);