diff options
Diffstat (limited to 'urunlevel/my_linux/mkrootfs.c')
-rw-r--r-- | urunlevel/my_linux/mkrootfs.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/urunlevel/my_linux/mkrootfs.c b/urunlevel/my_linux/mkrootfs.c new file mode 100644 index 0000000..9098be6 --- /dev/null +++ b/urunlevel/my_linux/mkrootfs.c | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
17 | * 02111-1307 USA | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include <dirent.h> | ||
22 | #include <fcntl.h> | ||
23 | #include <unistd.h> | ||
24 | #include <errno.h> | ||
25 | #include <signal.h> | ||
26 | #include <string.h> | ||
27 | #include <sys/poll.h> | ||
28 | #include <sys/wait.h> | ||
29 | #include <sys/utsname.h> /* for uname(2) */ | ||
30 | |||
31 | #include "busybox.h" | ||
32 | #include "lib_init_d.h" | ||
33 | |||
34 | |||
35 | void mkrootfs(const char *directories[], const nodes_t *nodes, const char *files[][2], const char *scripts[][2], const char *links[][2]) | ||
36 | { | ||
37 | int i; | ||
38 | char temp[64]; | ||
39 | |||
40 | umask(022); | ||
41 | sprintf(temp, "/dev"); | ||
42 | bb_make_directory(temp, -1l, FILEUTILS_RECUR); | ||
43 | mknod("/dev/console", S_IFCHR, makedev(4, 0)); | ||
44 | chmod("/dev/console", S_IRUSR | S_IWUSR); | ||
45 | mknod("/dev/null", S_IFCHR, makedev(1, 3)); | ||
46 | chmod("/dev/null", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); | ||
47 | mknod("/dev/ptmx", S_IFCHR, makedev(5, 2)); | ||
48 | chmod("/dev/ptmx", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); | ||
49 | sprintf(temp, "/bin"); | ||
50 | bb_make_directory(temp, -1l, FILEUTILS_RECUR); | ||
51 | symlink("/bin/busybox", "/bin/sh"); | ||
52 | |||
53 | bb_printf("\n\nCreating directories, devices, files, and links.\n"); | ||
54 | for (i = 0; directories[i] != 0; i++) | ||
55 | { | ||
56 | /* Can't use it directly, coz bb_make_directory segfaults. */ | ||
57 | sprintf(temp, "/%s", directories[i]); | ||
58 | bb_make_directory(temp, -1l, FILEUTILS_RECUR); | ||
59 | } | ||
60 | |||
61 | symlink("/var/etc", "/etc"); | ||
62 | symlink("/proc/mounts", "/var/etc/mtab"); | ||
63 | quick_mount("proc", "proc", "/proc", ""); | ||
64 | quick_mount("sysfs", "sysfs", "/sys", ""); | ||
65 | for (i = 0; nodes[i].name != 0; i++) | ||
66 | { | ||
67 | if (nodes[i].count) | ||
68 | { | ||
69 | int j; | ||
70 | for (j = 0; j <= nodes[i].count; j++) | ||
71 | { | ||
72 | sprintf(temp, "/dev/%s%i", nodes[i].name, j); | ||
73 | mknod(temp, nodes[i].mode, makedev(nodes[i].major, nodes[i].minor + j)); | ||
74 | } | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | sprintf(temp, "/dev/%s", nodes[i].name); | ||
79 | mknod(temp, nodes[i].mode, makedev(nodes[i].major, nodes[i].minor)); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | for (i = 0; files[i][0] != NULL; i++) | ||
84 | quick_write(files[i][0], files[i][1]); | ||
85 | |||
86 | for (i = 0; scripts[i][0] != NULL; i++) | ||
87 | { | ||
88 | quick_write(scripts[i][0], scripts[i][1]); | ||
89 | chmod(scripts[i][0], S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | ||
90 | } | ||
91 | |||
92 | for (i = 0; links[i][0] != NULL; i++) | ||
93 | symlink(links[i][0], links[i][1]); | ||
94 | |||
95 | quick_mount("devpts", "devpts", "/dev/pts", ""); | ||
96 | doit(0, "busybox --install"); | ||
97 | |||
98 | /* This must be last, as it currently defines a valid install. */ | ||
99 | /* Can't use it directly, coz bb_make_directory segfaults. */ | ||
100 | sprintf(temp, "/var/lib/distro"); | ||
101 | bb_make_directory(temp, -1l, FILEUTILS_RECUR); | ||
102 | |||
103 | bb_printf("Created.\n"); | ||
104 | } | ||