xref: /illumos-gate/usr/src/uts/common/sys/fs/pc_node.h (revision a38ddfee9c8c6b6c5a2947ff52fd2338362a4444)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <vm/page.h>
36 #include <sys/buf.h>
37 #include <sys/vnode.h>
38 
39 /*
40  * This overlays the fid structure (see vfs.h)
41  *
42  * 10 bytes max.
43  */
44 struct pc_fid {
45 	ushort_t	pcfid_len;
46 	uint32_t	pcfid_block;	/* dblock containing directory entry */
47 	uint16_t	pcfid_offset;	/* offset within block of entry */
48 	uint16_t	pcfid_ctime;	/* creation time of entry (~= i_gen) */
49 };
50 
51 struct pcnode {
52 	struct pcnode	*pc_forw;	/* active list ptrs, must be first */
53 	struct pcnode	*pc_back;
54 	int pc_flags;			/* see below */
55 	struct vnode	*pc_vn;		/* vnode for pcnode */
56 	uint_t pc_size;			/* size of file */
57 	pc_cluster32_t	pc_scluster;	/* starting cluster of file */
58 	daddr_t pc_eblkno;		/* disk blkno for entry */
59 	int pc_eoffset;			/* offset in disk block of entry */
60 	struct pcdir pc_entry;		/* directory entry of file */
61 	pc_cluster32_t	pc_lcluster;	/* last cluster visited */
62 	daddr_t		pc_lindex;	/* index of last cluster visited */
63 };
64 
65 /*
66  * flags
67  */
68 #define	PC_MOD		0x01		/* file data has been modified */
69 #define	PC_CHG		0x02		/* node data has been changed */
70 #define	PC_INVAL	0x04		/* node is invalid */
71 #define	PC_EXTERNAL	0x08		/* vnode ref is held externally */
72 #define	PC_ACC		0x10		/* file data has been accessed */
73 #define	PC_RELEHOLD	0x80		/* node is being released */
74 
75 #define	PCTOV(PCP)	((PCP)->pc_vn)
76 #define	VTOPC(VP)	((struct pcnode *)((VP)->v_data))
77 
78 /*
79  * Make a unique integer for a file
80  */
81 #define	pc_makenodeid(BN, OFF, ATTR, SCLUSTER, ENTPS) \
82 	(ino_t)((ATTR) & PCA_DIR ? \
83 		(uint32_t)(-(SCLUSTER) - 1) : \
84 		((BN) * (ENTPS)) + ((OFF) / sizeof (struct pcdir)))
85 
86 #define	NPCHASH 1
87 
88 #if NPCHASH == 1
89 #define	PCFHASH(FSP, BN, O)	0
90 #define	PCDHASH(FSP, SC)	0
91 #else
92 #define	PCFHASH(FSP, BN, O)	(((unsigned)FSP + BN + O) % NPCHASH)
93 #define	PCDHASH(FSP, SC)	(((unsigned)FSP + SC) % NPCHASH)
94 #endif
95 
96 struct pchead {
97 	struct pcnode *pch_forw;
98 	struct pcnode *pch_back;
99 };
100 
101 /*
102  * pcnode file and directory operations vectors
103  */
104 extern struct vnodeops *pcfs_fvnodeops;
105 extern struct vnodeops *pcfs_dvnodeops;
106 extern const struct fs_operation_def pcfs_fvnodeops_template[];
107 extern const struct fs_operation_def pcfs_dvnodeops_template[];
108 extern struct pchead pcfhead[];
109 extern struct pchead pcdhead[];
110 
111 /*
112  * pcnode routines
113  */
114 extern void pc_init(void);
115 extern struct pcnode *pc_getnode(struct pcfs *, daddr_t, int, struct pcdir *);
116 extern void pc_rele(struct pcnode *);
117 extern void pc_mark_mod(struct pcfs *, struct pcnode *);
118 extern void pc_mark_acc(struct pcfs *, struct pcnode *);
119 extern int pc_nodesync(struct pcnode *);
120 extern int pc_nodeupdate(struct pcnode *);
121 extern int pc_bmap(struct pcnode *, daddr_t, daddr_t *, uint_t *);
122 
123 extern int pc_balloc(struct pcnode *, daddr_t, int, daddr_t *);
124 extern int pc_bfree(struct pcnode *, pc_cluster32_t);
125 extern int pc_verify(struct pcfs *);
126 extern void pc_diskchanged(struct pcfs *);
127 extern void pc_mark_irrecov(struct pcfs *);
128 
129 extern int pc_dirlook(struct pcnode *, char *, struct pcnode **);
130 extern int pc_direnter(struct pcnode *, char *, struct vattr *,
131 	struct pcnode **);
132 extern int pc_dirremove(struct pcnode *, char *, struct vnode *, enum vtype,
133 		caller_context_t *);
134 extern int pc_rename(struct pcnode *, struct pcnode *, char *, char *,
135 		caller_context_t *);
136 extern int pc_blkatoff(struct pcnode *, offset_t, struct buf **,
137 	struct pcdir **);
138 extern int pc_truncate(struct pcnode *, uint_t);
139 extern int pc_fileclsize(struct pcfs *, pc_cluster32_t, pc_cluster32_t *);
140 extern int pcfs_putapage(struct vnode *, page_t *, u_offset_t *, size_t *, int,
141 	struct cred *);
142 extern void pc_badfs(struct pcfs *);
143 
144 #ifdef	__cplusplus
145 }
146 #endif
147 
148 #endif	/* _SYS_FS_PC_NODE_H */
149