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