xref: /netbsd-src/lib/libc/sys/mount.2 (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1.\"	$NetBSD: mount.2,v 1.38 2007/11/30 23:01:03 rillig 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 July 14, 2007
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_NOEXEC
85Do not allow files to be executed from the file system.
86.It Dv MNT_NOSUID
87Do not honor setuid or setgid bits on files when executing them.
88.It Dv MNT_NODEV
89Do not interpret special files on the file system.
90.It Dv MNT_UNION
91Union with underlying filesystem instead of obscuring it.
92.It Dv MNT_SYNCHRONOUS
93All I/O to the file system should be done synchronously.
94.It Dv MNT_ASYNC
95All I/O to the file system should be done asynchronously.
96.It Dv MNT_NOCOREDUMP
97Do not allow programs to dump core files on the file system.
98.It Dv MNT_NOATIME
99Never update access time in the file system.
100.It Dv MNT_SYMPERM
101Recognize the permission of symbolic link when reading or traversing.
102.It Dv MNT_NODEVMTIME
103Never update modification time of device files.
104.It Dv MNT_SOFTDEP
105Use soft dependencies.
106.El
107.Pp
108The
109.Dv MNT_UPDATE
110and the
111.Dv MNT_GETARGS
112flags indicate that the mount command is being applied
113to an already mounted file system.
114The
115.Dv MNT_UPDATE
116flag allows the mount flags to be changed without requiring
117that the file system be unmounted and remounted.
118Some file systems may not allow all flags to be changed.
119For example,
120most file systems will not allow a change from read-write to read-only.
121The
122.Dv MNT_GETARGS
123flag does not alter any of the mounted filesystem's properties,
124but returns the filesystem-specific arguments for the currently mounted
125filesystem.
126.Pp
127The
128.Fa type
129argument defines the type of the file system.
130The types of file systems known to the system are defined in
131.Aq Pa sys/mount.h .
132.\" XXX from lite-2:
133.\" The types of filesystems known to the system can be obtained with
134.\" .Xr sysctl 8
135.\" by using the command:
136.\" .Bd -literal -offset indent
137.\" sysctl vfs
138.\" .Ed
139.\" .Pp
140.Fa data
141is a pointer to a structure that contains the type
142specific arguments to mount.
143Some of the currently supported types of file systems and
144their type specific data are:
145.Pp
146.Dv MOUNT_FFS
147.Bd -literal -offset indent -compact
148struct ufs_args {
149      char      *fspec;             /* block special file to mount */
150};
151.Ed
152.Pp
153.Dv MOUNT_NFS
154.Bd -literal -offset indent -compact
155struct nfs_args {
156      int             version;      /* args structure version */
157      struct sockaddr *addr;        /* file server address */
158      int             addrlen;      /* length of address */
159      int             sotype;       /* Socket type */
160      int             proto;        /* and Protocol */
161      u_char          *fh;          /* File handle to be mounted */
162      int             fhsize;       /* Size, in bytes, of fh */
163      int             flags;        /* flags */
164      int             wsize;        /* write size in bytes */
165      int             rsize;        /* read size in bytes */
166      int             readdirsize;  /* readdir size in bytes */
167      int             timeo;        /* initial timeout in .1 secs */
168      int             retrans;      /* times to retry send */
169      int             maxgrouplist; /* Max. size of group list */
170      int             readahead;    /* # of blocks to readahead */
171      int             leaseterm;    /* Term (sec) of lease */
172      int             deadthresh;   /* Retrans threshold */
173      char            *hostname;    /* server's name */
174};
175.Ed
176.Pp
177.Dv MOUNT_MFS
178.Bd -literal -offset indent -compact
179struct mfs_args {
180      char	*fspec;             /* name to export for statfs */
181      struct	export_args30 pad;  /* unused */
182      caddr_t	base;               /* base of file system in mem */
183      u_long	size;               /* size of file system */
184};
185.Ed
186.\" XXX from lite-2:
187.\" The format for these argument structures is described in the
188.\" manual page for each filesystem.
189.\" By convention filesystem manual pages are named
190.\" by prefixing ``mount_'' to the name of the filesystem as returned by
191.\" .Xr sysctl 8 .
192.\" Thus the
193.\" .Nm NFS
194.\" filesystem is described by the
195.\" .Xr mount_nfs 8
196.\" manual page.
197.Pp
198The
199.Fn unmount
200function call disassociates the file system from the specified
201mount point
202.Fa dir .
203.Pp
204The
205.Fa flags
206argument may specify
207.Dv MNT_FORCE
208to specify that the file system should be forcibly unmounted even if files are
209still active.
210Active special devices continue to work,
211but any further accesses to any other active files result in errors
212even if the file system is later remounted.
213.Sh RETURN VALUES
214.Fn mount
215returns the value 0 if the mount was successful,
216the number of bytes written to
217.Ar data
218for
219.Dv MNT_GETARGS ,
220otherwise \-1 is returned and the variable
221.Va errno
222is set to indicate the error.
223.Pp
224.Fn unmount
225returns the value 0 if the unmount succeeded; otherwise \-1 is returned
226and the variable
227.Va errno
228is set to indicate the error.
229.Sh ERRORS
230.Fn mount
231will fail when one of the following occurs:
232.Bl -tag -width Er
233.It Bq Er EPERM
234The caller is not the super-user.
235.It Bq Er ENAMETOOLONG
236A component of a pathname exceeded
237.Dv {NAME_MAX}
238characters, or an entire path name exceeded
239.Dv {PATH_MAX}
240characters.
241.It Bq Er ELOOP
242Too many symbolic links were encountered in translating a pathname.
243.It Bq Er ENOENT
244A component of
245.Fa dir
246does not exist.
247.It Bq Er ENOTDIR
248A component of
249.Ar name
250is not a directory,
251or a path prefix of
252.Ar special
253is not a directory.
254.It Bq Er EBUSY
255Another process currently holds a reference to
256.Fa dir .
257.It Bq Er EFAULT
258.Fa dir
259points outside the process's allocated address space.
260.El
261.Pp
262The following errors can occur for a
263.Em ufs
264file system mount:
265.Bl -tag -width Er
266.It Bq Er ENODEV
267A component of ufs_args
268.Ar fspec
269does not exist.
270.It Bq Er ENOTBLK
271.Ar Fspec
272is not a block device.
273.It Bq Er ENXIO
274The major device number of
275.Ar fspec
276is out of range (this indicates no device driver exists
277for the associated hardware).
278.It Bq Er EBUSY
279.Ar Fspec
280is already mounted.
281.It Bq Er EMFILE
282No space remains in the mount table.
283.It Bq Er EINVAL
284The super block for the file system had a bad magic
285number or an out of range block size.
286.It Bq Er ENOMEM
287Not enough memory was available to read the cylinder
288group information for the file system.
289.It Bq Er EIO
290An I/O error occurred while reading the super block or
291cylinder group information.
292.It Bq Er EFAULT
293.Ar Fspec
294points outside the process's allocated address space.
295.El
296.Pp
297The following errors can occur for a
298.Em nfs
299file system mount:
300.Bl -tag -width Er
301.It Bq Er ETIMEDOUT
302.Em Nfs
303timed out trying to contact the server.
304.It Bq Er EFAULT
305Some part of the information described by nfs_args
306points outside the process's allocated address space.
307.El
308.Pp
309The following errors can occur for a
310.Em mfs
311file system mount:
312.Bl -tag -width Er
313.It Bq Er EMFILE
314No space remains in the mount table.
315.It Bq Er EINVAL
316The super block for the file system had a bad magic
317number or an out of range block size.
318.It Bq Er ENOMEM
319Not enough memory was available to read the cylinder
320group information for the file system.
321.It Bq Er EIO
322A paging error occurred while reading the super block or
323cylinder group information.
324.It Bq Er EFAULT
325.Em Name
326points outside the process's allocated address space.
327.El
328.Pp
329.Fn unmount
330may fail with one of the following errors:
331.Bl -tag -width Er
332.It Bq Er EPERM
333The caller is not the super-user.
334.It Bq Er ENOTDIR
335A component of the path is not a directory.
336.It Bq Er ENAMETOOLONG
337A component of a pathname exceeded
338.Dv {NAME_MAX}
339characters, or an entire path name exceeded
340.Dv {PATH_MAX}
341characters.
342.It Bq Er ELOOP
343Too many symbolic links were encountered in translating the pathname.
344.It Bq Er EINVAL
345The requested directory is not in the mount table.
346.It Bq Er EBUSY
347A process is holding a reference to a file located
348on the file system.
349.It Bq Er EIO
350An I/O error occurred while writing cached file system information.
351.It Bq Er EFAULT
352.Fa dir
353points outside the process's allocated address space.
354.El
355.Pp
356A
357.Em ufs
358or
359.Em mfs
360mount can also fail if the maximum number of file systems are currently
361mounted.
362.Sh SEE ALSO
363.Xr getvfsstat 2 ,
364.Xr nfssvc 2 ,
365.Xr getmntinfo 3 ,
366.Xr symlink 7 ,
367.Xr mount 8 ,
368.Xr sysctl 8 ,
369.Xr umount 8
370.Sh HISTORY
371The
372.Fn mount
373and
374.Fn umount
375(now
376.Fn unmount )
377function calls appeared in
378.At v6 .
379.Pp
380Prior to NetBSD 4.0 the
381.Nm
382call was used to NFS export filesystems.
383This is now done through
384.Fn nfssvc .
385.Pp
386The
387.Dv data_len
388argument was added for NetBSD 5.0.
389.Sh BUGS
390Some of the error codes need translation to more obvious messages.
391.Pp
392Far more filesystems are supported than those those listed.
393