Home | History | Annotate | Line # | Download | only in udf
udf.h revision 1.3
      1 /* $NetBSD: udf.h,v 1.3 2006/02/02 15:52:23 reinoud 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 
     37 #include <sys/queue.h>
     38 #include <sys/uio.h>
     39 
     40 #include "udf_osta.h"
     41 #include "ecma167-udf.h"
     42 #include <sys/cdio.h>
     43 #include <miscfs/genfs/genfs_node.h>
     44 
     45 #ifndef _FS_UDF_UDF_H_
     46 #define _FS_UDF_UDF_H_
     47 
     48 
     49 /* TODO make `udf_verbose' set by sysctl */
     50 /* debug section */
     51 extern int udf_verbose;
     52 
     53 /* initial value of udf_verbose */
     54 #define UDF_DEBUGGING		0x000
     55 
     56 /* debug categories */
     57 #define UDF_DEBUG_VOLUMES	0x001
     58 #define UDF_DEBUG_LOCKING	0x002
     59 #define UDF_DEBUG_NODE		0x004
     60 #define UDF_DEBUG_LOOKUP	0x008
     61 #define UDF_DEBUG_READDIR	0x010
     62 #define UDF_DEBUG_FIDS		0x020
     63 #define UDF_DEBUG_DESCRIPTOR	0x040
     64 #define UDF_DEBUG_TRANSLATE	0x080
     65 #define UDF_DEBUG_STRATEGY	0x100
     66 #define UDF_DEBUG_READ		0x200
     67 #define UDF_DEBUG_CALL		0x400
     68 #define UDF_DEBUG_NOTIMPL	UDF_DEBUG_CALL
     69 
     70 
     71 #ifdef DEBUG
     72 #define DPRINTF(name, arg) { \
     73 		if (udf_verbose & UDF_DEBUG_##name) {\
     74 			printf arg;\
     75 		};\
     76 	}
     77 #define DPRINTFIF(name, cond, arg) { \
     78 		if (udf_verbose & UDF_DEBUG_##name) { \
     79 			if (cond) printf arg;\
     80 		};\
     81 	}
     82 #else
     83 #define DPRINTF(name, arg) {}
     84 #define DPRINTFIF(name, cond, arg) {}
     85 #endif
     86 
     87 
     88 /* constants to identify what kind of identifier we are dealing with */
     89 #define UDF_REGID_DOMAIN		 1
     90 #define UDF_REGID_UDF			 2
     91 #define UDF_REGID_IMPLEMENTATION	 3
     92 #define UDF_REGID_APPLICATION		 4
     93 #define UDF_REGID_NAME			99
     94 
     95 
     96 /* DON'T change these: they identify 13thmonkey's UDF implementation */
     97 #define APP_NAME		"*NetBSD UDF"
     98 #define APP_VERSION_MAIN	1
     99 #define APP_VERSION_SUB		0
    100 #define IMPL_NAME		"*13thMonkey.org"
    101 
    102 
    103 /* Configuration values */
    104 #define UDF_INODE_HASHBITS 	10
    105 #define UDF_INODE_HASHSIZE	(1<<UDF_INODE_HASHBITS)
    106 #define UDF_INODE_HASHMASK	(UDF_INODE_HASHSIZE - 1)
    107 
    108 
    109 /* structure space */
    110 #define UDF_ANCHORS		4	/* 256, 512, N-256, N */
    111 #define UDF_PARTITIONS		4	/* overkill */
    112 #define UDF_PMAPS		4	/* overkill */
    113 
    114 
    115 /* constants */
    116 #define UDF_MAX_NAMELEN		255			/* as per SPEC */
    117 #define UDF_TRANS_ZERO		((uint64_t) -1)
    118 #define UDF_TRANS_UNMAPPED	((uint64_t) -2)
    119 #define UDF_TRANS_INTERN	((uint64_t) -3)
    120 #define UDF_MAX_SECTOR		((uint64_t) -10)	/* high water mark */
    121 
    122 
    123 /* malloc pools */
    124 MALLOC_DECLARE(M_UDFMNT);
    125 MALLOC_DECLARE(M_UDFVOLD);
    126 MALLOC_DECLARE(M_UDFTEMP);
    127 
    128 struct pool udf_node_pool;
    129 
    130 struct udf_node;
    131 
    132 /* pre cleanup */
    133 struct udf_mount {
    134 	struct mount		*vfs_mountp;
    135 	struct vnode		*devvp;
    136 	struct mmc_discinfo	 discinfo;
    137 	struct udf_args		 mount_args;
    138 
    139 	/* read in structures */
    140 	struct anchor_vdp	*anchors[UDF_ANCHORS];	/* anchors to VDS    */
    141 	struct pri_vol_desc	*primary_vol;		/* identification    */
    142 	struct logvol_desc	*logical_vol;		/* main mapping v->p */
    143 	struct unalloc_sp_desc	*unallocated;		/* free UDF space    */
    144 	struct impvol_desc	*implementation;	/* likely reduntant  */
    145 	struct logvol_int_desc	*logvol_integrity;	/* current integrity */
    146 	struct part_desc	*partitions[UDF_PARTITIONS]; /* partitions   */
    147 
    148 	/* derived; points *into* other structures */
    149 	struct udf_logvol_info	*logvol_info;		/* integrity descr.  */
    150 
    151 	/* fileset and root directories */
    152 	struct fileset_desc	*fileset_desc;		/* normally one      */
    153 
    154 	/* logical to physical translations */
    155 	int 			 vtop[UDF_PMAPS+1];	/* vpartnr trans     */
    156 	int			 vtop_tp[UDF_PMAPS+1];	/* type of trans     */
    157 
    158 	uint32_t		 possible_vat_location;	/* predicted         */
    159 	uint32_t		 vat_table_alloc_length;
    160 	uint32_t		 vat_entries;
    161 	uint32_t		 vat_offset;		/* offset in table   */
    162 	uint8_t			*vat_table;		/* read in data      */
    163 
    164 	uint32_t		 sparable_packet_len;
    165 	struct udf_sparing_table*sparing_table;
    166 
    167 	struct udf_node 	*metafile;
    168 	struct udf_node 	*metabitmapfile;
    169 	struct udf_node 	*metacopyfile;
    170 	struct udf_node 	*metabitmapcopyfile;
    171 
    172 	/* disc allocation */
    173 	int			data_alloc, meta_alloc;	/* allocation scheme */
    174 
    175 	struct mmc_trackinfo	datatrack;
    176 	struct mmc_trackinfo	metadatatrack;
    177 		/* TODO free space and usage per partition */
    178 		/* ... [UDF_PARTITIONS]; */
    179 
    180 	/* hash table to lookup ino_t -> udf_node */
    181 	LIST_HEAD(, udf_node) udf_nodes[UDF_INODE_HASHSIZE];
    182 
    183 	/* allocation pool for udf_node's descriptors */
    184 	struct pool desc_pool;
    185 
    186 	/* locks */
    187 	struct simplelock ihash_slock;
    188 	struct lock       get_node_lock;
    189 
    190 	/* lists */
    191 	STAILQ_HEAD(, udf_node) dirty_nodes;
    192 	STAILQ_HEAD(udfmntpts, udf_mount) all_udf_mntpnts;
    193 };
    194 
    195 
    196 #define UDF_VTOP_RAWPART UDF_PMAPS	/* [0..UDF_PMAPS> are normal     */
    197 
    198 /* virtual to physical mapping types */
    199 #define UDF_VTOP_TYPE_RAW            0
    200 #define UDF_VTOP_TYPE_UNKNOWN        0
    201 #define UDF_VTOP_TYPE_PHYS           1
    202 #define UDF_VTOP_TYPE_VIRT           2
    203 #define UDF_VTOP_TYPE_SPARABLE       3
    204 #define UDF_VTOP_TYPE_META           4
    205 
    206 /* allocation strategies */
    207 #define UDF_ALLOC_SPACEMAP           1  /* spacemaps                     */
    208 #define UDF_ALLOC_SEQUENTIAL         2  /* linear on NWA                 */
    209 #define UDF_ALLOC_VAT                3  /* VAT handling                  */
    210 #define UDF_ALLOC_METABITMAP         4  /* metadata bitmap               */
    211 #define UDF_ALLOC_METASEQUENTIAL     5  /* in chunks seq., nodes not seq */
    212 #define UDF_ALLOC_RELAXEDSEQUENTIAL  6  /* only nodes not seq.           */
    213 
    214 /* readdir cookies */
    215 #define UDF_DIRCOOKIE_DOT 1
    216 
    217 
    218 struct udf_node {
    219 	struct genfs_node	i_gnode;		/* has to be first   */
    220 	struct vnode		*vnode;			/* vnode associated  */
    221 	struct udf_mount	*ump;
    222 
    223 	/* one of `fe' or `efe' can be set, not both (UDF file entry dscr.)  */
    224 	struct file_entry	*fe;
    225 	struct extfile_entry	*efe;
    226 
    227 	/* location found and recording location & hints */
    228 	struct long_ad		 loc;			/* FID/hash loc.     */
    229 	struct long_ad		 next_loc;		/* strat 4096 loc    */
    230 	int			 needs_indirect;	/* has missing indr. */
    231 
    232 	/* TODO support for allocation extents? */
    233 
    234 	/* device number from extended attributes = makedev(min,maj) */
    235 	dev_t			 rdev;
    236 
    237 	/* misc */
    238 	struct lockf		*lockf;			/* lock list         */
    239 
    240 	/* possibly not needed */
    241 	long			 refcnt;
    242 	int			 dirty;
    243 	int			 hold;
    244 
    245 	struct udf_node		*extattr;
    246 	struct udf_node		*streamdir;
    247 
    248 	LIST_ENTRY(udf_node)	 hashchain;		/* all udf nodes     */
    249 	STAILQ_ENTRY(udf_node)	 dirty_nodes;		/* dirty udf nodes   */
    250 };
    251 
    252 #endif /* !_FS_UDF_UDF_H_ */
    253 
    254