}
/*
- * We also want to add some permissions here, and possibly some symlinks
+ * we possibly want to add some symlinks here
+ * only numeric owner/group id's are supported
*/
static int create_node(struct udevice *dev)
{
char filename[255];
int retval = 0;
+ uid_t uid = 0;
+ gid_t gid = 0;
dev_t res;
strncpy(filename, udev_root, sizeof(filename));
return -EINVAL;
}
+ /* create subdirectories if requested */
+ if (strchr(dev->name, '/')) {
+ char path[255];
+ char *pos;
+ struct stat stats;
+
+ strncpy(path, filename, sizeof(path));
+ pos = strchr(path+1, '/');
+ while (1) {
+ pos = strchr(pos+1, '/');
+ if (pos == NULL)
+ break;
+ *pos = 0x00;
+ if (stat(path, &stats)) {
+ retval = mkdir(path, 0755);
+ if (retval) {
+ dbg("mkdir(%s) failed with error '%s'",
+ path, strerror(errno));
+ return retval;
+ }
+ dbg("created %s", path);
+ }
+ *pos = '/';
+ }
+ }
+
dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
retval = mknod(filename, dev->mode, res);
if (retval)
dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
filename, dev->mode, dev->major, dev->minor, strerror(errno));
- // FIXME set the ownership of the node
+ if (*dev->owner) {
+ char *endptr;
+ 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);
+ }
+
+ if (*dev->group) {
+ char *endptr;
+ 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);
+ }
+
+ if (uid || gid) {
+ dbg("chown(%s, %u, %u)", filename, uid, gid);
+ retval = chown(filename, uid, gid);
+ if (retval)
+ dbg("chown(%s, %u, %u) failed with error '%s'", filename,
+ uid, gid, strerror(errno));
+ }
+
return retval;
}
static int sleep_for_dev(char *path)
{
char filename[SYSFS_PATH_MAX + 6];
- struct stat buf;
- int loop = 0;
- int retval = -ENODEV;
+ int loop = SECONDS_TO_WAIT_FOR_DEV;
+ int retval;
strcpy(filename, sysfs_path);
strcat(filename, path);
strcat(filename, "/dev");
- while (loop < SECONDS_TO_WAIT_FOR_DEV) {
+ while (loop--) {
+ struct stat buf;
+
dbg("looking for %s", filename);
retval = stat(filename, &buf);
- if (retval == 0) {
- retval = 0;
+ if (!retval)
goto exit;
- }
/* sleep for a second or two to give the kernel a chance to
* create the dev file */
sleep(1);
- ++loop;
}
retval = -ENODEV;
exit: