1MOUNT(2)                   Linux Programmer's Manual                  MOUNT(2)
2
3
4

NAME

6       mount - mount file system
7

SYNOPSIS

9       #include <sys/mount.h>
10
11       int mount(const char *source, const char *target,
12                 const char *filesystemtype, unsigned long mountflags,
13                 const void *data);
14

DESCRIPTION

16       mount()  attaches the file system specified by source (which is often a
17       device name, but can also be a directory name or a dummy) to the direc‐
18       tory specified by target.
19
20       Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required
21       to mount file systems.
22
23       Since Linux 2.4 a single file system can be visible at  multiple  mount
24       points, and multiple mounts can be stacked on the same mount point.
25
26       Values  for  the  filesystemtype  argument  supported by the kernel are
27       listed in /proc/filesystems  (e.g.,  "minix",  "ext2",  "ext3",  "jfs",
28       "xfs",  "reiserfs",  "msdos", "proc", "nfs", "iso9660").  Further types
29       may become available when the appropriate modules are loaded.
30
31       The mountflags argument may have the magic number  0xC0ED  (MS_MGC_VAL)
32       in  the top 16 bits (this was required in kernel versions prior to 2.4,
33       but is no longer required and ignored if specified), and various  mount
34       flags in the low order 16 bits:
35
36       MS_BIND (Linux 2.4 onward)
37              Perform a bind mount, making a file or a directory subtree visi‐
38              ble at another point within a  file  system.   Bind  mounts  may
39              cross  file  system  boundaries  and  span chroot(2) jails.  The
40              filesystemtype and data arguments are ignored.  Up  until  Linux
41              2.6.26, mountflags was also ignored (the bind mount has the same
42              mount options as the underlying mount point).
43
44       MS_DIRSYNC (since Linux 2.5.19)
45              Make directory changes on this file system  synchronous.   (This
46              property  can be obtained for individual directories or subtrees
47              using chattr(1).)
48
49       MS_MANDLOCK
50              Permit mandatory locking on files in this file system.   (Manda‐
51              tory  locking  must  still  be  enabled  on a per-file basis, as
52              described in fcntl(2).)
53
54       MS_MOVE
55              Move a subtree.  source specifies an existing  mount  point  and
56              target  specifies  the  new location.  The move is atomic: at no
57              point is the subtree unmounted.  The filesystemtype, mountflags,
58              and data arguments are ignored.
59
60       MS_NOATIME
61              Do not update access times for (all types of) files on this file
62              system.
63
64       MS_NODEV
65              Do not allow access to devices (special files) on this file sys‐
66              tem.
67
68       MS_NODIRATIME
69              Do  not update access times for directories on this file system.
70              This flag provides a subset of  the  functionality  provided  by
71              MS_NOATIME; that is, MS_NOATIME implies MS_NODIRATIME.
72
73       MS_NOEXEC
74              Do not allow programs to be executed from this file system.
75
76       MS_NOSUID
77              Do  not  honor  set-user-ID and set-group-ID bits when executing
78              programs from this file system.
79
80       MS_RDONLY
81              Mount file system read-only.
82
83       MS_RELATIME (Since Linux 2.6.20)
84              When a file on this file system is accessed, update  the  file's
85              last  access  time (atime) only if the current value of atime is
86              less than or equal to the file's last modification time  (mtime)
87              or  last  status change time (ctime).  This option is useful for
88              programs, such as mutt(1), that need to know  when  a  file  has
89              been  read  since it was last modified.  Since Linux 2.6.30, the
90              kernel defaults to the behavior provided by  this  flag  (unless
91              MS_NOATIME  was  specified),  and  the  MS_STRICTATIME  flag  is
92              required to obtain traditional semantics.   In  addition,  since
93              Linux  2.6.30,  the file's last access time is always updated if
94              it is more than 1 day old.
95
96       MS_REMOUNT
97              Remount an existing mount.  This allows you to change the mount‐
98              flags  and  data  of an existing mount without having to unmount
99              and remount the file system.  target should be  the  same  value
100              specified in the initial mount() call; source and filesystemtype
101              are ignored.
102
103              The following mountflags can be changed: MS_RDONLY,  MS_SYNCHRO‐
104              NOUS,  MS_MANDLOCK;  before  kernel  2.6.16, the following could
105              also be changed: MS_NOATIME and  MS_NODIRATIME;  and,  addition‐
106              ally, before kernel 2.4.10, the following could also be changed:
107              MS_NOSUID, MS_NODEV, MS_NOEXEC.
108
109       MS_SILENT (since Linux 2.6.17)
110              Suppress the display of certain (printk()) warning  messages  in
111              the  kernel log.  This flag supersedes the misnamed and obsolete
112              MS_VERBOSE flag (available since Linux 2.4.12),  which  has  the
113              same meaning.
114
115       MS_STRICTATIME (Since Linux 2.6.30)
116              Always  update  the  last access time (atime) when files on this
117              file system are accessed.  (This was the default behavior before
118              Linux  2.6.30.)   Specifying  this  flag overrides the effect of
119              setting the MS_NOATIME and MS_RELATIME flags.
120
121       MS_SYNCHRONOUS
122              Make writes on this  file  system  synchronous  (as  though  the
123              O_SYNC  flag to open(2) was specified for all file opens to this
124              file system).
125
126       From Linux 2.4 onward, the MS_NODEV, MS_NOEXEC, and MS_NOSUID flags are
127       settable  on  a  per-mount-point  basis.   From  kernel  2.6.16 onward,
128       MS_NOATIME and MS_NODIRATIME are also  settable  on  a  per-mount-point
129       basis.   The  MS_RELATIME  flag  is  also settable on a per-mount-point
130       basis.
131
132       The data argument is interpreted by the different file systems.   Typi‐
133       cally it is a string of comma-separated options understood by this file
134       system.  See mount(8) for details of the  options  available  for  each
135       filesystem type.
136

