]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/mount.2
Updated FIXME
[thirdparty/man-pages.git] / man2 / mount.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (C) 1993 Rickard E. Faith <faith@cs.unc.edu>
4 .\" and Copyright (C) 1994 Andries E. Brouwer <aeb@cwi.nl>
5 .\" and Copyright (C) 2002, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
6 .\"
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"
27 .\" Modified 1996-11-04 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified 2001-10-13 by Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Added note on historical behavior of MS_NOSUID
30 .\" Modified 2002-05-16 by Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Extensive changes and additions
32 .\" Modified 2002-05-27 by aeb
33 .\" Modified 2002-06-11 by Michael Kerrisk <mtk.manpages@gmail.com>
34 .\" Enhanced descriptions of MS_MOVE, MS_BIND, and MS_REMOUNT
35 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
36 .\" 2005-05-18, mtk, Added MNT_EXPIRE, plus a few other tidy-ups.
37 .\"
38 .TH MOUNT 2 2007-12-17 "Linux" "Linux Programmer's Manual"
39 .SH NAME
40 mount, umount, umount2 \- mount and unmount file systems
41 .SH SYNOPSIS
42 .nf
43 .B "#include <sys/mount.h>"
44 .sp
45 .BI "int mount(const char *" source ", const char *" target ,
46 .BI " const char *" filesystemtype ", unsigned long " mountflags ,
47 .BI " const void *" data );
48 .sp
49 .BI "int umount(const char *" target );
50 .sp
51 .BI "int umount2(const char *" target ", int " flags );
52 .fi
53 .SH DESCRIPTION
54 .BR mount ()
55 attaches the file system specified by
56 .I source
57 (which is often a device name, but can also be a directory name
58 or a dummy) to the directory specified by
59 .IR target .
60
61 .BR umount ()
62 and
63 .BR umount2 ()
64 remove the attachment of the (topmost) file system mounted on
65 .IR target .
66
67 Appropriate privilege (Linux: the
68 .B CAP_SYS_ADMIN
69 capability) is required to mount and unmount file systems.
70
71 Since Linux 2.4 a single file system can be visible at
72 multiple mount points, and multiple mounts can be stacked
73 on the same mount point.
74 .\" Multiple mounts on same mount point: since 2.3.99pre7.
75
76 Values for the
77 .I filesystemtype
78 argument supported by the kernel are listed in
79 .I /proc/filesystems
80 (like "minix", "ext2", "msdos", "proc", "nfs", "iso9660" etc.).
81 Further types may become available when the appropriate modules
82 are loaded.
83
84 The
85 .I mountflags
86 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
87 in the top 16 bits (this was required in kernel versions prior to 2.4, but
88 is no longer required and ignored if specified),
89 and various mount flags (as defined in \fI<linux/fs.h>\fP for libc4 and libc5
90 and in \fI<sys/mount.h>\fP for glibc2) in the low order 16 bits:
91 .\" FIXME 2.6.15 added flags for "shared sub-tree" functionality:
92 .\" MS_UNBINDABLE, MS_PRIVATE, MS_SHARED, MS_SLAVE
93 .\" These need to be documented on this page.
94 .\" See:
95 .\" Documentation/filesystems/sharedsubtree.txt
96 .\"
97 .\" http://lwn.net/Articles/159077/
98 .\"
99 .\" http://myweb.sudhaa.com:2022/~ram/sharedsubtree/paper/sharedsubtree.1.pdf
100 .\" Shared-Subtree Concept, Implementation, and Applications in Linux
101 .\" Al Viro viro@ftp.linux.org.uk
102 .\" Ram Pai linuxram@us.ibm.com
103 .\"
104 .\" http://foss.in/2005/slides/sharedsubtree1.pdf
105 .\" Shared Subtree Concept and Implementation in the Linux Kernel
106 .\" Ram Pai
107 .\"
108 .TP
109 .BR MS_BIND " (Linux 2.4 onwards)"
110 .\" since 2.4.0-test9
111 Perform a bind mount, making a file or a directory subtree visible at
112 another point within a file system.
113 Bind mounts may cross file system boundaries and span
114 .BR chroot (2)
115 jails.
116 The
117 .IR filesystemtype ", " mountflags ", and " data
118 arguments are ignored.
119 .\" with the exception of the "hidden" MS_REC mountflags bit
120 .TP
121 .BR MS_DIRSYNC " (since Linux 2.5.19)"
122 Make directory changes on this file system synchronous.
123 (This property can be obtained for individual directories
124 or subtrees using
125 .BR chattr (1).)
126 .TP
127 .B MS_MANDLOCK
128 Permit mandatory locking on files in this file system.
129 (Mandatory locking must still be enabled on a per-file basis,
130 as described in
131 .BR fcntl (2).)
132 .\" FIXME Say more about MS_MOVE
133 .TP
134 .B MS_MOVE
135 Move a subtree.
136 .I source
137 specifies an existing mount point and
138 .I target
139 specifies the new location.
140 The move is atomic: at no point is the subtree unmounted.
141 The
142 .IR filesystemtype ", " mountflags ", and " data
143 arguments are ignored.
144 .TP
145 .B MS_NOATIME
146 Do not update access times for (all types of) files on this file system.
147 .TP
148 .B MS_NODEV
149 Do not allow access to devices (special files) on this file system.
150 .TP
151 .B MS_NODIRATIME
152 Do not update access times for directories on this file system.
153 This flag provides a subset of the functionality provided by
154 .BR MS_NOATIME ;
155 that is,
156 .BR MS_NOATIME
157 implies
158 .BR MS_NODIRATIME .
159 .TP
160 .B MS_NOEXEC
161 Do not allow programs to be executed from this file system.
162 .\" (Possibly useful for a file system that contains non-Linux executables.
163 .\" Often used as a security feature, e.g., to make sure that restricted
164 .\" users cannot execute files uploaded using ftp or so.)
165 .TP
166 .B MS_NOSUID
167 Do not honor set-user-ID and set-group-ID bits when executing
168 programs from this file system.
169 .\" (This is a security feature to prevent users executing set-user-ID and
170 .\" set-group-ID programs from removable disk devices.)
171 .TP
172 .B MS_RDONLY
173 Mount file system read-only.
174 .\"
175 .\" FIXME Document MS_REC, available since 2.4.11.
176 .\" This flag has meaning in conjunction with MS_BIND and
177 .\" also with the shared sub-tree flags.
178 .TP
179 .BR MS_RELATIME " (Since Linux 2.6.20)"
180 When a file on this file system is accessed,
181 only update the file's last access time (atime) if the current value
182 of atime is less than or equal to the file's last modification (mtime)
183 or last status change time (ctime).
184 This option is useful for programs, such as
185 .BR mutt (1),
186 that need to know when a file has been read since it was last modified.
187 .TP
188 .B MS_REMOUNT
189 Remount an existing mount.
190 This allows you to change the
191 .I mountflags
192 and
193 .I data
194 of an existing mount without having to unmount and remount the file system.
195 .I source
196 and
197 .I target
198 should be the same values specified in the initial
199 .BR mount ()
200 call;
201 .I filesystemtype
202 is ignored.
203
204 The following
205 .I mountflags
206 can be changed:
207 .BR MS_RDONLY ,
208 .BR MS_SYNCHRONOUS ,
209 .BR MS_MANDLOCK ;
210 before kernel 2.6.16, the following could also be changed:
211 .B MS_NOATIME
212 and
213 .BR MS_NODIRATIME ;
214 and, additionally, before kernel 2.4.10, the following could also be changed:
215 .BR MS_NOSUID ,
216 .BR MS_NODEV ,
217 .BR MS_NOEXEC .
218 .TP
219 .B MS_SYNCHRONOUS
220 Make writes on this file system synchronous (as though
221 the
222 .B O_SYNC
223 flag to
224 .BR open (2)
225 was specified for all file opens to this file system).
226 .PP
227 From Linux 2.4 onwards, the
228 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
229 flags are settable on a per-mount-point basis.
230 From kernel 2.6.16 onwards,
231 .B MS_NOATIME
232 and
233 .B MS_NODIRATIME
234 are also settable on a per-mount-point basis.
235 The
236 .B MS_RELATIME
237 flag is also settable on a per-mount-point basis.
238 .PP
239 The
240 .I data
241 argument is interpreted by the different file systems.
242 Typically it is a string of comma-separated options
243 understood by this file system.
244 See
245 .BR mount (8)
246 for details of the options available for each filesystem type.
247 .PP
248 .\" Note: the kernel naming differs from the glibc naming
249 .\" umount2 is the glibc name for what the kernel now calls umount
250 .\" and umount is the glibc name for oldumount
251 Linux 2.1.116 added the
252 .BR umount2 ()
253 system call, which, like
254 .BR umount (),
255 unmounts a target, but allows additional
256 .I flags
257 controlling the behavior of the operation:
258 .TP
259 .BR MNT_FORCE " (since Linux 2.1.116)"
260 Force unmount even if busy.
261 This can cause data loss.
262 (Only for NFS mounts.)
263 .\" FIXME Can MNT_FORCE result in data loss? According to
264 .\" the Solaris manual page it can cause data loss on Solaris.
265 .\" If the same holds on Linux, then this should be documented.
266 .TP
267 .BR MNT_DETACH " (since Linux 2.4.11)"
268 Perform a lazy unmount: make the mount point unavailable for
269 new accesses, and actually perform the unmount when the mount point
270 ceases to be busy.
271 .TP
272 .BR MNT_EXPIRE " (since Linux 2.6.8)"
273 Mark the mount point as expired.
274 If a mount point is not currently in use, then an initial call to
275 .BR umount2 ()
276 with this flag fails with the error
277 .BR EAGAIN ,
278 but marks the mount point as expired.
279 The mount point remains expired as long as it isn't accessed
280 by any process.
281 A second
282 .BR umount2 ()
283 call specifying
284 .B MNT_EXPIRE
285 unmounts an expired mount point.
286 This flag cannot be specified with either
287 .B MNT_FORCE
288 or
289 .BR MNT_DETACH .
290 .SH "RETURN VALUE"
291 On success, zero is returned.
292 On error, \-1 is returned, and
293 .I errno
294 is set appropriately.
295 .SH ERRORS
296 The error values given below result from filesystem type independent
297 errors.
298 Each filesystem type may have its own special errors and its
299 own special behavior.
300 See the kernel source code for details.
301 .TP
302 .B EACCES
303 A component of a path was not searchable.
304 (See also
305 .BR path_resolution (7).)
306 Or, mounting a read-only filesystem was attempted without giving the
307 .B MS_RDONLY
308 flag.
309 Or, the block device
310 .I source
311 is located on a filesystem mounted with the
312 .B MS_NODEV
313 option.
314 .\" mtk: Probably: write permission is required for MS_BIND, with
315 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
316 .TP
317 .B EAGAIN
318 A call to
319 .BR umount2 ()
320 specifying
321 .B MNT_EXPIRE
322 successfully marked an unbusy file system as expired.
323 .TP
324 .B EBUSY
325 .I source
326 is already mounted.
327 Or, it cannot be remounted read-only,
328 because it still holds files open for writing.
329 Or, it cannot be mounted on
330 .I target
331 because
332 .I target
333 is still busy (it is the working directory of some task,
334 the mount point of another device, has open files, etc.).
335 Or, it could not be unmounted because it is busy.
336 .TP
337 .B EFAULT
338 One of the pointer arguments points outside the user address space.
339 .TP
340 .B EINVAL
341 .I source
342 had an invalid superblock.
343 Or, a remount
344 .RB ( MS_REMOUNT )
345 was attempted, but
346 .I source
347 was not already mounted on
348 .IR target .
349 Or, a move
350 .RB ( MS_MOVE )
351 was attempted, but
352 .I source
353 was not a mount point, or was '/'.
354 Or, an unmount was attempted, but
355 .I target
356 was not a mount point.
357 Or,
358 .BR umount2 ()
359 was called with
360 .B MNT_EXPIRE
361 and either
362 .B MNT_DETACH
363 or
364 .BR MNT_FORCE .
365 .TP
366 .B ELOOP
367 Too many link encountered during pathname resolution.
368 Or, a move was attempted, while
369 .I target
370 is a descendant of
371 .IR source .
372 .TP
373 .B EMFILE
374 (In case no block device is required:)
375 Table of dummy devices is full.
376 .TP
377 .B ENAMETOOLONG
378 A pathname was longer than
379 .BR MAXPATHLEN .
380 .TP
381 .B ENODEV
382 .I filesystemtype
383 not configured in the kernel.
384 .TP
385 .B ENOENT
386 A pathname was empty or had a nonexistent component.
387 .TP
388 .B ENOMEM
389 The kernel could not allocate a free page to copy filenames or data into.
390 .TP
391 .B ENOTBLK
392 .I source
393 is not a block device (and a device was required).
394 .TP
395 .B ENOTDIR
396 The second argument, or a prefix of the first argument, is not
397 a directory.
398 .TP
399 .B ENXIO
400 The major number of the block device
401 .I source
402 is out of range.
403 .TP
404 .B EPERM
405 The caller does not have the required privileges.
406 .SH "CONFORMING TO"
407 These functions are Linux-specific and should not be used in
408 programs intended to be portable.
409 .SH NOTES
410 .SS Linux Notes
411 The original
412 .BR umount ()
413 function was called as \fIumount(device)\fP and would return
414 .B ENOTBLK
415 when called with something other than a block device.
416 In Linux 0.98p4 a call \fIumount(dir)\fP was added, in order to
417 support anonymous devices.
418 In Linux 2.3.99-pre7 the call \fIumount(device)\fP was removed,
419 leaving only \fIumount(dir)\fP (since now devices can be mounted
420 in more than one place, so specifying the device does not suffice).
421 .LP
422 The original
423 .B MS_SYNC
424 flag was renamed
425 .B MS_SYNCHRONOUS
426 in 1.1.69
427 when a different
428 .B MS_SYNC
429 was added to \fI<mman.h>\fP.
430 .LP
431 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
432 on a filesystem mounted with
433 .B MS_NOSUID
434 would fail with
435 .BR EPERM .
436 Since Linux 2.4 the set-user-ID and set-group-ID bits are
437 just silently ignored in this case.
438 .\" The change is in patch-2.4.0-prerelease.
439 .SH "SEE ALSO"
440 .BR path_resolution (7),
441 .BR mount (8),
442 .BR umount (8)