diff options
Diffstat (limited to 'mount.c')
-rw-r--r-- | mount.c | 86 |
1 files changed, 79 insertions, 7 deletions
@@ -46,6 +46,10 @@ | |||
46 | #include <sys/mount.h> | 46 | #include <sys/mount.h> |
47 | #include <ctype.h> | 47 | #include <ctype.h> |
48 | #include <fstab.h> | 48 | #include <fstab.h> |
49 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
50 | #include <linux/devmtab.h> | ||
51 | #endif | ||
52 | |||
49 | 53 | ||
50 | #if defined BB_FEATURE_MOUNT_LOOP | 54 | #if defined BB_FEATURE_MOUNT_LOOP |
51 | #include <fcntl.h> | 55 | #include <fcntl.h> |
@@ -221,9 +225,8 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
221 | { | 225 | { |
222 | int status = 0; | 226 | int status = 0; |
223 | 227 | ||
224 | char buf[255]; | ||
225 | |||
226 | #if defined BB_FEATURE_USE_PROCFS | 228 | #if defined BB_FEATURE_USE_PROCFS |
229 | char buf[255]; | ||
227 | if (strcmp(filesystemType, "auto") == 0) { | 230 | if (strcmp(filesystemType, "auto") == 0) { |
228 | FILE *f = fopen("/proc/filesystems", "r"); | 231 | FILE *f = fopen("/proc/filesystems", "r"); |
229 | 232 | ||
@@ -252,6 +255,43 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
252 | fclose(f); | 255 | fclose(f); |
253 | } else | 256 | } else |
254 | #endif | 257 | #endif |
258 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
259 | if (strcmp(filesystemType, "auto") == 0) { | ||
260 | int fd, i, numfilesystems; | ||
261 | char device[] = "/dev/mtab"; | ||
262 | struct k_fstype *fslist; | ||
263 | |||
264 | /* open device */ | ||
265 | fd = open(device, O_RDONLY); | ||
266 | if (fd < 0) | ||
267 | fatalError("open failed for `%s': %s\n", device, strerror (errno)); | ||
268 | |||
269 | /* How many filesystems? We need to know to allocate enough space */ | ||
270 | numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS); | ||
271 | if (numfilesystems<0) | ||
272 | fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno)); | ||
273 | fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype)); | ||
274 | |||
275 | /* Grab the list of available filesystems */ | ||
276 | status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist); | ||
277 | if (status<0) | ||
278 | fatalError("\nDEVMTAB_GET_FILESYSTEMS: %s\n", strerror (errno)); | ||
279 | |||
280 | /* Walk the list trying to mount filesystems | ||
281 | * that do not claim to be nodev filesystems */ | ||
282 | for( i = 0 ; i < numfilesystems ; i++) { | ||
283 | if (fslist[i].mnt_nodev) | ||
284 | continue; | ||
285 | status = do_mount(blockDevice, directory, fslist[i].mnt_type, | ||
286 | flags | MS_MGC_VAL, string_flags, | ||
287 | useMtab, fakeIt, mtab_opts); | ||
288 | if (status == TRUE) | ||
289 | break; | ||
290 | } | ||
291 | free( fslist); | ||
292 | close(fd); | ||
293 | } else | ||
294 | #endif | ||
255 | { | 295 | { |
256 | status = do_mount(blockDevice, directory, filesystemType, | 296 | status = do_mount(blockDevice, directory, filesystemType, |
257 | flags | MS_MGC_VAL, string_flags, useMtab, | 297 | flags | MS_MGC_VAL, string_flags, useMtab, |
@@ -285,6 +325,39 @@ extern int mount_main(int argc, char **argv) | |||
285 | /* Only compiled in if BB_MTAB is not defined */ | 325 | /* Only compiled in if BB_MTAB is not defined */ |
286 | whine_if_fstab_is_missing(); | 326 | whine_if_fstab_is_missing(); |
287 | 327 | ||
328 | #if defined BB_FEATURE_USE_DEVPS_N_DEVMTAB | ||
329 | if (argc == 1) { | ||
330 | int fd, i, numfilesystems; | ||
331 | char device[] = "/dev/mtab"; | ||
332 | struct k_mntent *mntentlist; | ||
333 | |||
334 | /* open device */ | ||
335 | fd = open(device, O_RDONLY); | ||
336 | if (fd < 0) | ||
337 | fatalError("open failed for `%s': %s\n", device, strerror (errno)); | ||
338 | |||
339 | /* How many mounted filesystems? We need to know to | ||
340 | * allocate enough space for later... */ | ||
341 | numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS); | ||
342 | if (numfilesystems<0) | ||
343 | fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno)); | ||
344 | mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent)); | ||
345 | |||
346 | /* Grab the list of mounted filesystems */ | ||
347 | if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0) | ||
348 | fatalError( "\nDEVMTAB_GET_MOUNTS: %s\n", strerror (errno)); | ||
349 | |||
350 | for( i = 0 ; i < numfilesystems ; i++) { | ||
351 | fprintf( stdout, "%s %s %s %s %d %d\n", mntentlist[i].mnt_fsname, | ||
352 | mntentlist[i].mnt_dir, mntentlist[i].mnt_type, | ||
353 | mntentlist[i].mnt_opts, mntentlist[i].mnt_freq, | ||
354 | mntentlist[i].mnt_passno); | ||
355 | } | ||
356 | free( mntentlist); | ||
357 | close(fd); | ||
358 | exit(TRUE); | ||
359 | } | ||
360 | #else | ||
288 | if (argc == 1) { | 361 | if (argc == 1) { |
289 | FILE *mountTable = setmntent(mtab_file, "r"); | 362 | FILE *mountTable = setmntent(mtab_file, "r"); |
290 | 363 | ||
@@ -310,7 +383,7 @@ extern int mount_main(int argc, char **argv) | |||
310 | } | 383 | } |
311 | exit(TRUE); | 384 | exit(TRUE); |
312 | } | 385 | } |
313 | 386 | #endif | |
314 | 387 | ||
315 | /* Parse options */ | 388 | /* Parse options */ |
316 | i = --argc; | 389 | i = --argc; |
@@ -372,10 +445,9 @@ extern int mount_main(int argc, char **argv) | |||
372 | struct mntent *m; | 445 | struct mntent *m; |
373 | FILE *f = setmntent("/etc/fstab", "r"); | 446 | FILE *f = setmntent("/etc/fstab", "r"); |
374 | 447 | ||
375 | if (f == NULL) { | 448 | if (f == NULL) |
376 | perror("/etc/fstab"); | 449 | fatalError( "\nCannot ream /etc/fstab: %s\n", strerror (errno)); |
377 | exit(FALSE); | 450 | |
378 | } | ||
379 | while ((m = getmntent(f)) != NULL) { | 451 | while ((m = getmntent(f)) != NULL) { |
380 | // If the file system isn't noauto, | 452 | // If the file system isn't noauto, |
381 | // and isn't swap or nfs, then mount it | 453 | // and isn't swap or nfs, then mount it |