FreeBSD kernel kern code
vfs_mount.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/libkern.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/mutex.h>
#include <sys/namei.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/filedesc.h>
#include <sys/reboot.h>
#include <sys/sbuf.h>
#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/systm.h>
#include <sys/vnode.h>
#include <vm/uma.h>
#include <geom/geom.h>
#include <machine/stdarg.h>
#include <security/audit/audit.h>
#include <security/mac/mac_framework.h>
Include dependency graph for vfs_mount.c:

Go to the source code of this file.

Data Structures

struct  mount_args
 
struct  unmount_args
 
struct  mntaarg
 
struct  mntarg
 

Macros

#define VFS_MOUNTARG_SIZE_MAX   (1024 * 64)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static int vfs_domount (struct thread *td, const char *fstype, char *fspath, uint64_t fsflags, struct vfsoptlist **optlist)
 
static void free_mntarg (struct mntarg *ma)
 
 SYSCTL_INT (_vfs, OID_AUTO, usermount, CTLFLAG_RW,&usermount, 0,"Unprivileged users may mount and unmount file systems")
 
 MALLOC_DEFINE (M_MOUNT,"mount","vfs mount structure")
 
 MTX_SYSINIT (mountlist,&mountlist_mtx,"mountlist", MTX_DEF)
 
static int mount_init (void *mem, int size, int flags)
 
static void mount_fini (void *mem, int size)
 
static void vfs_mount_init (void *dummy __unused)
 
 SYSINIT (vfs_mount, SI_SUB_VFS, SI_ORDER_ANY, vfs_mount_init, NULL)
 
static void vfs_freeopt (struct vfsoptlist *opts, struct vfsopt *opt)
 
void vfs_freeopts (struct vfsoptlist *opts)
 
void vfs_deleteopt (struct vfsoptlist *opts, const char *name)
 
static int vfs_isopt_ro (const char *opt)
 
static int vfs_isopt_rw (const char *opt)
 
static int vfs_equalopts (const char *opt1, const char *opt2)
 
static void vfs_sanitizeopts (struct vfsoptlist *opts)
 
int vfs_buildopts (struct uio *auio, struct vfsoptlist **options)
 
static void vfs_mergeopts (struct vfsoptlist *toopts, struct vfsoptlist *oldopts)
 
int sys_nmount (struct thread *td, struct nmount_args *uap)
 
void vfs_ref (struct mount *mp)
 
void vfs_rel (struct mount *mp)
 
struct mount * vfs_mount_alloc (struct vnode *vp, struct vfsconf *vfsp, const char *fspath, struct ucred *cred)
 
void vfs_mount_destroy (struct mount *mp)
 
int vfs_donmount (struct thread *td, uint64_t fsflags, struct uio *fsoptions)
 
int sys_mount (struct thread *td, struct mount_args *uap)
 
static int vfs_domount_first (struct thread *td, struct vfsconf *vfsp, char *fspath, struct vnode *vp, uint64_t fsflags, struct vfsoptlist **optlist)
 
static int vfs_domount_update (struct thread *td, struct vnode *vp, uint64_t fsflags, struct vfsoptlist **optlist)
 
int sys_unmount (struct thread *td, struct unmount_args *uap)
 
int dounmount (struct mount *mp, int flags, struct thread *td)
 
void vfs_mount_error (struct mount *mp, const char *fmt,...)
 
void vfs_opterror (struct vfsoptlist *opts, const char *fmt,...)
 
int vfs_filteropt (struct vfsoptlist *opts, const char **legal)
 
int vfs_getopt (struct vfsoptlist *opts, const char *name, void **buf, int *len)
 
int vfs_getopt_pos (struct vfsoptlist *opts, const char *name)
 
char * vfs_getopts (struct vfsoptlist *opts, const char *name, int *error)
 
int vfs_flagopt (struct vfsoptlist *opts, const char *name, uint64_t *w, uint64_t val)
 
int vfs_scanopt (struct vfsoptlist *opts, const char *name, const char *fmt,...)
 
int vfs_setopt (struct vfsoptlist *opts, const char *name, void *value, int len)
 
int vfs_setopt_part (struct vfsoptlist *opts, const char *name, void *value, int len)
 
int vfs_setopts (struct vfsoptlist *opts, const char *name, const char *value)
 
int vfs_copyopt (struct vfsoptlist *opts, const char *name, void *dest, int len)
 
 MALLOC_DECLARE (M_VNODE_MARKER)
 
