udf.h revision 1.11 1 /* $NetBSD: udf.h,v 1.11 2008/05/14 16:49:48 reinoud Exp $ */
2
3 /*
4 * Copyright (c) 2006, 2008 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 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29 #ifndef _FS_UDF_UDF_H_
30 #define _FS_UDF_UDF_H_
31
32 #include <sys/queue.h>
33 #include <sys/uio.h>
34 #include <sys/mutex.h>
35
36 #include "udf_osta.h"
37 #include "ecma167-udf.h"
38 #include <sys/cdio.h>
39 #include <sys/bufq.h>
40 #include <sys/disk.h>
41 #include <sys/kthread.h>
42 #include <miscfs/genfs/genfs_node.h>
43
44 /* debug section */
45 extern int udf_verbose;
46
47 /* undefine UDF_COMPLETE_DELETE to need `purge'; but purge is not implemented */
48 #define UDF_COMPLETE_DELETE
49
50 /* debug categories */
51 #define UDF_DEBUG_VOLUMES 0x00001
52 #define UDF_DEBUG_LOCKING 0x00002
53 #define UDF_DEBUG_NODE 0x00004
54 #define UDF_DEBUG_LOOKUP 0x00008
55 #define UDF_DEBUG_READDIR 0x00010
56 #define UDF_DEBUG_FIDS 0x00020
57 #define UDF_DEBUG_DESCRIPTOR 0x00040
58 #define UDF_DEBUG_TRANSLATE 0x00080
59 #define UDF_DEBUG_STRATEGY 0x00100
60 #define UDF_DEBUG_READ 0x00200
61 #define UDF_DEBUG_WRITE 0x00400
62 #define UDF_DEBUG_CALL 0x00800
63 #define UDF_DEBUG_ATTR 0x01000
64 #define UDF_DEBUG_EXTATTR 0x02000
65 #define UDF_DEBUG_ALLOC 0x04000
66 #define UDF_DEBUG_ADWLK 0x08000
67 #define UDF_DEBUG_NOTIMPL 0x10000
68 #define UDF_DEBUG_SHEDULE 0x20000
69 #define UDF_DEBUG_SYNC 0x40000
70 #define UDF_DEBUG_PARANOIA 0x80000
71
72 /* initial value of udf_verbose */
73 #define UDF_DEBUGGING 0
74
75
76 #ifdef DEBUG
77 #ifdef SYSCTL_SETUP_PROTO
78 SYSCTL_SETUP_PROTO(sysctl_vfs_udf_setup);
79 #endif /* SYSCTL_SETUP_PROTO */
80 #endif
81
82
83 #ifdef DEBUG
84 #define DPRINTF(name, arg) { \
85 if (udf_verbose & UDF_DEBUG_##name) {\
86 printf arg;\
87 };\
88 }
89 #define DPRINTFIF(name, cond, arg) { \
90 if (udf_verbose & UDF_DEBUG_##name) { \
91 if (cond) printf arg;\
92 };\
93 }
94 #else
95 #define DPRINTF(name, arg) {}
96 #define DPRINTFIF(name, cond, arg) {}
97 #endif
98
99
100 /* constants to identify what kind of identifier we are dealing with */
101 #define UDF_REGID_DOMAIN 1
102 #define UDF_REGID_UDF 2
103 #define UDF_REGID_IMPLEMENTATION 3
104 #define UDF_REGID_APPLICATION 4
105 #define UDF_REGID_NAME 99
106
107
108 /* DON'T change these: they identify 13thmonkey's UDF implementation */
109 #define APP_NAME "*NetBSD UDF"
110 #define APP_VERSION_MAIN 0
111 #define APP_VERSION_SUB 4
112 #define IMPL_NAME "*NetBSD kernel UDF"
113
114
115 /* Configuration values */
116 #define UDF_INODE_HASHBITS 10
117 #define UDF_INODE_HASHSIZE (1<<UDF_INODE_HASHBITS)
118 #define UDF_INODE_HASHMASK (UDF_INODE_HASHSIZE - 1)
119 #define UDF_ECCBUF_HASHBITS 10
120 #define UDF_ECCBUF_HASHSIZE (1<<UDF_ECCBUF_HASHBITS)
121 #define UDF_ECCBUF_HASHMASK (UDF_ECCBUF_HASHSIZE -1)
122
123 #define UDF_ECCLINE_MAXFREE 10 /* picked */
124 #define UDF_ECCLINE_MAXBUSY 100 /* picked */
125
126 #define UDF_MAX_MAPPINGS (MAXPHYS/DEV_BSIZE) /* 128 */
127 #define UDF_VAT_CHUNKSIZE (64*1024) /* picked */
128 #define UDF_SYMLINKBUFLEN (64*1024) /* picked */
129
130
131 /* structure space */
132 #define UDF_ANCHORS 4 /* 256, 512, N-256, N */
133 #define UDF_PARTITIONS 4 /* overkill */
134 #define UDF_PMAPS 5 /* overkill */
135 #define UDF_LVDINT_SEGMENTS 100 /* big overkill */
136 #define UDF_LVINT_LOSSAGE 4 /* lose 2 openings */
137 #define UDF_MAX_ALLOC_EXTENTS 10 /* overkill */
138
139
140 /* constants */
141 #define UDF_MAX_NAMELEN 255 /* as per SPEC */
142 #define UDF_TRANS_ZERO ((uint64_t) -1)
143 #define UDF_TRANS_UNMAPPED ((uint64_t) -2)
144 #define UDF_TRANS_INTERN ((uint64_t) -3)
145 #define UDF_MAX_SECTOR ((uint64_t) -10) /* high water mark */
146
147
148 /* RW content hint for allocation and other purposes */
149 #define UDF_C_PROCESSED 0 /* not relevant */
150 #define UDF_C_USERDATA 1 /* all but userdata is metadata */
151 //#define UDF_C_METADATA 2 /* unspecified metadata */
152 #define UDF_C_DSCR 3 /* update sectornr and CRC */
153 #define UDF_C_NODE 4 /* file/dir node, update sectornr and CRC */
154 #define UDF_C_EXTATTRS 5 /* dunno what to do yet */
155 #define UDF_C_FIDS 6 /* update all contained fids */
156
157
158 /* use unused b_freelistindex for our UDF_C_TYPE */
159 #define b_udf_c_type b_freelistindex
160
161
162 /* virtual to physical mapping types */
163 #define UDF_VTOP_RAWPART UDF_PMAPS /* [0..UDF_PMAPS> are normal */
164
165 #define UDF_VTOP_TYPE_RAW 0
166 #define UDF_VTOP_TYPE_UNKNOWN 0
167 #define UDF_VTOP_TYPE_PHYS 1
168 #define UDF_VTOP_TYPE_VIRT 2
169 #define UDF_VTOP_TYPE_SPARABLE 3
170 #define UDF_VTOP_TYPE_META 4
171
172
173 /* allocation strategies */
174 #define UDF_ALLOC_SEQUENTIAL 1 /* linear on NWA */
175 #define UDF_ALLOC_VAT 2 /* VAT handling */
176 #define UDF_ALLOC_SPACEMAP 3 /* spacemaps */
177 #define UDF_ALLOC_METABITMAP 4 /* metadata bitmap */
178 #define UDF_ALLOC_METASEQUENTIAL 5 /* in chunks seq., nodes not seq */
179 #define UDF_ALLOC_RELAXEDSEQUENTIAL 6 /* only nodes not seq. */
180
181
182 /* logical volume open/close actions */
183 #define UDF_OPEN_SESSION 0x01 /* if needed writeout VRS + VDS */
184 #define UDF_CLOSE_SESSION 0x02 /* close session after writing VAT */
185 #define UDF_WRITE_VAT 0x04 /* sequential VAT filesystem */
186 #define UDF_WRITE_LVINT 0x08 /* write out open lvint */
187 #define UDF_WRITE_PART_BITMAPS 0x10 /* write out partition space bitmaps */
188 #define UDF_APPENDONLY_LVINT 0x20 /* no shifting, only appending */
189 #define UDFLOGVOL_BITS "\20\1OPENSESSION\2CLOSESESSION\3WRITEVAT\4WRITELVINT"\
190 "\5APPENDONLY"
191
192 /* logical volume error handling actions */
193 #define UDF_UPDATE_TRACKINFO 0x01 /* update trackinfo and re-shedule */
194 #define UDF_REMAP_BLOCK 0x02 /* remap the failing block length */
195 #define UDFONERROR_BITS "\20\1UPDATE_TRACKINFO\2REMAP_BLOCK"
196
197
198 /* readdir cookies */
199 #define UDF_DIRCOOKIE_DOT 1
200
201
202 /* malloc pools */
203 MALLOC_DECLARE(M_UDFMNT);
204 MALLOC_DECLARE(M_UDFVOLD);
205 MALLOC_DECLARE(M_UDFTEMP);
206
207 struct pool udf_node_pool;
208 struct udf_node;
209 struct udf_strategy;
210
211
212 struct udf_lvintq {
213 uint32_t start;
214 uint32_t end;
215 uint32_t pos;
216 uint32_t wpos;
217 };
218
219
220 struct udf_bitmap {
221 uint8_t *blob; /* allocated */
222 uint8_t *bits; /* bits themselves */
223 uint8_t *pages; /* dirty pages */
224 uint32_t max_offset; /* in bits */
225 uint32_t data_pos; /* position in data */
226 uint32_t metadata_pos; /* .. in metadata */
227 };
228
229
230 struct udf_strat_args {
231 struct udf_mount *ump;
232 struct udf_node *udf_node;
233 struct long_ad *icb;
234 union dscrptr *dscr;
235 struct buf *nestbuf;
236 kauth_cred_t cred;
237 int waitfor;
238 };
239
240 struct udf_strategy {
241 int (*create_logvol_dscr) (struct udf_strat_args *args);
242 void (*free_logvol_dscr) (struct udf_strat_args *args);
243 int (*read_logvol_dscr) (struct udf_strat_args *args);
244 int (*write_logvol_dscr) (struct udf_strat_args *args);
245 void (*queuebuf) (struct udf_strat_args *args);
246 void (*discstrat_init) (struct udf_strat_args *args);
247 void (*discstrat_finish) (struct udf_strat_args *args);
248 };
249
250 extern struct udf_strategy udf_strat_bootstrap;
251 extern struct udf_strategy udf_strat_sequential;
252 extern struct udf_strategy udf_strat_direct;
253 extern struct udf_strategy udf_strat_rmw;
254
255
256 /* pre cleanup */
257 struct udf_mount {
258 struct mount *vfs_mountp;
259 struct vnode *devvp;
260 struct mmc_discinfo discinfo;
261 struct udf_args mount_args;
262
263 /* format descriptors */
264 kmutex_t logvol_mutex;
265 struct anchor_vdp *anchors[UDF_ANCHORS]; /* anchors to VDS */
266 struct pri_vol_desc *primary_vol; /* identification */
267 struct logvol_desc *logical_vol; /* main mapping v->p */
268 struct unalloc_sp_desc *unallocated; /* free UDF space */
269 struct impvol_desc *implementation; /* likely reduntant */
270 struct logvol_int_desc *logvol_integrity; /* current integrity */
271 struct part_desc *partitions[UDF_PARTITIONS]; /* partitions */
272 /* logvol_info is derived; points *into* other structures */
273 struct udf_logvol_info *logvol_info; /* integrity descr. */
274
275 /* fileset and root directories */
276 struct fileset_desc *fileset_desc; /* normally one */
277
278 /* tracing logvol integrity history */
279 struct udf_lvintq lvint_trace[UDF_LVDINT_SEGMENTS];
280 int lvopen; /* logvol actions */
281 int lvclose; /* logvol actions */
282
283 /* disc allocation / writing method */
284 int lvreadwrite; /* bits */
285 int data_alloc; /* all userdata */
286 int meta_alloc; /* all metadata */
287 int data_part;
288 int metadata_part;
289 kmutex_t allocate_mutex;
290
291 /* logical to physical translations */
292 int vtop[UDF_PMAPS+1]; /* vpartnr trans */
293 int vtop_tp[UDF_PMAPS+1]; /* type of trans */
294
295 /* sequential track info */
296 struct mmc_trackinfo data_track;
297 struct mmc_trackinfo metadata_track;
298
299 /* VAT */
300 uint32_t first_possible_vat_location;
301 uint32_t last_possible_vat_location;
302 uint32_t vat_entries;
303 uint32_t vat_offset; /* offset in table */
304 uint32_t vat_last_free_lb; /* last free lb_num */
305 uint32_t vat_table_len;
306 uint32_t vat_table_alloc_len;
307 uint8_t *vat_table;
308 uint8_t *vat_pages; /* TODO */
309 struct udf_node *vat_node; /* system node */
310
311 /* space bitmaps */
312 struct space_bitmap_desc*part_unalloc_dscr[UDF_PARTITIONS];
313 struct space_bitmap_desc*part_freed_dscr [UDF_PARTITIONS];
314 struct udf_bitmap part_unalloc_bits[UDF_PARTITIONS];
315 struct udf_bitmap part_freed_bits [UDF_PARTITIONS];
316
317 /* sparable */
318 uint32_t sparable_packet_size;
319 uint32_t packet_size;
320 struct udf_sparing_table*sparing_table;
321
322 /* meta */
323 struct udf_node *metadata_node; /* system node */
324 struct udf_node *metadatamirror_node; /* system node */
325 struct udf_node *metadatabitmap_node; /* system node */
326 struct udf_bitmap metadata_bitmap; /* TODO : readin */
327
328 /* hash table to lookup icb -> udf_node and sorted list for sync */
329 kmutex_t ihash_lock;
330 kmutex_t get_node_lock;
331 LIST_HEAD(, udf_node) udf_nodes[UDF_INODE_HASHSIZE];
332 LIST_HEAD(, udf_node) sorted_udf_nodes; /* sorted sync list */
333
334 /* syncing */
335 int syncing; /* are we syncing? */
336 kcondvar_t dirtynodes_cv; /* sleeping on sync */
337
338 /* late allocation */
339 uint32_t uncomitted_lb; /* for free space */
340 struct long_ad *la_node_ad_cpy; /* issue buf */
341 uint64_t *la_lmapping, *la_pmapping; /* issue buf */
342
343 /* lists */
344 STAILQ_HEAD(udfmntpts, udf_mount) all_udf_mntpnts;
345
346 /* device strategy */
347 struct udf_strategy *strategy;
348 void *strategy_private;
349 };
350
351 /*
352 * UDF node describing a file/directory.
353 *
354 * BUGALERT claim node_mutex before reading/writing to prevent inconsistencies !
355 */
356 struct udf_node {
357 struct genfs_node i_gnode; /* has to be first */
358 struct vnode *vnode; /* vnode associated */
359 struct udf_mount *ump;
360
361 kmutex_t node_mutex;
362 kcondvar_t node_lock; /* sleeping lock */
363 char const *lock_fname;
364 int lock_lineno;
365
366 /* one of `fe' or `efe' can be set, not both (UDF file entry dscr.) */
367 struct file_entry *fe;
368 struct extfile_entry *efe;
369 struct alloc_ext_entry *ext[UDF_MAX_ALLOC_EXTENTS];
370 int num_extensions;
371
372 /* location found, recording location & hints */
373 struct long_ad loc; /* FID/hash loc. */
374 struct long_ad write_loc; /* strat 4096 loc */
375 int needs_indirect; /* has missing indr. */
376 struct long_ad ext_loc[UDF_MAX_ALLOC_EXTENTS];
377
378 uint64_t last_diroffset; /* speeding up lookup*/
379
380 /* misc */
381 uint32_t i_flags; /* associated flags */
382 struct lockf *lockf; /* lock list */
383 uint32_t outstanding_bufs; /* file data */
384 uint32_t outstanding_nodedscr; /* node dscr */
385
386 /* references to associated nodes */
387 struct udf_node *extattr;
388 struct udf_node *streamdir;
389 struct udf_node *my_parent; /* if extended attr. */
390
391 LIST_ENTRY(udf_node) hashchain; /* inside hash line */
392 LIST_ENTRY(udf_node) sortchain; /* sorted udf nodes */
393 };
394
395
396 /* misc. flags stored in i_flags (XXX needs cleaning up) */
397 #define IN_ACCESS 0x0001 /* Inode access time update request. */
398 #define IN_CHANGE 0x0002 /* Inode change time update request. */
399 #define IN_UPDATE 0x0004 /* Inode was written to; update mtime*/
400 #define IN_MODIFY 0x0008 /* Modification time update request. */
401 #define IN_MODIFIED 0x0010 /* node has been modified. */
402 #define IN_ACCESSED 0x0020 /* node has been accessed. */
403 #define IN_RENAME 0x0040 /* node is being renamed. XXX ?? */
404 #define IN_DELETED 0x0080 /* node is unlinked, no FID reference */
405 #define IN_LOCKED 0x0100 /* node is locked by condvar */
406 #define IN_SYNCED 0x0200 /* node is being used by sync */
407 #define IN_CALLBACK_ULK 0x0400 /* node will be unlocked by callback */
408
409
410 #define IN_FLAGBITS \
411 "\10\1IN_ACCESS\2IN_CHANGE\3IN_UPDATE\4IN_MODIFY\5IN_MODIFIED" \
412 "\6IN_ACCESSED\7IN_RENAME\10IN_DELETED\11IN_LOCKED\12IN_SYNCED" \
413 "\13IN_CALLBACK_ULK"
414
415 #endif /* !_FS_UDF_UDF_H_ */
416