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