xref: /titanic_52/usr/src/lib/libbc/inc/include/sys/vfs.h (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1988 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * File system identifier. Should be unique (at least per machine).
31  */
32 
33 #ifndef _sys_vfs_h
34 #define _sys_vfs_h
35 
36 typedef struct {
37 	long val[2];			/* file system id type */
38 } fsid_t;
39 
40 /*
41  * File identifier. Should be unique per filesystem on a single machine.
42  */
43 #define	MAXFIDSZ	16
44 #define	freefid(fidp) \
45     kmem_free((caddr_t)(fidp), sizeof (struct fid) - MAXFIDSZ + (fidp)->fid_len)
46 
47 struct fid {
48 	u_short		fid_len;		/* length of data in bytes */
49 	char		fid_data[MAXFIDSZ];	/* data (variable length) */
50 };
51 
52 /*
53  * Structure per mounted file system.
54  * Each mounted file system has an array of
55  * operations and an instance record.
56  * The file systems are put on a singly linked list.
57  * If vfs_stats is non-NULL statistics are gathered, see vfs_stat.h
58  */
59 struct vfs {
60 	struct vfs	*vfs_next;		/* next vfs in vfs list */
61 	struct vfsops	*vfs_op;		/* operations on vfs */
62 	struct vnode	*vfs_vnodecovered;	/* vnode we mounted on */
63 	int		vfs_flag;		/* flags */
64 	int		vfs_bsize;		/* native block size */
65 	fsid_t		vfs_fsid;		/* file system id */
66 	caddr_t 	vfs_stats;		/* filesystem statistics */
67 	caddr_t		vfs_data;		/* private data */
68 };
69 
70 /*
71  * vfs flags.
72  * VFS_MLOCK lock the vfs so that name lookup cannot proceed past the vfs.
73  * This keeps the subtree stable during mounts and unmounts.
74  */
75 #define VFS_RDONLY	0x01		/* read only vfs */
76 #define VFS_MLOCK	0x02		/* lock vfs so that subtree is stable */
77 #define VFS_MWAIT	0x04		/* someone is waiting for lock */
78 #define VFS_NOSUID	0x08		/* turn off set-uid on exec */
79 #define VFS_GRPID	0x10		/* Old BSD group-id on create */
80 #define VFS_NOSUB	0x20		/* No mounts allowed beneath this fs */
81 #define VFS_REMOUNT	0x40		/* modify mount otions only */
82 #define VFS_MULTI	0x80		/* Do multi-component lookup on files */
83 
84 /*
85  * Operations supported on virtual file system.
86  */
87 struct vfsops {
88 	int	(*vfs_mount)();		/* mount file system */
89 	int	(*vfs_unmount)();	/* unmount file system */
90 	int	(*vfs_root)();		/* get root vnode */
91 	int	(*vfs_statfs)();	/* get fs statistics */
92 	int	(*vfs_sync)();		/* flush fs buffers */
93 	int	(*vfs_vget)();		/* get vnode from fid */
94 	int	(*vfs_mountroot)();	/* mount the root filesystem */
95 	int	(*vfs_swapvp)();	/* return vnode for swap */
96 };
97 
98 #define VFS_MOUNT(VFSP, PATH, DATA) \
99 				 (*(VFSP)->vfs_op->vfs_mount)(VFSP, PATH, DATA)
100 #define VFS_UNMOUNT(VFSP)	 (*(VFSP)->vfs_op->vfs_unmount)(VFSP)
101 #define VFS_ROOT(VFSP, VPP)	 (*(VFSP)->vfs_op->vfs_root)(VFSP,VPP)
102 #define VFS_STATFS(VFSP, SBP)	 (*(VFSP)->vfs_op->vfs_statfs)(VFSP,SBP)
103 #define VFS_SYNC(VFSP)		 (*(VFSP)->vfs_op->vfs_sync)(VFSP)
104 #define VFS_VGET(VFSP, VPP, FIDP) (*(VFSP)->vfs_op->vfs_vget)(VFSP, VPP, FIDP)
105 #define VFS_MOUNTROOT(VFSP, VPP, NM) \
106 				 (*(VFSP)->vfs_op->vfs_mountroot)(VFSP, VPP, NM)
107 #define VFS_SWAPVP(VFSP, VPP, NM) (*(VFSP)->vfs_op->vfs_swapvp)(VFSP, VPP, NM)
108 
109 /*
110  * file system statistics
111  */
112 struct statfs {
113 	long f_type;			/* type of info, zero for now */
114 	long f_bsize;			/* fundamental file system block size */
115 	long f_blocks;			/* total blocks in file system */
116 	long f_bfree;			/* free block in fs */
117 	long f_bavail;			/* free blocks avail to non-superuser */
118 	long f_files;			/* total file nodes in file system */
119 	long f_ffree;			/* free file nodes in fs */
120 	fsid_t f_fsid;			/* file system id */
121 	long f_spare[7];		/* spare for later */
122 };
123 
124 #ifdef KERNEL
125 /*
126  * Filesystem type switch table
127  */
128 struct vfssw {
129 	char		*vsw_name;	/* type name string */
130 	struct vfsops	*vsw_ops;	/* filesystem operations vector */
131 };
132 
133 /*
134  * public operations
135  */
136 extern void	vfs_mountroot();	/* mount the root */
137 extern int	vfs_add();		/* add a new vfs to mounted vfs list */
138 extern void	vfs_remove();		/* remove a vfs from mounted vfs list */
139 extern int	vfs_lock();		/* lock a vfs */
140 extern void	vfs_unlock();		/* unlock a vfs */
141 extern struct vfs *getvfs();		/* return vfs given fsid */
142 extern struct vfssw *getfstype();	/* find default filesystem type */
143 extern int vfs_getmajor();		/* get major device # for an fs type */
144 extern void vfs_putmajor();		/* free major device # for an fs type */
145 extern int vfs_getnum();		/* get device # for an fs type */
146 extern void vfs_putnum();		/* release device # for an fs type */
147 
148 #define VFS_INIT(VFSP, OP, DATA)	{ \
149 	(VFSP)->vfs_next = (struct vfs *)0; \
150 	(VFSP)->vfs_op = (OP); \
151 	(VFSP)->vfs_flag = 0; \
152 	(VFSP)->vfs_stats = NULL; \
153 	(VFSP)->vfs_data = (DATA); \
154 }
155 
156 /*
157  * globals
158  */
159 extern struct vfs *rootvfs;		/* ptr to root vfs structure */
160 extern struct vfssw vfssw[];		/* table of filesystem types */
161 extern struct vfssw *vfsNVFS;		/* vfs switch table end marker */
162 #endif
163 
164 #endif /*!_sys_vfs_h*/
165