2 #include <linux/kernel.h>
3 #include <linux/dirent.h>
4 #include <linux/string.h>
8 void __init
mount_devfs(void)
10 sys_mount("devfs", "/dev", "devfs", 0, NULL
);
13 void __init
umount_devfs(char *path
)
19 * If the dir will fit in *buf, return its length. If it won't fit, return
20 * zero. Return -ve on error.
22 static int __init
do_read_dir(int fd
, void *buf
, int len
)
28 for (bytes
= 0; bytes
< len
; bytes
+= n
) {
29 n
= sys_getdents64(fd
, (struct linux_dirent64
*)(p
+ bytes
),
40 * Try to read all of a directory. Returns the contents at *p, which
41 * is kmalloced memory. Returns the number of bytes read at *len. Returns
44 static void * __init
read_dir(char *path
, int *len
)
47 int fd
= sys_open(path
, 0, 0);
53 for (size
= 1 << 9; size
<= (PAGE_SIZE
<< MAX_ORDER
); size
<<= 1) {
54 void *p
= kmalloc(size
, GFP_KERNEL
);
58 n
= do_read_dir(fd
, p
, size
);
66 continue; /* Try a larger buffer */
75 * recursively scan <path>, looking for a device node of type <dev>
77 static int __init
find_in_devfs(char *path
, unsigned dev
)
79 char *end
= path
+ strlen(path
);
80 int rest
= path
+ 64 - end
;
82 char *p
= read_dir(path
, &size
);
87 for (s
= p
; s
< p
+ size
; s
+= ((struct linux_dirent64
*)s
)->d_reclen
) {
88 struct linux_dirent64
*d
= (struct linux_dirent64
*)s
;
89 if (strlen(d
->d_name
) + 2 > rest
)
93 sprintf(end
, "/%s", d
->d_name
);
94 if (bstat(path
) != dev
)
99 if (strcmp(d
->d_name
, ".") == 0)
101 if (strcmp(d
->d_name
, "..") == 0)
103 sprintf(end
, "/%s", d
->d_name
);
104 if (find_in_devfs(path
, dev
) < 0)
115 * create a device node called <name> which points to
116 * <devfs_name> if possible, otherwise find a device node
117 * which matches <dev> and make <name> a symlink pointing to it.
119 int __init
create_dev(char *name
, dev_t dev
, char *devfs_name
)
124 if (devfs_name
&& devfs_name
[0]) {
125 if (strncmp(devfs_name
, "/dev/", 5) == 0)
127 sprintf(path
, "/dev/%s", devfs_name
);
128 if (sys_access(path
, 0) == 0)
129 return sys_symlink(devfs_name
, name
);
133 strcpy(path
, "/dev");
134 if (find_in_devfs(path
, new_encode_dev(dev
)) < 0)
136 return sys_symlink(path
+ 5, name
);