1 /* umount - unmount a file system Author: Andy Tanenbaum */
3 #define _MINIX 1 /* for proto of the non-POSIX umount() */
4 #define _POSIX_SOURCE 1 /* for PATH_MAX from limits.h */
6 #include <minix/type.h>
13 #include <minix/minlib.h>
17 #include <sys/mount.h>
20 int main(int argc
, char **argv
);
21 int find_mtab_entry(char *name
);
22 void update_mtab(void);
25 static char device
[PATH_MAX
+1], mountpoint
[PATH_MAX
+1], vs
[10], rw
[10];
37 while ((c
= getopt (argc
, argv
, "e")) != -1)
40 case 'e': flags
|= MS_EXISTING
; break;
45 if (argc
- optind
!= 1) {
52 found
= find_mtab_entry(name
);
55 if (umount2(name
, flags
) < 0) {
57 std_err("umount: Device not mounted\n");
58 else if (errno
== ENOTBLK
)
59 std_err("umount: Not a mountpoint\n");
65 printf("%s unmounted from %s\n", device
, mountpoint
);
68 else printf("%s unmounted (mtab not updated)\n", name
);
72 int find_mtab_entry(name
)
75 /* Find a matching mtab entry for 'name' which may be a special or a path,
76 * and generate a new mtab file without this entry on the fly. Do not write
77 * out the result yet. Return whether we found a matching entry.
79 char special
[PATH_MAX
+1], mounted_on
[PATH_MAX
+1], version
[10], rw_flag
[10];
80 struct stat nstat
, mstat
;
83 if (load_mtab("umount") < 0) return 0;
85 if (stat(name
, &nstat
) != 0) return 0;
89 n
= get_mtab_entry(special
, mounted_on
, version
, rw_flag
);
91 if (strcmp(name
, special
) == 0 || (stat(mounted_on
, &mstat
) == 0 &&
92 mstat
.st_dev
== nstat
.st_dev
&& mstat
.st_ino
== nstat
.st_ino
))
94 /* If we found an earlier match, keep that one. Mountpoints
95 * may be stacked on top of each other, and unmounting should
96 * take place in the reverse order of mounting.
99 (void) put_mtab_entry(device
, mountpoint
, vs
, rw
);
102 strcpy(device
, special
);
103 strcpy(mountpoint
, mounted_on
);
109 (void) put_mtab_entry(special
, mounted_on
, version
, rw_flag
);
117 /* Write out the new mtab file. */
120 n
= rewrite_mtab("umount");
122 std_err("/etc/mtab not updated.\n");
129 std_err("Usage: umount [-e] name\n");