pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / simple / mount.c
blobabbd533e0712d9ab4cfca1cbe1c02339f535055c
1 /* mount - mount a file system Author: Andy Tanenbaum */
3 #include <errno.h>
4 #include <sys/types.h>
5 #include <limits.h>
6 #include <stdlib.h>
7 #include <dirent.h>
8 #include <string.h>
9 #include <sys/mount.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <minix/config.h>
13 #include <minix/const.h>
14 #include <minix/minlib.h>
15 #include <sys/svrctl.h>
16 #include <stdio.h>
17 #include "../../servers/mfs/const.h"
19 #define MINIX_FS_TYPE "mfs"
21 _PROTOTYPE(int main, (int argc, char **argv));
22 _PROTOTYPE(void list, (void));
23 _PROTOTYPE(void usage, (void));
25 int main(argc, argv)
26 int argc;
27 char *argv[];
29 int i, n, v, mountflags;
30 char **ap, *vs, *opt, *err, *type, *args, *device;
31 char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
33 if (argc == 1) list(); /* just list /etc/mtab */
34 mountflags = 0;
35 type = NULL;
36 args = NULL;
37 ap = argv+1;
38 for (i = 1; i < argc; i++) {
39 if (argv[i][0] == '-') {
40 opt = argv[i]+1;
41 while (*opt != 0) switch (*opt++) {
42 case 'r': mountflags |= MS_RDONLY; break;
43 case 't': if (++i == argc) usage();
44 type = argv[i];
45 break;
46 case 'i': mountflags |= MS_REUSE; break;
47 case 'o': if (++i == argc) usage();
48 args = argv[i];
49 break;
50 default: usage();
52 } else {
53 *ap++ = argv[i];
56 *ap = NULL;
57 argc = (ap - argv);
59 if (argc != 3 || *argv[1] == 0) usage();
61 device = argv[1];
62 if (!strcmp(device, "none")) device = NULL;
64 if (mount(device, argv[2], mountflags, type, args) < 0) {
65 err = strerror(errno);
66 fprintf(stderr, "mount: Can't mount %s on %s: %s\n",
67 argv[1], argv[2], err);
68 exit(1);
71 /* The mount has completed successfully. Tell the user. */
72 printf("%s is read-%s mounted on %s\n",
73 argv[1], mountflags & MS_RDONLY ? "only" : "write", argv[2]);
75 /* Update /etc/mtab. */
76 n = load_mtab("mount");
77 if (n < 0) exit(1); /* something is wrong. */
79 /* Loop on all the /etc/mtab entries, copying each one to the output buf. */
80 while (1) {
81 n = get_mtab_entry(special, mounted_on, version, rw_flag);
82 if (n < 0) break;
83 n = put_mtab_entry(special, mounted_on, version, rw_flag);
84 if (n < 0) {
85 std_err("mount: /etc/mtab has grown too large\n");
86 exit(1);
89 /* For MFS, use a version number. Otherwise, use the FS type name. */
90 if (type == NULL || !strcmp(type, MINIX_FS_TYPE)) {
91 v = fsversion(argv[1], "mount");
92 if (v == 1)
93 vs = "1";
94 else if (v == 2)
95 vs = "2";
96 else if (v == 3)
97 vs = "3";
98 else
99 vs = "0";
100 } else {
101 /* Keep the version field sufficiently short. */
102 if (strlen(type) < sizeof(version))
103 vs = type;
104 else
105 vs = "-";
107 n = put_mtab_entry(argv[1], argv[2], vs,
108 (mountflags & MS_RDONLY ? "ro" : "rw") );
109 if (n < 0) {
110 std_err("mount: /etc/mtab has grown too large\n");
111 exit(1);
114 n = rewrite_mtab("mount");
115 return(0);
119 void list()
121 int n;
122 char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10];
124 /* Read and print /etc/mtab. */
125 n = load_mtab("mount");
126 if (n < 0) exit(1);
128 while (1) {
129 n = get_mtab_entry(special, mounted_on, version, rw_flag);
130 if (n < 0) break;
131 printf("%s is read-%s mounted on %s (type %s)\n",
132 special, strcmp(rw_flag, "rw") == 0 ? "write" : "only",
133 mounted_on, version);
135 exit(0);
139 void usage()
141 std_err("Usage: mount [-r] [-t type] [-o options] special name\n");
142 exit(1);