struct vnode * __mnt_vnode_next (struct vnode **mvp, struct mount *mp)
 
struct vnode * __mnt_vnode_first (struct vnode **mvp, struct mount *mp)
 
void __mnt_vnode_markerfree (struct vnode **mvp, struct mount *mp)
 
int __vfs_statfs (struct mount *mp, struct statfs *sbp)
 
void vfs_mountedfrom (struct mount *mp, const char *from)
 
struct mntargmount_argb (struct mntarg *ma, int flag, const char *name)
 
struct mntargmount_argf (struct mntarg *ma, const char *name, const char *fmt,...)
 
struct mntargmount_argsu (struct mntarg *ma, const char *name, const void *val, int len)
 
struct mntargmount_arg (struct mntarg *ma, const char *name, const void *val, int len)
 
int kernel_mount (struct mntarg *ma, uint64_t flags)
 
int kernel_vmount (int flags,...)
 
void vfs_oexport_conv (const struct oexport_args *oexp, struct export_args *exp)
 

Variables

static int usermount = 0
 
static uma_zone_t mount_zone
 
struct mntlist mountlist = TAILQ_HEAD_INITIALIZER(mountlist)
 
struct mtx mountlist_mtx
 
static const char * global_opts []
 

Macro Definition Documentation

#define VFS_MOUNTARG_SIZE_MAX   (1024 * 64)

Definition at line 71 of file vfs_mount.c.

Referenced by vfs_buildopts().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
struct vnode* __mnt_vnode_first ( struct vnode **  mvp,
struct mount *  mp 
)

Definition at line 1708 of file vfs_mount.c.

References free(), and malloc().

Here is the call graph for this function:

void __mnt_vnode_markerfree ( struct vnode **  mvp,
struct mount *  mp 
)

Definition at line 1751 of file vfs_mount.c.

References free().

Referenced by __mnt_vnode_next().

Here is the call graph for this function:

Here is the caller graph for this function:

struct vnode* __mnt_vnode_next ( struct vnode **  mvp,
struct mount *  mp 
)

Definition at line 1681 of file vfs_mount.c.

References __mnt_vnode_markerfree(), kern_yield(), and should_yield().

Here is the call graph for this function:

int __vfs_statfs ( struct mount *  mp,
struct statfs *  sbp 
)

Definition at line 1769 of file vfs_mount.c.

int dounmount ( struct mount *  mp,
int  flags,
struct thread *  td 
)
static void free_mntarg ( struct mntarg ma)
static

Definition at line 1929 of file vfs_mount.c.

References free(), and mntarg::v.

Referenced by kernel_mount().

Here is the call graph for this function:

Here is the caller graph for this function:

int kernel_mount ( struct mntarg ma,
uint64_t  flags 
)

Definition at line 1946 of file vfs_mount.c.

References mntarg::error, free_mntarg(), mntarg::len, mntarg::v, and vfs_donmount().

Referenced by kernel_vmount(), and parse_mount().

Here is the call graph for this function:

Here is the caller graph for this function:

int kernel_vmount ( int  flags,
  ... 
)

Definition at line 1970 of file vfs_mount.c.

References mntarg::error, kernel_mount(), and mount_arg().

Here is the call graph for this function:

MALLOC_DECLARE ( M_VNODE_MARKER  )
MALLOC_DEFINE ( M_MOUNT  ,
"mount"  ,
"vfs mount structure"   
)
struct mntarg* mount_arg ( struct mntarg ma,
const char *  name,
const void *  val,
int  len 
)

Definition at line 1900 of file vfs_mount.c.

References mntarg::error, mntarg::len, malloc(), name, realloc(), and mntarg::v.

Referenced by kernel_vmount(), mount_argb(), mount_argsu(), parse_mount(), and parse_mountroot_options().

Here is the call graph for this function:

Here is the caller graph for this function:

struct mntarg* mount_argb ( struct mntarg ma,
int  flag,
const char *  name 
)

Definition at line 1819 of file vfs_mount.c.

References mount_arg().

Referenced by sys_mount().

Here is the call graph for this function:

Here is the caller graph for this function:

struct mntarg* mount_argf ( struct mntarg ma,
const char *  name,
const char *  fmt,
  ... 
)

Definition at line 1832 of file vfs_mount.c.

