xref: /freebsd/sys/fs/udf/udf.h (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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$
29  */
30 
31 #define UDF_HASHTBLSIZE 100
32 
33 struct udf_node {
34 	struct vnode	*i_vnode;
35 	struct udf_mnt	*udfmp;
36 	ino_t		hash_id;
37 	long		diroff;
38 	struct file_entry *fentry;
39 };
40 
41 struct udf_mnt {
42 	int			im_flags;
43 	struct mount		*im_mountp;
44 	struct g_consumer	*im_cp;
45 	struct bufobj		*im_bo;
46 	struct cdev *im_dev;
47 	struct vnode		*im_devvp;
48 	int			bsize;
49 	int			bshift;
50 	int			bmask;
51 	uint32_t		part_start;
52 	uint32_t		part_len;
53 	uint64_t		root_id;
54 	struct long_ad		root_icb;
55 	int			p_sectors;
56 	int			s_table_entries;
57 	struct udf_sparing_table *s_table;
58 	void			*im_d2l;	/* disk->local iconv handle */
59 #if 0
60 	void			*im_l2d;	/* local->disk iconv handle */
61 #endif
62 };
63 
64 struct udf_dirstream {
65 	struct udf_node	*node;
66 	struct udf_mnt	*udfmp;
67 	struct buf	*bp;
68 	uint8_t		*data;
69 	uint8_t		*buf;
70 	int		fsize;
71 	int		off;
72 	int		this_off;
73 	int		offset;
74 	int		size;
75 	int		error;
76 	int		fid_fragment;
77 };
78 
79 struct ifid {
80 	u_short	ifid_len;
81 	u_short	ifid_pad;
82 	int	ifid_ino;
83 	long	ifid_start;
84 };
85 
86 #define	VFSTOUDFFS(mp)	((struct udf_mnt *)((mp)->mnt_data))
87 #define	VTON(vp)	((struct udf_node *)((vp)->v_data))
88 
89 /*
90  * The block layer refers to things in terms of 512 byte blocks by default.
91  * btodb() is expensive, so speed things up.
92  * XXX Can the block layer be forced to use a different block size?
93  */
94 #define	RDSECTOR(devvp, sector, size, bp) \
95 	bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp)
96 
97 MALLOC_DECLARE(M_UDFFENTRY);
98 
99 static __inline int
100 udf_readdevblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp)
101 {
102 	return (RDSECTOR(udfmp->im_devvp, sector,
103 			 (size + udfmp->bmask) & ~udfmp->bmask, bp));
104 }
105 
106 /*
107  * Produce a suitable file number from an ICB.  The passed in ICB is expected
108  * to be in little endian (meaning that it hasn't been swapped for big
109  * endian machines yet).
110  * XXX If the fileno resolves to 0, we might be in big trouble.
111  * XXX Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
112  *     but not ext_ad.
113  */
114 static __inline ino_t
115 udf_getid(struct long_ad *icb)
116 {
117 	return (le32toh(icb->loc.lb_num));
118 }
119 
120 int udf_allocv(struct mount *, struct vnode **, struct thread *);
121 int udf_checktag(struct desc_tag *, uint16_t);
122 int udf_vget(struct mount *, ino_t, int, struct vnode **);
123 
124 extern uma_zone_t udf_zone_trans;
125 extern uma_zone_t udf_zone_node;
126 extern uma_zone_t udf_zone_ds;
127 
128 extern struct vop_vector udf_fifoops;
129