source: trunk/minix/commands/simple/umount.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.8 KB
Line 
1/* umount - unmount a file system Author: Andy Tanenbaum */
2
3#define _MINIX 1 /* for proto of the non-POSIX umount() */
4#define _POSIX_SOURCE 1 /* for PATH_MAX from limits.h */
5
6#include <sys/types.h>
7#include <sys/svrctl.h>
8#include <fcntl.h>
9#include <errno.h>
10#include <limits.h>
11#include <minix/minlib.h>
12#include <stdlib.h>
13#include <string.h>
14#include <unistd.h>
15#include <stdio.h>
16
17_PROTOTYPE(int main, (int argc, char **argv));
18_PROTOTYPE(void update_mtab, (char *devname));
19_PROTOTYPE(void usage, (void));
20_PROTOTYPE(void tell, (char *this));
21
22static char mountpoint[PATH_MAX+1];
23
24int main(argc, argv)
25int argc;
26char *argv[];
27{
28 int sflag = 0;
29
30 while (argc > 1 && argv[1][0] == '-') {
31 char *opt = argv[1]+1;
32 while (*opt) if (*opt++ == 's') sflag = 1; else usage();
33 argc--;
34 argv++;
35 }
36 if (argc != 2) usage();
37 if ((sflag ? svrctl(MMSWAPOFF, NULL) : umount(argv[1])) < 0) {
38 if (errno == EINVAL)
39 std_err("Device not mounted\n");
40 else
41 perror("umount");
42 exit(1);
43 }
44 update_mtab(argv[1]);
45 tell(argv[1]);
46 tell(" unmounted");
47 if (*mountpoint != '\0') {
48 tell(" from ");
49 tell(mountpoint);
50 }
51 tell("\n");
52 return(0);
53}
54
55void update_mtab(devname)
56char *devname;
57{
58/* Remove an entry from /etc/mtab. */
59 int n;
60 char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
61
62 if (load_mtab("umount") < 0) {
63 std_err("/etc/mtab not updated.\n");
64 exit(1);
65 }
66 while (1) {
67 n = get_mtab_entry(special, mounted_on, version, rw_flag);
68 if (n < 0) break;
69 if (strcmp(devname, special) == 0) {
70 strcpy(mountpoint, mounted_on);
71 continue;
72 }
73 (void) put_mtab_entry(special, mounted_on, version, rw_flag);
74 }
75 n = rewrite_mtab("umount");
76 if (n < 0) {
77 std_err("/etc/mtab not updated.\n");
78 exit(1);
79 }
80}
81
82void usage()
83{
84 std_err("Usage: umount [-s] special\n");
85 exit(1);
86}
87
88void tell(this)
89char *this;
90{
91 write(1, this, strlen(this));
92}
Note: See TracBrowser for help on using the repository browser.