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