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