]>
git.ipfire.org Git - thirdparty/systemd.git/blob - udev-remove.c
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"
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
))
57 if (errno
== ENOTEMPTY
)
59 dbg("rmdir(%s) failed with error '%s'",
60 path
, strerror(errno
));
63 dbg("removed '%s'", path
);
68 static int delete_node(struct udevice
*dev
)
71 char partitionname
[255];
77 strfieldcpy(filename
, udev_root
);
78 strfieldcat(filename
, dev
->name
);
80 info("removing device node '%s'", filename
);
81 retval
= unlink(filename
);
85 dbg("unlink(%s) failed with error '%s'",
86 filename
, strerror(errno
));
90 /* remove partition nodes */
91 if (dev
->partitions
> 0) {
92 info("removing partitions '%s[1-%i]'", filename
, dev
->partitions
);
93 for (i
= 1; i
<= dev
->partitions
; i
++) {
94 strfieldcpy(partitionname
, filename
);
95 strintcat(partitionname
, i
);
96 unlink(partitionname
);
100 /* remove subdirectories */
101 if (strchr(dev
->name
, '/'))
102 delete_path(filename
);
104 if (dev
->symlink
[0] != '\0') {
105 symlinks
= dev
->symlink
;
107 linkname
= strsep(&symlinks
, " ");
108 if (linkname
== NULL
)
111 strfieldcpy(filename
, udev_root
);
112 strfieldcat(filename
, linkname
);
114 dbg("unlinking symlink '%s'", filename
);
115 retval
= unlink(filename
);
119 dbg("unlink(%s) failed with error '%s'",
120 filename
, strerror(errno
));
123 if (strchr(dev
->symlink
, '/')) {
124 delete_path(filename
);
133 * Look up the sysfs path in the database to see if we have named this device
134 * something different from the kernel name. If we have, us it. If not, use
135 * the default kernel name for lack of anything else to know to do.
137 int udev_remove_device(char *path
, char *subsystem
)
143 memset(&dev
, 0, sizeof(dev
));
145 retval
= udevdb_get_dev(path
, &dev
);
147 dbg("'%s' not found in database, falling back on default name", path
);
148 temp
= strrchr(path
, '/');
151 strfieldcpy(dev
.name
, &temp
[1]);
154 dbg("name is '%s'", dev
.name
);
155 udevdb_delete_dev(path
);
157 sysbus_send_remove(dev
.name
, path
);
159 retval
= delete_node(&dev
);