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

NAME

6       mount, umount - mount and unmount filesystems
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
15       int umount(const char *target);
16
17       int umount2(const char *target, int flags);
18

DESCRIPTION

20       mount()  attaches  the filesystem specified by source (which is often a
21       device name, but can also be a directory name or a dummy) to the direc‐
22       tory specified by target.
23
24       umount()  and umount2() remove the attachment of the (topmost) filesys‐
25       tem mounted on target.
26
27       Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required
28       to mount and unmount filesystems.
29
30       Since  Linux  2.4  a single filesystem can be visible at multiple mount
31       points, and multiple mounts can be stacked on the same mount point.
32
33       Values for the filesystemtype argument  supported  by  the  kernel  are
34       listed  in  /proc/filesystems  (like  "minix", "ext2", "msdos", "proc",
35       "nfs", "iso9660" etc.).  Further types may become  available  when  the
36       appropriate modules are loaded.
37
38       The  mountflags  argument may have the magic number 0xC0ED (MS_MGC_VAL)
39       in the top 16 bits (this was required in kernel versions prior to  2.4,
40       but  is no longer required and ignored if specified), and various mount
41       flags  (as  defined  in  <linux/fs.h>  for  libc4  and  libc5  and   in
42       <sys/mount.h> for glibc2) in the low order 16 bits:
43
44       MS_BIND
45              (Linux  2.4  onwards)  Perform  a bind mount, making a file or a
46              directory subtree visible at another point within a file system.
47              Bind  mounts may cross file system boundaries and span chroot(2)
48              jails.  The filesystemtype, mountflags, and data  arguments  are
49              ignored.
50
51       MS_DIRSYNC (since Linux 2.5.19)
52              Make  directory  changes on this file system synchronous.  (This
53              property can be obtained for individual directories or  subtrees
54              using chattr(8).)
55
56       MS_MANDLOCK
57              Permit  mandatory locking on files in this file system.  (Manda‐
58              tory locking must still be  enabled  on  a  per-file  basis,  as
59              described in fcntl(2).)
60
61       MS_MOVE
62              Move  a  subtree.   source specifies an existing mount point and
63              target specifies the new location.  The move is  atomic:  at  no
64              point is the subtree unmounted.  The filesystemtype, mountflags,
65              and data arguments are ignored.
66
67       MS_NOATIME
68              Do not update access times for (all types of) files on this file
69              system.
70
71       MS_NODEV
72              Do not allow access to devices (special files) on this file sys‐
73              tem.
74
75       MS_NODIRATIME
76              Do not update access times for directories on this file system.
77
78       MS_NOEXEC
79              Do not allow programs to be executed from this file system.
80
81       MS_NOSUID
82              Do not honour set-user-ID and set-group-ID bits  when  executing
83              programs from this file system.
84
85       MS_RDONLY
86              Mount file system read-only.
87
88       MS_RELATIME(Since Linux 2.6.20)
89              When  a  file  on  this file system is accessed, only update the
90              file's last accessed time (atime) if the current value of  atime
91              is  less  than  or  equal to the file's last modified (mtime) or
92              last status change time (ctime).  This option is useful for pro‐
93              grams,  such  as mutt(1), that need to know when a file has been
94              read since it was last modified.
95
96       MS_REMOUNT
97              Remount an existing mount.  This is allows  you  to  change  the
98              mountflags  and  data  of  an  existing  mount without having to
99              unmount and remount the file system.  source and  target  should
100              be  the  same  values  specified  in  the  initial mount() call;
101              filesystemtype is 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, the following could also be changed:
107              MS_NOSUID, MS_NODEV, MS_NOEXEC.
108
109       MS_SYNCHRONOUS
110              Make writes on this  file  system  synchronous  (as  though  the
111              O_SYNC  flag to open(2) was specified for all file opens to this
112              file system).
113
114       From Linux 2.4 onwards, the MS_NODEV, MS_NOEXEC,  and  MS_NOSUID  flags
115       are  settable  on a per-mount-point basis.  From kernel 2.6.16 onwards,
116       MS_NOATIME and MS_NODIRATIME are also  settable  on  a  per-mount-point
117       basis.   The  MS_RELATIME  flag  is  also settable on a per-mount-point
118       basis.
119
120       The data argument is interpreted by the different file systems.   Typi‐
121       cally it is a string of comma-separated options understood by this file
122       system.  See mount(8) for details of the  options  available  for  each
123       filesystem type.
124
125       Linux  2.1.116  added  the umount2() system call, which, like umount(),
126       unmounts a target, but allows additional flags controlling  the  behav‐
127       iour of the operation. Now there is only one possible flag:
128
129       MNT_FORCE (since Linux 2.1.116)
130              Force  unmount  even  if busy.  This can cause data loss.  (Only
131              for NFS mounts.)
132
133       In previous version of kernel there were two more possible
134              flags: MNT_DETACH (since Linux 2.4.11) Perform a  lazy  unmount:
135              make  the mount point unavailable for new accesses, and actually
136              perform the unmount when the mount point ceases to be busy.
137
138       MNT_EXPIRE (since Linux 2.6.8)
139              Mark the mount point as expired.  If a mount point is  not  cur‐
140              rently  in use, then an initial call to umount2() with this flag
141              fails with the error  EAGAIN,  but  marks  the  mount  point  as
142              expired.   The  mount  point remains expired as long as it isn't
143              accessed by any process.  A  second  umount2()  call  specifying
144              MNT_EXPIRE unmounts an expired mount point.  This flag cannot be
145              specified with either MNT_FORCE or MNT_DETACH.
146

