initial commit
[glibc.git] / sysdeps / unix / bsd / bsd4.4 / kfreebsd / sys / mount.h
1 /* Header file for handling mounted filesystems. FreeBSD version.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20 #ifndef _SYS_MOUNT_H
21 #define _SYS_MOUNT_H 1
22
23 #include <features.h>
24
25 /* Retrieving the list of mounted filesystems. */
26
27 #include <sys/stat.h>
28 #include <sys/statfs.h>
29 #include <sys/ucred.h>
30 #include <sys/queue.h>
31
32 /* For getvfsbyname. */
33 #include <stddef.h>
34 #include <sys/mount.h>
35 #include <sys/sysctl.h>
36 #include <errno.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 /*
41 * File identifier.
42 * These are unique per filesystem on a single machine.
43 */
44 #define MAXFIDSZ 16
45
46 struct fid {
47 __u_short fid_len; /* length of data in bytes */
48 __u_short fid_reserved; /* force longword alignment */
49 char fid_data[MAXFIDSZ]; /* data (variable length) */
50 };
51
52 /*
53 * filesystem statistics
54 */
55 #define MFSNAMELEN 16 /* length of type name including null */
56 #define MNAMELEN 88 /* size of on/from name bufs */
57 #define STATFS_VERSION 0x20030518 /* current version number */
58
59
60 /*
61 * User specifiable flags.
62 */
63 #define MNT_RDONLY 0x0000000000000001ULL /* read only filesystem */
64 #define MNT_SYNCHRONOUS 0x0000000000000002ULL /* fs written synchronously */
65 #define MNT_NOEXEC 0x0000000000000004ULL /* can't exec from filesystem */
66 #define MNT_NOSUID 0x0000000000000008ULL /* don't honor setuid fs bits */
67 #define MNT_NFS4ACLS 0x0000000000000010ULL /* enable NFS version 4 ACLs */
68 #define MNT_UNION 0x0000000000000020ULL /* union with underlying fs */
69 #define MNT_ASYNC 0x0000000000000040ULL /* fs written asynchronously */
70 #define MNT_SUIDDIR 0x0000000000100000ULL /* special SUID dir handling */
71 #define MNT_SOFTDEP 0x0000000000200000ULL /* using soft updates */
72 #define MNT_NOSYMFOLLOW 0x0000000000400000ULL /* do not follow symlinks */
73 #define MNT_GJOURNAL 0x0000000002000000ULL /* GEOM journal support enabled */
74 #define MNT_MULTILABEL 0x0000000004000000ULL /* MAC support for objects */
75 #define MNT_ACLS 0x0000000008000000ULL /* ACL support enabled */
76 #define MNT_NOATIME 0x0000000010000000ULL /* dont update file access time */
77 #define MNT_NOCLUSTERR 0x0000000040000000ULL /* disable cluster read */
78 #define MNT_NOCLUSTERW 0x0000000080000000ULL /* disable cluster write */
79 #define MNT_SUJ 0x0000000100000000ULL /* using journaled soft updates */
80
81 /*
82 * NFS export related mount flags.
83 */
84 #define MNT_EXRDONLY 0x0000000000000080ULL /* exported read only */
85 #define MNT_EXPORTED 0x0000000000000100ULL /* filesystem is exported */
86 #define MNT_DEFEXPORTED 0x0000000000000200ULL /* exported to the world */
87 #define MNT_EXPORTANON 0x0000000000000400ULL /* anon uid mapping for all */
88 #define MNT_EXKERB 0x0000000000000800ULL /* exported with Kerberos */
89 #define MNT_EXPUBLIC 0x0000000020000000ULL /* public export (WebNFS) */
90
91 /*
92 * Flags set by internal operations,
93 * but visible to the user.
94 * XXX some of these are not quite right.. (I've never seen the root flag set)
95 */
96 #define MNT_LOCAL 0x0000000000001000ULL /* filesystem is stored locally */
97 #define MNT_QUOTA 0x0000000000002000ULL /* quotas are enabled on fs */
98 #define MNT_ROOTFS 0x0000000000004000ULL /* identifies the root fs */
99 #define MNT_USER 0x0000000000008000ULL /* mounted by a user */
100 #define MNT_IGNORE 0x0000000000800000ULL /* do not show entry in df */
101
102 /*
103 * Mask of flags that are visible to statfs().
104 * XXX I think that this could now become (~(MNT_CMDFLAGS))
105 * but the 'mount' program may need changing to handle this.
106 */
107 #define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \
108 MNT_NOSUID | MNT_UNION | MNT_SUJ | \
109 MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \
110 MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \
111 MNT_LOCAL | MNT_USER | MNT_QUOTA | \
112 MNT_ROOTFS | MNT_NOATIME | MNT_NOCLUSTERR| \
113 MNT_NOCLUSTERW | MNT_SUIDDIR | MNT_SOFTDEP | \
114 MNT_IGNORE | MNT_EXPUBLIC | MNT_NOSYMFOLLOW | \
115 MNT_GJOURNAL | MNT_MULTILABEL | MNT_ACLS | \
116 MNT_NFS4ACLS)
117
118 /* Mask of flags that can be updated. */
119 #define MNT_UPDATEMASK (MNT_NOSUID | MNT_NOEXEC | \
120 MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | \
121 MNT_NOATIME | \
122 MNT_NOSYMFOLLOW | MNT_IGNORE | \
123 MNT_NOCLUSTERR | MNT_NOCLUSTERW | MNT_SUIDDIR | \
124 MNT_ACLS | MNT_USER | MNT_NFS4ACLS)
125
126 /*
127 * External filesystem command modifier flags.
128 * Unmount can use the MNT_FORCE flag.
129 * XXX These are not STATES and really should be somewhere else.
130 */
131 #define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
132 #define MNT_DELEXPORT 0x00020000 /* delete export host lists */
133 #define MNT_RELOAD 0x00040000 /* reload filesystem data */
134 #define MNT_FORCE 0x00080000 /* force unmount or readonly change */
135 #define MNT_SNAPSHOT 0x01000000 /* snapshot the filesystem */
136 #define MNT_BYFSID 0x08000000 /* specify filesystem by ID. */
137 #define MNT_CMDFLAGS (MNT_UPDATE | MNT_DELEXPORT | MNT_RELOAD | \
138 MNT_FORCE | MNT_SNAPSHOT | MNT_BYFSID)
139 /*
140 * Internal filesystem control flags stored in mnt_kern_flag.
141 *
142 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
143 * past the mount point. This keeps the subtree stable during mounts
144 * and unmounts.
145 *
146 * MNTK_UNMOUNTF permits filesystems to detect a forced unmount while
147 * dounmount() is still waiting to lock the mountpoint. This allows
148 * the filesystem to cancel operations that might otherwise deadlock
149 * with the unmount attempt (used by NFS).
150 */
151 #define MNTK_UNMOUNTF 0x00000001 /* forced unmount in progress */
152 #define MNTK_ASYNC 0x00000002 /* filtered async flag */
153 #define MNTK_SOFTDEP 0x00000004 /* async disabled by softdep */
154 #define MNTK_NOINSMNTQ 0x00000008 /* insmntque is not allowed */
155 #define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
156 #define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */
157 #define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */
158 #define MNTK_SUSPEND2 0x04000000 /* block secondary writes */
159 #define MNTK_SUSPEND 0x08000000 /* request write suspension */
160 #define MNTK_SUSPENDED 0x10000000 /* write operations are suspended */
161 #define MNTK_MPSAFE 0x20000000 /* Filesystem is MPSAFE. */
162 #define MNTK_NOKNOTE 0x80000000 /* Don't send KNOTEs from VOP hooks */
163 #define MNTK_LOOKUP_SHARED 0x40000000 /* FS supports shared lock lookups */
164
165 /*
166 * Sysctl CTL_VFS definitions.
167 *
168 * Second level identifier specifies which filesystem. Second level
169 * identifier VFS_VFSCONF returns information about all filesystems.
170 * Second level identifier VFS_GENERIC is non-terminal.
171 */
172 #define VFS_VFSCONF 0 /* get configured filesystems */
173 #define VFS_GENERIC 0 /* generic filesystem information */
174 /*
175 * Third level identifiers for VFS_GENERIC are given below; third
176 * level identifiers for specific filesystems are given in their
177 * mount specific header files.
178 */
179 #define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
180 #define VFS_CONF 2 /* struct: vfsconf for filesystem given
181 as next argument */
182
183 /*
184 * Flags for various system call interfaces.
185 *
186 * waitfor flags to vfs_sync() and getfsstat()
187 */
188 #define MNT_WAIT 1 /* synchronously wait for I/O to complete */
189 #define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
190 #define MNT_LAZY 3 /* push data not written by filesystem syncer */
191 #define MNT_SUSPEND 4 /* Suspend file system after sync */
192
193 /*
194 * Generic file handle
195 */
196 struct fhandle {
197 __fsid_t fh_fsid; /* Filesystem id of mount point */
198 struct fid fh_fid; /* Filesys specific id */
199 };
200 typedef struct fhandle fhandle_t;
201
202 /*
203 * Old export arguments without security flavor list
204 */
205 struct oexport_args {
206 int ex_flags; /* export related flags */
207 uid_t ex_root; /* mapping for root uid */
208 struct xucred ex_anon; /* mapping for anonymous user */
209 struct sockaddr *ex_addr; /* net address to which exported */
210 __u_char ex_addrlen; /* and the net address length */
211 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
212 __u_char ex_masklen; /* and the smask length */
213 char *ex_indexfile; /* index file for WebNFS URLs */
214 };
215
216 /*
217 * Export arguments for local filesystem mount calls.
218 */
219 #define MAXSECFLAVORS 5
220 struct export_args {
221 int ex_flags; /* export related flags */
222 uid_t ex_root; /* mapping for root uid */
223 struct xucred ex_anon; /* mapping for anonymous user */
224 struct sockaddr *ex_addr; /* net address to which exported */
225 __u_char ex_addrlen; /* and the net address length */
226 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
227 __u_char ex_masklen; /* and the smask length */
228 char *ex_indexfile; /* index file for WebNFS URLs */
229 int ex_numsecflavors; /* security flavor count */
230 int ex_secflavors[MAXSECFLAVORS]; /* list of security flavors */
231 };
232
233 /*
234 * Structure holding information for a publicly exported filesystem
235 * (WebNFS). Currently the specs allow just for one such filesystem.
236 */
237 struct nfs_public {
238 int np_valid; /* Do we hold valid information */
239 fhandle_t np_handle; /* Filehandle for pub fs (internal) */
240 struct mount *np_mount; /* Mountpoint of exported fs */
241 char *np_index; /* Index file */
242 };
243
244 /*
245 * Filesystem configuration information. One of these exists for each
246 * type of filesystem supported by the kernel. These are searched at
247 * mount time to identify the requested filesystem.
248 *
249 * XXX: Never change the first two arguments!
250 */
251 struct vfsconf {
252 __u_int vfc_version; /* ABI version number */
253 char vfc_name[MFSNAMELEN]; /* filesystem type name */
254 struct vfsops *vfc_vfsops; /* filesystem operations vector */
255 int vfc_typenum; /* historic filesystem type number */
256 int vfc_refcount; /* number mounted of this type */
257 int vfc_flags; /* permanent flags */
258 struct vfsoptdecl *vfc_opts; /* mount options */
259 TAILQ_ENTRY(vfsconf) vfc_list; /* list of vfscons */
260 };
261
262 /* Userland version of the struct vfsconf. */
263 struct xvfsconf {
264 struct vfsops *vfc_vfsops; /* filesystem operations vector */
265 char vfc_name[MFSNAMELEN]; /* filesystem type name */
266 int vfc_typenum; /* historic filesystem type number */
267 int vfc_refcount; /* number mounted of this type */
268 int vfc_flags; /* permanent flags */
269 struct vfsconf *vfc_next; /* next in list */
270 };
271
272 #ifndef BURN_BRIDGES
273 struct ovfsconf {
274 void *vfc_vfsops;
275 char vfc_name[32];
276 int vfc_index;
277 int vfc_refcount;
278 int vfc_flags;
279 };
280 #endif
281
282 /*
283 * NB: these flags refer to IMPLEMENTATION properties, not properties of
284 * any actual mounts; i.e., it does not make sense to change the flags.
285 */
286 #define VFCF_STATIC 0x00010000 /* statically compiled into kernel */
287 #define VFCF_NETWORK 0x00020000 /* may get data over the network */
288 #define VFCF_READONLY 0x00040000 /* writes are not implemented */
289 #define VFCF_SYNTHETIC 0x00080000 /* data does not represent real files */
290 #define VFCF_LOOPBACK 0x00100000 /* aliases some other mounted FS */
291 #define VFCF_UNICODE 0x00200000 /* stores file names as Unicode*/
292 #define VFCF_JAIL 0x00400000 /* can be mounted from within a jail */
293
294 typedef u_int32_t fsctlop_t;
295
296 struct vfsidctl {
297 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */
298 __fsid_t vc_fsid; /* fsid to operate on. */
299 char vc_fstypename[MFSNAMELEN];
300 /* type of fs 'nfs' or '*' */
301 fsctlop_t vc_op; /* operation VFS_CTL_* (below) */
302 void *vc_ptr; /* pointer to data structure. */
303 size_t vc_len; /* sizeof said structure. */
304 u_int32_t vc_spare[12]; /* spare (must be zero). */
305 };
306
307 /* vfsidctl API version. */
308 #define VFS_CTL_VERS1 0x01
309
310 /*
311 * New style VFS sysctls, do not reuse/conflict with the namespace for
312 * private sysctls.
313 * All "global" sysctl ops have the 33rd bit set:
314 * 0x...1....
315 * Private sysctl ops should have the 33rd bit unset.
316 */
317 #define VFS_CTL_QUERY 0x00010001 /* anything wrong? (vfsquery) */
318 #define VFS_CTL_TIMEO 0x00010002 /* set timeout for vfs notification */
319 #define VFS_CTL_NOLOCKS 0x00010003 /* disable file locking */
320
321 struct vfsquery {
322 u_int32_t vq_flags;
323 u_int32_t vq_spare[31];
324 };
325
326 /* vfsquery flags */
327 #define VQ_NOTRESP 0x0001 /* server down */
328 #define VQ_NEEDAUTH 0x0002 /* server bad auth */
329 #define VQ_LOWDISK 0x0004 /* we're low on space */
330 #define VQ_MOUNT 0x0008 /* new filesystem arrived */
331 #define VQ_UNMOUNT 0x0010 /* filesystem has left */
332 #define VQ_DEAD 0x0020 /* filesystem is dead, needs force unmount */
333 #define VQ_ASSIST 0x0040 /* filesystem needs assistance from external
334 program */
335 #define VQ_NOTRESPLOCK 0x0080 /* server lockd down */
336 #define VQ_FLAG0100 0x0100 /* placeholder */
337 #define VQ_FLAG0200 0x0200 /* placeholder */
338 #define VQ_FLAG0400 0x0400 /* placeholder */
339 #define VQ_FLAG0800 0x0800 /* placeholder */
340 #define VQ_FLAG1000 0x1000 /* placeholder */
341 #define VQ_FLAG2000 0x2000 /* placeholder */
342 #define VQ_FLAG4000 0x4000 /* placeholder */
343 #define VQ_FLAG8000 0x8000 /* placeholder */
344
345
346 struct iovec;
347 struct uio;
348
349 __BEGIN_DECLS
350
351 /* Mounting and unmounting filesystems. */
352 int mount(const char *, const char *, int, void *);
353 int nmount(struct iovec *, unsigned int, int);
354 int unmount(const char *, int);
355
356 /*
357 * Copyright (c) 1995
358 * The Regents of the University of California. All rights reserved.
359 *
360 * Redistribution and use in source and binary forms, with or without
361 * modification, are permitted provided that the following conditions
362 * are met:
363 * 1. Redistributions of source code must retain the above copyright
364 * notice, this list of conditions and the following disclaimer.
365 * 2. Redistributions in binary form must reproduce the above copyright
366 * notice, this list of conditions and the following disclaimer in the
367 * documentation and/or other materials provided with the distribution.
368 * 4. Neither the name of the University nor the names of its contributors
369 * may be used to endorse or promote products derived from this software
370 * without specific prior written permission.
371 *
372 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
373 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
374 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
375 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
376 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
377 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
378 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
379 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
380 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
381 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
382 * SUCH DAMAGE.
383 */
384
385 /*
386 * Given a filesystem name, determine if it is resident in the kernel,
387 * and if it is resident, return its xvfsconf structure.
388 */
389 static __inline int
390 getvfsbyname(const char *fsname, struct xvfsconf *vfcp)
391 {
392 struct xvfsconf *xvfsp;
393 size_t buflen;
394 int cnt, i;
395
396 if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
397 return (-1);
398 xvfsp = (struct xvfsconf *) malloc(buflen);
399 if (xvfsp == NULL)
400 return (-1);
401 if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) {
402 free(xvfsp);
403 return (-1);
404 }
405 cnt = buflen / sizeof(struct xvfsconf);
406 for (i = 0; i < cnt; i++) {
407 if (strcmp(fsname, xvfsp[i].vfc_name) == 0) {
408 memcpy(vfcp, xvfsp + i, sizeof(struct xvfsconf));
409 free(xvfsp);
410 return (0);
411 }
412 }
413 free(xvfsp);
414 errno = ENOENT;
415 return (-1);
416 }
417
418 /* getfsstat() appears in BSD 4.4. A variant of this API is found on OSF/1,
419 but on that system the user also needs to include <sys/fs_types.h>. */
420
421 #ifndef __USE_FILE_OFFSET64
422 extern int getfsstat (struct statfs *__buf, long __bufsize,
423 int __flags) __THROW;
424 #else
425 # ifdef __REDIRECT
426 extern int __REDIRECT (getfsstat,
427 (struct statfs *__buf, long __bufsize, int __flags),
428 getfsstat64);
429 # else
430 # define getfsstat getfsstat64
431 # endif
432 #endif
433 #ifdef __USE_LARGEFILE64
434 extern int getfsstat64 (struct statfs64 *__buf, long __bufsize,
435 int __flags) __THROW;
436 #endif
437
438 #ifdef _LIBC
439 extern int __getfsstat (struct statfs *__buf, long __bufsize, int __flags);
440 extern int __getfsstat64 (struct statfs64 *__buf, long __bufsize, int __flags);
441 #endif
442
443 /* getmntinfo() appears in BSD 4.4. */
444
445 #ifndef __USE_FILE_OFFSET64
446 extern int getmntinfo (struct statfs **__mntbufp, int __flags) __THROW;
447 #else
448 # ifdef __REDIRECT
449 extern int __REDIRECT (getmntinfo,
450 (struct statfs **__mntbufp, int __flags),
451 getmntinfo64);
452 # else
453 # define getmntinfo getmntinfo64
454 # endif
455 #endif
456 #ifdef __USE_LARGEFILE64
457 extern int getmntinfo64 (struct statfs64 **__mntbufp, int __flags) __THROW;
458 #endif
459
460 #ifdef _LIBC
461 extern int __getmntinfo (struct statfs **__mntbufp, int __flags);
462 #endif
463
464 __END_DECLS
465
466
467 /* Opening files on specified mounted filesystems.
468 These system calls are reserved to the superuser, for security reasons. */
469
470 __BEGIN_DECLS
471
472 /* Return in *FHP the file handle corresponding to the file or directory
473 PATH. */
474 extern int getfh (__const char *__path, fhandle_t *__fhp) __THROW;
475
476 /* Return in *FHP the file handle corresponding to the file or directory
477 PATH. */
478 extern int lgetfh (__const char *__path, fhandle_t *__fhp) __THROW;
479
480 /* Open a file handle *FHP, using the open() like FLAGS. Return the
481 new file descriptor. */
482 extern int fhopen (__const fhandle_t *__fhp, int __flags) __THROW;
483
484 /* Get file attributes for the file whose handle is *FHP, and return them
485 in *BUF. Like fhopen + fstat + close. */
486 #ifndef __USE_FILE_OFFSET64
487 extern int fhstat (__const fhandle_t *__fhp, struct stat *__buf) __THROW;
488 #else
489 # ifdef __REDIRECT
490 extern int __REDIRECT (fhstat,
491 (__const fhandle_t *__fhp, struct stat *__buf),
492 fhstat64);
493 # else
494 # define fhstat fhstat64
495 # endif
496 #endif
497 #ifdef __USE_LARGEFILE64
498 extern int fhstat64 (__const fhandle_t *__fhp, struct stat64 *__buf) __THROW;
499 #endif
500
501 /* Return information about the filesystem on which the file resides whose
502 handle is *FHP. Like fhopen + fstatfs + close. */
503 #ifndef __USE_FILE_OFFSET64
504 extern int fhstatfs (__const fhandle_t *__fhp, struct statfs *__buf) __THROW;
505 #else
506 # ifdef __REDIRECT
507 extern int __REDIRECT (fhstatfs,
508 (__const fhandle_t *__fhp, struct statfs *__buf),
509 fhstatfs64);
510 # else
511 # define fhstatfs fhstatfs64
512 # endif
513 #endif
514 #ifdef __USE_LARGEFILE64
515 extern int fhstatfs64 (__const fhandle_t *__fhp,
516 struct statfs64 *__buf) __THROW;
517 #endif
518
519 __END_DECLS
520
521 #endif /* _SYS_MOUNT_H */