xref: /openbsd-src/sys/isofs/udf/udf.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: udf.h,v 1.14 2011/07/04 04:30:41 tedu Exp $	*/
2 
3 /*
4  * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
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 AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD: src/sys/fs/udf/udf.h,v 1.9 2004/10/29 10:40:58 phk Exp $
29  */
30 
31 /*
32  * Ported to OpenBSD by Pedro Martelletto in February 2005.
33  */
34 
35 #define UDF_HASHTBLSIZE 100
36 
37 struct unode {
38 	LIST_ENTRY(unode) u_le;
39 	struct vnode *u_vnode;
40 	struct vnode *u_devvp;
41 	struct umount *u_ump;
42 	struct lock u_lock;
43 	dev_t u_dev;
44 	ino_t u_ino;
45 	union {
46 		long u_diroff;
47 		long u_vatlen;
48 	} un_u;
49 	struct extfile_entry *u_fentry;
50 };
51 
52 #define	u_diroff	un_u.u_diroff
53 #define	u_vatlen	un_u.u_vatlen
54 
55 struct umount {
56 	int um_flags;
57 	struct mount *um_mountp;
58 	struct vnode *um_devvp;
59 	dev_t um_dev;
60 	int um_bsize;
61 	int um_bshift;
62 	int um_bmask;
63 	uint32_t um_start;
64 	uint32_t um_realstart;
65 	uint32_t um_len;
66 	uint32_t um_reallen;
67 	uint32_t um_meta_start;
68 	uint32_t um_meta_len;
69 	struct unode *um_vat;
70 	struct long_ad um_root_icb;
71 	LIST_HEAD(udf_hash_lh, unode) *um_hashtbl;
72 	u_long um_hashsz;
73 	struct mutex um_hashmtx;
74 	int um_psecs;
75 	int um_stbl_len;
76 	struct udf_sparing_table *um_stbl;
77 };
78 
79 #define	UDF_MNT_FIND_VAT	0x01	/* Indicates a VAT must be found */
80 #define	UDF_MNT_USES_VAT	0x02	/* Indicates a VAT must be used */
81 #define	UDF_MNT_USES_META	0x04	/* Indicates we are using a Metadata partition*/
82 
83 struct udf_dirstream {
84 	struct unode	*node;
85 	struct umount	*ump;
86 	struct buf	*bp;
87 	uint8_t		*data;
88 	uint8_t		*buf;
89 	int		fsize;
90 	int		off;
91 	int		this_off;
92 	int		offset;
93 	int		size;
94 	int		error;
95 	int		fid_fragment;
96 };
97 
98 #define	VFSTOUDFFS(mp)	((struct umount *)((mp)->mnt_data))
99 #define	VTOU(vp)	((struct unode *)((vp)->v_data))
100 
101 /*
102  * The block layer refers to things in terms of 512 byte blocks by default.
103  * btodb() is expensive, so speed things up.
104  * Can the block layer be forced to use a different block size?
105  */
106 #define	RDSECTOR(devvp, sector, size, bp) \
107 	bread(devvp, sector << (ump->um_bshift - DEV_BSHIFT), size, bp)
108 
109 static __inline int
110 udf_readlblks(struct umount *ump, int sector, int size, struct buf **bp)
111 {
112 	return (RDSECTOR(ump->um_devvp, sector,
113 			 (size + ump->um_bmask) & ~ump->um_bmask, bp));
114 }
115 
116 /*
117  * Produce a suitable file number from an ICB.  The passed in ICB is expected
118  * to be in little endian (meaning that it hasn't been swapped for big
119  * endian machines yet).
120  * If the fileno resolves to 0, we might be in big trouble.
121  * Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
122  *     but not ext_ad.
123  */
124 static __inline ino_t
125 udf_getid(struct long_ad *icb)
126 {
127 	return (letoh32(icb->loc.lb_num));
128 }
129 
130 int udf_allocv(struct mount *, struct vnode **, struct proc *);
131 int udf_hashlookup(struct umount *, ino_t, int, struct vnode **);
132 int udf_hashins(struct unode *);
133 int udf_hashrem(struct unode *);
134 int udf_checktag(struct desc_tag *, uint16_t);
135 
136 typedef	uint16_t unicode_t;
137