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