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>
12 #include <minix/minlib.h>
16 #include <sys/mount.h>
19 _PROTOTYPE(int main
, (int argc
, char **argv
));
20 _PROTOTYPE(int find_mtab_entry
, (char *name
));
21 _PROTOTYPE(void update_mtab
, (void));
22 _PROTOTYPE(void usage
, (void));
24 static char device
[PATH_MAX
+1], mountpoint
[PATH_MAX
+1], vs
[10], rw
[10];
32 if (argc
!= 2) usage();
33 found
= find_mtab_entry(argv
[1]);
34 if (umount(argv
[1]) < 0) {
36 std_err("umount: Device not mounted\n");
37 else if (errno
== ENOTBLK
)
38 std_err("unount: Not a mountpoint\n");
44 printf("%s unmounted from %s\n", device
, mountpoint
);
47 else printf("%s unmounted (mtab not updated)\n", argv
[1]);
51 int find_mtab_entry(name
)
54 /* Find a matching mtab entry for 'name' which may be a special or a path,
55 * and generate a new mtab file without this entry on the fly. Do not write
56 * out the result yet. Return whether we found a matching entry.
58 char special
[PATH_MAX
+1], mounted_on
[PATH_MAX
+1], version
[10], rw_flag
[10];
59 struct stat nstat
, mstat
;
62 if (load_mtab("umount") < 0) return 0;
64 if (stat(name
, &nstat
) != 0) return 0;
68 n
= get_mtab_entry(special
, mounted_on
, version
, rw_flag
);
70 if (strcmp(name
, special
) == 0 || (stat(mounted_on
, &mstat
) == 0 &&
71 mstat
.st_dev
== nstat
.st_dev
&& mstat
.st_ino
== nstat
.st_ino
))
73 /* If we found an earlier match, keep that one. Mountpoints
74 * may be stacked on top of each other, and unmounting should
75 * take place in the reverse order of mounting.
78 (void) put_mtab_entry(device
, mountpoint
, vs
, rw
);
81 strcpy(device
, special
);
82 strcpy(mountpoint
, mounted_on
);
88 (void) put_mtab_entry(special
, mounted_on
, version
, rw_flag
);
96 /* Write out the new mtab file. */
99 n
= rewrite_mtab("umount");
101 std_err("/etc/mtab not updated.\n");
108 std_err("Usage: umount name\n");