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