* Copyright (c) 1980, 1989 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1980, 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)mount.c 5.48 (Berkeley) %G%";
#define DEFAULT_ROOTUID -2
(strcmp(type, FSTAB_RO) && strcmp(type, FSTAB_RW) && \
(!strcmp(type, FSTAB_RW) || !strcmp(type, FSTAB_RQ))
int fake
, verbose
, updateflg
, mnttype
;
char **vfslist
, **makevfslist();
register struct fstab
*fs
;
int all
, ch
, rval
, flags
, ret
, pid
, i
;
struct statfs
*mntbuf
, *getmntpt();
char *type
, *options
= NULL
;
while ((ch
= getopt(argc
, argv
, "afrwuvt:o:")) != EOF
)
vfslist
= makevfslist(optarg
);
mnttype
= getmnttype(optarg
);
while (fs
= getfsent()) {
if (BADTYPE(fs
->fs_type
))
if (badvfsname(fs
->fs_vfstype
, vfslist
))
/* `/' is special, it's always mounted */
if (!strcmp(fs
->fs_file
, "/"))
mnttype
= getmnttype(fs
->fs_vfstype
);
rval
|= mountfs(fs
->fs_spec
, fs
->fs_file
, flags
,
type
, options
, fs
->fs_mntops
);
if (verbose
|| fake
|| type
)
if ((mntsize
= getmntinfo(&mntbuf
, MNT_NOWAIT
)) == 0) {
"mount: cannot get mount information\n");
for (i
= 0; i
< mntsize
; i
++) {
if (badvfstype(mntbuf
[i
].f_type
, vfslist
))
prmount(mntbuf
[i
].f_mntfromname
, mntbuf
[i
].f_mntonname
,
if (argc
== 1 && updateflg
) {
if ((mntbuf
= getmntpt(*argv
)) == NULL
) {
"mount: unknown special file or file system %s.\n",
mnttype
= mntbuf
->f_type
;
if (!strcmp(mntbuf
->f_mntfromname
, "root_device")) {
strcpy(mntbuf
->f_mntfromname
, fs
->fs_spec
);
ret
= mountfs(mntbuf
->f_mntfromname
, mntbuf
->f_mntonname
,
updateflg
, type
, options
, (char *)NULL
);
if (!(fs
= getfsfile(*argv
)) && !(fs
= getfsspec(*argv
))) {
"mount: unknown special file or file system %s.\n",
if (BADTYPE(fs
->fs_type
)) {
"mount: %s has unknown file system type.\n", *argv
);
mnttype
= getmnttype(fs
->fs_vfstype
);
ret
= mountfs(fs
->fs_spec
, fs
->fs_file
, updateflg
,
type
, options
, fs
->fs_mntops
);
* If -t flag has not been specified, and spec
* contains either a ':' or a '@' then assume that
* an NFS filesystem is being specified ala Sun.
if (vfslist
== (char **)0 &&
(index(argv
[0], ':') || index(argv
[0], '@'))) {
ret
= mountfs(argv
[0], argv
[1], updateflg
, type
, options
,
if ((pidfile
= fopen(_PATH_MOUNTDPID
, "r")) != NULL
) {
fscanf(pidfile
, "%d", &pid
);
mountfs(spec
, name
, flags
, type
, options
, mntopts
)
char *spec
, *name
, *type
, *options
, *mntopts
;
char execname
[MAXPATHLEN
+ 1], flagval
[12];
getstdopts(mntopts
, &flags
);
getstdopts(options
, &flags
);
getstdopts(type
, &flags
);
getufsopts(mntopts
, &flags
);
getufsopts(options
, &flags
);
args
.exroot
= DEFAULT_ROOTUID
;
args
.exflags
= MNT_EXRDONLY
;
sprintf(flagval
, "%d", flags
);
argc
+= getexecopts(mntopts
, &argv
[argc
]);
argc
+= getexecopts(options
, &argv
[argc
]);
sprintf(execname
, "%s/mount_%s", _PATH_EXECDIR
, mntname
);
(void)printf("exec: %s", execname
);
for (i
= 1; i
< argc
- 1; i
++)
(void)printf(" %s", argv
[i
]);
perror("mount: vfork starting file system");
if (waitpid(pid
, (int *)&status
, 0) != -1 &&
WEXITSTATUS(status
) != 0)
return (WEXITSTATUS(status
));
execve(execname
, argv
, envp
);
(void) fprintf(stderr
, "mount: cannot exec %s for %s: ",
if (!fake
&& mount(mnttype
, name
, flags
, argp
)) {
(void) fprintf(stderr
, "%s on %s: ", spec
, name
);
(void) fprintf(stderr
, "Mount table full\n");
(void) fprintf(stderr
, "Specified device %s\n",
"does not match mounted device");
else if (mnttype
== MOUNT_UFS
)
(void) fprintf(stderr
, "Bogus super block\n");
prmount(spec
, name
, flags
);
prmount(spec
, name
, flags
)
(void)printf("%s on %s", spec
, name
);
if (!(flags
& MNT_VISFLAGMASK
)) {
#define PR(msg) (void)printf("%s%s", !first++ ? " (" : ", ", msg)
if (flags
& MNT_SYNCHRONOUS
)
if (flags
& MNT_EXPORTED
)
if (!strcmp(fstype
, "ufs"))
if (!strcmp(fstype
, "nfs"))
if (!strcmp(fstype
, "mfs"))
if (!strcmp(fstype
, "lfs"))
"usage:\n mount %s %s\n mount %s\n mount %s\n",
"[ -frwu ] [ -t ufs | external_type ]",
"[ -o options ] special node",
"[ -afrwu ] [ -t ufs | external_type ]",
"[ -frwu ] special | node");
getstdopts(options
, flagp
)
(void)strcpy(optbuf
, options
);
for (opt
= strtok(optbuf
, ","); opt
; opt
= strtok((char *)NULL
, ",")) {
if (opt
[0] == 'n' && opt
[1] == 'o') {
if (!negative
&& !strcasecmp(opt
, FSTAB_RO
)) {
if (!negative
&& !strcasecmp(opt
, FSTAB_RW
)) {
if (!strcasecmp(opt
, "exec")) {
if (!strcasecmp(opt
, "suid")) {
if (!strcasecmp(opt
, "dev")) {
if (!strcasecmp(opt
, "synchronous")) {
*flagp
|= MNT_SYNCHRONOUS
;
*flagp
&= ~MNT_SYNCHRONOUS
;
getufsopts(options
, flagp
)
getexecopts(options
, argv
)
for (opt
= strtok(options
, ","); opt
; opt
= strtok((char *)NULL
, ",")) {
if (opt
[2] == '\0' || opt
[2] != '=')
mntsize
= getmntinfo(&mntbuf
, MNT_NOWAIT
);
for (i
= 0; i
< mntsize
; i
++) {
if (!strcmp(mntbuf
[i
].f_mntfromname
, name
) ||
!strcmp(mntbuf
[i
].f_mntonname
, name
))
return ((struct statfs
*)0);
badvfstype(vfstype
, vfslist
)
if (vfstype
== getmnttype(*vfslist
))
badvfsname(vfsname
, vfslist
)
if (strcmp(vfsname
, *vfslist
) == 0)
register char **av
, *nextcp
;
if (fslist
[0] == 'n' && fslist
[1] == 'o') {
for (i
= 0, nextcp
= fslist
; *nextcp
; nextcp
++)
av
= (char **)malloc((size_t)(i
+2) * sizeof(char *));
while (nextcp
= index(nextcp
, ',')) {