xref: /openbsd/lib/libc/sys/mount.2 (revision 76d0caae)
1.\"	$OpenBSD: mount.2,v 1.50 2021/01/03 18:10:27 rob Exp $
2.\"	$NetBSD: mount.2,v 1.12 1996/02/29 23:47:48 jtc Exp $
3.\"
4.\" Copyright (c) 1980, 1989, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)mount.2	8.2 (Berkeley) 12/11/93
32.\"
33.Dd $Mdocdate: January 3 2021 $
34.Dt MOUNT 2
35.Os
36.Sh NAME
37.Nm mount ,
38.Nm unmount
39.Nd mount or dismount a filesystem
40.Sh SYNOPSIS
41.In sys/types.h
42.In sys/mount.h
43.Ft int
44.Fn mount "const char *type" "const char *dir" "int flags" "void *data"
45.Ft int
46.Fn unmount "const char *dir" "int flags"
47.Sh DESCRIPTION
48The
49.Fn mount
50function grafts
51a filesystem object onto the system file tree
52at the point
53.Fa dir .
54The argument
55.Fa data
56describes the filesystem object to be mounted.
57The argument
58.Fa type
59tells the kernel how to interpret
60.Fa data
61(see
62.Fa type
63below).
64The contents of the filesystem
65become available through the new mount point
66.Fa dir .
67Any files in
68.Fa dir
69at the time
70of a successful mount are swept under the carpet, so to speak, and
71are unavailable until the filesystem is unmounted.
72.Pp
73The following
74.Fa flags
75may be specified to
76suppress default semantics which affect filesystem access.
77.Bl -tag -width MNT_SYNCHRONOUS
78.It Dv MNT_RDONLY
79The filesystem should be treated as read-only:
80even the superuser may not write to it.
81.It Dv MNT_NOATIME
82Do not update the access time on files in the filesystem unless
83the modification or status change times are also being updated.
84.It Dv MNT_NOEXEC
85Do not allow files to be executed from the filesystem.
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 filesystem.
90.It Dv MNT_SYNCHRONOUS
91All I/O to the filesystem should be done synchronously.
92.It Dv MNT_ASYNC
93All I/O to the filesystem should be done asynchronously.
94.It Dv MNT_SOFTDEP
95Use soft dependencies.
96Applies to FFS filesystems only (see 'softdep' in
97.Xr mount 8 ) .
98.It Dv MNT_WXALLOWED
99Processes that ask for memory to be made writeable plus executable
100using the
101.Xr mmap 2
102and
103.Xr mprotect 2
104system calls are killed by default.
105This option allows those processes to continue operation.
106The option is typically used on the
107.Pa /usr/local
108filesystem.
109.El
110.Pp
111The flag
112.Dv MNT_UPDATE
113indicates that the mount command is being applied
114to an already mounted filesystem.
115This allows the mount flags to be changed without requiring
116that the filesystem be unmounted and remounted.
117Some filesystems may not allow all flags to be changed.
118For example,
119most filesystems will not allow a change from read-write to read-only.
120.Pp
121The
122.Fa type
123argument defines the type of the filesystem.
124The types of filesystems known to the system are defined in
125.In sys/mount.h .
126.Fa data
127is a pointer to a structure that contains the type
128specific arguments to mount.
129The currently supported types of filesystems and
130their type specific data are:
131.Pp
132.Dv MOUNT_CD9660
133.Bd -literal -offset indent -compact
134struct iso_args {
135    char	*fspec;	    /* block special device to mount */
136    struct	export_args export_info;
137    			    /* network export info */
138    int	flags;		    /* mounting flags, see below */
139};
140#define	ISOFSMNT_NORRIP	  0x00000001 /* disable Rock Ridge Ext.*/
141#define	ISOFSMNT_GENS	  0x00000002 /* enable generation numbers */
142#define	ISOFSMNT_EXTATT	  0x00000004 /* enable extended attributes */
143#define	ISOFSMNT_NOJOLIET 0x00000008 /* disable Joliet Ext.*/
144#define	ISOFSMNT_SESS	  0x00000010 /* use iso_args.sess */
145.Ed
146.Pp
147.Dv MOUNT_FFS
148.Bd -literal -offset indent -compact
149struct ufs_args {
150      char      *fspec;             /* block special file to mount */
151      struct    export_args export_info;
152      				    /* network export information */
153};
154.Ed
155.Pp
156.Dv MOUNT_MFS
157.Bd -literal -offset indent -compact
158struct mfs_args {
159      char	*fspec;             /* name to export for statfs */
160      struct	export_args export_info;
161      				    /* if we can export an MFS */
162      caddr_t	base;               /* base of filesystem in mem */
163      u_long	size;               /* size of filesystem */
164};
165.Ed
166.Pp
167.Dv MOUNT_MSDOS
168.Bd -literal -offset indent -compact
169struct msdosfs_args {
170	char	*fspec;	   /* blocks special holding fs to mount */
171	struct	export_args export_info;
172			   /* network export information */
173	uid_t	uid;	   /* uid that owns msdosfs files */
174	gid_t	gid;	   /* gid that owns msdosfs files */
175	mode_t  mask;	   /* mask to be applied for msdosfs perms */
176	int	flags;	   /* see below */
177};
178
179/*
180 * Msdosfs mount options:
181 */
182#define	MSDOSFSMNT_SHORTNAME 1  /* Force old DOS short names only */
183#define	MSDOSFSMNT_LONGNAME  2  /* Force Win'95 long names */
184#define	MSDOSFSMNT_NOWIN95   4  /* Completely ignore Win95 entries */
185.Ed
186.Pp
187.Dv MOUNT_NFS
188.Bd -literal -offset indent -compact
189struct nfs_args {
190      int	version;	/* args structure version */
191      struct sockaddr *addr;	/* file server address */
192      int	addrlen;	/* length of address */
193      int	sotype;       	/* Socket type */
194      int	proto;        	/* and Protocol */
195      u_char	*fh;          	/* File handle to be mounted */
196      int	fhsize;       	/* Size, in bytes, of fh */
197      int	flags;        	/* flags */
198      int	wsize;        	/* write size in bytes */
199      int	rsize;        	/* read size in bytes */
200      int	readdirsize;  	/* readdir size in bytes */
201      int	timeo;        	/* initial timeout in .1 secs */
202      int	retrans;      	/* times to retry send */
203      int	maxgrouplist; 	/* Max. size of group list */
204      int	readahead;    	/* # of blocks to readahead */
205      int	leaseterm;    	/* Term (sec) of lease */
206      int	deadthresh;   	/* Retrans threshold */
207      char	*hostname;    	/* server's name */
208      int	acregmin;     /* Attr cache file recently modified */
209      int	acregmax;     	/* ac file not recently modified */
210      int	acdirmin;     	/* ac for dir recently modified */
211      int	acdirmax;     /* ac for dir not recently modified */
212};
213.Ed
214.Pp
215.Dv MOUNT_NTFS
216.Bd -literal -offset indent -compact
217struct ntfs_args {
218        char    *fspec;	/* block special device to mount */
219        struct  export_args export_info;
220			/* network export information */
221        uid_t   uid;	/* uid that owns ntfs files */
222        gid_t   gid;	/* gid that owns ntfs files */
223        mode_t  mode;	/* mask to be applied for ntfs perms */
224        u_long  flag;	/* additional flags */
225};
226
227/*
228 * ntfs mount options:
229 */
230#define     NTFS_MFLAG_CASEINS      0x00000001
231#define     NTFS_MFLAG_ALLNAMES     0x00000002
232.Ed
233.Pp
234.Dv MOUNT_UDF
235.Bd -literal -offset indent -compact
236struct udf_args {
237	char	*fspec;	/* block special device to mount */
238};
239.Ed
240.Pp
241The
242.Fn unmount
243function call disassociates the filesystem from the specified
244mount point
245.Fa dir .
246.Pp
247The
248.Fa flags
249argument may specify
250.Dv MNT_FORCE
251to specify that the filesystem should be forcibly unmounted even if files are
252still active.
253Active special devices continue to work,
254but any further accesses to any other active files result in errors
255even if the filesystem is later remounted.
256.Sh RETURN VALUES
257.Rv -std
258.Sh ERRORS
259.Fn mount
260will fail when one of the following occurs:
261.Bl -tag -width [ENAMETOOLONG]
262.It Bq Er EPERM
263The caller is not the superuser.
264.It Bq Er ENAMETOOLONG
265The pathname exceeded
266.Dv MNAMELEN
267characters.
268.It Bq Er ELOOP
269Too many symbolic links were encountered in translating a pathname.
270.It Bq Er ENOENT
271A component of
272.Fa dir
273does not exist.
274.It Bq Er ENOTDIR
275A component of
276.Ar name
277is not a directory,
278or a path prefix of
279.Ar special
280is not a directory.
281.It Bq Er EINVAL
282An argument given was invalid.
283.It Bq Er EBUSY
284Another process currently holds a reference to
285.Fa dir .
286.It Bq Er EFAULT
287.Fa dir
288points outside the process's allocated address space.
289.It Bq Er EOPNOTSUPP
290.Fa type
291is not supported by the kernel.
292.El
293.Pp
294The following errors can occur for a
295.Dq ufs
296filesystem mount:
297.Bl -tag -width [ENOTBLK]
298.It Bq Er ENODEV
299A component of ufs_args
300.Fa fspec
301does not exist.
302.It Bq Er ENOTBLK
303.Fa fspec
304is not a block device.
305.It Bq Er ENXIO
306The major device number of
307.Fa fspec
308is out of range (this indicates no device driver exists
309for the associated hardware).
310.It Bq Er EBUSY
311.Fa fspec
312is already mounted.
313.It Bq Er EINVAL
314The super block for the filesystem had a bad magic number, an out of range
315block size, or an invalid combination of flags.
316.It Bq Er ENOMEM
317Not enough memory was available to read the cylinder
318group information for the filesystem.
319.It Bq Er EIO
320An I/O error occurred while reading the super block or
321cylinder group information.
322.It Bq Er EFAULT
323.Fa fspec
324points outside the process's allocated address space.
325.It Bq Er EROFS
326The filesystem was not unmounted cleanly and
327.Dv MNT_FORCE
328was not specified.
329.It Bq Er EROFS
330An attempt was made to mount a
331.Bx 4.2
332filesystem without the
333.Dv MNT_RDONLY
334flag.
335.El
336.Pp
337The following errors can occur for an
338.Em NFS
339filesystem mount:
340.Bl -tag -width [ETIMEDOUT]
341.It Bq Er ETIMEDOUT
342.Em NFS
343timed out trying to contact the server.
344.It Bq Er EFAULT
345Some part of the information described by nfs_args
346points outside the process's allocated address space.
347.El
348.Pp
349The following errors can occur for a
350.Em mfs
351filesystem mount:
352.Bl -tag -width [EMFILE]
353.It Bq Er EMFILE
354No space remains in the mount table.
355.It Bq Er EINVAL
356The super block for the filesystem had a bad magic
357number or an out of range block size.
358.It Bq Er ENOMEM
359Not enough memory was available to read the cylinder
360group information for the filesystem.
361.It Bq Er EIO
362A paging error occurred while reading the super block or
363cylinder group information.
364.It Bq Er EFAULT
365.Em Name
366points outside the process's allocated address space.
367.El
368.Pp
369.Fn unmount
370may fail with one of the following errors:
371.Bl -tag -width [ENAMETOOLONG]
372.It Bq Er EPERM
373The caller is not the superuser.
374.It Bq Er ENOTDIR
375A component of the path is not a directory.
376.It Bq Er EINVAL
377An argument given was invalid.
378.It Bq Er ENAMETOOLONG
379A component of a pathname exceeded
380.Dv NAME_MAX
381characters, or an entire pathname (including the terminating NUL)
382exceeded
383.Dv PATH_MAX
384bytes.
385.It Bq Er ELOOP
386Too many symbolic links were encountered in translating the pathname.
387.It Bq Er EINVAL
388The requested directory is not in the mount table.
389.It Bq Er EBUSY
390A process is holding a reference to a file located
391on the filesystem.
392.It Bq Er EIO
393An I/O error occurred while writing cached filesystem information.
394.It Bq Er EFAULT
395.Fa dir
396points outside the process's allocated address space.
397.El
398.Sh SEE ALSO
399.Xr statfs 2 ,
400.Xr mount 8 ,
401.Xr mount_mfs 8 ,
402.Xr umount 8
403.Sh HISTORY
404The
405.Fn mount
406and
407.Fn unmount
408system calls first appeared in
409.At v1 .
410The
411.Fa flags
412argument is supported by
413.Fn mount
414since
415.At v5
416and by
417.Fn unmount
418since
419.Bx 4.3 Reno .
420The current calling convention involving
421.Fa type
422and
423.Fa data
424arguments was introduced by
425.Bx 4.3 Reno
426as well.
427.Sh BUGS
428Some of the error codes need translation to more obvious messages.
429