OSDN Git Service

(split) LDP: Update original to LDP v3.41.
[linuxjm/LDP_man-pages.git] / original / 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 .\" 2008-10-06, mtk: move umount*() material into separate umount.2 page.
38 .\" 2008-10-06, mtk: Add discussion of namespaces.
39 .\"
40 .TH MOUNT 2 2012-05-10 "Linux" "Linux Programmer's Manual"
41 .SH NAME
42 mount \- mount file system
43 .SH SYNOPSIS
44 .nf
45 .B "#include <sys/mount.h>"
46 .sp
47 .BI "int mount(const char *" source ", const char *" target ,
48 .BI "          const char *" filesystemtype ", unsigned long " mountflags ,
49 .BI "          const void *" data );
50 .fi
51 .SH DESCRIPTION
52 .BR mount ()
53 attaches the file system specified by
54 .I source
55 (which is often a device name, but can also be a directory name
56 or a dummy) to the directory specified by
57 .IR target .
58
59 Appropriate privilege (Linux: the
60 .B CAP_SYS_ADMIN
61 capability) is required to mount file systems.
62
63 Since Linux 2.4 a single file system can be visible at
64 multiple mount points, and multiple mounts can be stacked
65 on the same mount point.
66 .\" Multiple mounts on same mount point: since 2.3.99pre7.
67
68 Values for the
69 .I filesystemtype
70 argument supported by the kernel are listed in
71 .I /proc/filesystems
72 (e.g., "minix", "ext2", "ext3", "jfs", "xfs", "reiserfs",
73 "msdos", "proc", "nfs", "iso9660").
74 Further types may become available when the appropriate modules
75 are loaded.
76
77 The
78 .I mountflags
79 argument may have the magic number 0xC0ED (\fBMS_MGC_VAL\fP)
80 in the top 16 bits (this was required in kernel versions prior to 2.4, but
81 is no longer required and ignored if specified),
82 and various mount flags
83 .\" (as defined in \fI<linux/fs.h>\fP for libc4 and libc5
84 .\" and in \fI<sys/mount.h>\fP for glibc2)
85 in the low order 16 bits:
86 .\" FIXME 2.6.15 added flags for "shared subtree" functionality:
87 .\" MS_UNBINDABLE, MS_PRIVATE, MS_SHARED, MS_SLAVE
88 .\" These need to be documented on this page.
89 .\" See:
90 .\" Documentation/filesystems/sharedsubtree.txt
91 .\"
92 .\" http://lwn.net/Articles/159077/
93 .\"
94 .\" http://myweb.sudhaa.com:2022/~ram/sharedsubtree/paper/sharedsubtree.1.pdf
95 .\" Shared-Subtree Concept, Implementation, and Applications in Linux
96 .\" Al Viro viro@ftp.linux.org.uk
97 .\" Ram Pai linuxram@us.ibm.com
98 .\"
99 .\" http://foss.in/2005/slides/sharedsubtree1.pdf
100 .\" Shared Subtree Concept and Implementation in the Linux Kernel
101 .\" Ram Pai
102 .\"
103 .\" 2.6.25 Added MS_I_VERSION, which needs to be documented.
104 .\"
105 .TP
106 .BR MS_BIND " (Linux 2.4 onward)"
107 .\" since 2.4.0-test9
108 Perform a bind mount, making a file or a directory subtree visible at
109 another point within a file system.
110 Bind mounts may cross file system boundaries and span
111 .BR chroot (2)
112 jails.
113 The
114 .IR filesystemtype
115 and
116 .IR data
117 arguments are ignored.
118 Up until Linux 2.6.26,
119 .I mountflags
120 was also ignored
121 .\" with the exception of the "hidden" MS_REC mountflags bit
122 (the bind mount has the same mount options as
123 the underlying mount point).
124 .TP
125 .BR MS_DIRSYNC " (since Linux 2.5.19)"
126 Make directory changes on this file system synchronous.
127 (This property can be obtained for individual directories
128 or subtrees using
129 .BR chattr (1).)
130 .TP
131 .B MS_MANDLOCK
132 Permit mandatory locking on files in this file system.
133 (Mandatory locking must still be enabled on a per-file basis,
134 as described in
135 .BR fcntl (2).)
136 .\" FIXME Say more about MS_MOVE
137 .TP
138 .B MS_MOVE
139 Move a subtree.
140 .I source
141 specifies an existing mount point and
142 .I target
143 specifies the new location.
144 The move is atomic: at no point is the subtree unmounted.
145 The
146 .IR filesystemtype ", " mountflags ", and " data
147 arguments are ignored.
148 .TP
149 .B MS_NOATIME
150 Do not update access times for (all types of) files on this file system.
151 .TP
152 .B MS_NODEV
153 Do not allow access to devices (special files) on this file system.
154 .TP
155 .B MS_NODIRATIME
156 Do not update access times for directories on this file system.
157 This flag provides a subset of the functionality provided by
158 .BR MS_NOATIME ;
159 that is,
160 .BR MS_NOATIME
161 implies
162 .BR MS_NODIRATIME .
163 .TP
164 .B MS_NOEXEC
165 Do not allow programs to be executed from this file system.
166 .\" (Possibly useful for a file system that contains non-Linux executables.
167 .\" Often used as a security feature, e.g., to make sure that restricted
168 .\" users cannot execute files uploaded using ftp or so.)
169 .TP
170 .B MS_NOSUID
171 Do not honor set-user-ID and set-group-ID bits when executing
172 programs from this file system.
173 .\" (This is a security feature to prevent users executing set-user-ID and
174 .\" set-group-ID programs from removable disk devices.)
175 .TP
176 .B MS_RDONLY
177 Mount file system read-only.
178 .\"
179 .\" FIXME Document MS_REC, available since 2.4.11.
180 .\" This flag has meaning in conjunction with MS_BIND and
181 .\" also with the shared subtree flags.
182 .TP
183 .BR MS_RELATIME " (Since Linux 2.6.20)"
184 When a file on this file system is accessed,
185 only update the file's last access time (atime) if the current value
186 of atime is less than or equal to the file's last modification time (mtime)
187 or last status change time (ctime).
188 This option is useful for programs, such as
189 .BR mutt (1),
190 that need to know when a file has been read since it was last modified.
191 Since Linux 2.6.30, the kernel defaults to the behavior provided
192 by this flag (unless
193 .BR MS_NOATIME
194 was specified), and the
195 .B MS_STRICTATIME
196 flag is required to obtain traditional semantics.
197 In addition, since Linux 2.6.30,
198 the file's last access time is always updated if it
199 is more than 1 day old.
200 .\" Matthew Garrett notes in the patch that added this behavior
201 .\" that this lets utilities such as tmpreaper (which deletes
202 .\" files based on last acces time) work correctly.
203 .TP
204 .B MS_REMOUNT
205 Remount an existing mount.
206 This allows you to change the
207 .I mountflags
208 and
209 .I data
210 of an existing mount without having to unmount and remount the file system.
211 .I source
212 and
213 .I target
214 should be the same values specified in the initial
215 .BR mount ()
216 call;
217 .I filesystemtype
218 is ignored.
219
220 The following
221 .I mountflags
222 can be changed:
223 .BR MS_RDONLY ,
224 .BR MS_SYNCHRONOUS ,
225 .BR MS_MANDLOCK ;
226 before kernel 2.6.16, the following could also be changed:
227 .B MS_NOATIME
228 and
229 .BR MS_NODIRATIME ;
230 and, additionally, before kernel 2.4.10, the following could also be changed:
231 .BR MS_NOSUID ,
232 .BR MS_NODEV ,
233 .BR MS_NOEXEC .
234 .TP
235 .BR MS_SILENT " (since Linux 2.6.17)"
236 Suppress the display of certain
237 .RI ( printk ())
238 warning messages in the kernel log.
239 This flag supersedes the misnamed and obsolete
240 .BR MS_VERBOSE
241 flag (available since Linux 2.4.12), which has the same meaning.
242 .TP
243 .BR MS_STRICTATIME " (Since Linux 2.6.30)"
244 Always update the last access time (atime) when files on this
245 file system are accessed.
246 (This was the default behavior before Linux 2.6.30.)
247 Specifying this flag overrides the effect of setting the
248 .BR MS_NOATIME
249 and
250 .BR MS_RELATIME
251 flags.
252 .TP
253 .B MS_SYNCHRONOUS
254 Make writes on this file system synchronous (as though
255 the
256 .B O_SYNC
257 flag to
258 .BR open (2)
259 was specified for all file opens to this file system).
260 .PP
261 From Linux 2.4 onward, the
262 .BR MS_NODEV ", " MS_NOEXEC ", and " MS_NOSUID
263 flags are settable on a per-mount-point basis.
264 From kernel 2.6.16 onward,
265 .B MS_NOATIME
266 and
267 .B MS_NODIRATIME
268 are also settable on a per-mount-point basis.
269 The
270 .B MS_RELATIME
271 flag is also settable on a per-mount-point basis.
272 .PP
273 The
274 .I data
275 argument is interpreted by the different file systems.
276 Typically it is a string of comma-separated options
277 understood by this file system.
278 See
279 .BR mount (8)
280 for details of the options available for each filesystem type.
281 .SH "RETURN VALUE"
282 On success, zero is returned.
283 On error, \-1 is returned, and
284 .I errno
285 is set appropriately.
286 .SH ERRORS
287 The error values given below result from filesystem type independent
288 errors.
289 Each file-system type may have its own special errors and its
290 own special behavior.
291 See the kernel source code for details.
292 .TP
293 .B EACCES
294 A component of a path was not searchable.
295 (See also
296 .BR path_resolution (7).)
297 Or, mounting a read-only file system was attempted without giving the
298 .B MS_RDONLY
299 flag.
300 Or, the block device
301 .I source
302 is located on a file system mounted with the
303 .B MS_NODEV
304 option.
305 .\" mtk: Probably: write permission is required for MS_BIND, with
306 .\" the error EPERM if not present; CAP_DAC_OVERRIDE is required.
307 .TP
308 .B EBUSY
309 .I source
310 is already mounted.
311 Or, it cannot be remounted read-only,
312 because it still holds files open for writing.
313 Or, it cannot be mounted on
314 .I target
315 because
316 .I target
317 is still busy (it is the working directory of some thread,
318 the mount point of another device, has open files, etc.).
319 .TP
320 .B EFAULT
321 One of the pointer arguments points outside the user address space.
322 .TP
323 .B EINVAL
324 .I source
325 had an invalid superblock.
326 Or, a remount
327 .RB ( MS_REMOUNT )
328 was attempted, but
329 .I source
330 was not already mounted on
331 .IR target .
332 Or, a move
333 .RB ( MS_MOVE )
334 was attempted, but
335 .I source
336 was not a mount point, or was \(aq/\(aq.
337 .TP
338 .B ELOOP
339 Too many links encountered during pathname resolution.
340 Or, a move was attempted, while
341 .I target
342 is a descendant of
343 .IR source .
344 .TP
345 .B EMFILE
346 (In case no block device is required:)
347 Table of dummy devices is full.
348 .TP
349 .B ENAMETOOLONG
350 A pathname was longer than
351 .BR MAXPATHLEN .
352 .TP
353 .B ENODEV
354 .I filesystemtype
355 not configured in the kernel.
356 .TP
357 .B ENOENT
358 A pathname was empty or had a nonexistent component.
359 .TP
360 .B ENOMEM
361 The kernel could not allocate a free page to copy filenames or data into.
362 .TP
363 .B ENOTBLK
364 .I source
365 is not a block device (and a device was required).
366 .TP
367 .B ENOTDIR
368 .IR target ,
369 or a prefix of
370 .IR source ,
371 is not a directory.
372 .TP
373 .B ENXIO
374 The major number of the block device
375 .I source
376 is out of range.
377 .TP
378 .B EPERM
379 The caller does not have the required privileges.
380 .SH VERSIONS
381 The definitions of
382 .BR MS_DIRSYNC ,
383 .BR MS_MOVE ,
384 .BR MS_REC ,
385 .BR MS_RELATIME ,
386 and
387 .BR MS_STRICTATIME
388 were only added to glibc headers in version 2.12.
389 .\" FIXME: Definitions of the so-far-undocumented MS_UNBINDABLE, MS_PRIVATE,
390 .\"  MS_SHARED, and MS_SLAVE were (also) only added to glibc headers in 2.12.
391 .SH "CONFORMING TO"
392 This function is Linux-specific and should not be used in
393 programs intended to be portable.
394 .SH NOTES
395 The original
396 .B MS_SYNC
397 flag was renamed
398 .B MS_SYNCHRONOUS
399 in 1.1.69
400 when a different
401 .B MS_SYNC
402 was added to \fI<mman.h>\fP.
403 .LP
404 Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program
405 on a file system mounted with
406 .B MS_NOSUID
407 would fail with
408 .BR EPERM .
409 Since Linux 2.4 the set-user-ID and set-group-ID bits are
410 just silently ignored in this case.
411 .\" The change is in patch-2.4.0-prerelease.
412 .SS Per-process Namespaces
413 Starting with kernel 2.4.19, Linux provides
414 per-process mount namespaces.
415 A mount namespace is the set of file system mounts that
416 are visible to a process.
417 Mount-point namespaces can be (and usually are)
418 shared between multiple processes,
419 and changes to the namespace (i.e., mounts and unmounts) by one process
420 are visible to all other processes sharing the same namespace.
421 (The pre-2.4.19 Linux situation can be considered as one in which
422 a single namespace was shared by every process on the system.)
423
424 A child process created by
425 .BR fork (2)
426 shares its parent's mount namespace;
427 the mount namespace is preserved across an
428 .BR execve (2).
429
430 A process can obtain a private mount namespace if:
431 it was created using the
432 .BR clone (2)
433 .BR CLONE_NEWNS
434 flag,
435 in which case its new namespace is initialized to be a
436 .I copy
437 of the namespace of the process that called
438 .BR clone (2);
439 or it calls
440 .BR unshare (2)
441 with the
442 .BR CLONE_NEWNS
443 flag,
444 which causes the caller's mount namespace to obtain a private copy
445 of the namespace that it was previously sharing with other processes,
446 so that future mounts and unmounts by the caller are invisible
447 to other processes (except child processes that the caller
448 subsequently creates) and vice versa.
449
450 The Linux-specific
451 .I /proc/PID/mounts
452 file exposes the list of mount points in the mount
453 namespace of the process with the specified ID; see
454 .BR proc (5)
455 for details.
456 .SH "SEE ALSO"
457 .BR umount (2),
458 .BR path_resolution (7),
459 .BR mount (8),
460 .BR umount (8)