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