RETURN VALUE

148       On success, zero is returned.  On error, -1 is returned, and  errno  is
149       set appropriately.
150

ERRORS

152       The  error  values  given below result from filesystem type independent
153       errors. Each filesystem type may have its own special  errors  and  its
154       own special behavior.  See the kernel source code for details.
155
156
157       EACCES A component of a path was not searchable. (See also path_resolu‐
158              tion(2).)  Or, mounting a  read-only  filesystem  was  attempted
159              without  giving the MS_RDONLY flag.  Or, the block device source
160              is located on a filesystem mounted with the MS_NODEV option.
161
162       EAGAIN A call to umount2() specifying MNT_EXPIRE successfully marked an
163              unbusy file system as expired.
164
165       EBUSY  source is already mounted. Or, it cannot be remounted read-only,
166              because it still holds files open for writing.  Or, it cannot be
167              mounted  on target because target is still busy (it is the work‐
168              ing directory of some task, the mount point of  another  device,
169              has open files, etc.).  Or, it could not be unmounted because it
170              is busy.
171
172       EFAULT One of the pointer arguments points  outside  the  user  address
173              space.
174
175       EINVAL source  had  an  invalid superblock.  Or, a remount (MS_REMOUNT)
176              was attempted, but source was not  already  mounted  on  target.
177              Or,  a  move (MS_MOVE) was attempted, but source was not a mount
178              point, or was '/'.  Or, an unmount was attempted, but target was
179              not a mount point.  Or, umount2() was called with MNT_EXPIRE and
180              either MNT_DETACH or MNT_FORCE.
181
182       ELOOP  Too many link encountered during  pathname  resolution.   Or,  a
183              move was attempted, while target is a descendant of source.
184
185       EMFILE (In case no block device is required:) Table of dummy devices is
186              full.
187
188       ENAMETOOLONG
189              A pathname was longer than MAXPATHLEN.
190
191       ENODEV filesystemtype not configured in the kernel.
192
193       ENOENT A pathname was empty or had a nonexistent component.
194
195       ENOMEM The kernel could not allocate a free page to copy  filenames  or
196              data into.
197
198       ENOTBLK
199              source is not a block device (and a device was required).
200
201       ENOTDIR
202              The second argument, or a prefix of the first argument, is not a
203              directory.
204
205       ENXIO  The major number of the block device source is out of range.
206
207       EPERM  The caller does not have the required privileges.
208

CONFORMING TO

210       These functions are Linux specific and should not be used  in  programs
211       intended to be portable.
212

HISTORY

214       The  original  umount() function was called as umount(device) and would
215       return ENOTBLK when called with something other than  a  block  device.
216       In  Linux  0.98p4  a  call  umount(dir)  was added, in order to support
217       anonymous devices.  In Linux 2.3.99-pre7 the  call  umount(device)  was
218       removed,  leaving only umount(dir) (since now devices can be mounted in
219       more than one place, so specifying the device does not suffice).
220
221       The original MS_SYNC flag was renamed MS_SYNCHRONOUS in 1.1.69  when  a
222       different MS_SYNC was added to <mman.h>.
223
224       Before  Linux  2.4  an attempt to execute a set-user-ID or set-group-ID
225       program on a filesystem mounted with MS_NOSUID would fail  with  EPERM.
226       Since Linux 2.4 the set-user-ID and set-group-ID bits are just silently
227       ignored in this case.
228

SEE ALSO

230       path_resolution(2), mount(8), umount(8)
231
232
233
234Linux 2.6.12                      2004-05-18                          MOUNT(2)
Impressum