xref: /titanic_41/usr/src/uts/common/sys/fs/hsfs_node.h (revision c5024742c2f7d10880eae26cc592353b20a58f4a)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * High Sierra filesystem structure definitions
24  * Copyright 2004 Sun Microsystems, Inc.
25  * All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #ifndef	_SYS_FS_HSFS_NODE_H
30 #define	_SYS_FS_HSFS_NODE_H
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 struct	hs_direntry {
39 	uint_t		ext_lbn;	/* LBN of start of extent */
40 	uint_t		ext_size;    	/* no. of data bytes in extent */
41 	struct timeval	cdate;		/* creation date */
42 	struct timeval	mdate;		/* last modification date */
43 	struct timeval	adate;		/* last access date */
44 	enum vtype	type;		/* file type */
45 	mode_t		mode;		/* mode and type of file (UNIX) */
46 	uint_t		nlink;		/* no. of links to file */
47 	uid_t		uid;		/* owner's user id */
48 	gid_t		gid;		/* owner's group id */
49 	dev_t		r_dev;		/* major/minor device numbers */
50 	uint_t		xar_prot :1;	/* 1 if protection in XAR */
51 	uchar_t		xar_len;	/* no. of Logical blocks in XAR */
52 	uchar_t		intlf_sz;	/* intleaving size */
53 	uchar_t		intlf_sk;	/* intleaving skip factor */
54 	ushort_t	sym_link_flag;	/* flags for sym link */
55 	char		*sym_link; 	/* path of sym link for readlink() */
56 };
57 
58 struct	ptable {
59 	uchar_t	filler[7];		/* filler */
60 	uchar_t	dname_len;		/* length of directory name */
61 	uchar_t	dname[HS_DIR_NAMELEN+1];	/* directory name */
62 };
63 
64 struct ptable_idx {
65 	struct ptable_idx *idx_pptbl_idx; /* parent's path table index entry */
66 	struct ptable	*idx_mptbl;	/* path table entry for myself */
67 	ushort_t idx_nochild;		/* no. of children */
68 	ushort_t idx_childid;		/* directory no of first child */
69 };
70 
71 /*
72  * hsnode structure:
73  *
74  * hs_offset, hs_ptbl_idx, base  apply to VDIR type only
75  *
76  * nodeid uniquely identifies an hsnode, ISO9660 means
77  * nodeid can be very big.
78  * For directories it is the disk address of
79  * the data extent of the dir (the directory itself,
80  * ".", and ".." all point to same data extent).
81  * For non-directories, it is the disk address of the
82  * directory entry for the file; note that this does
83  * not permit hard links, as it assumes a single dir
84  * entry per file.
85  */
86 
87 struct  hsnode {
88 	struct hsnode	*hs_hash;	/* next hsnode in hash list */
89 	struct hsnode	*hs_freef;	/* next hsnode in free list */
90 	struct hsnode	*hs_freeb;	/* previous hsnode in free list */
91 	struct vnode	*hs_vnode;	/* the real vnode for the file */
92 	struct hs_direntry hs_dirent;	/* the directory entry for this file */
93 	ino64_t		hs_nodeid;	/* "inode" number for hsnode */
94 	uint_t		hs_dir_lbn;	/* LBN of directory entry */
95 	uint_t		hs_dir_off;	/* offset in LBN of directory entry */
96 	struct ptable_idx	*hs_ptbl_idx;	/* path table index */
97 	uint_t		hs_offset;	/* start offset in dir for searching */
98 	long		hs_mapcnt;	/* mappings to file pages */
99 	uint_t		hs_seq;		/* sequence number */
100 	uint_t		hs_flags;	/* (see below) */
101 	kmutex_t	hs_contents_lock;	/* protects hsnode contents */
102 						/* 	except hs_offset */
103 };
104 
105 /* hs_flags */
106 #define	HREF	1			/* hsnode is referenced */
107 
108 /* hs_modes */
109 
110 #define	HFDIR	0040000			/* directory */
111 #define	HFREG	0100000			/* regular file */
112 
113 struct  hsfid {
114 	ushort_t	hf_len;		/* length of fid */
115 	ushort_t	hf_dir_off;	/* offset in LBN of directory entry */
116 	uint_t		hf_dir_lbn;	/* LBN of directory */
117 };
118 
119 
120 /*
121  * All of the fields in the hs_volume are read-only once they have been
122  * initialized.
123  */
124 struct	hs_volume {
125 	ulong_t		vol_size; 	/* no. of Logical blocks in Volume */
126 	uint_t		lbn_size;	/* no. of bytes in a block */
127 	uint_t		lbn_shift;	/* shift to convert lbn to bytes */
128 	uint_t		lbn_secshift;	/* shift to convert lbn to sec */
129 	uint_t		lbn_maxoffset;	/* max lbn-relative offset and mask */
130 	uchar_t		file_struct_ver; /* version of directory structure */
131 	uid_t		vol_uid;	/* uid of volume */
132 	gid_t		vol_gid;	/* gid of volume */
133 	uint_t		vol_prot;	/* protection (mode) of volume */
134 	struct timeval	cre_date;	/* volume creation time */
135 	struct timeval	mod_date;	/* volume modification time */
136 	struct	hs_direntry root_dir;	/* dir entry for Root Directory */
137 	ushort_t	ptbl_len;	/* number of bytes in Path Table */
138 	uint_t		ptbl_lbn;	/* logical block no of Path Table */
139 	ushort_t	vol_set_size;	/* number of CD in this vol set */
140 	ushort_t	vol_set_seq;	/* the sequence number of this CD */
141 	char		vol_id[32];		/* volume id in PVD */
142 };
143 
144 /*
145  * The hsnode table is no longer fixed in size but grows
146  * and shrinks dynamically. However a cache of nodes is still maintained
147  * for efficiency. This cache size (nhsnode) is a tunable which
148  * is either specified in /etc/system or calculated as the number
149  * that will fit into the number of bytes defined by HS_HSNODESPACE (below).
150  */
151 #define	HS_HASHSIZE	32		/* hsnode hash table size */
152 #define	HS_HSNODESPACE	16384		/* approx. space used for hsnodes */
153 
154 /*
155  * High Sierra filesystem structure.
156  * There is one of these for each mounted High Sierra filesystem.
157  */
158 enum hs_vol_type {
159 	HS_VOL_TYPE_HS = 0, HS_VOL_TYPE_ISO = 1
160 };
161 #define	HSFS_MAGIC 0x03095500
162 struct hsfs {
163 	struct hsfs	*hsfs_next;	/* ptr to next entry in linked list */
164 	long		hsfs_magic;	/* should be HSFS_MAGIC */
165 	struct vfs	*hsfs_vfs;	/* vfs for this fs */
166 	struct vnode	*hsfs_rootvp;	/* vnode for root of filesystem */
167 	struct vnode	*hsfs_devvp;	/* device mounted on */
168 	enum hs_vol_type hsfs_vol_type; /* 0 hsfs 1 iso 2 hsfs+sun 3 iso+sun */
169 	struct hs_volume hsfs_vol;	/* File Structure Volume Descriptor */
170 	struct ptable	*hsfs_ptbl;	/* pointer to incore Path Table */
171 	int		hsfs_ptbl_size;	/* size of incore path table */
172 	struct ptable_idx *hsfs_ptbl_idx; /* pointer to path table index */
173 	int		hsfs_ptbl_idx_size;	/* no. of path table index */
174 	ulong_t		hsfs_ext_impl;	/* ext. information bits */
175 	ushort_t	hsfs_sua_off;	/* the SUA offset */
176 	ushort_t	hsfs_namemax;	/* maximum file name length */
177 	ulong_t		hsfs_err_flags;	/* ways in which fs is non-conformant */
178 	char		*hsfs_fsmnt;	/* name mounted on */
179 	ulong_t		hsfs_flags;	/* hsfs-specific mount flags */
180 	krwlock_t	hsfs_hash_lock;	/* protect hash table & hst_nohsnode */
181 	struct hsnode	*hsfs_hash[HS_HASHSIZE]; /* head of hash lists */
182 	uint32_t	hsfs_nohsnode;	/* no. of allocated hsnodes */
183 	kmutex_t	hsfs_free_lock;	/* protects free list */
184 	struct hsnode	*hsfs_free_f;	/* first entry of free list */
185 	struct hsnode	*hsfs_free_b;	/* last entry of free list */
186 };
187 
188 /*
189  * Error types: bit offsets into hsfs_err_flags.
190  * Also serves as index into hsfs_error[], so must be
191  * kept in sync with that data structure.
192  */
193 #define	HSFS_ERR_TRAILING_JUNK	0
194 #define	HSFS_ERR_LOWER_CASE_NM	1
195 #define	HSFS_ERR_BAD_ROOT_DIR	2
196 #define	HSFS_ERR_UNSUP_TYPE	3
197 #define	HSFS_ERR_BAD_FILE_LEN	4
198 
199 #define	HSFS_HAVE_LOWER_CASE(fsp) \
200 	((fsp)->hsfs_err_flags & (1 << HSFS_ERR_LOWER_CASE_NM))
201 
202 
203 /*
204  * File system parameter macros
205  */
206 #define	hs_blksize(HSFS, HSP, OFF)	/* file system block size */ \
207 	((HSP)->hs_vn.v_flag & VROOT ? \
208 	    ((OFF) >= \
209 		((HSFS)->hsfs_rdirsec & ~((HSFS)->hsfs_spcl - 1))*HS_SECSIZE ?\
210 		((HSFS)->hsfs_rdirsec & ((HSFS)->hsfs_spcl - 1))*HS_SECSIZE :\
211 		(HSFS)->hsfs_clsize): \
212 	    (HSFS)->hsfs_clsize)
213 #define	hs_blkoff(OFF)		/* offset within block */ \
214 	((OFF) & (HS_SECSIZE - 1))
215 
216 /*
217  * Conversion macros
218  */
219 #define	VFS_TO_HSFS(VFSP)	((struct hsfs *)(VFSP)->vfs_data)
220 #define	HSFS_TO_VFS(FSP)	((FSP)->hsfs_vfs)
221 
222 #define	VTOH(VP)		((struct hsnode *)(VP)->v_data)
223 #define	HTOV(HP)		(((HP)->hs_vnode))
224 
225 /*
226  * Convert between Logical Block Number and Sector Number.
227  */
228 #define	LBN_TO_SEC(lbn, vfsp)	((lbn)>>((struct hsfs *)((vfsp)->vfs_data))->  \
229 				hsfs_vol.lbn_secshift)
230 
231 #define	SEC_TO_LBN(sec, vfsp)	((sec)<<((struct hsfs *)((vfsp)->vfs_data))->  \
232 				hsfs_vol.lbn_secshift)
233 
234 #define	LBN_TO_BYTE(lbn, vfsp)	((lbn)<<((struct hsfs *)((vfsp)->vfs_data))->  \
235 				hsfs_vol.lbn_shift)
236 #define	BYTE_TO_LBN(boff, vfsp)	((boff)>>((struct hsfs *)((vfsp)->vfs_data))-> \
237 				hsfs_vol.lbn_shift)
238 
239 /*
240  * Create a nodeid.
241  * We construct the nodeid from the location of the directory
242  * entry which points to the file.  We divide by 32 to
243  * compress the range of nodeids; we know that the minimum size
244  * for an ISO9660 dirent is 34, so we will never have adjacent
245  * dirents with the same nodeid.
246  */
247 #define	HSFS_MIN_DL_SHFT	5
248 #define	MAKE_NODEID(lbn, off, vfsp) \
249 		((LBN_TO_BYTE((lbn), (vfsp)) + (off)) >> HSFS_MIN_DL_SHFT)
250 
251 #ifdef	__cplusplus
252 }
253 #endif
254 
255 #endif	/* _SYS_FS_HSFS_NODE_H */
256