xref: /freebsd/sys/fs/udf/udf.h (revision 6780ab54325a71e7e70112b11657973edde8655e)
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 struct udf_node {
30 	TAILQ_ENTRY(udf_node)	tq;
31 	struct vnode	*i_vnode;
32 	struct vnode	*i_devvp;
33 	struct udf_mnt	*udfmp;
34 	dev_t		i_dev;
35 	ino_t		hash_id;
36 	long		diroff;
37 	struct file_entry *fentry;
38 };
39 
40 struct udf_mnt {
41 	int			im_flags;
42 	struct mount		*im_mountp;
43 	dev_t			im_dev;
44 	struct vnode		*im_devvp;
45 	int			bsize;
46 	int			bshift;
47 	int			bmask;
48 	uint32_t		part_start;
49 	uint32_t		part_len;
50 	uint64_t		root_id;
51 	struct vnode		*root_vp;
52 	struct long_ad		root_icb;
53 	TAILQ_HEAD(, udf_node)	udf_tqh;
54 	struct mtx		hash_mtx;
55 	int			p_sectors;
56 	int			s_table_entries;
57 	struct udf_sparing_table *s_table;
58 };
59 
60 struct udf_dirstream {
61 	struct udf_node	*node;
62 	struct udf_mnt	*udfmp;
63 	struct buf	*bp;
64 	uint8_t		*data;
65 	uint8_t		*buf;
66 	int		fsize;
67 	int		off;
68 	int		this_off;
69 	int		offset;
70 	int		size;
71 	int		error;
72 	int		fid_fragment;
73 };
74 
75 #define	VFSTOUDFFS(mp)	((struct udf_mnt *)((mp)->mnt_data))
76 #define	VTON(vp)	((struct udf_node *)((vp)->v_data))
77 
78 /*
79  * The block layer refers to things in terms of 512 byte blocks by default.
80  * btodb() is expensive, so speed things up.
81  * XXX Can the block layer be forced to use a different block size?
82  */
83 #define	RDSECTOR(devvp, sector, size, bp) \
84 	bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp)
85 
86 MALLOC_DECLARE(M_UDFFENTRY);
87 
88 static __inline int
89 udf_readlblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp)
90 {
91 	return (bread(udfmp->im_devvp, sector << (udfmp->bshift - DEV_BSHIFT),
92 		      (size + udfmp->bmask) & ~udfmp->bmask, NOCRED, bp));
93 }
94 
95 static __inline int
96 udf_readalblks(struct udf_mnt *udfmp, int lsector, int size, struct buf **bp)
97 {
98 	daddr_t rablock, lblk;
99 	int rasize;
100 
101 	lblk = (lsector + udfmp->part_start) << (udfmp->bshift - DEV_BSHIFT);
102 	rablock = (lblk + 1) << udfmp->bshift;
103 	rasize = size;
104 
105 	return (breadn(udfmp->im_devvp, lblk,
106 		       (size + udfmp->bmask) & ~udfmp->bmask,
107 		       &rablock, &rasize, 1,  NOCRED, bp));
108 }
109 
110 /*
111  * Produce a suitable file number from an ICB.
112  * XXX If the fileno resolves to 0, we might be in big trouble.
113  * XXX Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
114  *     but not ext_ad.
115  */
116 static ino_t
117 udf_getid(struct long_ad *icb)
118 {
119 	return (icb->loc.lb_num);
120 }
121 
122 int udf_allocv(struct mount *, struct vnode **, struct thread *);
123 int udf_hashlookup(struct udf_mnt *, ino_t, int, struct vnode **);
124 int udf_hashins(struct udf_node *);
125 int udf_hashrem(struct udf_node *);
126 int udf_checktag(struct desc_tag *, uint16_t);
127 int udf_vget(struct mount *, ino_t, int, struct vnode **);
128 
129 extern uma_zone_t udf_zone_trans;
130 extern uma_zone_t udf_zone_node;
131 extern uma_zone_t udf_zone_ds;
132