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