33 |
int fd; |
int fd; |
34 |
|
|
35 |
if (type) { |
if (type) { |
36 |
DEBUG(("kinit: trying to mount %s on %s with type %s\n", |
dprintf("kinit: trying to mount %s on %s with type %s\n", |
37 |
source, target, type)); |
source, target, type); |
38 |
int rv = mount(source, target, type, flags, data); |
int rv = mount(source, target, type, flags, data); |
39 |
/* Mount readonly if necessary */ |
/* Mount readonly if necessary */ |
40 |
if (rv == -1 && errno == EACCES && !(flags & MS_RDONLY)) |
if (rv == -1 && errno == EACCES && !(flags & MS_RDONLY)) |
52 |
close(fd); |
close(fd); |
53 |
|
|
54 |
if (!err && type) { |
if (!err && type) { |
55 |
DEBUG(("kinit: %s appears to be a %s filesystem\n", |
dprintf("kinit: %s appears to be a %s filesystem\n", |
56 |
source, type)); |
source, type); |
57 |
type = mount_block(source, target, type, flags, data); |
type = mount_block(source, target, type, flags, data); |
58 |
if (type) |
if (type) |
59 |
return type; |
return type; |
60 |
} |
} |
61 |
} |
} |
62 |
|
|
63 |
DEBUG(("kinit: failed to identify filesystem %s, trying all\n", |
dprintf("kinit: failed to identify filesystem %s, trying all\n", |
64 |
source)); |
source); |
65 |
|
|
66 |
fsbytes = readfile("/proc/filesystems", &fslist); |
fsbytes = readfile("/proc/filesystems", &fslist); |
67 |
|
|
139 |
return 0; |
return 0; |
140 |
} |
} |
141 |
|
|
142 |
|
static int |
143 |
|
mount_roots(int argc, char *argv[], const char *root_dev_name) |
144 |
|
{ |
145 |
|
char *roots = strdup(root_dev_name); |
146 |
|
char *root; |
147 |
|
const char *sep = ","; |
148 |
|
char *saveptr; |
149 |
|
int ret = -ESRCH; |
150 |
|
|
151 |
|
root = strtok_r(roots, sep, &saveptr); |
152 |
|
while (root) { |
153 |
|
dev_t root_dev; |
154 |
|
|
155 |
|
dprintf("kinit: trying to mount %s\n", root); |
156 |
|
root_dev = name_to_dev_t(root); |
157 |
|
ret = mount_root(argc, argv, root_dev, root); |
158 |
|
if (!ret) |
159 |
|
break; |
160 |
|
root = strtok_r(NULL, sep, &saveptr); |
161 |
|
} |
162 |
|
free(roots); |
163 |
|
return ret; |
164 |
|
} |
165 |
|
|
166 |
int |
int |
167 |
mount_root(int argc, char *argv[], dev_t root_dev, const char *root_dev_name) |
mount_root(int argc, char *argv[], dev_t root_dev, const char *root_dev_name) |
168 |
{ |
{ |
171 |
const char *type = get_arg(argc, argv, "rootfstype="); |
const char *type = get_arg(argc, argv, "rootfstype="); |
172 |
|
|
173 |
if (get_flag(argc, argv, "rw") > get_flag(argc, argv, "ro")) { |
if (get_flag(argc, argv, "rw") > get_flag(argc, argv, "ro")) { |
174 |
DEBUG(("kinit: mounting root rw\n")); |
dprintf("kinit: mounting root rw\n"); |
175 |
flags &= ~MS_RDONLY; |
flags &= ~MS_RDONLY; |
176 |
} |
} |
177 |
|
|
207 |
const char *load_ramdisk = get_arg(argc, argv, "load_ramdisk="); |
const char *load_ramdisk = get_arg(argc, argv, "load_ramdisk="); |
208 |
dev_t root_dev = 0; |
dev_t root_dev = 0; |
209 |
|
|
210 |
DEBUG(("kinit: do_mounts\n")); |
dprintf("kinit: do_mounts\n"); |
211 |
|
|
212 |
if (root_delay) { |
if (root_delay) { |
213 |
int delay = atoi(root_delay); |
int delay = atoi(root_delay); |
229 |
root_dev = (dev_t) rootdev; |
root_dev = (dev_t) rootdev; |
230 |
} |
} |
231 |
|
|
232 |
DEBUG(("kinit: root_dev = %s\n", bdevname(root_dev))); |
dprintf("kinit: root_dev = %s\n", bdevname(root_dev)); |
233 |
|
|
234 |
if (initrd_load(argc, argv, root_dev)) { |
if (initrd_load(argc, argv, root_dev)) { |
235 |
DEBUG(("initrd loaded\n")); |
dprintf("initrd loaded\n"); |
236 |
return 0; |
return 0; |
237 |
} |
} |
238 |
|
|
239 |
if (load_ramdisk && atoi(load_ramdisk)) { |
if (load_ramdisk && atoi(load_ramdisk)) { |
240 |
if (ramdisk_load(argc, argv, root_dev)) |
if (ramdisk_load(argc, argv)) |
241 |
root_dev = Root_RAM0; |
root_dev = Root_RAM0; |
242 |
} |
} |
243 |
|
|
244 |
|
if (root_dev == Root_MULTI) |
245 |
|
return mount_roots(argc, argv, root_dev_name); |
246 |
return mount_root(argc, argv, root_dev, root_dev_name); |
return mount_root(argc, argv, root_dev, root_dev_name); |
247 |
} |
} |