1mount(2) System Calls mount(2)
2
3
4
6 mount - mount a file system
7
9 #include <sys/types.h>
10 #include <sys/mount.h>
11 #include <sys/mntent.h>
12
13 int mount(const char *spec, const char *dir, int mflag,
14 char *fstype, char *dataptr,int datalen, char *optptr,
15 int optlen);
16
17
19 The mount() function requests that a removable file system contained on
20 the block special file identified by spec be mounted on the directory
21 identified by dir. The spec and dir arguments are pointers to path
22 names.
23
24
25 After a successful call to mount(), all references to the file dir
26 refer to the root directory on the mounted file system. The mounted
27 file system is inserted into the kernel list of all mounted file sys‐
28 tems. This list can be examined through the mounted file system table
29 (see mnttab(4)).
30
31
32 The fstype argument is the file system type name. Standard file system
33 names are defined with the prefix MNTTYPE_ in <sys/mntent.h>. If nei‐
34 ther MS_DATA nor MS_OPTIONSTR is set in mflag, then fstype is ignored
35 and the type of the root file system is assumed.
36
37
38 The dataptr argument is 0 if no file system-specific data is to be
39 passed; otherwise it points to an area of size datalen that contains
40 the file system-specific data for this mount and the MS_DATA flag
41 should be set.
42
43
44 If the MS_OPTIONSTR flag is set, then optptr points to a buffer con‐
45 taining the list of options to be used for this mount. The optlen argu‐
46 ment specifies the length of the buffer. On completion of the mount()
47 call, the options in effect for the mounted file system are returned in
48 this buffer. If MS_OPTIONSTR is not specified, then the options for
49 this mount will not appear in the mounted file systems table.
50
51
52 If the caller does not have all privileges available in the current
53 zone, the nosuid option is automatically set on the mount point. The
54 restrict option is automatically added for autofs mounts.
55
56
57 If the caller is not in the global zone, the nodevices option is auto‐
58 matically set.
59
60
61 The mflag argument is constructed by a bitwise-inclusive-OR of flags
62 from the following list, defined in <sys/mount.h>.
63
64 MS_DATA The dataptr and datalen arguments describe a block of
65 file system-specific binary data at address dataptr of
66 length datalen. This is interpreted by file system-spe‐
67 cific code within the operating system and its format
68 depends on the file system type. If a particular file
69 system type does not require this data, dataptr and
70 datalen should both be 0.
71
72
73 MS_GLOBAL Mount a file system globally if the system is config‐
74 ured and booted as part of a cluster (see clinfo(1M)).
75
76
77 MS_NOSUID Prevent programs that are marked set-user-ID or set-
78 group-ID from executing (see chmod(1)). It also causes
79 open(2) to return ENXIO when attempting to open block
80 or character special files.
81
82
83 MS_OPTIONSTR The optptr and optlen arguments describe a character
84 buffer at address optptr of size optlen. When calling
85 mount(), the character buffer should contain a null-
86 terminated string of options to be passed to the file
87 system-specific code within the operating system. On a
88 successful return, the file system-specific code will
89 return the list of options recognized. Unrecognized
90 options are ignored. The format of the string is a list
91 of option names separated by commas. Options that have
92 values (rather than binary options such as suid or
93 nosuid), are separated by "=" such as dev=2c4046c.
94 Standard option names are defined in <sys/mntent.h>.
95 Only strings defined in the "C" locale are supported.
96 The maximum length option string that can be passed to
97 or returned from a mount() call is defined by the
98 MAX_MNTOPT_STR constant. The buffer should be long
99 enough to contain more options than were passed in, as
100 the state of any default options that were not passed
101 in the input option string may also be returned in the
102 recognized options list that is returned.
103
104
105 MS_OVERLAY Allow the file system to be mounted over an existing
106 file system mounted on dir, making the underlying file
107 system inaccessible. If a mount is attempted on a pre-
108 existing mount point without setting this flag, the
109 mount will fail.
110
111
112 MS_RDONLY Mount the file system for reading only. This flag
113 should also be specified for file systems that are
114 incapable of writing (for example, CDROM). Without this
115 flag, writing is permitted according to individual file
116 accessibility.
117
118
119 MS_REMOUNT Remount a read-only file system as read-write.
120
121
123 Upon successful completion, 0 is returned. Otherwise, −1 is returned
124 and errno is set to indicate the error.
125
127 The mount() function will fail if:
128
129 EACCES The permission bits of the mount point do not permit
130 read/write access or search permission is denied on a
131 component of the path prefix.
132
133 The calling process is not the owner of the mountpoint.
134
135 The mountpoint is not a regular file or a directory and
136 the caller does not have all privileges available in a
137 its zone.
138
139 The special device device does not permit read access
140 in the case of read-only mounts or read-write access in
141 the case of read/write mounts.
142
143
144 EBUSY The dir argument is currently mounted on, is someone's
145 current working directory, or is otherwise busy; or the
146 device associated with spec is currently mounted.
147
148
149 EFAULT The spec, dir, fstype, dataptr, or optptr argument
150 points outside the allocated address space of the
151 process.
152
153
154 EINVAL The super block has an invalid magic number, the fstype
155 is invalid, or dir is not an absolute path.
156
157
158 ELOOP Too many symbolic links were encountered in translating
159 spec or dir.
160
161
162 ENAMETOOLONG The length of the path argument exceeds PATH_MAX, or
163 the length of a path component exceeds NAME_MAX while
164 _POSIX_NO_TRUNC is in effect.
165
166
167 ENOENT None of the named files exists or is a null pathname.
168
169
170 ENOLINK The path argument points to a remote machine and the
171 link to that machine is no longer active.
172
173
174 ENOSPC The file system state in the super-block is not FsOKAY
175 and mflag requests write permission.
176
177
178 ENOTBLK The spec argument is not a block special device.
179
180
181 ENOTDIR The dir argument is not a directory, or a component of
182 a path prefix is not a directory.
183
184
185 ENOTSUP A global mount is attempted (the MS_GLOBAL flag is set
186 in mflag) on a machine which is not booted as a clus‐
187 ter; a local mount is attempted and dir is within a
188 globally mounted file system; or a remount was
189 attempted on a file system that does not support
190 remounting.
191
192
193 ENXIO The device associated with spec does not exist.
194
195
196 EOVERFLOW The length of the option string to be returned in the
197 optptr argument exceeds the size of the buffer speci‐
198 fied by optlen.
199
200
201 EPERM The {PRIV_SYS_MOUNT} privilege is not asserted in the
202 effective set of the calling process.
203
204
205 EREMOTE The spec argument is remote and cannot be mounted.
206
207
208 EROFS The spec argument is write protected and mflag requests
209 write permission.
210
211
213 The mount() function can be invoked only by processes with appropriate
214 privileges.
215
217 mount(1M), umount(2), mnttab(4)
218
220 MS_OPTIONSTR-type option strings should be used.
221
222
223 Some flag bits set file system options that can also be passed in an
224 option string. Options are first set from the option string with the
225 last setting of an option in the string determining the value to be set
226 by the option string. Any options controlled by flags are then applied,
227 overriding any value set by the option string.
228
229
230
231SunOS 5.11 26 Feb 2004 mount(2)