2 #include <linux/kernel.h>
3 #include <linux/dirent.h>
4 #include <linux/string.h>
5 #include <linux/syscalls.h>
9 void __init mount_devfs(void)
11 sys_mount("devfs", "/dev", "devfs", 0, NULL);
14 void __init umount_devfs(char *path)
20 * If the dir will fit in *buf, return its length. If it won't fit, return
21 * zero. Return -ve on error.
23 static int __init do_read_dir(int fd, void *buf, int len)
29 for (bytes = 0; bytes < len; bytes += n) {
30 n = sys_getdents64(fd, (struct linux_dirent64 *)(p + bytes),
41 * Try to read all of a directory. Returns the contents at *p, which
42 * is kmalloced memory. Returns the number of bytes read at *len. Returns
45 static void * __init read_dir(char *path, int *len)
48 int fd = sys_open(path, 0, 0);
54 for (size = 1 << 9; size <= (PAGE_SIZE << MAX_ORDER); size <<= 1) {
55 void *p = kmalloc(size, GFP_KERNEL);
59 n = do_read_dir(fd, p, size);
67 continue; /* Try a larger buffer */
76 * recursively scan <path>, looking for a device node of type <dev>
78 static int __init find_in_devfs(char *path, unsigned dev)
80 char *end = path + strlen(path);
81 int rest = path + 64 - end;
83 char *p = read_dir(path, &size);
88 for (s = p; s < p + size; s += ((struct linux_dirent64 *)s)->d_reclen) {
89 struct linux_dirent64 *d = (struct linux_dirent64 *)s;
90 if (strlen(d->d_name) + 2 > rest)
94 sprintf(end, "/%s", d->d_name);
95 if (bstat(path) != dev)
100 if (strcmp(d->d_name, ".") == 0)
102 if (strcmp(d->d_name, "..") == 0)
104 sprintf(end, "/%s", d->d_name);
105 if (find_in_devfs(path, dev) < 0)
116 * create a device node called <name> which points to
117 * <devfs_name> if possible, otherwise find a device node
118 * which matches <dev> and make <name> a symlink pointing to it.
120 int __init create_dev(char *name, dev_t dev, char *devfs_name)
125 if (devfs_name && devfs_name[0]) {
126 if (strncmp(devfs_name, "/dev/", 5) == 0)
128 sprintf(path, "/dev/%s", devfs_name);
129 if (sys_access(path, 0) == 0)
130 return sys_symlink(devfs_name, name);
134 strcpy(path, "/dev");
135 if (find_in_devfs(path, new_encode_dev(dev)) < 0)
137 return sys_symlink(path + 5, name);