diff options
Diffstat (limited to 'sbin/mount')
-rw-r--r-- | sbin/mount/Makefile | 14 | ||||
-rw-r--r-- | sbin/mount/getmntopts.c | 307 | ||||
-rw-r--r-- | sbin/mount/mntopts.3 | 381 | ||||
-rw-r--r-- | sbin/mount/mntopts.h | 111 | ||||
-rw-r--r-- | sbin/mount/mount.8 | 60 | ||||
-rw-r--r-- | sbin/mount/mount.c | 53 | ||||
-rw-r--r-- | sbin/mount/mount_fs.c | 16 | ||||
-rw-r--r-- | sbin/mount/pathnames.h | 2 | ||||
-rw-r--r-- | sbin/mount/vfslist.c | 6 |
9 files changed, 69 insertions, 881 deletions
diff --git a/sbin/mount/Makefile b/sbin/mount/Makefile index 98ac87c2d741..e2a3098813c4 100644 --- a/sbin/mount/Makefile +++ b/sbin/mount/Makefile @@ -1,17 +1,7 @@ -# @(#)Makefile 8.6 (Berkeley) 5/8/95 - PACKAGE=runtime PROG= mount -SRCS= mount.c mount_fs.c getmntopts.c vfslist.c -MAN= mntopts.3 mount.8 -MLINKS+= mntopts.3 getmntopts.3 -MLINKS+= mntopts.3 getmntpoint.3 -MLINKS+= mntopts.3 chkdoreload.3 -MLINKS+= mntopts.3 build_iovec.3 -MLINKS+= mntopts.3 build_iovec_argf.3 -MLINKS+= mntopts.3 free_iovec.3 -MLINKS+= mntopts.3 checkpath.3 -MLINKS+= mntopts.3 rmslashes.3 +SRCS= mount.c mount_fs.c vfslist.c +MAN= mount.8 LIBADD= util xo diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c deleted file mode 100644 index 31987f7b0b78..000000000000 --- a/sbin/mount/getmntopts.c +++ /dev/null @@ -1,307 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if 0 -#ifndef lint -static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95"; -#endif /* not lint */ -#endif -#include <sys/cdefs.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <sys/uio.h> - -#include <err.h> -#include <errno.h> -#include <paths.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "mntopts.h" - -int getmnt_silent = 0; - -void -getmntopts(const char *options, const struct mntopt *m0, int *flagp, - int *altflagp) -{ - const struct mntopt *m; - int negative, len; - char *opt, *optbuf, *p; - int *thisflagp; - - /* Copy option string, since it is about to be torn asunder... */ - if ((optbuf = strdup(options)) == NULL) - err(1, NULL); - - for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { - /* Check for "no" prefix. */ - if (opt[0] == 'n' && opt[1] == 'o') { - negative = 1; - opt += 2; - } else - negative = 0; - - /* - * for options with assignments in them (ie. quotas) - * ignore the assignment as it's handled elsewhere - */ - p = strchr(opt, '='); - if (p != NULL) - *++p = '\0'; - - /* Scan option table. */ - for (m = m0; m->m_option != NULL; ++m) { - len = strlen(m->m_option); - if (strncasecmp(opt, m->m_option, len) == 0) - if (opt[len] == '\0' || opt[len] == '=') - break; - } - - /* Save flag, or fail if option is not recognized. */ - if (m->m_option) { - thisflagp = m->m_altloc ? altflagp : flagp; - if (negative == m->m_inverse) - *thisflagp |= m->m_flag; - else - *thisflagp &= ~m->m_flag; - } else if (!getmnt_silent) { - errx(1, "-o %s: option not supported", opt); - } - } - - free(optbuf); -} - -void -rmslashes(char *rrpin, char *rrpout) -{ - char *rrpoutstart; - - *rrpout = *rrpin; - for (rrpoutstart = rrpout; *rrpin != '\0'; *rrpout++ = *rrpin++) { - - /* skip all double slashes */ - while (*rrpin == '/' && *(rrpin + 1) == '/') - rrpin++; - } - - /* remove trailing slash if necessary */ - if (rrpout - rrpoutstart > 1 && *(rrpout - 1) == '/') - *(rrpout - 1) = '\0'; - else - *rrpout = '\0'; -} - -int -checkpath(const char *path, char *resolved) -{ - struct stat sb; - - if (realpath(path, resolved) == NULL || stat(resolved, &sb) != 0) - return (1); - if (!S_ISDIR(sb.st_mode)) { - errno = ENOTDIR; - return (1); - } - return (0); -} - -int -checkpath_allow_file(const char *path, char *resolved) -{ - struct stat sb; - - if (realpath(path, resolved) == NULL || stat(resolved, &sb) != 0) - return (1); - if (!S_ISDIR(sb.st_mode) && !S_ISREG(sb.st_mode)) { - errno = ENOTDIR; - return (1); - } - return (0); -} - -/* - * Get the mount point information for name. Name may be mount point name - * or device name (with or without /dev/ preprended). - */ -struct statfs * -getmntpoint(const char *name) -{ - struct stat devstat, mntdevstat; - char device[sizeof(_PATH_DEV) - 1 + MNAMELEN]; - char *ddevname; - struct statfs *mntbuf, *statfsp; - int i, mntsize, isdev; - u_long len; - - if (stat(name, &devstat) != 0) - return (NULL); - if (S_ISCHR(devstat.st_mode) || S_ISBLK(devstat.st_mode)) - isdev = 1; - else - isdev = 0; - mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); - for (i = 0; i < mntsize; i++) { - statfsp = &mntbuf[i]; - if (isdev == 0) { - if (strcmp(name, statfsp->f_mntonname)) - continue; - return (statfsp); - } - ddevname = statfsp->f_mntfromname; - if (*ddevname != '/') { - if ((len = strlen(_PATH_DEV) + strlen(ddevname) + 1) > - sizeof(statfsp->f_mntfromname) || - len > sizeof(device)) - continue; - strncpy(device, _PATH_DEV, len); - strncat(device, ddevname, len); - if (stat(device, &mntdevstat) == 0) - strncpy(statfsp->f_mntfromname, device, len); - } - if (stat(ddevname, &mntdevstat) == 0 && - mntdevstat.st_rdev == devstat.st_rdev) - return (statfsp); - } - return (NULL); -} - -/* - * If possible reload a mounted filesystem. - * When prtmsg != NULL print a warning if a reload is attempted, but fails. - * Return 0 on success, 1 on failure. - */ -int -chkdoreload(struct statfs *mntp, - void (*prtmsg)(const char *, ...) __printflike(1,2)) -{ - struct iovec *iov; - int iovlen, error; - char errmsg[255]; - - /* - * If the filesystem is not mounted it does not need to be reloaded. - * If it is mounted for writing, then it could not have been opened - * for writing by a utility, so does not need to be reloaded. - */ - if (mntp == NULL || (mntp->f_flags & MNT_RDONLY) == 0) - return (0); - - /* - * We modified a mounted file system. Do a mount update on - * it so we can continue using it as safely as possible. - */ - iov = NULL; - iovlen = 0; - errmsg[0] = '\0'; - build_iovec(&iov, &iovlen, "fstype", __DECONST(void *, "ffs"), 4); - build_iovec(&iov, &iovlen, "from", mntp->f_mntfromname, (size_t)-1); - build_iovec(&iov, &iovlen, "fspath", mntp->f_mntonname, (size_t)-1); - build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg)); - build_iovec(&iov, &iovlen, "update", NULL, 0); - build_iovec(&iov, &iovlen, "reload", NULL, 0); - /* - * XX: We need the following line until we clean up - * nmount parsing of root mounts and NFS root mounts. - */ - build_iovec(&iov, &iovlen, "ro", NULL, 0); - error = nmount(iov, iovlen, mntp->f_flags); - free_iovec(&iov, &iovlen); - if (error == 0) - return (0); - if (prtmsg != NULL) - prtmsg("mount reload of '%s' failed: %s %s\n\n", - mntp->f_mntonname, strerror(errno), errmsg); - return (1); -} - -void -build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, - size_t len) -{ - int i; - - if (*iovlen < 0) - return; - i = *iovlen; - *iov = realloc(*iov, sizeof **iov * (i + 2)); - if (*iov == NULL) { - *iovlen = -1; - return; - } - (*iov)[i].iov_base = strdup(name); - (*iov)[i].iov_len = strlen(name) + 1; - i++; - (*iov)[i].iov_base = val; - if (len == (size_t)-1) { - if (val != NULL) - len = strlen(val) + 1; - else - len = 0; - } - (*iov)[i].iov_len = (int)len; - *iovlen = ++i; -} - -/* - * This function is needed for compatibility with parameters - * which used to use the mount_argf() command for the old mount() syscall. - */ -void -build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, - const char *fmt, ...) -{ - va_list ap; - char val[255] = { 0 }; - - va_start(ap, fmt); - vsnprintf(val, sizeof(val), fmt, ap); - va_end(ap); - build_iovec(iov, iovlen, name, strdup(val), (size_t)-1); -} - -/* - * Free the iovec and reset to NULL with zero length. Useful for calling - * nmount in a loop. - */ -void -free_iovec(struct iovec **iov, int *iovlen) -{ - int i; - - for (i = 0; i < *iovlen; i += 2) - free((*iov)[i].iov_base); - free(*iov); -} diff --git a/sbin/mount/mntopts.3 b/sbin/mount/mntopts.3 deleted file mode 100644 index 782acabef1a0..000000000000 --- a/sbin/mount/mntopts.3 +++ /dev/null @@ -1,381 +0,0 @@ -.\" Copyright (c) 2023 Marshall Kirk McKusick -.\" Copyright (c) 1994 The Regents of the University of California. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)getmntopts.3 8.3 (Berkeley) 3/30/95 -.\" -.Dd January 19, 2023 -.Dt MNTOPTS 3 -.Os -.Sh NAME -.Nm getmntopts , -.Nm getmntpoint , -.Nm chkdoreload , -.Nm build_iovec , -.Nm build_iovec_argf , -.Nm free_iovec , -.Nm checkpath , -.Nm rmslashes -.Nd "mount point operations" -.Sh SYNOPSIS -.In mntopts.h -.Ft void -.Fo getmntopts -.Fa "const char *options" "const struct mntopt *mopts" -.Fa "int *flagp" "int *altflagp" -.Fc -.Ft struct statfs * -.Fn getmntpoint "const char *name" -.Ft int -.Fo chkdoreload -.Fa "struct statfs *mntp" -.Fa "void (*prtmsg)(const char *fmt, ...)" -.Fc -.Ft void -.Fo build_iovec -.Fa "struct iovec **iov" "int *iovlen" "const char *name" "void *val" -.Fa "size_t len" -.Fc -.Ft void -.Fo build_iovec_argf -.Fa "struct iovec **iov" "int *iovlen" "const char *name" -.Fa "const char *fmt" "..." -.Fc -.Ft void -.Fn free_iovec "struct iovec **iov" "int *iovlen" -.Ft int -.Fn checkpath "const char *path" "char *resolved" -.Ft void -.Fn rmslashes "char *rrpin" "char *rrpout" -.Sh DESCRIPTION -The -.Nm mntopts -functions support operations associated with a mount point. -For historic reasons are in a file in the sources for the -.Xr mount 8 -program. -Thus, to access them the following lines need to be added to the -.Nm Makefile -of the program wanting to use them: -.Bd -literal -SRCS+= getmntopts.c -MOUNT= ${SRCTOP}/sbin/mount -CFLAGS+= -I${MOUNT} -\&.PATH: ${MOUNT} -.Ed -.Pp -The -.Fn getmntopts -function takes a comma separated option list and a list -of valid option names, and computes the bitmask -corresponding to the requested set of options. -.Pp -The string -.Fa options -is broken down into a sequence of comma separated tokens. -Each token is looked up in the table described by -.Fa mopts -and the bits in -the word referenced by either -.Fa flagp -or -.Fa altflagp -(depending on the -.Va m_altloc -field of the option's table entry) -are updated. -The flag words are not initialized by -.Fn getmntopts . -The table, -.Fa mopts , -has the following format: -.Bd -literal -struct mntopt { - char *m_option; /* option name */ - int m_inverse; /* is this a negative option, e.g., "dev" */ - int m_flag; /* bit to set, e.g., MNT_RDONLY */ - int m_altloc; /* non-zero to use altflagp rather than flagp */ -}; -.Ed -.Pp -The members of this structure are: -.Bl -tag -width m_inverse -.It Va m_option -the option name, -for example -.Dq Li suid . -.It Va m_inverse -tells -.Fn getmntopts -that the name has the inverse meaning of the -bit. -For example, -.Dq Li suid -is the string, whereas the -mount flag is -.Dv MNT_NOSUID . -In this case, the sense of the string and the flag -are inverted, so the -.Va m_inverse -flag should be set. -.It Va m_flag -the value of the bit to be set or cleared in -the flag word when the option is recognized. -The bit is set when the option is discovered, -but cleared if the option name was preceded -by the letters -.Dq Li no . -The -.Va m_inverse -flag causes these two operations to be reversed. -.It Va m_altloc -the bit should be set or cleared in -.Fa altflagp -rather than -.Fa flagp . -.El -.Pp -Each of the user visible -.Dv MNT_ -flags has a corresponding -.Dv MOPT_ -macro which defines an appropriate -.Vt "struct mntopt" -entry. -To simplify the program interface and ensure consistency across all -programs, a general purpose macro, -.Dv MOPT_STDOPTS , -is defined which -contains an entry for all the generic VFS options. -In addition, the macros -.Dv MOPT_FORCE -and -.Dv MOPT_UPDATE -exist to enable the -.Dv MNT_FORCE -and -.Dv MNT_UPDATE -flags to be set. -Finally, the table must be terminated by an entry with a -.Dv NULL -first element. -.Pp -The -.Fn getmntpoint -function takes the pathname of a possible mount point -or of a device (with or without -.Pa /dev/ -prepended to it). -If the pathname is a directory or a file, -.Fn getmntpoint -checks to see if the mount point currently has a filesystem -mounted on it. -If the pathname is a device, -.Fn getmntpoint -checks to see if it is currently mounted. -If there is an associated mount, a pointer to a -.Vt "struct statfs" -is returned. -The returned result is stored in a static buffer that is over-written -each time the -.Fn getmntpoint -function or the -.Xr getmntinfo 3 -library routine is called. -If no mount is found, NULL is returned. -.Pp -The -.Fn chkdoreload -function takes a pointer to a -.Vt "struct statfs" . -If the filesystem associated with the mount point is mounted read-only, -.Fn chkdoreload -requests the filesystem to reload all of its metadata from its backing store. -The second parameter is the function to call to print an error message -if the reload fails. -If no error message is desired, a -.Dv NULL -can be passed as the second argument. -The -.Fn chkdoreload -function returns zero on success or non-zero on failure. -.Pp -The -.Fn build_iovec -function adds a parameter to a list of parameters to be passed to the -.Xr nmount 2 -system call. -The parameter list is built up in -.Va iov -and its length is kept in -.Va iovlen . -Before the first call to -.Fn build_iovec , -.Va iov -should be set to -.Dv NULL -and -.Va iovlen -should be set to 0. -The parameter name is passed in -.Va name . -The value of the parameter name is pointed to by -.Va val . -The size of the value is passed in -.Va len . -If the value is a string, a -.Va len -of -1 is passed to indicate that the length should be determined using -.Xr strlen 3 . -If the parameter has no value, -.Va name -should be -.Dv NULL -and -.Va len -should be 0. -.Pp -The -.Fn build_iovec_argf -function adds a formatted parameter to a list of parameters to be passed -to the -.Xr nmount 2 -system call. -The parameter list is built up in -.Va iov -and its length is kept in -.Va iovlen . -Before the first call to -.Fn build_iovec_argf , -.Va iov -should be set to -.Dv NULL -and -.Va iovlen -should be set to 0. -The parameter name is passed in -.Va name . -The value of the parameter name is described by a format string pointed to by -.Va fmt . -If the parameter has no value, -.Va name -should be -.Dv NULL . -.Pp -The -.Fn free_iovec -function frees the memory in the -.Va iov -vector of the length specified in -.Va iovlen -that was previously allocated by the -.Fn build_iovec -and / or -.Fn build_iovec_argf -functions. -The -.Va iov -is set to -.Dv NULL -and the -.Va iovlen -is set to 0 to indicate that the space has been freed. -.Pp -The -.Fn checkpath -function uses -.Xr realpath 3 -to verify that its -.Va path -argument is valid and references a directory. -The -.Fn checkpath -function returns zero on success or non-zero on failure. -.Pp -The -.Fn rmslashes -function removes all double slashes and trailing slashes from its -.Va rrpin -pathname parameter and returns the resulting pathname in its -.Va rrpout -parameter. -.Sh EXAMPLES -Most commands will use the standard option set. -Local file systems which support the -.Dv MNT_UPDATE -flag, would also have an -.Dv MOPT_UPDATE -entry. -This can be declared and used as follows: -.Bd -literal -#include "mntopts.h" - -struct mntopt mopts[] = { - MOPT_STDOPTS, - MOPT_UPDATE, - { NULL } -}; - - ... - mntflags = mntaltflags = 0; - ... - getmntopts(options, mopts, &mntflags, &mntaltflags); - ... -.Ed -.Sh DIAGNOSTICS -If the external integer variable -.Va getmnt_silent -is zero, then the -.Fn getmntopts -function displays an error message and exits if an -unrecognized option is encountered. -Otherwise unrecognized options are silently ignored. -By default -.Va getmnt_silent -is zero. -.Sh SEE ALSO -.Xr err 3 , -.Xr mount 8 , -.Xr nmount 8 -.Sh HISTORY -The -.Fn getmntopts -function appeared in -.Bx 4.4 . -The -.Fn build_iovec , -.Fn build_iovec_argf , -.Fn free_iovec , -.Fn checkpath , -and -.Fn rmslashes -functions were added with -.Xr nmount 8 -in -.Fx 5.0 . -The -.Fn getmntpoint -and -.Fn chkdoreload -functions were added in -.Fx 14.0 . diff --git a/sbin/mount/mntopts.h b/sbin/mount/mntopts.h deleted file mode 100644 index 21d4965ea39b..000000000000 --- a/sbin/mount/mntopts.h +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mntopts.h 8.7 (Berkeley) 3/29/95 - */ - -struct mntopt { - const char *m_option; /* option name */ - int m_inverse; /* if a negative option, e.g. "atime" */ - long long m_flag; /* bit to set, e.g. MNT_RDONLY */ - int m_altloc; /* 1 => set bit in altflags */ -}; - -/* User-visible MNT_ flags. */ -#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 } -#define MOPT_NOATIME { "atime", 1, MNT_NOATIME, 0 } -#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 } -#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 } -#define MOPT_NOSYMFOLLOW { "symfollow", 1, MNT_NOSYMFOLLOW, 0 } -#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 } -#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 } -#define MOPT_UNION { "union", 0, MNT_UNION, 0 } -#define MOPT_USERQUOTA { "userquota", 0, 0, 0 } -#define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 } -#define MOPT_NOCLUSTERR { "clusterr", 1, MNT_NOCLUSTERR, 0 } -#define MOPT_NOCLUSTERW { "clusterw", 1, MNT_NOCLUSTERW, 0 } -#define MOPT_SUIDDIR { "suiddir", 0, MNT_SUIDDIR, 0 } -#define MOPT_SNAPSHOT { "snapshot", 0, MNT_SNAPSHOT, 0 } -#define MOPT_MULTILABEL { "multilabel", 0, MNT_MULTILABEL, 0 } -#define MOPT_ACLS { "acls", 0, MNT_ACLS, 0 } -#define MOPT_NFS4ACLS { "nfsv4acls", 0, MNT_NFS4ACLS, 0 } -#define MOPT_AUTOMOUNTED { "automounted",0, MNT_AUTOMOUNTED, 0 } -#define MOPT_UNTRUSTED { "untrusted", 0, MNT_UNTRUSTED, 0 } - -/* Control flags. */ -#define MOPT_FORCE { "force", 0, MNT_FORCE, 0 } -#define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 } -#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 } -#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 } -#define MOPT_NOCOVER { "cover", 1, MNT_NOCOVER, 0 } -#define MOPT_EMPTYDIR { "emptydir", 0, MNT_EMPTYDIR, 0 } -/* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */ -#define MOPT_AUTO { "auto", 0, 0, 0 } - -/* A handy macro as terminator of MNT_ array. */ -#define MOPT_END { NULL, 0, 0, 0 } - -#define MOPT_FSTAB_COMPAT \ - MOPT_RO, \ - MOPT_RW, \ - MOPT_AUTO - -/* Standard options which all mounts can understand. */ -#define MOPT_STDOPTS \ - MOPT_USERQUOTA, \ - MOPT_GROUPQUOTA, \ - MOPT_FSTAB_COMPAT, \ - MOPT_NOATIME, \ - MOPT_NOEXEC, \ - MOPT_SUIDDIR, /* must be before MOPT_NOSUID */ \ - MOPT_NOSUID, \ - MOPT_NOSYMFOLLOW, \ - MOPT_RDONLY, \ - MOPT_UNION, \ - MOPT_NOCLUSTERR, \ - MOPT_NOCLUSTERW, \ - MOPT_MULTILABEL, \ - MOPT_ACLS, \ - MOPT_NFS4ACLS, \ - MOPT_AUTOMOUNTED, \ - MOPT_UNTRUSTED, \ - MOPT_NOCOVER, \ - MOPT_EMPTYDIR - -void getmntopts(const char *, const struct mntopt *, int *, int *); -void rmslashes(char *, char *); -int checkpath(const char *, char resolved_path[]); -int checkpath_allow_file(const char *, char resolved_path[]); -struct statfs *getmntpoint(const char *); -int chkdoreload(struct statfs *, void (*)(const char *, ...) __printflike(1,2)); -extern int getmnt_silent; -void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, size_t len); -void build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, const char *fmt, ...); -void free_iovec(struct iovec **iovec, int *iovlen); diff --git a/sbin/mount/mount.8 b/sbin/mount/mount.8 index 5632ad678ffb..7bfc21ea41d5 100644 --- a/sbin/mount/mount.8 +++ b/sbin/mount/mount.8 @@ -1,3 +1,6 @@ +.\" +.\" SPDX-License-Identifier: BSD-3-Clause +.\" .\" Copyright (c) 1980, 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -25,9 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)mount.8 8.8 (Berkeley) 6/16/94 -.\" -.Dd March 17, 2022 +.Dd July 16, 2025 .Dt MOUNT 8 .Os .Sh NAME @@ -39,7 +40,7 @@ .Op Fl adflpruvw .Op Fl F Ar fstab .Op Fl o Ar options -.Op Fl t Oo Cm no Oc Ns Cm Ar type Ns Op Cm , Ns Ar type ... +.Op Fl t Oo Cm no Oc Ns Ar type Ns Op , Ns Ar type ... .Nm .Op Fl -libxo .Op Fl dfpruvw @@ -48,7 +49,7 @@ .Op Fl -libxo .Op Fl dfpruvw .Op Fl o Ar options -.Op Fl t Oo Cm no Oc Ns Cm Ar type Ns Op Cm , Ns Ar type ... +.Op Fl t Oo Cm no Oc Ns Ar type Ns Op , Ns Ar type ... .Ar special node .Sh DESCRIPTION The @@ -79,7 +80,7 @@ Generate output via .Xr libxo 3 in a selection of different human and machine readable formats. See -.Xr xo_parse_args 3 +.Xr xo_options 7 for details on command line arguments. .It Fl a All the file systems described in @@ -157,6 +158,9 @@ For this reason, the .Cm async flag should be used sparingly, and only when some data recovery mechanism is present. +.It Cm atime +Update the file access time when reading from a file. +This is the default. .It Cm automounted This flag indicates that the file system was mounted by .Xr automountd 8 . @@ -269,9 +273,11 @@ It is set automatically when the user does not have super-user privileges. Do not follow symlinks on the mounted file system. .It Cm ro -The same as -.Fl r ; -mount the file system read-only (even the super-user may not write it). +Mount the filesystem read-only, even the super-user may not write it. +Equivalent to +.Fl r . +.It Cm rw +Mount the filesystem read-write. .It Cm snapshot Take a snapshot of the specified filesystem. When this option is used, all other options are ignored. @@ -431,7 +437,7 @@ The same as the argument to the .Fl o option. -.It Fl t Oo Cm no Oc Ns Cm Ar type Ns Op Cm , Ns Ar type ... +.It Fl t Oo Cm no Oc Ns Ar type Ns Op , Ns Ar type ... The argument following the .Fl t is used to indicate the file system type. @@ -546,6 +552,10 @@ for more information.) .It Pa /etc/fstab file system table .El +.Sh EXAMPLES +Remount the root filesystem with read-write permissions: +.Pp +.Dl mount -uw / .Sh DIAGNOSTICS Various, most of them are self-explanatory. .Pp @@ -561,15 +571,18 @@ support for a particular file system might be provided either on a static .Xr setfacl 1 , .Xr nmount 2 , .Xr acl 3 , +.Xr getmntinfo 3 , .Xr libxo 3 , -.Xr xo_parse_args 3 , +.Xr xo_options 7 , +.Xr cd9660 4 , +.Xr devfs 4 , +.Xr ext2fs 4 , +.Xr ffs 4 , .Xr mac 4 , -.Xr cd9660 5 , -.Xr devfs 5 , -.Xr ext2fs 5 , +.Xr procfs 4 , +.Xr tarfs 4 , +.Xr tmpfs 4 , .Xr fstab 5 , -.Xr procfs 5 , -.Xr tmpfs 5 , .Xr automount 8 , .Xr fstyp 8 , .Xr kldload 8 , @@ -580,6 +593,7 @@ support for a particular file system might be provided either on a static .Xr mount_smbfs 8 , .Xr mount_udf 8 , .Xr mount_unionfs 8 , +.Xr quotacheck 8 , .Xr umount 8 , .Xr zfs 8 , .Xr zpool 8 @@ -612,3 +626,17 @@ only when the file system is mounted via .Nm . .Sh BUGS It is possible for a corrupted file system to cause a crash. +.Pp +The +.Fl p +option will not list +.Cm userquota +or +.Cm groupquota +items from +.Xr fstab 5 +because they are not true mount options and are not information returned by +.Xr getmntinfo 3 . +At boot +.Xr quotacheck 8 , +processes these items. diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index 2fcc94e40818..496d71b57e4c 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -1,4 +1,4 @@ -/*- +/* * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1980, 1989, 1993, 1994 @@ -29,16 +29,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1980, 1989, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#if 0 -static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95"; -#endif -#endif /* not lint */ - -#include <sys/cdefs.h> #include <sys/param.h> #define _WANT_MNTOPTNAMES #include <sys/mount.h> @@ -46,9 +36,10 @@ static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95"; #include <sys/wait.h> #include <ctype.h> -#include <err.h> + #include <errno.h> #include <fstab.h> +#include <mntopts.h> #include <paths.h> #include <pwd.h> #include <signal.h> @@ -61,12 +52,12 @@ static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95"; #include <libxo/xo.h> #include "extern.h" -#include "mntopts.h" #include "pathnames.h" #define EXIT(a) { \ xo_close_container("mount"); \ - xo_finish(); \ + if (xo_finish() < 0) \ + xo_err(EXIT_FAILURE, "stdout"); \ exit(a); \ } @@ -152,7 +143,7 @@ exec_mountprog(const char *name, const char *execname, char *const argv[]) switch (pid = fork()) { case -1: /* Error. */ xo_warn("fork"); - EXIT(1); + EXIT(EXIT_FAILURE); case 0: /* Child. */ /* Go find an executable. */ execvP(execname, _PATH_SYSPATH, argv); @@ -162,7 +153,7 @@ exec_mountprog(const char *name, const char *execname, char *const argv[]) xo_warnx("in path: %s", _PATH_SYSPATH); } } - EXIT(1); + EXIT(EXIT_FAILURE); default: /* Parent. */ if (waitpid(pid, &status, 0) < 0) { xo_warn("waitpid"); @@ -227,7 +218,7 @@ main(int argc, char *argv[]) argc = xo_parse_args(argc, argv); if (argc < 0) - exit(1); + exit(EXIT_FAILURE); xo_open_container("mount"); while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1) @@ -299,7 +290,7 @@ main(int argc, char *argv[]) if ((init_flags & MNT_UPDATE) && (ro == 0)) options = catopt(options, "noro"); - rval = 0; + rval = EXIT_SUCCESS; switch (argc) { case 0: if ((mntsize = getmntinfo(&mntbuf, @@ -330,7 +321,7 @@ main(int argc, char *argv[]) if (mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, init_flags, options, fs->fs_mntops) && !failok) - rval = 1; + rval = EXIT_FAILURE; } } else if (fstab_style) { xo_open_list("fstab"); @@ -451,7 +442,7 @@ main(int argc, char *argv[]) * If the mount was successfully, and done by root, tell mountd the * good news. */ - if (rval == 0 && getuid() == 0) + if (rval == EXIT_SUCCESS && getuid() == 0) restart_mountd(); EXIT(rval); @@ -891,19 +882,21 @@ usage(void) { xo_error("%s\n%s\n%s\n", -"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]", +"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t [no]type[,type ...]]", " mount [-dfpruvw] special | node", -" mount [-dfpruvw] [-o options] [-t ufs | external_type] special node"); - EXIT(1); +" mount [-dfpruvw] [-o options] [-t [no]type[,type ...]] special node"); + EXIT(EXIT_FAILURE); } void putfsent(struct statfs *ent) { struct fstab *fst; + const char *mntfromname; char *opts, *rw; int l; + mntfromname = ent->f_mntfromname; opts = NULL; /* flags2opts() doesn't return the "rw" option. */ if ((ent->f_flags & MNT_RDONLY) != 0) @@ -914,16 +907,14 @@ putfsent(struct statfs *ent) opts = flags2opts(ent->f_flags); opts = catopt(rw, opts); - if (strncmp(ent->f_mntfromname, "<below>", 7) == 0 || - strncmp(ent->f_mntfromname, "<above>", 7) == 0) { - strlcpy(ent->f_mntfromname, - (strnstr(ent->f_mntfromname, ":", 8) +1), - sizeof(ent->f_mntfromname)); + if (strncmp(mntfromname, "<below>:", 8) == 0 || + strncmp(mntfromname, "<above>:", 8) == 0) { + mntfromname += 8; } - l = strlen(ent->f_mntfromname); + l = strlen(mntfromname); xo_emit("{:device}{P:/%s}{P:/%s}{P:/%s}", - ent->f_mntfromname, + mntfromname, l < 8 ? "\t" : "", l < 16 ? "\t" : "", l < 24 ? "\t" : " "); @@ -939,7 +930,7 @@ putfsent(struct statfs *ent) l < 8 ? "\t" : " "); free(opts); - if ((fst = getfsspec(ent->f_mntfromname))) + if ((fst = getfsspec(mntfromname))) xo_emit("{P:\t}{n:dump/%u}{P: }{n:pass/%u}\n", fst->fs_freq, fst->fs_passno); else if ((fst = getfsfile(ent->f_mntonname))) diff --git a/sbin/mount/mount_fs.c b/sbin/mount/mount_fs.c index 5674e94594bf..30c34ae32f31 100644 --- a/sbin/mount/mount_fs.c +++ b/sbin/mount/mount_fs.c @@ -32,33 +32,19 @@ * SUCH DAMAGE. */ -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1992, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)mount_fs.c 8.6 (Berkeley) 4/26/95"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - #include <sys/param.h> #include <sys/mount.h> #include <err.h> #include <getopt.h> #include <libgen.h> +#include <mntopts.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "extern.h" -#include "mntopts.h" static struct mntopt mopts[] = { MOPT_STDOPTS, diff --git a/sbin/mount/pathnames.h b/sbin/mount/pathnames.h index f584d7ce9f12..169d5384cc7b 100644 --- a/sbin/mount/pathnames.h +++ b/sbin/mount/pathnames.h @@ -27,8 +27,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)pathnames.h 8.2 (Berkeley) 3/27/94 */ #define _PATH_MOUNTDPID "/var/run/mountd.pid" diff --git a/sbin/mount/vfslist.c b/sbin/mount/vfslist.c index 3785451e65b2..ea6086651483 100644 --- a/sbin/mount/vfslist.c +++ b/sbin/mount/vfslist.c @@ -29,12 +29,6 @@ * SUCH DAMAGE. */ -#ifndef lint -#if 0 -static char sccsid[] = "@(#)vfslist.c 8.1 (Berkeley) 5/8/95"; -#endif -#endif /* not lint */ -#include <sys/cdefs.h> #include <err.h> #include <stdlib.h> #include <string.h> |