References mntarg::error, mntarg::len, malloc(), name, realloc(), sbuf_data(), sbuf_delete(), sbuf_finish(), sbuf_len(), sbuf_vprintf(), and mntarg::v.

Here is the call graph for this function:

struct mntarg* mount_argsu ( struct mntarg ma,
const char *  name,
const void *  val,
int  len 
)

Definition at line 1874 of file vfs_mount.c.

References mntarg::error, malloc(), and mount_arg().

Referenced by sys_mount().

Here is the call graph for this function:

Here is the caller graph for this function:

static void mount_fini ( void *  mem,
int  size 
)
static

Definition at line 117 of file vfs_mount.c.

References lockdestroy(), and mtx_destroy().

Referenced by vfs_mount_init().

Here is the call graph for this function:

Here is the caller graph for this function:

static int mount_init ( void *  mem,
int  size,
int  flags 
)
static

Definition at line 106 of file vfs_mount.c.

References lockinit(), and mtx_init().

Referenced by vfs_mount_init().

Here is the call graph for this function:

Here is the caller graph for this function:

MTX_SYSINIT ( mountlist  ,
mountlist_mtx,
"mountlist"  ,
MTX_DEF   
)
int sys_mount ( struct thread *  td,
struct mount_args uap 
)

Definition at line 698 of file vfs_mount.c.

References mount_args::data, mntarg::error, mount_args::flags, free(), Giant, malloc(), mount_argb(), mount_argsu(), mount_args::path, mount_args::type, vfs_byname_kld(), and vfsconf.

Here is the call graph for this function:

int sys_nmount ( struct thread *  td,
struct nmount_args *  uap 
)

Definition at line 367 of file vfs_mount.c.

References copyinuio(), free(), and vfs_donmount().

Here is the call graph for this function:

int sys_unmount ( struct thread *  td,
struct unmount_args uap 
)

Definition at line 1131 of file vfs_mount.c.

References dounmount(), free(), Giant, jailed(), malloc(), mountlist, mountlist_mtx, namei(), NDFREE(), priv_check(), sscanf(), usermount, vn_path_to_global_path(), and vput().

Here is the call graph for this function:

SYSCTL_INT ( _vfs  ,
OID_AUTO  ,
usermount  ,
CTLFLAG_RW  ,
usermount,
,
"Unprivileged users may mount and unmount file systems"   
)
SYSINIT ( vfs_mount  ,
SI_SUB_VFS  ,
SI_ORDER_ANY  ,
vfs_mount_init  ,
NULL   
)
int vfs_buildopts ( struct uio *  auio,
struct vfsoptlist **  options 
)

Definition at line 260 of file vfs_mount.c.

References malloc(), vfs_freeopts(), VFS_MOUNTARG_SIZE_MAX, and vfs_sanitizeopts().

Referenced by kern_jail_get(), kern_jail_set(), and vfs_donmount().

Here is the call graph for this function:

Here is the caller graph for this function:

int vfs_copyopt ( struct vfsoptlist *  opts,
const char *  name,
void *  dest,
int  len 
)

Definition at line 1649 of file vfs_mount.c.

Referenced by kern_jail_get(), kern_jail_set(), and vfs_domount_update().

Here is the caller graph for this function:

void vfs_deleteopt ( struct vfsoptlist *  opts,
const char *  name 
)

Definition at line 166 of file vfs_mount.c.

References vfs_freeopt().

Referenced by vfs_export().

Here is the call graph for this function:

Here is the caller graph for this function:

static int vfs_domount ( struct thread *  td,
const char *  fstype,
char *  fspath,
uint64_t  fsflags,
struct vfsoptlist **  optlist 
)
static

Definition at line 1023 of file vfs_mount.c.

References free(), Giant, jailed(), malloc(), namei(), NDFREE(), priv_check(), usermount, vfs_byname(), vfs_byname_kld(), vfs_domount_first(), vfs_domount_update(), vfsconf, and vn_path_to_global_path().

Referenced by vfs_donmount().

Here is the call graph for this function:

Here is the caller graph for this function:

static int vfs_domount_first ( struct thread *  td,
struct vfsconf vfsp,
char *  fspath,
struct vnode *  vp,
uint64_t  fsflags,
struct vfsoptlist **  optlist 
)
static

Definition at line 766 of file vfs_mount.c.

