* Copyright (c) 1980, 1989, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1980, 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)mount.c 8.10 (Berkeley) %G%";
int debug
, force
, verbose
, mnttype
, skipvfs
;
int badvfsname
__P((char *, char **));
int badvfstype
__P((int, char **));
int getexecopts
__P((char *, char **));
int getmnttype
__P((char *));
void getstdopts
__P((char *, int *));
void getufsopts
__P((char *, int *));
char **makevfslist
__P((char *));
int mountfs
__P((char *, char *, int, char *, char *, char *));
void prmount
__P((char *, char *, int));
int all
, ch
, i
, pid
, ret
, rval
, updateflg
;
char *cp
, *type
, *options
, **vfslist
;
while ((ch
= getopt(argc
, argv
, "adfo:rwt:uv")) != EOF
)
vfslist
= makevfslist(optarg
);
mnttype
= getmnttype(optarg
);
(strcmp(type, FSTAB_RO) && \
strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
while ((fs
= getfsent()) != NULL
) {
if (BADTYPE(fs
->fs_type
))
if (badvfsname(fs
->fs_vfstype
, vfslist
))
/* `/' is special, it's always mounted. */
mnttype
= getmnttype(fs
->fs_vfstype
);
rval
|= mountfs(fs
->fs_spec
, fs
->fs_file
, updateflg
,
type
, options
, fs
->fs_mntops
);
if (verbose
|| debug
|| type
)
if ((mntsize
= getmntinfo(&mntbuf
, MNT_NOWAIT
)) == 0) {
errx(1, "cannot get mount information");
for (i
= 0; i
< mntsize
; i
++) {
if (badvfstype(mntbuf
[i
].f_type
, vfslist
))
prmount(mntbuf
[i
].f_mntfromname
,
mntbuf
[i
].f_mntonname
, mntbuf
[i
].f_flags
);
if (argc
== 1 && vfslist
!= NULL
)
if (argc
== 1 && updateflg
) {
if ((mntbuf
= getmntpt(*argv
)) == NULL
)
"unknown special file or file system %s.", *argv
);
mnttype
= mntbuf
->f_type
;
if ((fs
= getfsfile(mntbuf
->f_mntonname
)) == NULL
)
errx(1, "can't find fstab entry for %s.", *argv
);
mntname
= fs
->fs_vfstype
;
* Default type to fstab version if none specified on the
* Default options to fstab version if none specified on the
* Concat the two strings with the command line
* options last so that they will override the
i
= strlen(fs
->fs_mntops
) + strlen(options
) + 2;
if ((cp
= malloc((size_t)i
)) == NULL
)
errx(1, "-u malloc failed");
(void)snprintf(cp
, i
, "%s,%s", fs
->fs_mntops
, options
);
ret
= mountfs(fs
->fs_spec
,
mntbuf
->f_mntonname
, updateflg
, type
, options
, NULL
);
if ((fs
= getfsfile(*argv
)) == NULL
&&
(fs
= getfsspec(*argv
)) == NULL
)
"unknown special file or file system %s.\n", *argv
);
if (BADTYPE(fs
->fs_type
))
errx(1, "%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
(strchr(argv
[0], ':') || strchr(argv
[0], '@'))) {
ret
= mountfs(argv
[0], argv
[1], updateflg
, type
, options
, NULL
);
if ((pidfile
= fopen(_PATH_MOUNTDPID
, "r")) != NULL
) {
(void)fscanf(pidfile
, "%ld", &pid
);
if (pid
> 0 && kill(pid
, SIGHUP
))
mountfs(spec
, name
, flags
, type
, options
, mntopts
)
char *spec
, *name
, *type
, *options
, *mntopts
;
char execname
[MAXPATHLEN
+ 1], flagval
[12], mntpath
[MAXPATHLEN
];
getstdopts(mntopts
, &flags
);
getstdopts(options
, &flags
);
getstdopts(type
, &flags
);
if (realpath(name
, mntpath
) == 0) {
if (strcmp(name
, "/") == 0)
getufsopts(mntopts
, &flags
);
getufsopts(options
, &flags
);
#define DEFAULT_ROOTUID -2
args
.export
.ex_root
= DEFAULT_ROOTUID
;
args
.export
.ex_flags
= MNT_EXRDONLY
;
args
.export
.ex_flags
= 0;
(void)snprintf(flagval
, sizeof(flagval
), "%d", flags
);
argc
+= getexecopts(mntopts
, &argv
[argc
]);
argc
+= getexecopts(options
, &argv
[argc
]);
snprintf(execname
, sizeof(execname
),
"%s/mount_%s", _PATH_EXECDIR
, mntname
);
(void)printf("exec: %s", execname
);
for (i
= 1; i
< argc
- 1; i
++)
(void)printf(" %s", argv
[i
]);
warn("vfork starting file system");
if (waitpid(pid
, &status
, 0) != -1 &&
WEXITSTATUS(status
) != 0)
return (WEXITSTATUS(status
));
err(1, "cannot exec %s for %s", execname
, name
);
if (!debug
&& 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
)
return (strcmp(fstype
, "ufs") == 0 ? MOUNT_UFS
: 0);
getstdopts(options
, flagp
)
char *opt
, optbuf
[BUFSIZ
];
(void)strcpy(optbuf
, options
);
for (opt
= strtok(optbuf
, ","); opt
; opt
= strtok(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
;
if (!strcasecmp(opt
, "asynchronous")) {
if (!strcasecmp(opt
, "union")) {
(void)fprintf(stderr
, "mount: %s: unknown option\n", opt
);
getufsopts(options
, flagp
)
getexecopts(options
, argv
)
for (opt
= strtok(options
, ","); opt
; opt
= strtok(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
))
badvfstype(vfstype
, vfslist
)
while (*vfslist
!= NULL
) {
if (vfstype
== getmnttype(*vfslist
))
badvfsname(vfsname
, vfslist
)
while (*vfslist
!= NULL
) {
if (strcmp(vfsname
, *vfslist
) == 0)
if (fslist
[0] == 'n' && fslist
[1] == 'o') {
for (i
= 0, nextcp
= fslist
; *nextcp
; nextcp
++)
av
= malloc((size_t)(i
+ 2) * sizeof(char *));
while ((nextcp
= index(nextcp
, ',')) != NULL
) {
"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");