RETURN VALUE

138       On  success,  zero is returned.  On error, -1 is returned, and errno is
139       set appropriately.
140

ERRORS

142       The error values given below result from  filesystem  type  independent
143       errors.   Each file-system type may have its own special errors and its
144       own special behavior.  See the Linux kernel source code for details.
145
146       EACCES A component of a path was not searchable.  (See also  path_reso‐
147              lution(7).)   Or, mounting a read-only file system was attempted
148              without giving the MS_RDONLY flag.  Or, the block device  source
149              is located on a file system mounted with the MS_NODEV option.
150
151       EBUSY  source  is  already  mounted.   Or, it cannot be remounted read-
152              only, because it still holds files open  for  writing.   Or,  it
153              cannot  be mounted on target because target is still busy (it is
154              the working directory of some thread, the mount point of another
155              device, has open files, etc.).
156
157       EFAULT One  of  the  pointer  arguments points outside the user address
158              space.
159
160       EINVAL source had an invalid superblock.  Or,  a  remount  (MS_REMOUNT)
161              was  attempted,  but  source  was not already mounted on target.
162              Or, a move (MS_MOVE) was attempted, but source was not  a  mount
163              point, or was '/'.
164
165       ELOOP  Too  many  links  encountered during pathname resolution.  Or, a
166              move was attempted, while target is a descendant of source.
167
168       EMFILE (In case no block device is required:) Table of dummy devices is
169              full.
170
171       ENAMETOOLONG
172              A pathname was longer than MAXPATHLEN.
173
174       ENODEV filesystemtype not configured in the kernel.
175
176       ENOENT A pathname was empty or had a nonexistent component.
177
178       ENOMEM The  kernel  could not allocate a free page to copy filenames or
179              data into.
180
181       ENOTBLK
182              source is not a block device (and a device was required).
183
184       ENOTDIR
185              target, or a prefix of source, is not a directory.
186
187       ENXIO  The major number of the block device source is out of range.
188
189       EPERM  The caller does not have the required privileges.
190

VERSIONS

192       The  definitions  of  MS_DIRSYNC,  MS_MOVE,  MS_REC,  MS_RELATIME,  and
193       MS_STRICTATIME were added to glibc headers in version 2.12.
194

CONFORMING TO

196       This  function  is  Linux-specific  and  should not be used in programs
197       intended to be portable.
198

NOTES

200       The original MS_SYNC flag was renamed MS_SYNCHRONOUS in 1.1.69  when  a
201       different MS_SYNC was added to <mman.h>.
202
203       Before  Linux  2.4  an attempt to execute a set-user-ID or set-group-ID
204       program on a file system mounted with MS_NOSUID would fail with  EPERM.
205       Since Linux 2.4 the set-user-ID and set-group-ID bits are just silently
206       ignored in this case.
207
208   Per-process namespaces
209       Starting with kernel 2.4.19, Linux provides  per-process  mount  names‐
210       paces.   A  mount  namespace  is the set of file system mounts that are
211       visible to a process.  Mount-point namespaces can be (and usually  are)
212       shared  between multiple processes, and changes to the namespace (i.e.,
213       mounts and unmounts) by one process are visible to all other  processes
214       sharing  the  same  namespace.   (The pre-2.4.19 Linux situation can be
215       considered as one in which a  single  namespace  was  shared  by  every
216       process on the system.)
217
218       A child process created by fork(2) shares its parent's mount namespace;
219       the mount namespace is preserved across an execve(2).
220
221       A process can obtain a private mount namespace if: it was created using
222       the  clone(2) CLONE_NEWNS flag, in which case its new namespace is ini‐
223       tialized to be a copy of the  namespace  of  the  process  that  called
224       clone(2);  or  it  calls  unshare(2)  with  the CLONE_NEWNS flag, which
225       causes the caller's mount namespace to obtain a  private  copy  of  the
226       namespace  that it was previously sharing with other processes, so that
227       future mounts and unmounts by the caller are invisible  to  other  pro‐
228       cesses  (except  child  processes that the caller subsequently creates)
229       and vice versa.
230
231       The Linux-specific /proc/PID/mounts file  exposes  the  list  of  mount
232       points in the mount namespace of the process with the specified ID; see
233       proc(5) for details.
234

SEE ALSO

236       umount(2), namespaces(7), path_resolution(7), mount(8), umount(8)
237

COLOPHON

239       This page is part of release 3.53 of the Linux  man-pages  project.   A
240       description  of  the project, and information about reporting bugs, can
241       be found at http://www.kernel.org/doc/man-pages/.
242
243
244
245Linux                             2012-07-05                          MOUNT(2)
Impressum