- endmntent (f);
- } else {
- if (device && directory) {
-#ifdef BB_NFSMOUNT
- if (strcmp(filesystemType, "nfs") == 0) {
- if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0)
- exit(FALSE);
- }
+
+ if (optind + 1 < argc)
+ directory = simplify_path(argv[optind + 1]);
+
+ if (all || 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 && optind + 1 == argc && (
+ (strcmp(device, m->mnt_fsname) != 0) &&
+ (strcmp(device, m->mnt_dir) != 0) ) ) {
+ continue;
+ }
+
+ if (all && ( // 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 || flags == 0) { // Allow single mount to override fstab flags
+ flags = 0;
+ string_flags = string_flags_buf;
+ *string_flags = '\0';
+ parse_mount_options(m->mnt_opts, &flags, string_flags);
+ }
+
+ strcpy(device, m->mnt_fsname);
+ strcpy(directory, m->mnt_dir);
+ filesystemType = xstrdup(m->mnt_type);
+singlemount:
+ string_flags = xstrdup(string_flags);
+ rc = EXIT_SUCCESS;
+#ifdef CONFIG_NFSMOUNT
+ if (strchr(device, ':') != NULL) {
+ filesystemType = "nfs";
+ if (nfsmount (device, directory, &flags, &extra_opts,
+ &string_flags, 1)) {
+ perror_msg("nfsmount failed");
+ rc = EXIT_FAILURE;
+ }
+ }