OSDN Git Service

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