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