- endmntent (f);
- } else {
- if (device && directory) {
- exit (mount_one (device, directory, filesystemType,
- flags, string_flags, useMtab, fakeIt));
- } else {
- fprintf (stderr, "%s\n", mount_usage);
- exit( FALSE);
+
+ if (all == TRUE || optind + 1 == argc) {
+ struct mntent *m = NULL;
+ FILE *f = setmntent("/etc/fstab", "r");
+ fstabmount = TRUE;
+
+ if (f == NULL)
+ perror_msg_and_die( "\nCannot read /etc/fstab");
+
+ while ((m = getmntent(f)) != NULL) {
+ if (all == FALSE && optind + 1 == argc && (
+ (strcmp(device, m->mnt_fsname) != 0) &&
+ (strcmp(device, m->mnt_dir) != 0) ) ) {
+ continue;
+ }
+
+ if (all == TRUE && ( // If we're mounting 'all'
+ (strstr(m->mnt_opts, "noauto")) || // and the file system isn't noauto,
+ (strstr(m->mnt_type, "swap")) || // and isn't swap or nfs, then mount it
+ (strstr(m->mnt_type, "nfs")) ) ) {
+ continue;
+ }
+
+ if (all == TRUE || flags == 0) { // Allow single mount to override fstab flags
+ flags = 0;
+ *string_flags = '\0';
+ parse_mount_options(m->mnt_opts, &flags, string_flags);
+ }
+
+ strcpy(device, m->mnt_fsname);
+ strcpy(directory, m->mnt_dir);
+ filesystemType = strdup(m->mnt_type);
+singlemount:
+ string_flags = strdup(string_flags);
+ rc = EXIT_SUCCESS;
+#ifdef BB_NFSMOUNT
+ if (strchr(device, ':') != NULL)
+ filesystemType = "nfs";
+ if (strcmp(filesystemType, "nfs") == 0) {
+ if (nfsmount (device, directory, &flags, &extra_opts,
+ &string_flags, 1)) {
+ perror_msg("nfsmount failed");
+ rc = EXIT_FAILURE;
+ }
+ }
+#endif
+ if (!mount_one(device, directory, filesystemType, flags,
+ string_flags, useMtab, fakeIt, extra_opts, TRUE, all))
+ rc = EXIT_FAILURE;
+
+ if (all == FALSE)
+ break;
+ }
+ if (fstabmount == TRUE)
+ endmntent(f);
+
+ if (all == FALSE && fstabmount == TRUE && m == NULL)
+ fprintf(stderr, "Can't find %s in /etc/fstab\n", device);
+
+ return rc;