xref: /titanic_52/usr/src/ucbhead/sys/vfs.h (revision c2580b931007758eab8cb5ae8726ebe1588e259b)
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 1998 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef _SYS_VFS_H
41 #define	_SYS_VFS_H
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #include <sys/types.h>
46 #include <sys/cred.h>
47 #include <sys/vnode.h>
48 #include <sys/statvfs.h>
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /*
55  * Data associated with mounted file systems.
56  */
57 
58 /*
59  * File system identifier. Should be unique (at least per machine).
60  */
61 typedef struct {
62 	int val[2];			/* file system id type */
63 } fsid_t;
64 
65 /*
66  * File identifier.  Should be unique per filesystem on a single
67  * machine.  This is typically called by a stateless file server
68  * in order to generate "file handles".
69  */
70 #define	MAXFIDSZ	16
71 #define	freefid(fidp) \
72     kmem_free((caddr_t)(fidp), sizeof (struct fid) - MAXFIDSZ + (fidp)->fid_len)
73 
74 typedef struct fid {
75 	ushort_t	fid_len;		/* length of data in bytes */
76 	char		fid_data[MAXFIDSZ];	/* data (variable length) */
77 } fid_t;
78 
79 /*
80  * Structure per mounted file system.  Each mounted file system has
81  * an array of operations and an instance record.  The file systems
82  * are kept on a singly linked list headed by "rootvfs" and terminated
83  * by NULL.
84  */
85 typedef struct vfs {
86 	struct vfs	*vfs_next;		/* next VFS in VFS list */
87 	struct vfsops	*vfs_op;		/* operations on VFS */
88 	struct vnode	*vfs_vnodecovered;	/* vnode mounted on */
89 	ulong_t		vfs_flag;		/* flags */
90 	ulong_t		vfs_bsize;		/* native block size */
91 	int		vfs_fstype;		/* file system type index */
92 	fsid_t		vfs_fsid;		/* file system id */
93 	caddr_t		vfs_data;		/* private data */
94 	l_dev_t		vfs_dev;		/* device of mounted VFS */
95 	ulong_t		vfs_bcount;		/* I/O count (accounting) */
96 	ushort_t	vfs_nsubmounts;		/* immediate sub-mount count */
97 } vfs_t;
98 
99 /*
100  * VFS flags.
101  */
102 #define	VFS_RDONLY	0x01		/* read-only vfs */
103 #define	VFS_MLOCK	0x02		/* lock vfs so that subtree is stable */
104 #define	VFS_MWAIT	0x04		/* someone is waiting for lock */
105 #define	VFS_NOSUID	0x08		/* setuid disallowed */
106 #define	VFS_REMOUNT	0x10		/* modify mount options only */
107 #define	VFS_NOTRUNC	0x20		/* does not truncate long file names */
108 
109 /*
110  * Argument structure for mount(2).
111  */
112 struct mounta {
113 	char	*spec;
114 	char	*dir;
115 	int	flags;
116 	char	*fstype;
117 	char	*dataptr;
118 	int	datalen;
119 };
120 
121 /*
122  * Reasons for calling the vfs_mountroot() operation.
123  */
124 
125 enum whymountroot { ROOT_INIT, ROOT_REMOUNT, ROOT_UNMOUNT };
126 typedef enum whymountroot whymountroot_t;
127 
128 /*
129  * Operations supported on virtual file system.
130  */
131 typedef struct vfsops {
132 #if defined(__STDC__)
133 	int	(*vfs_mount)(struct vfs *, struct vnode *, struct mounta *,
134 			struct cred *);
135 	int	(*vfs_unmount)(struct vfs *, struct cred *);
136 	int	(*vfs_root)(struct vfs *, struct vnode **);
137 	int	(*vfs_statvfs)(struct vfs *, struct statvfs64 *);
138 	int	(*vfs_sync)(struct vfs *, short, struct cred *);
139 	int	(*vfs_vget)(struct vfs *, struct vnode **, struct fid *);
140 	int	(*vfs_mountroot)(struct vfs *, enum whymountroot);
141 	int	(*vfs_swapvp)(struct vfs *, struct vnode **, char *);
142 	int	(*vfs_filler[4])(void);
143 #else
144 	int	(*vfs_mount)();		/* mount file system */
145 	int	(*vfs_unmount)();	/* unmount file system */
146 	int	(*vfs_root)();		/* get root vnode */
147 	int	(*vfs_statvfs)();	/* get file system statistics */
148 	int	(*vfs_sync)();		/* flush fs buffers */
149 	int	(*vfs_vget)();		/* get vnode from fid */
150 	int	(*vfs_mountroot)();	/* mount the root filesystem */
151 	int	(*vfs_swapvp)();	/* return vnode for swap */
152 	int	(*vfs_filler[4])();	/* for future expansion */
153 #endif
154 } vfsops_t;
155 
156 #define	VFS_MOUNT(vfsp, mvp, uap, cr) \
157 	(*(vfsp)->vfs_op->vfs_mount)(vfsp, mvp, uap, cr)
158 #define	VFS_UNMOUNT(vfsp, cr)	(*(vfsp)->vfs_op->vfs_unmount)(vfsp, cr)
159 #define	VFS_ROOT(vfsp, vpp)	(*(vfsp)->vfs_op->vfs_root)(vfsp, vpp)
160 #define	VFS_STATVFS(vfsp, sp)	(*(vfsp)->vfs_op->vfs_statvfs)(vfsp, sp)
161 #define	VFS_SYNC(vfsp)	(*(vfsp)->vfs_op->vfs_sync)(vfsp)
162 #define	VFS_VGET(vfsp, vpp, fidp) \
163 		(*(vfsp)->vfs_op->vfs_vget)(vfsp, vpp, fidp)
164 #define	VFS_MOUNTROOT(vfsp, init) \
165 		(*(vfsp)->vfs_op->vfs_mountroot)(vfsp, init)
166 #define	VFS_SWAPVP(vfsp, vpp, nm) \
167 		(*(vfsp)->vfs_op->vfs_swapvp)(vfsp, vpp, nm)
168 
169 /*
170  * Filesystem type switch table.
171  */
172 typedef struct vfssw {
173 	char		*vsw_name;	/* type name string */
174 #if defined(__STDC__)
175 	int		(*vsw_init)(struct vfssw *, int);
176 #else
177 	int		(*vsw_init)();	/* init routine */
178 #endif
179 	struct vfsops	*vsw_vfsops;	/* filesystem operations vector */
180 	int		vsw_flag;	/* flags */
181 } vfssw_t;
182 
183 /*
184  * Public operations.
185  */
186 #if defined(__STDC__)
187 void	vfs_mountroot(void);
188 void	vfs_add(vnode_t *, struct vfs *, int);
189 void	vfs_remove(struct vfs *);
190 int	vfs_lock(struct vfs *);
191 void	vfs_unlock(struct vfs *);
192 struct vfs *getvfs(fsid_t *);
193 struct vfs *vfs_devsearch(dev_t);
194 struct vfssw *vfs_getvfssw(char *);
195 u_int	vf_to_stf(u_int);
196 #else
197 extern void	vfs_mountroot();	/* mount the root */
198 extern void	vfs_add();		/* add a new vfs to mounted vfs list */
199 extern void	vfs_remove();		/* remove a vfs from mounted vfs list */
200 extern int	vfs_lock();		/* lock a vfs */
201 extern void	vfs_unlock();		/* unlock a vfs */
202 extern vfs_t	*getvfs();		/* return vfs given fsid */
203 extern vfs_t	*vfs_devsearch();	/* find vfs given device */
204 extern vfssw_t	*vfs_getvfssw();	/* find vfssw ptr given fstype name */
205 extern ulong_t	vf_to_stf();		/* map VFS flags to statfs flags */
206 #endif
207 
208 #define	VFS_INIT(vfsp, op, data)	{ \
209 	(vfsp)->vfs_next = (struct vfs *)0; \
210 	(vfsp)->vfs_op = (op); \
211 	(vfsp)->vfs_flag = 0; \
212 	(vfsp)->vfs_data = (data); \
213 	(vfsp)->vfs_nsubmounts = 0; \
214 }
215 
216 /*
217  * Globals.
218  */
219 extern struct vfs *rootvfs;		/* ptr to root vfs structure */
220 extern struct vfssw vfssw[];		/* table of filesystem types */
221 extern char rootfstype[];		/* name of root fstype */
222 extern int nfstype;			/* # of elements in vfssw array */
223 
224 /*
225  * file system statistics, from SunOS 4.1
226  */
227 #if _FILE_OFFSET_BITS == 32
228 struct statfs {
229 	int f_type;		/* type of info, zero for now */
230 	int f_bsize;		/* fundamental file system block size */
231 	int f_blocks;		/* total blocks in file system */
232 	int f_bfree;		/* free blocks in fs */
233 	int f_bavail;		/* free blocks avail to non-superuser */
234 	int f_files;		/* total file nodes in file system */
235 	int f_ffree;		/* free files nodes in fs */
236 	fsid_t f_fsid;		/* file system id */
237 	int f_spare[7];		/* spare for later */
238 };
239 #elif _FILE_OFFSET_BITS == 64
240 struct statfs {
241 	long f_type;		/* type of info, zero for now */
242 	ulong_t f_bsize;	/* fundamental file system block size */
243 	fsblkcnt_t f_blocks;	/* total blocks in file system */
244 	fsblkcnt_t f_bfree;	/* free blocks in fs */
245 	fsblkcnt_t f_bavail;	/* free blocks avail to non-superuser */
246 	fsfilcnt_t f_files;	/* total file nodes in file system */
247 	fsfilcnt_t f_ffree;	/* free files nodes in fs */
248 	fsid_t f_fsid;		/* file system id */
249 	int f_spare[7];		/* spare for later */
250 };
251 #endif
252 #if	defined(_LARGEFILE64_SOURCE)
253 struct statfs64 {
254 	long f_type;		/* type of info, zero for now */
255 
256 	ulong_t f_bsize;	/* fundamental file system block size */
257 	fsblkcnt_t f_blocks;	/* total blocks in file system */
258 	fsblkcnt_t f_bfree;	/* free blocks in fs */
259 	fsblkcnt_t f_bavail;	/* free blocks avail to non-superuser */
260 	fsfilcnt_t f_files;	/* total file nodes in file system */
261 	fsfilcnt_t f_ffree;	/* free files nodes in fs */
262 	fsid_t f_fsid;		/* file system id */
263 	int f_spare[7];		/* spare for later */
264 };
265 #endif
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #endif	/* _SYS_VFS_H */
272