xref: /openbsd-src/sys/isofs/udf/udf.h (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /*	$OpenBSD: udf.h,v 1.19 2013/09/17 04:31:56 mlarkin 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 typedef uint32_t udfino_t;
38 
39 struct unode {
40 	LIST_ENTRY(unode) u_le;
41 	struct vnode *u_vnode;
42 	struct vnode *u_devvp;
43 	struct umount *u_ump;
44 	struct lock u_lock;
45 	dev_t u_dev;
46 	udfino_t u_ino;
47 	union {
48 		long u_diroff;
49 		long u_vatlen;
50 	} un_u;
51 	struct extfile_entry *u_fentry;
52 };
53 
54 #define	u_diroff	un_u.u_diroff
55 #define	u_vatlen	un_u.u_vatlen
56 
57 struct umount {
58 	int um_flags;
59 	struct mount *um_mountp;
60 	struct vnode *um_devvp;
61 	dev_t um_dev;
62 	int um_bsize;
63 	int um_bshift;
64 	int um_bmask;
65 	uint32_t um_start;
66 	uint32_t um_realstart;
67 	uint32_t um_len;
68 	uint32_t um_reallen;
69 	uint32_t um_meta_start;
70 	uint32_t um_meta_len;
71 	struct unode *um_vat;
72 	struct long_ad um_root_icb;
73 	LIST_HEAD(udf_hash_lh, unode) *um_hashtbl;
74 	u_long um_hashsz;
75 	struct mutex um_hashmtx;
76 	int um_psecs;
77 	int um_stbl_len;
78 	struct udf_sparing_table *um_stbl;
79 };
80 
81 #define	UDF_MNT_FIND_VAT	0x01	/* Indicates a VAT must be found */
82 #define	UDF_MNT_USES_VAT	0x02	/* Indicates a VAT must be used */
83 #define	UDF_MNT_USES_META	0x04	/* Indicates we are using a Metadata partition*/
84 
85 #define	VTOU(vp)	((struct unode *)((vp)->v_data))
86 
87 #ifdef _KERNEL
88 
89 struct udf_dirstream {
90 	struct unode	*node;
91 	struct umount	*ump;
92 	struct buf	*bp;
93 	uint8_t		*data;
94 	uint8_t		*buf;
95 	int		fsize;
96 	int		off;
97 	int		this_off;
98 	int		offset;
99 	int		size;
100 	int		error;
101 	int		fid_fragment;
102 };
103 
104 #define	VFSTOUDFFS(mp)	((struct umount *)((mp)->mnt_data))
105 
106 /*
107  * The block layer refers to things in terms of 512 byte blocks by default.
108  * btodb() is expensive, so speed things up.
109  * Can the block layer be forced to use a different block size?
110  */
111 #define	RDSECTOR(devvp, sector, size, bp) \
112 	bread(devvp, \
113 		((daddr_t)(sector) << ump->um_bshift) / DEV_BSIZE, size, bp)
114 
115 static __inline int
116 udf_readlblks(struct umount *ump, int sector, int size, struct buf **bp)
117 {
118 	return (RDSECTOR(ump->um_devvp, sector,
119 			 (size + ump->um_bmask) & ~ump->um_bmask, bp));
120 }
121 
122 /*
123  * Produce a suitable file number from an ICB.  The passed in ICB is expected
124  * to be in little endian (meaning that it hasn't been swapped for big
125  * endian machines yet).
126  * If the fileno resolves to 0, we might be in big trouble.
127  * Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
128  *     but not ext_ad.
129  */
130 static __inline udfino_t
131 udf_getid(struct long_ad *icb)
132 {
133 	return (letoh32(icb->loc.lb_num));
134 }
135 
136 int udf_allocv(struct mount *, struct vnode **, struct proc *);
137 int udf_hashlookup(struct umount *, udfino_t, int, struct vnode **);
138 int udf_hashins(struct unode *);
139 int udf_hashrem(struct unode *);
140 int udf_checktag(struct desc_tag *, uint16_t);
141 
142 typedef	uint16_t unicode_t;
143 
144 #endif /* _KERNEL */
145 
146