27 |
off_t bytes; |
off_t bytes; |
28 |
struct stat st; |
struct stat st; |
29 |
|
|
30 |
DEBUG(("kinit: uncompressed initrd\n")); |
dprintf("kinit: uncompressed initrd\n"); |
31 |
|
|
32 |
if (ffd < 0 || fstat(ffd, &st) || !S_ISREG(st.st_mode) || |
if (ffd < 0 || fstat(ffd, &st) || !S_ISREG(st.st_mode) || |
33 |
(bytes = st.st_size) == 0) |
(bytes = st.st_size) == 0) |
37 |
ssize_t blocksize = ((bytes - 1) & (BUF_SIZE - 1)) + 1; |
ssize_t blocksize = ((bytes - 1) & (BUF_SIZE - 1)) + 1; |
38 |
off_t offset = bytes - blocksize; |
off_t offset = bytes - blocksize; |
39 |
|
|
40 |
DEBUG(("kinit: copying %zd bytes at offset %llu\n", |
dprintf("kinit: copying %zd bytes at offset %llu\n", |
41 |
blocksize, offset)); |
blocksize, offset); |
42 |
|
|
43 |
if (xpread(ffd, buffer, blocksize, offset) != blocksize || |
if (xpread(ffd, buffer, blocksize, offset) != blocksize || |
44 |
xpwrite(dfd, buffer, blocksize, offset) != blocksize) |
xpwrite(dfd, buffer, blocksize, offset) != blocksize) |
91 |
const char *ramdisk_name = "/dev/ram0"; |
const char *ramdisk_name = "/dev/ram0"; |
92 |
FILE *fp; |
FILE *fp; |
93 |
|
|
94 |
DEBUG(("kinit: mounting initrd\n")); |
dprintf("kinit: mounting initrd\n"); |
95 |
mkdir("/root", 0700); |
mkdir("/root", 0700); |
96 |
if (!mount_block(ramdisk_name, "/root", NULL, MS_VERBOSE, NULL)) |
if (!mount_block(ramdisk_name, "/root", NULL, MS_VERBOSE, NULL)) |
97 |
return -errno; |
return -errno; |
98 |
|
|
99 |
/* Write the current "real root device" out to procfs */ |
/* Write the current "real root device" out to procfs */ |
100 |
DEBUG(("kinit: real_root_dev = %#x\n", root_dev)); |
dprintf("kinit: real_root_dev = %#x\n", root_dev); |
101 |
fp = fopen("/proc/sys/kernel/real-root-dev", "w"); |
fp = fopen("/proc/sys/kernel/real-root-dev", "w"); |
102 |
fprintf(fp, "%u", root_dev); |
fprintf(fp, "%u", root_dev); |
103 |
fclose(fp); |
fclose(fp); |
121 |
execl("/linuxrc", "linuxrc", NULL); |
execl("/linuxrc", "linuxrc", NULL); |
122 |
_exit(255); |
_exit(255); |
123 |
} else if (pid > 0) { |
} else if (pid > 0) { |
124 |
DEBUG(("kinit: Waiting for linuxrc to complete...\n")); |
dprintf("kinit: Waiting for linuxrc to complete...\n"); |
125 |
while (waitpid(pid, NULL, 0) != pid) ; |
while (waitpid(pid, NULL, 0) != pid) ; |
126 |
DEBUG(("kinit: linuxrc done\n")); |
dprintf("kinit: linuxrc done\n"); |
127 |
} else { |
} else { |
128 |
return -errno; |
return -errno; |
129 |
} |
} |
170 |
if (access("/initrd.image", R_OK)) |
if (access("/initrd.image", R_OK)) |
171 |
return 0; /* No initrd */ |
return 0; /* No initrd */ |
172 |
|
|
173 |
DEBUG(("kinit: initrd found\n")); |
dprintf("kinit: initrd found\n"); |
174 |
|
|
175 |
create_dev("/dev/ram0", Root_RAM0); |
create_dev("/dev/ram0", Root_RAM0); |
176 |
|
|
180 |
return 0; /* Failed to copy initrd */ |
return 0; /* Failed to copy initrd */ |
181 |
} |
} |
182 |
|
|
183 |
DEBUG(("kinit: initrd copied\n")); |
dprintf("kinit: initrd copied\n"); |
184 |
|
|
185 |
|
if (root_dev == Root_MULTI) { |
186 |
|
dprintf("kinit: skipping linuxrc: incompatible with multiple roots\n"); |
187 |
|
/* Mounting initrd as ordinary root */ |
188 |
|
return 0; |
189 |
|
} |
190 |
|
|
191 |
if (root_dev != Root_RAM0) { |
if (root_dev != Root_RAM0) { |
192 |
int err; |
int err; |
193 |
DEBUG(("kinit: running linuxrc\n")); |
dprintf("kinit: running linuxrc\n"); |
194 |
err = run_linuxrc(argc, argv, root_dev); |
err = run_linuxrc(argc, argv, root_dev); |
195 |
if (err) |
if (err) |
196 |
fprintf(stderr, "%s: running linuxrc: %s\n", progname, |
fprintf(stderr, "%s: running linuxrc: %s\n", progname, |
197 |
strerror(-err)); |
strerror(-err)); |
198 |
return 1; /* initrd is root, or run_linuxrc took care of it */ |
return 1; /* initrd is root, or run_linuxrc took care of it */ |
199 |
} else { |
} else { |
200 |
DEBUG(("kinit: permament (or pivoting) initrd, not running linuxrc\n")); |
dprintf("kinit: permament (or pivoting) initrd, not running linuxrc\n"); |
201 |
return 0; /* Mounting initrd as ordinary root */ |
return 0; /* Mounting initrd as ordinary root */ |
202 |
} |
} |
203 |
} |
} |