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
], mount_point
[PATH_MAX
], type
[MNTNAMELEN
],
33 int umount_flags
= 0UL;
37 while ((c
= getopt (argc
, argv
, "e")) != -1)
40 case 'e': umount_flags
|= MS_EXISTING
; break;
45 if (argc
- optind
!= 1) {
51 found
= find_mtab_entry(name
);
53 if (umount2(name
, umount_flags
) < 0) {
55 std_err("umount: Device not mounted\n");
56 else if (errno
== ENOTBLK
)
57 std_err("umount: Not a mountpoint\n");
63 printf("%s unmounted from %s\n", device
, mount_point
);
68 int find_mtab_entry(name
)
71 /* Find a matching mtab entry for 'name' which may be a special or a path,
72 * and generate a new mtab file without this entry on the fly. Do not write
73 * out the result yet. Return whether we found a matching entry.
75 char e_dev
[PATH_MAX
], e_mount_point
[PATH_MAX
], e_type
[MNTNAMELEN
],
77 struct stat nstat
, mstat
;
80 if (load_mtab("umount") < 0) return 0;
82 if (stat(name
, &nstat
) != 0) return 0;
86 n
= get_mtab_entry(e_dev
, e_mount_point
, e_type
, e_flags
);
88 if (strcmp(name
, e_dev
) == 0 || (stat(e_mount_point
, &mstat
) == 0 &&
89 mstat
.st_dev
== nstat
.st_dev
&& mstat
.st_ino
== nstat
.st_ino
))
91 strlcpy(device
, e_dev
, PATH_MAX
);
92 strlcpy(mount_point
, e_mount_point
, PATH_MAX
);
93 strlcpy(type
, e_type
, MNTNAMELEN
);
94 strlcpy(flags
, e_flags
, MNTFLAGLEN
);
105 std_err("Usage: umount [-e] name\n");