1 /* mount - mount a file system Author: Andy Tanenbaum */
9 #include <minix/minlib.h>
13 #define MINIX_FS_TYPE "mfs"
15 int main(int argc
, char **argv
);
18 void update_mtab(char *dev
, char *mountpoint
, char *fstype
, int mountflags
);
21 static int write_mtab
= 1;
27 int all
= 0, i
, v
= 0, mountflags
;
28 char **ap
, *opt
, *err
, *type
, *args
, *device
;
30 if (argc
== 1) list(); /* just list /etc/mtab */
35 for (i
= 1; i
< argc
; i
++) {
36 if (argv
[i
][0] == '-') {
38 while (*opt
!= 0) switch (*opt
++) {
39 case 'r': mountflags
|= MS_RDONLY
; break;
40 case 't': if (++i
== argc
) usage();
43 case 'i': mountflags
|= MS_REUSE
; break;
44 case 'e': mountflags
|= MS_EXISTING
; break;
45 case 'n': write_mtab
= 0; break;
46 case 'o': if (++i
== argc
) usage();
49 case 'a': all
= 1; break;
59 if (!all
&& (argc
!= 3 || *argv
[1] == 0)) usage();
65 if (!strcmp(device
, "none")) device
= NULL
;
67 if ((type
== NULL
|| !strcmp(type
, MINIX_FS_TYPE
)) && device
!= NULL
) {
68 /* auto-detect type and/or version */
69 v
= fsversion(device
, "mount");
73 case FSVERSION_MFS3
: type
= MINIX_FS_TYPE
; break;
74 case FSVERSION_EXT2
: type
= "ext2"; break;
78 if (mount(device
, argv
[2], mountflags
, type
, args
) < 0) {
79 err
= strerror(errno
);
80 fprintf(stderr
, "mount: Can't mount %s on %s: %s\n",
81 argv
[1], argv
[2], err
);
85 printf("%s is mounted on %s\n", argv
[1], argv
[2]);
92 char dev
[PATH_MAX
], mountpoint
[PATH_MAX
], type
[MNTNAMELEN
], flags
[MNTFLAGLEN
];
94 /* Read and print /etc/mtab. */
95 n
= load_mtab("mount");
99 n
= get_mtab_entry(dev
, mountpoint
, type
, flags
);
101 printf("%s on %s type %s (%s)\n", dev
, mountpoint
, type
, flags
);
107 has_opt(char *mntopts
, char *option
)
112 optbuf
= strdup(mntopts
);
113 for (opt
= optbuf
; (opt
= strtok(opt
, ",")) != NULL
; opt
= NULL
) {
114 if (!strcmp(opt
, option
)) found
= 1;
126 char mountpoint
[PATH_MAX
];
129 while ((fs
= getfsent()) != NULL
) {
133 if (realpath(fs
->fs_file
, mountpoint
) == NULL
) {
134 fprintf(stderr
, "Can't mount on %s\n", fs
->fs_file
);
135 return(EXIT_FAILURE
);
137 if (has_opt(fs
->fs_mntops
, "noauto"))
139 if (!strcmp(mountpoint
, "/"))
140 continue; /* Not remounting root */
141 if (has_opt(fs
->fs_mntops
, "ro"))
144 mountflags
|= MS_RDONLY
;
147 device
= fs
->fs_spec
;
148 /* passing a null string for block special device means don't
149 * use a device at all and this is what we need to do for
150 * entries starting with "none"
152 if (!strcmp(device
, "none"))
155 if (mount(device
, mountpoint
, mountflags
, fs
->fs_vfstype
,
156 fs
->fs_mntops
) != 0) {
157 err
= strerror(errno
);
158 fprintf(stderr
, "mount: Can't mount %s on %s: %s\n",
159 fs
->fs_spec
, fs
->fs_file
, err
);
160 return(EXIT_FAILURE
);
163 return(EXIT_SUCCESS
);
168 std_err("Usage: mount [-a] [-r] [-e] [-t type] [-o options] special name\n");