#include <stdlib.h>
#include <string.h>
+#include <stddef.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "namedev.h"
#include "udevdb.h"
-static int delete_path(char *path)
+static int delete_path(const char *path)
{
char *pos;
int retval;
int i;
char *pos;
int len;
+ int num;
strfieldcpy(filename, udev_root);
strfieldcat(filename, dev->name);
if (retval)
return retval;
- /* remove partition nodes */
- if (dev->partitions > 0) {
- info("removing partitions '%s[1-%i]'", filename, dev->partitions);
- for (i = 1; i <= dev->partitions; i++) {
+ /* remove all_partitions nodes */
+ num = dev->partitions;
+ if (num > 0) {
+ info("removing all_partitions '%s[1-%i]'", filename, num);
+ if (num > PARTITIONS_COUNT) {
+ info("garbage from udev database, skip all_partitions removal");
+ return -1;
+ }
+ for (i = 1; i <= num; i++) {
strfieldcpy(partitionname, filename);
strintcat(partitionname, i);
secure_unlink(partitionname);
}
/*
- * Look up the sysfs path in the database to see if we have named this device
- * something different from the kernel name. If we have, us it. If not, use
- * the default kernel name for lack of anything else to know to do.
+ * look up the sysfs path in the database to get the node name to remove
+ * If we can't find it, use kernel name for lack of anything else to know to do
*/
-int udev_remove_device(const char *path, const char *subsystem)
+int udev_remove_device(struct udevice *udev)
{
- struct udevice dev;
- char *temp;
+ struct udevice db_dev;
+ const char *temp;
int retval;
- memset(&dev, 0x00, sizeof(dev));
+ if (udev->type != 'b' && udev->type != 'c')
+ return 0;
- retval = udevdb_get_dev(path, &dev);
- if (retval != 0) {
- dbg("'%s' not found in database, falling back on default name", path);
- temp = strrchr(path, '/');
+ retval = udevdb_get_dev(udev->devpath, &db_dev);
+ if (retval == 0) {
+ /* copy over the stored values to our device */
+ memcpy(udev, &db_dev, UDEVICE_DB_LEN);
+ } else {
+ /* fall back to kernel name */
+ temp = strrchr(udev->devpath, '/');
if (temp == NULL)
return -ENODEV;
- strfieldcpy(dev.name, &temp[1]);
+ strfieldcpy(udev->name, &temp[1]);
+ dbg("'%s' not found in database, falling back on default name", udev->name);
}
- dbg("name='%s'", dev.name);
- dev.type = get_device_type(path, subsystem);
- dev_d_send(&dev, subsystem, path);
- udevdb_delete_dev(path);
+ dbg("remove name='%s'", udev->name);
+ udevdb_delete_dev(udev->devpath);
- if (dev.type == 'b' || dev.type == 'c')
- retval = delete_node(&dev);
- else if (dev.type == 'n')
- retval = 0;
+ /* use full path to the environment */
+ snprintf(udev->devname, NAME_SIZE-1, "%s%s", udev_root, udev->name);
- return retval;
+ return delete_node(udev);
}