xref: /netbsd-src/sys/fs/udf/udf.h (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /* $NetBSD: udf.h,v 1.10 2007/10/10 20:42:25 ad Exp $ */
2 
3 /*
4  * Copyright (c) 2006 Reinoud Zandijk
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *          This product includes software developed for the
18  *          NetBSD Project.  See http://www.NetBSD.org/ for
19  *          information about NetBSD.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #ifndef _FS_UDF_UDF_H_
37 #define _FS_UDF_UDF_H_
38 
39 #include <sys/queue.h>
40 #include <sys/uio.h>
41 #include <sys/mutex.h>
42 
43 #include "udf_osta.h"
44 #include "ecma167-udf.h"
45 #include <sys/cdio.h>
46 #include <miscfs/genfs/genfs_node.h>
47 
48 /* TODO make `udf_verbose' set by sysctl */
49 /* debug section */
50 extern int udf_verbose;
51 
52 /* initial value of udf_verbose */
53 #define UDF_DEBUGGING		0x000
54 
55 /* debug categories */
56 #define UDF_DEBUG_VOLUMES	0x001
57 #define UDF_DEBUG_LOCKING	0x002
58 #define UDF_DEBUG_NODE		0x004
59 #define UDF_DEBUG_LOOKUP	0x008
60 #define UDF_DEBUG_READDIR	0x010
61 #define UDF_DEBUG_FIDS		0x020
62 #define UDF_DEBUG_DESCRIPTOR	0x040
63 #define UDF_DEBUG_TRANSLATE	0x080
64 #define UDF_DEBUG_STRATEGY	0x100
65 #define UDF_DEBUG_READ		0x200
66 #define UDF_DEBUG_CALL		0x400
67 #define UDF_DEBUG_NOTIMPL	UDF_DEBUG_CALL
68 
69 
70 #ifdef DEBUG
71 #ifdef SYSCTL_SETUP_PROTO
72 SYSCTL_SETUP_PROTO(sysctl_vfs_udf_setup);
73 #endif /* SYSCTL_SETUP_PROTO */
74 #endif
75 
76 
77 #ifdef DEBUG
78 #define DPRINTF(name, arg) { \
79 		if (udf_verbose & UDF_DEBUG_##name) {\
80 			printf arg;\
81 		};\
82 	}
83 #define DPRINTFIF(name, cond, arg) { \
84 		if (udf_verbose & UDF_DEBUG_##name) { \
85 			if (cond) printf arg;\
86 		};\
87 	}
88 #else
89 #define DPRINTF(name, arg) {}
90 #define DPRINTFIF(name, cond, arg) {}
91 #endif
92 
93 
94 /* constants to identify what kind of identifier we are dealing with */
95 #define UDF_REGID_DOMAIN		 1
96 #define UDF_REGID_UDF			 2
97 #define UDF_REGID_IMPLEMENTATION	 3
98 #define UDF_REGID_APPLICATION		 4
99 #define UDF_REGID_NAME			99
100 
101 
102 /* DON'T change these: they identify 13thmonkey's UDF implementation */
103 #define APP_NAME		"*NetBSD UDF"
104 #define APP_VERSION_MAIN	1
105 #define APP_VERSION_SUB		0
106 #define IMPL_NAME		"*13thMonkey.org"
107 
108 
109 /* Configuration values */
110 #define UDF_INODE_HASHBITS 	10
111 #define UDF_INODE_HASHSIZE	(1<<UDF_INODE_HASHBITS)
112 #define UDF_INODE_HASHMASK	(UDF_INODE_HASHSIZE - 1)
113 
114 
115 /* structure space */
116 #define UDF_ANCHORS		4	/* 256, 512, N-256, N */
117 #define UDF_PARTITIONS		4	/* overkill */
118 #define UDF_PMAPS		4	/* overkill */
119 
120 
121 /* constants */
122 #define UDF_MAX_NAMELEN		255			/* as per SPEC */
123 #define UDF_TRANS_ZERO		((uint64_t) -1)
124 #define UDF_TRANS_UNMAPPED	((uint64_t) -2)
125 #define UDF_TRANS_INTERN	((uint64_t) -3)
126 #define UDF_MAX_SECTOR		((uint64_t) -10)	/* high water mark */
127 
128 
129 /* malloc pools */
130 MALLOC_DECLARE(M_UDFMNT);
131 MALLOC_DECLARE(M_UDFVOLD);
132 MALLOC_DECLARE(M_UDFTEMP);
133 
134 struct pool udf_node_pool;
135 
136 struct udf_node;
137 
138 /* pre cleanup */
139 struct udf_mount {
140 	struct mount		*vfs_mountp;
141 	struct vnode		*devvp;
142 	struct mmc_discinfo	 discinfo;
143 	struct udf_args		 mount_args;
144 
145 	/* read in structures */
146 	struct anchor_vdp	*anchors[UDF_ANCHORS];	/* anchors to VDS    */
147 	struct pri_vol_desc	*primary_vol;		/* identification    */
148 	struct logvol_desc	*logical_vol;		/* main mapping v->p */
149 	struct unalloc_sp_desc	*unallocated;		/* free UDF space    */
150 	struct impvol_desc	*implementation;	/* likely reduntant  */
151 	struct logvol_int_desc	*logvol_integrity;	/* current integrity */
152 	struct part_desc	*partitions[UDF_PARTITIONS]; /* partitions   */
153 
154 	/* derived; points *into* other structures */
155 	struct udf_logvol_info	*logvol_info;		/* integrity descr.  */
156 
157 	/* fileset and root directories */
158 	struct fileset_desc	*fileset_desc;		/* normally one      */
159 
160 	/* logical to physical translations */
161 	int 			 vtop[UDF_PMAPS+1];	/* vpartnr trans     */
162 	int			 vtop_tp[UDF_PMAPS+1];	/* type of trans     */
163 
164 	/* VAT */
165 	uint32_t		 first_possible_vat_location;
166 	uint32_t		 last_possible_vat_location;
167 	uint32_t		 vat_table_alloc_length;
168 	uint32_t		 vat_entries;
169 	uint32_t		 vat_offset;		/* offset in table   */
170 	uint8_t			*vat_table;		/* read in data      */
171 
172 	/* sparable */
173 	uint32_t		 sparable_packet_len;
174 	struct udf_sparing_table*sparing_table;
175 
176 	/* meta */
177 	struct udf_node 	*metadata_file;
178 	struct udf_node 	*metadatamirror_file;
179 	struct udf_node 	*metadatabitmap_file;
180 
181 	/* disc allocation */
182 	int			data_alloc, meta_alloc;	/* allocation scheme */
183 
184 	struct mmc_trackinfo	datatrack;
185 	struct mmc_trackinfo	metadatatrack;
186 		/* TODO free space and usage per partition */
187 		/* ... [UDF_PARTITIONS]; */
188 
189 	/* hash table to lookup ino_t -> udf_node */
190 	LIST_HEAD(, udf_node) udf_nodes[UDF_INODE_HASHSIZE];
191 
192 	/* allocation pool for udf_node's descriptors */
193 	struct pool *desc_pool;
194 
195 	/* locks */
196 	kmutex_t	ihash_lock;
197 	kmutex_t	get_node_lock;
198 
199 	/* lists */
200 	STAILQ_HEAD(, udf_node) dirty_nodes;
201 	STAILQ_HEAD(udfmntpts, udf_mount) all_udf_mntpnts;
202 };
203 
204 
205 #define UDF_VTOP_RAWPART UDF_PMAPS	/* [0..UDF_PMAPS> are normal     */
206 
207 /* virtual to physical mapping types */
208 #define UDF_VTOP_TYPE_RAW            0
209 #define UDF_VTOP_TYPE_UNKNOWN        0
210 #define UDF_VTOP_TYPE_PHYS           1
211 #define UDF_VTOP_TYPE_VIRT           2
212 #define UDF_VTOP_TYPE_SPARABLE       3
213 #define UDF_VTOP_TYPE_META           4
214 
215 /* allocation strategies */
216 #define UDF_ALLOC_SPACEMAP           1  /* spacemaps                     */
217 #define UDF_ALLOC_SEQUENTIAL         2  /* linear on NWA                 */
218 #define UDF_ALLOC_VAT                3  /* VAT handling                  */
219 #define UDF_ALLOC_METABITMAP         4  /* metadata bitmap               */
220 #define UDF_ALLOC_METASEQUENTIAL     5  /* in chunks seq., nodes not seq */
221 #define UDF_ALLOC_RELAXEDSEQUENTIAL  6  /* only nodes not seq.           */
222 
223 /* readdir cookies */
224 #define UDF_DIRCOOKIE_DOT 1
225 
226 
227 struct udf_node {
228 	struct genfs_node	i_gnode;		/* has to be first   */
229 	struct vnode		*vnode;			/* vnode associated  */
230 	struct udf_mount	*ump;
231 
232 	/* one of `fe' or `efe' can be set, not both (UDF file entry dscr.)  */
233 	struct file_entry	*fe;
234 	struct extfile_entry	*efe;
235 
236 	/* location found and recording location & hints */
237 	struct long_ad		 loc;			/* FID/hash loc.     */
238 	struct long_ad		 next_loc;		/* strat 4096 loc    */
239 	int			 needs_indirect;	/* has missing indr. */
240 	uint64_t		 last_diroffset;	/* speeding up lookup*/
241 
242 	/* TODO support for allocation extents? */
243 
244 	/* device number from extended attributes = makedev(min,maj) */
245 	dev_t			 rdev;
246 
247 	/* misc */
248 	struct lockf		*lockf;			/* lock list         */
249 
250 	/* possibly not needed */
251 	long			 refcnt;
252 	int			 dirty;
253 	int			 hold;
254 
255 	struct udf_node		*extattr;
256 	struct udf_node		*streamdir;
257 
258 	LIST_ENTRY(udf_node)	 hashchain;		/* all udf nodes     */
259 	STAILQ_ENTRY(udf_node)	 dirty_nodes;		/* dirty udf nodes   */
260 };
261 
262 #endif /* !_FS_UDF_UDF_H_ */
263