References cache_purge(), Giant, mountcheckdirs(), mountlist, mountlist_mtx, panic(), priv_check_cred(), vfs_allocate_syncvnode(), vfs_event_signal(), vfs_freeopts(), vfs_mount_alloc(), vfs_mount_destroy(), vfs_unbusy(), vinvalbuf(), vput(), and vrele().

Referenced by vfs_domount().

Here is the call graph for this function:

Here is the caller graph for this function:

static int vfs_domount_update ( struct thread *  td,
struct vnode *  vp,
uint64_t  fsflags,
struct vfsoptlist **  optlist 
)
static

Definition at line 878 of file vfs_mount.c.

References flag, Giant, vfs_allocate_syncvnode(), vfs_busy(), vfs_copyopt(), vfs_deallocate_syncvnode(), vfs_export(), vfs_freeopts(), vfs_mergeopts(), vfs_suser(), vfs_unbusy(), vput(), and vrele().

Referenced by vfs_domount().

Here is the call graph for this function:

Here is the caller graph for this function:

int vfs_donmount ( struct thread *  td,
uint64_t  fsflags,
struct uio *  fsoptions 
)

Definition at line 534 of file vfs_mount.c.

References free(), vfs_buildopts(), vfs_domount(), vfs_freeopt(), vfs_freeopts(), vfs_getopt(), and vfs_getopt_pos().

Referenced by kernel_mount(), and sys_nmount().

Here is the call graph for this function:

Here is the caller graph for this function:

static int vfs_equalopts ( const char *  opt1,
const char *  opt2 
)
static

Definition at line 201 of file vfs_mount.c.

References vfs_isopt_ro(), and vfs_isopt_rw().

Referenced by vfs_sanitizeopts().

Here is the call graph for this function:

Here is the caller graph for this function:

int vfs_filteropt ( struct vfsoptlist *  opts,
const char **  legal 
)

Definition at line 1416 of file vfs_mount.c.

References global_opts, printf(), and snprintf().

Here is the call graph for this function:

int vfs_flagopt ( struct vfsoptlist *  opts,
const char *  name,
uint64_t *  w,
uint64_t  val 
)

Definition at line 1536 of file vfs_mount.c.

Referenced by kern_jail_set().

Here is the caller graph for this function:

static void vfs_freeopt ( struct vfsoptlist *  opts,
struct vfsopt *  opt 
)
static

Definition at line 142 of file vfs_mount.c.

References free().

Referenced by vfs_deleteopt(), vfs_donmount(), vfs_freeopts(), and vfs_sanitizeopts().

Here is the call graph for this function:

Here is the caller graph for this function:

void vfs_freeopts ( struct vfsoptlist *  opts)

Definition at line 154 of file vfs_mount.c.

References free(), and vfs_freeopt().

Referenced by kern_jail_get(), kern_jail_set(), vfs_buildopts(), vfs_domount_first(), vfs_domount_update(), vfs_donmount(), and vfs_mount_destroy().

Here is the call graph for this function:

Here is the caller graph for this function:

int vfs_getopt ( struct vfsoptlist *  opts,
const char *  name,
void **  buf,
int *  len 
)

Definition at line 1474 of file vfs_mount.c.

Referenced by kern_jail_get(), kern_jail_set(), vfs_donmount(), vfs_mount_error(), and vfs_opterror().

Here is the caller graph for this function:

int vfs_getopt_pos ( struct vfsoptlist *  opts,
const char *  name 
)

Definition at line 1498 of file vfs_mount.c.

Referenced by kern_jail_get(), kern_jail_set(), and vfs_donmount().

Here is the caller graph for this function:

char* vfs_getopts ( struct vfsoptlist *  opts,
const char *  name,
int *  error 
)

Definition at line 1515 of file vfs_mount.c.

static int vfs_isopt_ro ( const char *  opt)
static

Definition at line 179 of file vfs_mount.c.

Referenced by vfs_equalopts().

Here is the caller graph for this function:

static int vfs_isopt_rw ( const char *  opt)
static

Definition at line 189 of file vfs_mount.c.

Referenced by vfs_equalopts().

Here is the caller graph for this function:

static void vfs_mergeopts ( struct vfsoptlist *  toopts,
struct vfsoptlist *  oldopts 
)
static

Definition at line 344 of file vfs_mount.c.

References malloc(), and vfs_sanitizeopts().

Referenced by vfs_domount_update().

Here is the call graph for this function:

Here is the caller graph for this function:

