1 /* mount - mount a file system Author: Andy Tanenbaum */
12 #include <minix/config.h>
13 #include <minix/const.h>
14 #include <minix/minlib.h>
15 #include <sys/svrctl.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));
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 */
38 for (i
= 1; i
< argc
; i
++) {
39 if (argv
[i
][0] == '-') {
41 while (*opt
!= 0) switch (*opt
++) {
42 case 'r': mountflags
|= MS_RDONLY
; break;
43 case 't': if (++i
== argc
) usage();
46 case 'i': mountflags
|= MS_REUSE
; break;
47 case 'o': if (++i
== argc
) usage();
59 if (argc
!= 3 || *argv
[1] == 0) usage();
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
);
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. */
81 n
= get_mtab_entry(special
, mounted_on
, version
, rw_flag
);
83 n
= put_mtab_entry(special
, mounted_on
, version
, rw_flag
);
85 std_err("mount: /etc/mtab has grown too large\n");
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");
101 /* Keep the version field sufficiently short. */
102 if (strlen(type
) < sizeof(version
))
107 n
= put_mtab_entry(argv
[1], argv
[2], vs
,
108 (mountflags
& MS_RDONLY
? "ro" : "rw") );
110 std_err("mount: /etc/mtab has grown too large\n");
114 n
= rewrite_mtab("mount");
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");
129 n
= get_mtab_entry(special
, mounted_on
, version
, rw_flag
);
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
);
141 std_err("Usage: mount [-r] [-t type] [-o options] special name\n");