xref: /titanic_51/usr/src/uts/common/sys/fs/pc_node.h (revision d67944fbe3fa0b31893a7116a09b0718eecf6078)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_FS_PC_NODE_H
27 #define	_SYS_FS_PC_NODE_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <vm/page.h>
34 #include <sys/buf.h>
35 #include <sys/vnode.h>
36 
37 #ifdef _KERNEL
38 #include <sys/vfs_opreg.h>
39 #endif
40 
41 /*
42  * This overlays the fid structure (see vfs.h)
43  *
44  * 10 bytes max.
45  */
46 struct pc_fid {
47 	ushort_t	pcfid_len;
48 	uint32_t	pcfid_block;	/* dblock containing directory entry */
49 	uint16_t	pcfid_offset;	/* offset within block of entry */
50 	uint16_t	pcfid_ctime;	/* creation time of entry (~= i_gen) */
51 };
52 
53 struct pcnode {
54 	struct pcnode	*pc_forw;	/* active list ptrs, must be first */
55 	struct pcnode	*pc_back;
56 	int pc_flags;			/* see below */
57 	struct vnode	*pc_vn;		/* vnode for pcnode */
58 	uint_t pc_size;			/* size of file */
59 	pc_cluster32_t	pc_scluster;	/* starting cluster of file */
60 	daddr_t pc_eblkno;		/* disk blkno for entry */
61 	int pc_eoffset;			/* offset in disk block of entry */
62 	struct pcdir pc_entry;		/* directory entry of file */
63 	pc_cluster32_t	pc_lcluster;	/* last cluster visited */
64 	daddr_t		pc_lindex;	/* index of last cluster visited */
65 };
66 
67 /*
68  * flags
69  */
70 #define	PC_MOD		0x01		/* file data has been modified */
71 #define	PC_CHG		0x02		/* node data has been changed */
72 #define	PC_INVAL	0x04		/* node is invalid */
73 #define	PC_EXTERNAL	0x08		/* vnode ref is held externally */
74 #define	PC_ACC		0x10		/* file data has been accessed */
75 #define	PC_RELEHOLD	0x80		/* node is being released */
76 
77 #define	PCTOV(PCP)	((PCP)->pc_vn)
78 #define	VTOPC(VP)	((struct pcnode *)((VP)->v_data))
79 
80 /*
81  * Make a unique integer for a file
82  */
83 #define	pc_makenodeid(BN, OFF, ATTR, SCLUSTER, ENTPS) \
84 	(ino_t)((ATTR) & PCA_DIR ? \
85 		(uint32_t)(-(SCLUSTER) - 1) : \
86 		((BN) * (ENTPS)) + ((OFF) / sizeof (struct pcdir)))
87 
88 #define	NPCHASH 1
89 
90 #if NPCHASH == 1
91 #define	PCFHASH(FSP, BN, O)	0
92 #define	PCDHASH(FSP, SC)	0
93 #else
94 #define	PCFHASH(FSP, BN, O)	(((unsigned)FSP + BN + O) % NPCHASH)
95 #define	PCDHASH(FSP, SC)	(((unsigned)FSP + SC) % NPCHASH)
96 #endif
97 
98 struct pchead {
99 	struct pcnode *pch_forw;
100 	struct pcnode *pch_back;
101 };
102 
103 /*
104  * pcnode file and directory operations vectors
105  */
106 extern struct vnodeops *pcfs_fvnodeops;
107 extern struct vnodeops *pcfs_dvnodeops;
108 
109 #ifdef _KERNEL
110 extern const struct fs_operation_def pcfs_fvnodeops_template[];
111 extern const struct fs_operation_def pcfs_dvnodeops_template[];
112 #endif
113 
114 extern struct pchead pcfhead[];
115 extern struct pchead pcdhead[];
116 
117 /*
118  * pcnode routines
119  */
120 extern void pc_init(void);
121 extern struct pcnode *pc_getnode(struct pcfs *, daddr_t, int, struct pcdir *);
122 extern void pc_rele(struct pcnode *);
123 extern void pc_mark_mod(struct pcfs *, struct pcnode *);
124 extern void pc_mark_acc(struct pcfs *, struct pcnode *);
125 extern int pc_nodesync(struct pcnode *);
126 extern int pc_nodeupdate(struct pcnode *);
127 extern int pc_bmap(struct pcnode *, daddr_t, daddr_t *, uint_t *);
128 
129 extern int pc_balloc(struct pcnode *, daddr_t, int, daddr_t *);
130 extern int pc_bfree(struct pcnode *, pc_cluster32_t);
131 extern int pc_verify(struct pcfs *);
132 extern void pc_diskchanged(struct pcfs *);
133 extern void pc_mark_irrecov(struct pcfs *);
134 
135 extern int pc_dirlook(struct pcnode *, char *, struct pcnode **);
136 extern int pc_direnter(struct pcnode *, char *, struct vattr *,
137 	struct pcnode **);
138 extern int pc_dirremove(struct pcnode *, char *, struct vnode *, enum vtype,
139 		caller_context_t *);
140 extern int pc_rename(struct pcnode *, struct pcnode *, char *, char *,
141 		caller_context_t *);
142 extern int pc_blkatoff(struct pcnode *, offset_t, struct buf **,
143 	struct pcdir **);
144 extern int pc_truncate(struct pcnode *, uint_t);
145 extern int pc_fileclsize(struct pcfs *, pc_cluster32_t, pc_cluster32_t *);
146 extern int pcfs_putapage(struct vnode *, page_t *, u_offset_t *, size_t *, int,
147 	struct cred *);
148 extern void pc_badfs(struct pcfs *);
149 
150 #ifdef	__cplusplus
151 }
152 #endif
153 
154 #endif	/* _SYS_FS_PC_NODE_H */
155