1/*-
2 * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#define UDF_HASHTBLSIZE 100
30
31struct udf_node {
32	struct vnode	*i_vnode;
33	struct udf_mnt	*udfmp;
34	ino_t		hash_id;
35	long		diroff;
36	struct file_entry *fentry;
37};
38
39struct udf_mnt {
40	int			im_flags;
41	struct mount		*im_mountp;
42	struct g_consumer	*im_cp;
43	struct bufobj		*im_bo;
44	struct cdev *im_dev;
45	struct vnode		*im_devvp;
46	int			bsize;
47	int			bshift;
48	int			bmask;
49	uint32_t		part_start;
50	uint32_t		part_len;
51	uint64_t		root_id;
52	struct long_ad		root_icb;
53	int			p_sectors;
54	int			s_table_entries;
55	struct udf_sparing_table *s_table;
56	void			*im_d2l;	/* disk->local iconv handle */
57#if 0
58	void			*im_l2d;	/* local->disk iconv handle */
59#endif
60};
61
62struct udf_dirstream {
63	struct udf_node	*node;
64	struct udf_mnt	*udfmp;
65	struct buf	*bp;
66	uint8_t		*data;
67	uint8_t		*buf;
68	int		fsize;
69	int		off;
70	int		this_off;
71	int		offset;
72	int		size;
73	int		error;
74	int		fid_fragment;
75};
76
77struct ifid {
78	u_short	ifid_len;
79	u_short	ifid_pad;
80	int	ifid_ino;
81	long	ifid_start;
82};
83
84#define	VFSTOUDFFS(mp)	((struct udf_mnt *)((mp)->mnt_data))
85#define	VTON(vp)	((struct udf_node *)((vp)->v_data))
86
87/*
88 * The block layer refers to things in terms of 512 byte blocks by default.
89 * btodb() is expensive, so speed things up.
90 * XXX Can the block layer be forced to use a different block size?
91 */
92#define	RDSECTOR(devvp, sector, size, bp) \
93	bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp)
94
95MALLOC_DECLARE(M_UDFFENTRY);
96
97static __inline int
98udf_readdevblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp)
99{
100	return (RDSECTOR(udfmp->im_devvp, sector,
101			 (size + udfmp->bmask) & ~udfmp->bmask, bp));
102}
103
104/*
105 * Produce a suitable file number from an ICB.  The passed in ICB is expected
106 * to be in little endian (meaning that it hasn't been swapped for big
107 * endian machines yet).
108 * XXX If the fileno resolves to 0, we might be in big trouble.
109 * XXX Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
110 *     but not ext_ad.
111 */
112static __inline ino_t
113udf_getid(struct long_ad *icb)
114{
115	return (le32toh(icb->loc.lb_num));
116}
117
118int udf_allocv(struct mount *, struct vnode **, struct thread *);
119int udf_checktag(struct desc_tag *, uint16_t);
120int udf_vget(struct mount *, ino_t, int, struct vnode **);
121
122extern uma_zone_t udf_zone_trans;
123extern uma_zone_t udf_zone_node;
124extern uma_zone_t udf_zone_ds;
125
126extern struct vop_vector udf_fifoops;
127