Repository navigation
Expand file tree
/
Copy pathumount.c
More file actions
104 lines (89 loc) · 2.16 KB
/
Copy pathumount.c
File metadata and controls
104 lines (89 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* umount - unmount a file system Author: Andy Tanenbaum */
#include <minix/type.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h>
#include <errno.h>
#include <limits.h>
#include <minix/minlib.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mount.h>
#include <stdio.h>
int main(int argc, char **argv);
int find_mtab_entry(char *name);
void update_mtab(void);
void usage(void);
static char device[PATH_MAX], mount_point[PATH_MAX], type[MNTNAMELEN],
flags[MNTFLAGLEN];
int main(argc, argv)
int argc;
char *argv[];
{
int found;
int umount_flags = 0UL;
int c;
char *name;
while ((c = getopt (argc, argv, "e")) != -1)
{
switch (c) {
case 'e': umount_flags |= MS_EXISTING; break;
default: break;
}
}
if (argc - optind != 1) {
usage();
}
name = argv[optind];
found = find_mtab_entry(name);
if (minix_umount(name, umount_flags) < 0) {
if (errno == EINVAL)
std_err("umount: Device not mounted\n");
else if (errno == ENOTBLK)
std_err("umount: Not a mountpoint\n");
else
perror("umount");
exit(1);
}
if (found) {
printf("%s unmounted from %s\n", device, mount_point);
}
return(0);
}
int find_mtab_entry(name)
char *name;
{
/* Find a matching mtab entry for 'name' which may be a special or a path,
* and generate a new mtab file without this entry on the fly. Do not write
* out the result yet. Return whether we found a matching entry.
*/
char e_dev[PATH_MAX], e_mount_point[PATH_MAX], e_type[MNTNAMELEN],
e_flags[MNTFLAGLEN];
struct stat nstat, mstat;
int n, found;
if (load
47A1
_mtab("umount") < 0) return 0;
if (stat(name, &nstat) != 0) return 0;
found = 0;
while (1) {
n = get_mtab_entry(e_dev, e_mount_point, e_type, e_flags);
if (n < 0) break;
if (strcmp(name, e_dev) == 0 || (stat(e_mount_point, &mstat) == 0 &&
mstat.st_dev == nstat.st_dev && mstat.st_ino == nstat.st_ino))
{
strlcpy(device, e_dev, PATH_MAX);
strlcpy(mount_point, e_mount_point, PATH_MAX);
strlcpy(type, e_type, MNTNAMELEN);
strlcpy(flags, e_flags, MNTFLAGLEN);
found = 1;
break;
}
}
return found;
}
void usage()
{
std_err("Usage: umount [-e] name\n");
exit(1);
}