1 /* umount - unmount a file system Author: Andy Tanenbaum */
3 #include <minix/type.h>
10 #include <minix/minlib.h>
14 #include <sys/mount.h>
17 int main(int argc
, char **argv
);
18 int find_mtab_entry(char *name
);
19 void update_mtab(void);
22 static char device
[PATH_MAX
], mount_point
[PATH_MAX
], type
[MNTNAMELEN
],
30 int umount_flags
= 0UL;
34 while ((c
= getopt (argc
, argv
, "e")) != -1)
37 case 'e': umount_flags
|= MS_EXISTING
; break;
42 if (argc
- optind
!= 1) {
48 found
= find_mtab_entry(name
);
50 if (minix_umount(name
, umount_flags
) < 0) {
52 std_err("umount: Device not mounted\n");
53 else if (errno
== ENOTBLK
)
54 std_err("umount: Not a mountpoint\n");
60 printf("%s unmounted from %s\n", device
, mount_point
);
65 int find_mtab_entry(name
)
68 /* Find a matching mtab entry for 'name' which may be a special or a path,
69 * and generate a new mtab file without this entry on the fly. Do not write
70 * out the result yet. Return whether we found a matching entry.
72 char e_dev
[PATH_MAX
], e_mount_point
[PATH_MAX
], e_type
[MNTNAMELEN
],
74 struct stat nstat
, mstat
;
77 if (load_mtab("umount") < 0) return 0;
79 if (stat(name
, &nstat
) != 0) return 0;
83 n
= get_mtab_entry(e_dev
, e_mount_point
, e_type
, e_flags
);
85 if (strcmp(name
, e_dev
) == 0 || (stat(e_mount_point
, &mstat
) == 0 &&
86 mstat
.st_dev
== nstat
.st_dev
&& mstat
.st_ino
== nstat
.st_ino
))
88 strlcpy(device
, e_dev
, PATH_MAX
);
89 strlcpy(mount_point
, e_mount_point
, PATH_MAX
);
90 strlcpy(type
, e_type
, MNTNAMELEN
);
91 strlcpy(flags
, e_flags
, MNTFLAGLEN
);
102 std_err("Usage: umount [-e] name\n");