xref: /openbsd/sys/isofs/udf/udf.h (revision 26b8ec94)
1 /*	$OpenBSD: udf.h,v 1.21 2016/06/19 11:54:33 natano 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 rrwlock 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 	SIPHASH_KEY um_hashkey;
75 	u_long um_hashsz;
76 	struct mutex um_hashmtx;
77 	int um_psecs;
78 	int um_stbl_len;
79 	struct udf_sparing_table *um_stbl;
80 };
81 
82 #define	UDF_MNT_FIND_VAT	0x01	/* Indicates a VAT must be found */
83 #define	UDF_MNT_USES_VAT	0x02	/* Indicates a VAT must be used */
84 #define	UDF_MNT_USES_META	0x04	/* Indicates we are using a Metadata partition*/
85 
86 #define	VTOU(vp)	((struct unode *)((vp)->v_data))
87 
88 #ifdef _KERNEL
89 
90 struct udf_dirstream {
91 	struct unode	*node;
92 	struct umount	*ump;
93 	struct buf	*bp;
94 	uint8_t		*data;
95 	uint8_t		*buf;
96 	int		fsize;
97 	int		off;
98 	int		this_off;
99 	int		offset;
100 	int		size;
101 	int		error;
102 	int		fid_fragment;
103 };
104 
105 #define	VFSTOUDFFS(mp)	((struct umount *)((mp)->mnt_data))
106 
107 /*
108  * The block layer refers to things in terms of 512 byte blocks by default.
109  * btodb() is expensive, so speed things up.
110  * Can the block layer be forced to use a different block size?
111  */
112 #define	RDSECTOR(devvp, sector, size, bp) \
113 	bread(devvp, \
114 		((daddr_t)(sector) << ump->um_bshift) / DEV_BSIZE, size, bp)
115 
116 static __inline int
udf_readlblks(struct umount * ump,int sector,int size,struct buf ** bp)117 udf_readlblks(struct umount *ump, int sector, int size, struct buf **bp)
118 {
119 	return (RDSECTOR(ump->um_devvp, sector,
120 			 (size + ump->um_bmask) & ~ump->um_bmask, bp));
121 }
122 
123 /*
124  * Produce a suitable file number from an ICB.  The passed in ICB is expected
125  * to be in little endian (meaning that it hasn't been swapped for big
126  * endian machines yet).
127  * If the fileno resolves to 0, we might be in big trouble.
128  * Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
129  *     but not ext_ad.
130  */
131 static __inline udfino_t
udf_getid(struct long_ad * icb)132 udf_getid(struct long_ad *icb)
133 {
134 	return (letoh32(icb->loc.lb_num));
135 }
136 
137 int udf_allocv(struct mount *, struct vnode **, struct proc *);
138 int udf_hashlookup(struct umount *, udfino_t, int, struct vnode **);
139 int udf_hashins(struct unode *);
140 int udf_hashrem(struct unode *);
141 int udf_checktag(struct desc_tag *, uint16_t);
142 
143 typedef	uint16_t unicode_t;
144 
145 #endif /* _KERNEL */
146 
147