6 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include "udev_version.h"
33 #include "udev_dbus.h"
36 #include "libsysfs/libsysfs.h"
38 static int delete_path(char *path)
43 pos = strrchr(path, '/');
46 pos = strrchr(path, '/');
48 /* don't remove the last one */
49 if ((pos == path) || (pos == NULL))
55 if (errno == ENOTEMPTY)
57 dbg("rmdir(%s) failed with error '%s'",
58 path, strerror(errno));
61 dbg("removed '%s'", path);
66 static int delete_node(struct udevice *dev)
73 strncpy(filename, udev_root, sizeof(filename));
74 strncat(filename, dev->name, sizeof(filename));
76 dbg("unlinking node '%s'", filename);
77 retval = unlink(filename);
79 dbg("unlink(%s) failed with error '%s'",
80 filename, strerror(errno));
84 /* remove subdirectories */
85 if (strchr(dev->name, '/'))
86 delete_path(filename);
89 symlinks = dev->symlink;
91 linkname = strsep(&symlinks, " ");
95 strncpy(filename, udev_root, sizeof(filename));
96 strncat(filename, linkname, sizeof(filename));
98 dbg("unlinking symlink '%s'", filename);
99 retval = unlink(filename);
101 dbg("unlink(%s) failed with error '%s'",
102 filename, strerror(errno));
105 if (strchr(dev->symlink, '/')) {
106 delete_path(filename);
115 * Look up the sysfs path in the database to see if we have named this device
116 * something different from the kernel name. If we have, us it. If not, use
117 * the default kernel name for lack of anything else to know to do.
119 int udev_remove_device(char *path, char *subsystem)
125 dev = udevdb_get_dev(path);
127 dbg("'%s' not found in database, falling back on default name", path);
128 temp = strrchr(path, '/');
131 strncpy(name, &temp[1], sizeof(name));
134 dbg("name is '%s'", dev->name);
135 udevdb_delete_dev(path);
137 sysbus_send_remove(name, path);
139 return delete_node(dev);