struct mount* vfs_mount_alloc ( struct vnode *  vp,
struct vfsconf vfsp,
const char *  fspath,
struct ucred *  cred 
)

Definition at line 452 of file vfs_mount.c.

References crdup(), mount_zone, and vfs_busy().

Referenced by vfs_domount_first(), and vfs_mountroot_devfs().

Here is the call graph for this function:

Here is the caller graph for this function:

void vfs_mount_destroy ( struct mount *  mp)

Definition at line 490 of file vfs_mount.c.

References crfree(), mount_zone, panic(), vfs_freeopts(), and wakeup().

Referenced by dounmount(), and vfs_domount_first().

Here is the call graph for this function:

Here is the caller graph for this function:

void vfs_mount_error ( struct mount *  mp,
const char *  fmt,
  ... 
)

Definition at line 1375 of file vfs_mount.c.

References vfs_getopt(), and vsnprintf().

Referenced by vfs_hang_addrlist().

Here is the call graph for this function:

Here is the caller graph for this function:

static void vfs_mount_init ( void *dummy  __unused)
static

Definition at line 127 of file vfs_mount.c.

References mount_fini(), mount_init(), and mount_zone.

Here is the call graph for this function:

void vfs_mountedfrom ( struct mount *  mp,
const char *  from 
)

Definition at line 1780 of file vfs_mount.c.

Referenced by mqfs_mount().

Here is the caller graph for this function:

void vfs_oexport_conv ( const struct oexport_args *  oexp,
struct export_args *  exp 
)

Definition at line 1993 of file vfs_mount.c.

void vfs_opterror ( struct vfsoptlist *  opts,
const char *  fmt,
  ... 
)

Definition at line 1392 of file vfs_mount.c.

References vfs_getopt(), and vsnprintf().

Referenced by kern_jail_get(), and kern_jail_set().

Here is the call graph for this function:

Here is the caller graph for this function:

void vfs_ref ( struct mount *  mp)

Definition at line 429 of file vfs_mount.c.

Referenced by kern_fstatfs(), kern_statfs(), sys_fhopen(), sys_quotactl(), vfs_getvfs(), vn_vget_ino(), and vop_stdgetwritemount().

Here is the caller graph for this function:

void vfs_rel ( struct mount *  mp)

Definition at line 439 of file vfs_mount.c.

Referenced by kern_fstatfs(), kern_statfs(), sys_fhopen(), sys_quotactl(), sysctl_vfs_ctl(), vfs_getnewfsid(), vn_start_secondary_write(), vn_vget_ino(), and vop_stdgetwritemount().

Here is the caller graph for this function:

static void vfs_sanitizeopts ( struct vfsoptlist *  opts)
static

Definition at line 238 of file vfs_mount.c.

References vfs_equalopts(), and vfs_freeopt().

Referenced by vfs_buildopts(), and vfs_mergeopts().

Here is the call graph for this function:

Here is the caller graph for this function:

int vfs_scanopt ( struct vfsoptlist *  opts,
const char *  name,
const char *  fmt,
  ... 
)

Definition at line 1555 of file vfs_mount.c.

References vsscanf().

Here is the call graph for this function:

int vfs_setopt ( struct vfsoptlist *  opts,
const char *  name,
void *  value,
int  len 
)

Definition at line 1580 of file vfs_mount.c.

Referenced by kern_jail_get().

Here is the caller graph for this function:

int vfs_setopt_part ( struct vfsoptlist *  opts,
const char *  name,
void *  value,
int  len 
)

Definition at line 1601 of file vfs_mount.c.

Referenced by kern_jail_get().

Here is the caller graph for this function:

int vfs_setopts ( struct vfsoptlist *  opts,
const char *  name,
const char *  value 
)

Definition at line 1623 of file vfs_mount.c.

Referenced by kern_jail_get().

Here is the caller graph for this function:

Variable Documentation

const char* global_opts[]
static
Initial value:
= {
"errmsg",
"fstype",
"fspath",
"ro",
"rw",
"nosuid",
"noexec",
NULL
}

Definition at line 94 of file vfs_mount.c.

Referenced by vfs_filteropt().

uma_zone_t mount_zone
static

Definition at line 82 of file vfs_mount.c.

Referenced by vfs_mount_alloc(), vfs_mount_destroy(), and vfs_mount_init().

int usermount = 0
static

Definition at line 77 of file vfs_mount.c.

Referenced by sys_unmount(), and vfs_domount().