FreeBSD/Linux Kernel Cross Reference
sys/sys/mount.h
1 /* $NetBSD: mount.h,v 1.181 2008/07/31 05:38:05 simonb Exp $ */
2
3 /*
4 * Copyright (c) 1989, 1991, 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.h 8.21 (Berkeley) 5/20/95
32 */
33
34 #ifndef _SYS_MOUNT_H_
35 #define _SYS_MOUNT_H_
36
37 #ifndef _KERNEL
38 #include <sys/featuretest.h>
39 #if defined(_NETBSD_SOURCE)
40 #include <sys/stat.h>
41 #endif /* _NETBSD_SOURCE */
42 #endif
43
44 #ifndef _STANDALONE
45 #include <sys/ucred.h>
46 #include <sys/fstypes.h>
47 #include <sys/queue.h>
48 #include <sys/rwlock.h>
49 #include <sys/statvfs.h>
50 #include <sys/specificdata.h>
51 #include <sys/condvar.h>
52 #endif /* !_STANDALONE */
53
54 /*
55 * file system statistics
56 */
57
58 #define MNAMELEN 90 /* length of buffer for returned name */
59
60 /*
61 * File system types.
62 */
63 #define MOUNT_FFS "ffs" /* UNIX "Fast" Filesystem */
64 #define MOUNT_UFS MOUNT_FFS /* for compatibility */
65 #define MOUNT_NFS "nfs" /* Network Filesystem */
66 #define MOUNT_MFS "mfs" /* Memory Filesystem */
67 #define MOUNT_MSDOS "msdos" /* MSDOS Filesystem */
68 #define MOUNT_LFS "lfs" /* Log-based Filesystem */
69 #define MOUNT_FDESC "fdesc" /* File Descriptor Filesystem */
70 #define MOUNT_PORTAL "portal" /* Portal Filesystem */
71 #define MOUNT_NULL "null" /* Minimal Filesystem Layer */
72 #define MOUNT_OVERLAY "overlay" /* Minimal Overlay Filesystem Layer */
73 #define MOUNT_UMAP "umap" /* User/Group Identifier Remapping Filesystem */
74 #define MOUNT_KERNFS "kernfs" /* Kernel Information Filesystem */
75 #define MOUNT_PROCFS "procfs" /* /proc Filesystem */
76 #define MOUNT_AFS "afs" /* Andrew Filesystem */
77 #define MOUNT_CD9660 "cd9660" /* ISO9660 (aka CDROM) Filesystem */
78 #define MOUNT_UNION "union" /* Union (translucent) Filesystem */
79 #define MOUNT_ADOSFS "adosfs" /* AmigaDOS Filesystem */
80 #define MOUNT_EXT2FS "ext2fs" /* Second Extended Filesystem */
81 #define MOUNT_CFS "coda" /* Coda Filesystem */
82 #define MOUNT_CODA MOUNT_CFS /* Coda Filesystem */
83 #define MOUNT_FILECORE "filecore" /* Acorn Filecore Filesystem */
84 #define MOUNT_NTFS "ntfs" /* Windows/NT Filesystem */
85 #define MOUNT_SMBFS "smbfs" /* CIFS (SMB) */
86 #define MOUNT_PTYFS "ptyfs" /* Pseudo tty filesystem */
87 #define MOUNT_TMPFS "tmpfs" /* Efficient memory file-system */
88 #define MOUNT_UDF "udf" /* UDF CD/DVD filesystem */
89 #define MOUNT_SYSVBFS "sysvbfs" /* System V Boot Filesystem */
90 #define MOUNT_PUFFS "puffs" /* Pass-to-Userspace filesystem */
91 #define MOUNT_HFS "hfs" /* Apple HFS+ Filesystem */
92 #define MOUNT_EFS "efs" /* SGI's Extent Filesystem */
93 #define MOUNT_ZFS "zfs" /* Sun ZFS */
94
95 #ifndef _STANDALONE
96
97 struct vnode;
98
99 /*
100 * Structure per mounted file system. Each mounted file system has an
101 * array of operations and an instance record. The file systems are
102 * put on a doubly linked list.
103 */
104 struct mount {
105 CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */
106 TAILQ_HEAD(, vnode) mnt_vnodelist; /* list of vnodes this mount */
107 struct vfsops *mnt_op; /* operations on fs */
108 struct vnode *mnt_vnodecovered; /* vnode we mounted on */
109 struct vnode *mnt_syncer; /* syncer vnode */
110 void *mnt_transinfo; /* for FS-internal use */
111 void *mnt_data; /* private data */
112 krwlock_t mnt_unmounting; /* to prevent new activity */
113 kmutex_t mnt_renamelock; /* per-fs rename lock */
114 int mnt_refcnt; /* ref count on this structure */
115 int mnt_recursecnt; /* count of write locks */
116 int mnt_flag; /* flags */
117 int mnt_iflag; /* internal flags */
118 int mnt_fs_bshift; /* offset shift for lblkno */
119 int mnt_dev_bshift; /* shift for device sectors */
120 struct statvfs mnt_stat; /* cache of filesystem stats */
121 specificdata_reference
122 mnt_specdataref; /* subsystem specific data */
123 kmutex_t mnt_updating; /* to serialize updates */
124 struct wapbl_ops
125 *mnt_wapbl_op; /* logging ops */
126 struct wapbl *mnt_wapbl; /* log info */
127 struct wapbl_replay
128 *mnt_wapbl_replay; /* replay support XXX: what? */
129 };
130
131 /*
132 * Sysctl CTL_VFS definitions.
133 *
134 * Second level identifier specifies which filesystem. Second level
135 * identifier VFS_GENERIC returns information about all filesystems.
136 *
137 * Note the slightly non-flat nature of these sysctl numbers. Oh for
138 * a better sysctl interface.
139 */
140 #define VFS_GENERIC 0 /* generic filesystem information */
141 #define VFS_MAXTYPENUM 1 /* int: highest defined fs type */
142 #define VFS_CONF 2 /* struct: vfsconf for filesystem given
143 as next argument */
144 #define VFS_USERMOUNT 3 /* enable/disable fs mnt by non-root */
145 #define VFS_MAGICLINKS 4 /* expand 'magic' symlinks */
146 #define VFSGEN_MAXID 5 /* number of valid vfs.generic ids */
147
148 /*
149 * USE THE SAME NAMES AS MOUNT_*!
150 *
151 * Only need to add new entry here if the filesystem actually supports
152 * sysctl(2).
153 */
154 #define CTL_VFS_NAMES { \
155 { "generic", CTLTYPE_NODE }, \
156 { MOUNT_FFS, CTLTYPE_NODE }, \
157 { MOUNT_NFS, CTLTYPE_NODE }, \
158 { MOUNT_MFS, CTLTYPE_NODE }, \
159 { MOUNT_MSDOS, CTLTYPE_NODE }, \
160 { MOUNT_LFS, CTLTYPE_NODE }, \
161 { 0, 0 }, /* MOUNT_LOFS */ \
162 { MOUNT_FDESC, CTLTYPE_NODE }, \
163 { MOUNT_PORTAL, CTLTYPE_NODE }, \
164 { MOUNT_NULL, CTLTYPE_NODE }, \
165 { MOUNT_UMAP, CTLTYPE_NODE }, \
166 { MOUNT_KERNFS, CTLTYPE_NODE }, \
167 { MOUNT_PROCFS, CTLTYPE_NODE }, \
168 { MOUNT_AFS, CTLTYPE_NODE }, \
169 { MOUNT_CD9660, CTLTYPE_NODE }, \
170 { MOUNT_UNION, CTLTYPE_NODE }, \
171 { MOUNT_ADOSFS, CTLTYPE_NODE }, \
172 { MOUNT_EXT2FS, CTLTYPE_NODE }, \
173 { MOUNT_CODA, CTLTYPE_NODE }, \
174 { MOUNT_FILECORE, CTLTYPE_NODE }, \
175 { MOUNT_NTFS, CTLTYPE_NODE }, \
176 }
177
178 #define VFS_MAXID 20 /* number of valid vfs ids */
179
180 #define CTL_VFSGENCTL_NAMES { \
181 { 0, 0 }, \
182 { "maxtypenum", CTLTYPE_INT }, \
183 { "conf", CTLTYPE_NODE }, /* Special */ \
184 { "usermount", CTLTYPE_INT }, \
185 { "magiclinks", CTLTYPE_INT }, \
186 }
187
188 #if defined(_KERNEL)
189 #if __STDC__
190 struct nameidata;
191 #endif
192
193 /*
194 * Operations supported on mounted file system.
195 */
196
197 struct vfsops {
198 const char *vfs_name;
199 size_t vfs_min_mount_data;
200 int (*vfs_mount) (struct mount *, const char *, void *,
201 size_t *);
202 int (*vfs_start) (struct mount *, int);
203 int (*vfs_unmount) (struct mount *, int);
204 int (*vfs_root) (struct mount *, struct vnode **);
205 int (*vfs_quotactl) (struct mount *, int, uid_t, void *);
206 int (*vfs_statvfs) (struct mount *, struct statvfs *);
207 int (*vfs_sync) (struct mount *, int, struct kauth_cred *);
208 int (*vfs_vget) (struct mount *, ino_t, struct vnode **);
209 int (*vfs_fhtovp) (struct mount *, struct fid *,
210 struct vnode **);
211 int (*vfs_vptofh) (struct vnode *, struct fid *, size_t *);
212 void (*vfs_init) (void);
213 void (*vfs_reinit) (void);
214 void (*vfs_done) (void);
215 int (*vfs_mountroot)(void);
216 int (*vfs_snapshot) (struct mount *, struct vnode *,
217 struct timespec *);
218 int (*vfs_extattrctl) (struct mount *, int,
219 struct vnode *, int, const char *);
220 int (*vfs_suspendctl) (struct mount *, int);
221 int (*vfs_renamelock_enter)(struct mount *);
222 void (*vfs_renamelock_exit)(struct mount *);
223 int (*vfs_fsync) (struct vnode *, int);
224 const struct vnodeopv_desc * const *vfs_opv_descs;
225 int vfs_refcount;
226 LIST_ENTRY(vfsops) vfs_list;
227 };
228
229 /* XXX vget is actually file system internal. */
230 #define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
231
232 #define VFS_RENAMELOCK_ENTER(MP) (*(MP)->mnt_op->vfs_renamelock_enter)(MP)
233 #define VFS_RENAMELOCK_EXIT(MP) (*(MP)->mnt_op->vfs_renamelock_exit)(MP)
234 #define VFS_FSYNC(MP, VP, FLG) (*(MP)->mnt_op->vfs_fsync)(VP, FLG)
235
236 int VFS_MOUNT(struct mount *, const char *, void *, size_t *);
237 int VFS_START(struct mount *, int);
238 int VFS_UNMOUNT(struct mount *, int);
239 int VFS_ROOT(struct mount *, struct vnode **);
240 int VFS_QUOTACTL(struct mount *, int, uid_t, void *);
241 int VFS_STATVFS(struct mount *, struct statvfs *);
242 int VFS_SYNC(struct mount *, int, struct kauth_cred *);
243 int VFS_FHTOVP(struct mount *, struct fid *, struct vnode **);
244 int VFS_VPTOFH(struct vnode *, struct fid *, size_t *);
245 void VFS_INIT(void);
246 void VFS_REINIT(void);
247 void VFS_DONE(void);
248 int VFS_MOUNTROOT(void);
249 int VFS_SNAPSHOT(struct mount *, struct vnode *, struct timespec *);
250 int VFS_EXTATTRCTL(struct mount *, int, struct vnode *, int, const char *);
251 int VFS_SUSPENDCTL(struct mount *, int);
252
253 #endif /* _KERNEL */
254
255 #ifdef _KERNEL
256 #if __STDC__
257 struct mbuf;
258 struct vnodeopv_desc;
259 struct kauth_cred;
260 #endif
261
262 #define VFS_MAX_MOUNT_DATA 8192
263
264 #define VFS_PROTOS(fsname) \
265 int fsname##_mount(struct mount *, const char *, void *, \
266 size_t *); \
267 int fsname##_start(struct mount *, int); \
268 int fsname##_unmount(struct mount *, int); \
269 int fsname##_root(struct mount *, struct vnode **); \
270 int fsname##_quotactl(struct mount *, int, uid_t, void *); \
271 int fsname##_statvfs(struct mount *, struct statvfs *); \
272 int fsname##_sync(struct mount *, int, struct kauth_cred *); \
273 int fsname##_vget(struct mount *, ino_t, struct vnode **); \
274 int fsname##_fhtovp(struct mount *, struct fid *, struct vnode **); \
275 int fsname##_vptofh(struct vnode *, struct fid *, size_t *); \
276 void fsname##_init(void); \
277 void fsname##_reinit(void); \
278 void fsname##_done(void); \
279 int fsname##_mountroot(void); \
280 int fsname##_snapshot(struct mount *, struct vnode *, \
281 struct timespec *); \
282 int fsname##_extattrctl(struct mount *, int, struct vnode *, int, \
283 const char *); \
284 int fsname##_suspendctl(struct mount *, int)
285
286 /*
287 * This operations vector is so wapbl can be wrapped into a filesystem lkm.
288 * XXX Eventually, we want to move this functionality
289 * down into the filesystems themselves so that this isn't needed.
290 */
291 struct wapbl_ops {
292 void (*wo_wapbl_discard)(struct wapbl *);
293 int (*wo_wapbl_replay_isopen)(struct wapbl_replay *);
294 int (*wo_wapbl_replay_read)(struct wapbl_replay *, void *, daddr_t, long);
295 void (*wo_wapbl_add_buf)(struct wapbl *, struct buf *);
296 void (*wo_wapbl_remove_buf)(struct wapbl *, struct buf *);
297 void (*wo_wapbl_resize_buf)(struct wapbl *, struct buf *, long, long);
298 int (*wo_wapbl_begin)(struct wapbl *, const char *, int);
299 void (*wo_wapbl_end)(struct wapbl *);
300 void (*wo_wapbl_junlock_assert)(struct wapbl *);
301 void (*wo_wapbl_biodone)(struct buf *);
302 };
303 #define WAPBL_DISCARD(MP) \
304 (*(MP)->mnt_wapbl_op->wo_wapbl_discard)((MP)->mnt_wapbl)
305 #define WAPBL_REPLAY_ISOPEN(MP) \
306 (*(MP)->mnt_wapbl_op->wo_wapbl_replay_isopen)((MP)->mnt_wapbl_replay)
307 #define WAPBL_REPLAY_READ(MP, DATA, BLK, LEN) \
308 (*(MP)->mnt_wapbl_op->wo_wapbl_replay_read)((MP)->mnt_wapbl_replay, \
309 (DATA), (BLK), (LEN))
310 #define WAPBL_ADD_BUF(MP, BP) \
311 (*(MP)->mnt_wapbl_op->wo_wapbl_add_buf)((MP)->mnt_wapbl, (BP))
312 #define WAPBL_REMOVE_BUF(MP, BP) \
313 (*(MP)->mnt_wapbl_op->wo_wapbl_remove_buf)((MP)->mnt_wapbl, (BP))
314 #define WAPBL_RESIZE_BUF(MP, BP, OLDSZ, OLDCNT) \
315 (*(MP)->mnt_wapbl_op->wo_wapbl_resize_buf)((MP)->mnt_wapbl, (BP), \
316 (OLDSZ), (OLDCNT))
317 #define WAPBL_BEGIN(MP) \
318 (*(MP)->mnt_wapbl_op->wo_wapbl_begin)((MP)->mnt_wapbl, \
319 __FILE__, __LINE__)
320 #define WAPBL_END(MP) \
321 (*(MP)->mnt_wapbl_op->wo_wapbl_end)((MP)->mnt_wapbl)
322 #define WAPBL_JUNLOCK_ASSERT(MP) \
323 (*(MP)->mnt_wapbl_op->wo_wapbl_junlock_assert)((MP)->mnt_wapbl)
324
325 struct vfs_hooks {
326 void (*vh_unmount)(struct mount *);
327 LIST_ENTRY(vfs_hooks) vfs_hooks_list;
328 };
329
330 void vfs_hooks_init(void);
331 int vfs_hooks_attach(struct vfs_hooks *);
332 int vfs_hooks_detach(struct vfs_hooks *);
333 void vfs_hooks_unmount(struct mount *);
334
335 #endif /* _KERNEL */
336
337 /*
338 * Export arguments for local filesystem mount calls.
339 *
340 * This structure is deprecated and is only provided for compatibility
341 * reasons with old binary utilities; several file systems expose an
342 * instance of this structure in their mount arguments structure, thus
343 * needing a padding in place of the old values. This definition cannot
344 * change in the future due to this reason.
345 * XXX: This should be moved to the compat subtree but cannot be done
346 * until we can move the mount args structures themselves.
347 *
348 * The current export_args structure can be found in nfs/nfs.h.
349 */
350 struct export_args30 {
351 int ex_flags; /* export related flags */
352 uid_t ex_root; /* mapping for root uid */
353 struct uucred ex_anon; /* mapping for anonymous user */
354 struct sockaddr *ex_addr; /* net address to which exported */
355 int ex_addrlen; /* and the net address length */
356 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
357 int ex_masklen; /* and the smask length */
358 char *ex_indexfile; /* index file for WebNFS URLs */
359 };
360
361 struct mnt_export_args30 {
362 const char *fspec; /* Always NULL */
363 struct export_args30 eargs;
364 };
365
366 #ifdef _KERNEL
367 #include <sys/mallocvar.h>
368 MALLOC_DECLARE(M_MOUNT);
369
370 /*
371 * exported VFS interface (see vfssubr(9))
372 */
373 struct mount *vfs_getvfs(fsid_t *); /* return vfs given fsid */
374 int vfs_composefh(struct vnode *, fhandle_t *, size_t *);
375 int vfs_composefh_alloc(struct vnode *, fhandle_t **);
376 void vfs_composefh_free(fhandle_t *);
377 int vfs_fhtovp(fhandle_t *, struct vnode **);
378 int vfs_mountedon(struct vnode *);/* is a vfs mounted on vp */
379 int vfs_mountroot(void);
380 void vfs_shutdown(void); /* unmount and sync file systems */
381 void vfs_unmountall(struct lwp *); /* unmount file systems */
382 int vfs_busy(struct mount *, struct mount **);
383 int vfs_rootmountalloc(const char *, const char *, struct mount **);
384 void vfs_unbusy(struct mount *, bool, struct mount **);
385 int vfs_attach(struct vfsops *);
386 int vfs_detach(struct vfsops *);
387 void vfs_reinit(void);
388 struct vfsops *vfs_getopsbyname(const char *);
389 void vfs_delref(struct vfsops *);
390 void vfs_destroy(struct mount *);
391 void vfs_scrubvnlist(struct mount *);
392
393 int vfs_stdextattrctl(struct mount *, int, struct vnode *,
394 int, const char *);
395
396 extern CIRCLEQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */
397 extern struct vfsops *vfssw[]; /* filesystem type table */
398 extern int nvfssw;
399 extern kmutex_t mountlist_lock;
400 extern kmutex_t vfs_list_lock;
401
402 long makefstype(const char *);
403 int dounmount(struct mount *, int, struct lwp *);
404 int do_sys_mount(struct lwp *, struct vfsops *, const char *, const char *,
405 int, void *, enum uio_seg, size_t, register_t *);
406 void vfsinit(void);
407 void vfs_opv_init(const struct vnodeopv_desc * const *);
408 void vfs_opv_free(const struct vnodeopv_desc * const *);
409 #ifdef DEBUG
410 void vfs_bufstats(void);
411 #endif
412
413 int mount_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
414 void mount_specific_key_delete(specificdata_key_t);
415 void mount_initspecific(struct mount *);
416 void mount_finispecific(struct mount *);
417 void * mount_getspecific(struct mount *, specificdata_key_t);
418 void mount_setspecific(struct mount *, specificdata_key_t, void *);
419
420 LIST_HEAD(vfs_list_head, vfsops);
421 extern struct vfs_list_head vfs_list;
422
423 #else /* _KERNEL */
424
425 #include <sys/cdefs.h>
426
427 __BEGIN_DECLS
428 #if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)
429 int getfh(const char *, void *, size_t *)
430 __RENAME(__getfh30);
431 #endif
432
433 int unmount(const char *, int);
434 #if defined(_NETBSD_SOURCE)
435 #ifndef __LIBC12_SOURCE__
436 int mount(const char *, const char *, int, void *, size_t) __RENAME(__mount50);
437 int fhopen(const void *, size_t, int) __RENAME(__fhopen40);
438 int fhstat(const void *, size_t, struct stat *) __RENAME(__fhstat40);
439 #endif
440 #endif /* _NETBSD_SOURCE */
441 __END_DECLS
442
443 #endif /* _KERNEL */
444 #endif /* !_STANDALONE */
445
446 #endif /* !_SYS_MOUNT_H_ */
Cache object: 48f6dd02ff3ad9350d038d1db4164d39
|