#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <grp.h>
+#ifndef __KLIBC__
+#include <pwd.h>
+#endif
#include "udev.h"
#include "udev_version.h"
#include "namedev.h"
#include "udevdb.h"
#include "libsysfs/libsysfs.h"
+#include "klibc_fixups.h"
/*
* Right now the major/minor of a device is stored in a file called
if (dev == NULL)
goto exit;
- dbg("dev = %s", dev);
+ dbg("dev='%s'", dev);
if (sscanf(dev, "%u:%u", &udev->major, &udev->minor) != 2)
goto exit;
- dbg("found major = %d, minor = %d", udev->major, udev->minor);
+ dbg("found major=%d, minor=%d", udev->major, udev->minor);
retval = 0;
exit:
path, strerror(errno));
return retval;
}
- dbg("created %s", path);
+ dbg("created '%s'", path);
}
*pos = '/';
}
unsigned long id = strtoul(dev->owner, &endptr, 10);
if (*endptr == 0x00)
uid = (uid_t) id;
- else
- dbg("only numeric owner id supported: %s", dev->owner);
+ else {
+ struct passwd *pw = getpwnam(dev->owner);
+ if (!pw)
+ dbg("user unknown '%s'", dev->owner);
+ else
+ uid = pw->pw_uid;
+ }
}
if (*dev->group) {
unsigned long id = strtoul(dev->group, &endptr, 10);
if (*endptr == 0x00)
gid = (gid_t) id;
- else
- dbg("only numeric group id supported: %s", dev->group);
+ else {
+ struct group *gr = getgrnam(dev->group);
+ if (!gr)
+ dbg("group unknown '%s'", dev->group);
+ else
+ gid = gr->gr_gid;
+ }
}
if (uid || gid) {
strcpy(dev_path, sysfs_path);
strcat(dev_path, device_name);
- dbg("looking at %s", dev_path);
+ dbg("looking at '%s'", dev_path);
/* open up the sysfs class device for this thing... */
class_dev = sysfs_open_class_device(dev_path);
dbg ("sysfs_open_class_device failed");
goto exit;
}
- dbg("class_dev->name = %s", class_dev->name);
+ dbg("class_dev->name='%s'", class_dev->name);
exit:
return class_dev;
while (loop--) {
struct stat buf;
- dbg("looking for %s", filename);
+ dbg("looking for '%s'", filename);
retval = stat(filename, &buf);
if (!retval)
goto exit;
- /* sleep for a second or two to give the kernel a chance to
- * create the dev file */
+ /* sleep to give the kernel a chance to create the dev file */
sleep(1);
}
retval = -ENODEV;
struct udevice dev;
int retval = -EINVAL;
+ memset(&dev, 0x00, sizeof(dev));
+
/* for now, the block layer is the only place where block devices are */
if (strcmp(subsystem, "block") == 0)
dev.type = 'b';
dbg("udevdb_add_dev failed, but we are going to try to create the node anyway. "
"But remove might not work properly for this device.");
- dbg("name = %s", dev.name);
+ dbg("name='%s'", dev.name);
retval = create_node(&dev);
exit:
return retval;
}
-