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
, srvflags
;
28 char **ap
, *opt
, *err
, *type
, *args
, *device
;
30 if (argc
== 1) list(); /* just list /etc/mtab */
36 for (i
= 1; i
< argc
; i
++) {
37 if (argv
[i
][0] == '-') {
39 while (*opt
!= 0) switch (*opt
++) {
40 case 'r': mountflags
|= MNT_RDONLY
; break;
41 case 't': if (++i
== argc
) usage();
44 case 'i': srvflags
|= MS_REUSE
; break;
45 case 'e': srvflags
|= MS_EXISTING
; break;
46 case 'n': write_mtab
= 0; break;
47 case 'o': if (++i
== argc
) usage();
50 case 'a': all
= 1; break;
60 if (!all
&& (argc
!= 3 || *argv
[1] == 0)) usage();
66 if (!strcmp(device
, "none")) device
= NULL
;
68 if ((type
== NULL
|| !strcmp(type
, MINIX_FS_TYPE
)) && device
!= NULL
) {
69 /* auto-detect type and/or version */
70 v
= fsversion(device
, "mount");
74 case FSVERSION_MFS3
: type
= MINIX_FS_TYPE
; break;
75 case FSVERSION_EXT2
: type
= "ext2"; break;
76 case FSVERSION_ISO9660
: type
= "isofs"; break;
80 if (minix_mount(device
, argv
[2], mountflags
, srvflags
, type
, args
) < 0) {
81 err
= strerror(errno
);
82 fprintf(stderr
, "mount: Can't mount %s on %s: %s\n",
83 argv
[1], argv
[2], err
);
87 printf("%s is mounted on %s\n", argv
[1], argv
[2]);
94 char dev
[PATH_MAX
], mountpoint
[PATH_MAX
], type
[MNTNAMELEN
], flags
[MNTFLAGLEN
];
96 /* Read and print /etc/mtab. */
97 n
= load_mtab("mount");
101 n
= get_mtab_entry(dev
, mountpoint
, type
, flags
);
103 printf("%s on %s type %s (%s)\n", dev
, mountpoint
, type
, flags
);
109 has_opt(char *mntopts
, char *option
)
114 optbuf
= strdup(mntopts
);
115 for (opt
= optbuf
; (opt
= strtok(opt
, ",")) != NULL
; opt
= NULL
) {
116 if (!strcmp(opt
, option
)) found
= 1;
128 char mountpoint
[PATH_MAX
];
131 while ((fs
= getfsent()) != NULL
) {
135 if (realpath(fs
->fs_file
, mountpoint
) == NULL
) {
136 fprintf(stderr
, "Can't mount on %s\n", fs
->fs_file
);
137 return(EXIT_FAILURE
);
139 if (has_opt(fs
->fs_mntops
, "noauto"))
141 if (!strcmp(mountpoint
, "/"))
142 continue; /* Not remounting root */
143 if (has_opt(fs
->fs_mntops
, "ro"))
146 mountflags
|= MNT_RDONLY
;
149 device
= fs
->fs_spec
;
150 /* passing a null string for block special device means don't
151 * use a device at all and this is what we need to do for
152 * entries starting with "none"
154 if (!strcmp(device
, "none"))
157 if (minix_mount(device
, mountpoint
, mountflags
, 0, fs
->fs_vfstype
,
158 fs
->fs_mntops
) != 0) {
159 err
= strerror(errno
);
160 fprintf(stderr
, "mount: Can't mount %s on %s: %s\n",
161 fs
->fs_spec
, fs
->fs_file
, err
);
162 return(EXIT_FAILURE
);
165 return(EXIT_SUCCESS
);
170 std_err("Usage: mount [-a] [-r] [-e] [-t type] [-o options] special name\n");