xref: /netbsd-src/lib/libc/sys/mount.2 (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1.\"	$NetBSD: mount.2,v 1.48 2011/06/17 18:12:32 wiz Exp $
2.\"
3.\" Copyright (c) 1980, 1989, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)mount.2	8.3 (Berkeley) 5/24/95
31.\"
32.Dd June 17, 2011
33.Dt MOUNT 2
34.Os
35.Sh NAME
36.Nm mount ,
37.Nm unmount
38.Nd mount or dismount a file system
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In sys/param.h
43.In sys/mount.h
44.Ft int
45.Fn mount "const char *type" "const char *dir" "int flags" "void *data" "size_t data_len"
46.Ft int
47.Fn unmount "const char *dir" "int flags"
48.Sh DESCRIPTION
49The
50.Fn mount
51function grafts
52a file system object onto the system file tree
53at the point
54.Ar dir .
55The argument
56.Ar data
57describes the file system object to be mounted, and is
58.Ar data_len
59bytes long.
60The argument
61.Ar type
62tells the kernel how to interpret
63.Ar data
64(See
65.Ar type
66below).
67The contents of the file system
68become available through the new mount point
69.Ar dir .
70Any files in
71.Ar dir
72at the time
73of a successful mount are swept under the carpet so to speak, and
74are unavailable until the file system is unmounted.
75.Pp
76The following
77.Ar flags
78may be specified to
79suppress default semantics which affect file system access.
80.Bl -tag -width MNT_SYNCHRONOUS
81.It Dv MNT_RDONLY
82The file system should be treated as read-only;
83even the super-user may not write on it.
84.It Dv MNT_UNION
85Union with underlying filesystem instead of obscuring it.
86.It Dv MNT_HIDDEN
87Cause the
88.Xr df 1
89program, and perhaps others, to, by default,
90exclude this filesystem from its output.
91.It Dv MNT_NOEXEC
92Do not allow files to be executed from the file system.
93.It Dv MNT_NOSUID
94Do not honor setuid or setgid bits on files when executing them.
95.It Dv MNT_NODEV
96Do not interpret special files on the file system.
97.It Dv MNT_NOCOREDUMP
98Do not allow programs to dump core files on the file system.
99.It Dv MNT_NOATIME
100Never update access time in the file system.
101.It Dv MNT_NODEVMTIME
102Never update modification time of device files.
103.It Dv MNT_SYMPERM
104Recognize the permission of symbolic link when reading or traversing.
105.It Dv MNT_SYNCHRONOUS
106All I/O to the file system should be done synchronously.
107This will slow I/O performance considerably, but
108enhances overall filesystem reliability.
109.It Dv MNT_ASYNC
110All I/O to the file system should be done asynchronously.
111This vastly improves I/O throughput,
112but at a cost of making the filesystem likely to be
113completely unrecoverable should the system crash while
114unwritten data is pending in kernel buffers.
115.It Dv MNT_LOG
116Use a filesystem journal.
117.Dv MNT_LOG
118causes a journal (or log) to be created in the
119filesystem, creating a record of meta-data writes to be
120performed, allowing the actual writes to be deferred.
121This improves performance in most cases.
122.It MNT_EXTATTR
123Enable extended attributes, if the filesystem supports them and
124does not enable them by default.
125Currently this is only the case for UFS1.
126.El
127.Pp
128The
129.Dv MNT_UPDATE ,
130.Dv MNT_RELOAD ,
131and
132.Dv MNT_GETARGS
133flags indicate that the mount command is being applied
134to an already mounted file system.
135The
136.Dv MNT_UPDATE
137flag allows the mount flags to be changed without requiring
138that the file system be unmounted and remounted.
139A conversion from read-write to read-only will fail if any files
140are currently open for writing on the filesystem, unless the
141.Dv MNT_FORCE
142flag is also applied.
143Some file systems may not allow all flags to be changed.
144For example,
145some file systems will not allow a change from read-write to read-only.
146The
147.Dv MNT_RELOAD
148flag causes kernel filesystem data to be reloaded from
149the filesystem device.
150It is only permitted on filesystems mounted read-only.
151Its purpose is to notify the system that the filesystem
152data has been modified by some external process.
153The
154.Dv MNT_GETARGS
155flag does not alter any of the mounted filesystem's properties,
156but returns the filesystem-specific arguments for the currently mounted
157filesystem.
158.Pp
159The
160.Fa type
161argument defines the type of the file system.
162The types of file systems known to the system are defined in
163.In sys/mount.h ,
164and those supported by the current running kernel obtained
165using
166.Xr sysctl 8
167to obtain the node
168.\" .Bd -literal -offset indent
169vfs.generic.fstypes.
170.\" XXX from lite-2:
171.\" The types of filesystems known to the system can be obtained with
172.\" .Xr sysctl 8
173.\" by using the command:
174.\" .Bd -literal -offset indent
175.\" sysctl vfs
176.\" .Ed
177.\" .Pp
178.Fa data
179is a pointer to a structure that contains the type
180specific arguments to mount.
181Some of the currently supported types of file systems and
182their type specific data are:
183.Pp
184.Dv MOUNT_FFS
185.Bd -literal -offset indent -compact
186struct ufs_args {
187      char      *fspec;             /* block special file to mount */
188};
189.Ed
190.Pp
191.Dv MOUNT_NFS
192.Bd -literal -offset indent -compact
193struct nfs_args {
194      int             version;      /* args structure version */
195      struct sockaddr *addr;        /* file server address */
196      int             addrlen;      /* length of address */
197      int             sotype;       /* Socket type */
198      int             proto;        /* and Protocol */
199      u_char          *fh;          /* File handle to be mounted */
200      int             fhsize;       /* Size, in bytes, of fh */
201      int             flags;        /* flags */
202      int             wsize;        /* write size in bytes */
203      int             rsize;        /* read size in bytes */
204      int             readdirsize;  /* readdir size in bytes */
205      int             timeo;        /* initial timeout in .1 secs */
206      int             retrans;      /* times to retry send */
207      int             maxgrouplist; /* Max. size of group list */
208      int             readahead;    /* # of blocks to readahead */
209      int             leaseterm;    /* Term (sec) of lease */
210      int             deadthresh;   /* Retrans threshold */
211      char            *hostname;    /* server's name */
212};
213.Ed
214.Pp
215.Dv MOUNT_MFS
216.Bd -literal -offset indent -compact
217struct mfs_args {
218      char	*fspec;             /* name to export for statfs */
219      struct	export_args30 pad;  /* unused */
220      caddr_t	base;               /* base of file system in mem */
221      u_long	size;               /* size of file system */
222};
223.Ed
224.\" XXX from lite-2:
225.\" The format for these argument structures is described in the
226.\" manual page for each filesystem.
227.\" By convention filesystem manual pages are named
228.\" by prefixing ``mount_'' to the name of the filesystem as returned by
229.\" .Xr sysctl 8 .
230.\" Thus the
231.\" .Nm NFS
232.\" filesystem is described by the
233.\" .Xr mount_nfs 8
234.\" manual page.
235.Pp
236The
237.Fn unmount
238function call disassociates the file system from the specified
239mount point
240.Fa dir .
241.Pp
242The
243.Fa flags
244argument may specify
245.Dv MNT_FORCE
246to specify that the file system should be forcibly unmounted even if files are
247still active.
248Active special devices continue to work,
249but any further accesses to any other active files result in errors
250even if the file system is later remounted.
251.Sh RETURN VALUES
252.Fn mount
253returns the value 0 if the mount was successful,
254the number of bytes written to
255.Ar data
256for
257.Dv MNT_GETARGS ,
258otherwise \-1 is returned and the variable
259.Va errno
260is set to indicate the error.
261.Pp
262.Fn unmount
263returns the value 0 if the unmount succeeded; otherwise \-1 is returned
264and the variable
265.Va errno
266is set to indicate the error.
267.Sh ERRORS
268.Fn mount
269will fail when one of the following occurs:
270.Bl -tag -width Er
271.It Bq Er EBUSY
272Another process currently holds a reference to
273.Fa dir ,
274or for an update from read-write to read-only
275there are files on the filesystem open for writes.
276.It Bq Er EFAULT
277.Fa dir
278points outside the process's allocated address space.
279.It Bq Er ELOOP
280Too many symbolic links were encountered in translating a pathname.
281.It Bq Er ENAMETOOLONG
282A component of a pathname exceeded
283.Brq Dv NAME_MAX
284characters, or an entire path name exceeded
285.Brq Dv PATH_MAX
286characters.
287.It Bq Er ENOENT
288A component of
289.Fa dir
290does not exist.
291.It Bq Er ENOTDIR
292A component of
293.Ar name
294is not a directory,
295or a path prefix of
296.Ar special
297is not a directory.
298.It Bq Er EPERM
299The caller is not the super-user,
300and ordinary user mounts are not permitted or
301this particular request violates the rules.
302.El
303.Pp
304The following errors can occur for a
305.Em ufs
306file system mount:
307.Bl -tag -width Er
308.It Bq Er EBUSY
309.Ar Fspec
310is already mounted.
311.It Bq Er EFAULT
312.Ar Fspec
313points outside the process's allocated address space.
314.It Bq Er EINVAL
315The super block for the file system had a bad magic
316number or an out of range block size.
317.It Bq Er EIO
318An I/O error occurred while reading the super block or
319cylinder group information.
320.It Bq Er EMFILE
321No space remains in the mount table.
322.It Bq Er ENODEV
323A component of ufs_args
324.Ar fspec
325does not exist.
326.It Bq Er ENOMEM
327Not enough memory was available to read the cylinder
328group information for the file system.
329.It Bq Er ENOTBLK
330.Ar Fspec
331is not a block device.
332.It Bq Er ENXIO
333The major device number of
334.Ar fspec
335is out of range (this indicates no device driver exists
336for the associated hardware).
337.El
338.Pp
339The following errors can occur for a
340.Em nfs
341file system mount:
342.Bl -tag -width Er
343.It Bq Er EFAULT
344Some part of the information described by nfs_args
345points outside the process's allocated address space.
346.It Bq Er ETIMEDOUT
347.Em Nfs
348timed out trying to contact the server.
349.El
350.Pp
351The following errors can occur for a
352.Em mfs
353file system mount:
354.Bl -tag -width Er
355.It Bq Er EFAULT
356.Em Name
357points outside the process's allocated address space.
358.It Bq Er EINVAL
359The super block for the file system had a bad magic
360number or an out of range block size.
361.It Bq Er EIO
362A paging error occurred while reading the super block or
363cylinder group information.
364.It Bq Er EMFILE
365No space remains in the mount table.
366.It Bq Er ENOMEM
367Not enough memory was available to read the cylinder
368group information for the file system.
369.El
370.Pp
371.Fn unmount
372may fail with one of the following errors:
373.Bl -tag -width Er
374.It Bq Er EBUSY
375A process is holding a reference to a file located
376on the file system.
377.It Bq Er EFAULT
378.Fa dir
379points outside the process's allocated address space.
380.It Bq Er EINVAL
381The requested directory is not in the mount table.
382.It Bq Er EIO
383An I/O error occurred while writing cached file system information.
384.It Bq Er ELOOP
385Too many symbolic links were encountered in translating the pathname.
386.It Bq Er ENAMETOOLONG
387A component of a pathname exceeded
388.Brq Dv NAME_MAX
389characters, or an entire path name exceeded
390.Brq Dv PATH_MAX
391characters.
392.It Bq Er ENOTDIR
393A component of the path is not a directory.
394.It Bq Er EPERM
395The caller is not the super-user.
396.El
397.Pp
398A
399.Em ufs
400or
401.Em mfs
402mount can also fail if the maximum number of file systems are currently
403mounted.
404.Sh SEE ALSO
405.Xr df 1 ,
406.Xr getvfsstat 2 ,
407.Xr nfssvc 2 ,
408.Xr getmntinfo 3 ,
409.Xr symlink 7 ,
410.Xr mount 8 ,
411.Xr sysctl 8 ,
412.Xr umount 8
413.Sh HISTORY
414The
415.Fn mount
416and
417.Fn umount
418(now
419.Fn unmount )
420function calls were all present in
421.At v6 .
422.Pp
423Prior to
424.Nx 4.0
425the
426.Nm
427call was used to export NFS filesystems.
428This is now done through
429.Fn nfssvc .
430.Pp
431The
432.Dv data_len
433argument was added for
434.Nx 5.0 .
435.Sh BUGS
436Some of the error codes need translation to more obvious messages.
437.Pp
438Far more filesystems are supported than those those listed.
439