1*26b8ec94Snatano /* $OpenBSD: udf.h,v 1.21 2016/06/19 11:54:33 natano Exp $ */
2d9ac8608Spedro
3d9ac8608Spedro /*
4d9ac8608Spedro * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
5d9ac8608Spedro * All rights reserved.
6d9ac8608Spedro *
7d9ac8608Spedro * Redistribution and use in source and binary forms, with or without
8d9ac8608Spedro * modification, are permitted provided that the following conditions
9d9ac8608Spedro * are met:
10d9ac8608Spedro * 1. Redistributions of source code must retain the above copyright
11d9ac8608Spedro * notice, this list of conditions and the following disclaimer.
12d9ac8608Spedro * 2. Redistributions in binary form must reproduce the above copyright
13d9ac8608Spedro * notice, this list of conditions and the following disclaimer in the
14d9ac8608Spedro * documentation and/or other materials provided with the distribution.
15d9ac8608Spedro *
16d9ac8608Spedro * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17d9ac8608Spedro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18d9ac8608Spedro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19d9ac8608Spedro * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20d9ac8608Spedro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21d9ac8608Spedro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22d9ac8608Spedro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23d9ac8608Spedro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24d9ac8608Spedro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25d9ac8608Spedro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26d9ac8608Spedro * SUCH DAMAGE.
27d9ac8608Spedro *
28d9ac8608Spedro * $FreeBSD: src/sys/fs/udf/udf.h,v 1.9 2004/10/29 10:40:58 phk Exp $
29d9ac8608Spedro */
30d9ac8608Spedro
31d9ac8608Spedro /*
32fcbf5195Sjmc * Ported to OpenBSD by Pedro Martelletto in February 2005.
33d9ac8608Spedro */
34d9ac8608Spedro
35d9ac8608Spedro #define UDF_HASHTBLSIZE 100
36d9ac8608Spedro
370cad8b22Sguenther typedef uint32_t udfino_t;
380cad8b22Sguenther
39797916ccSpedro struct unode {
40797916ccSpedro LIST_ENTRY(unode) u_le;
41797916ccSpedro struct vnode *u_vnode;
42797916ccSpedro struct vnode *u_devvp;
43884fd684Spedro struct umount *u_ump;
44*26b8ec94Snatano struct rrwlock u_lock;
45797916ccSpedro dev_t u_dev;
460cad8b22Sguenther udfino_t u_ino;
478eb7f8cbSpedro union {
48797916ccSpedro long u_diroff;
49797916ccSpedro long u_vatlen;
508eb7f8cbSpedro } un_u;
51b077103dSkrw struct extfile_entry *u_fentry;
52d9ac8608Spedro };
53d9ac8608Spedro
54797916ccSpedro #define u_diroff un_u.u_diroff
55797916ccSpedro #define u_vatlen un_u.u_vatlen
568eb7f8cbSpedro
57884fd684Spedro struct umount {
58884fd684Spedro int um_flags;
59884fd684Spedro struct mount *um_mountp;
60884fd684Spedro struct vnode *um_devvp;
61884fd684Spedro dev_t um_dev;
62884fd684Spedro int um_bsize;
63884fd684Spedro int um_bshift;
64884fd684Spedro int um_bmask;
65884fd684Spedro uint32_t um_start;
66b077103dSkrw uint32_t um_realstart;
67884fd684Spedro uint32_t um_len;
68b077103dSkrw uint32_t um_reallen;
69b077103dSkrw uint32_t um_meta_start;
70b077103dSkrw uint32_t um_meta_len;
71b97bc9b1Spedro struct unode *um_vat;
72884fd684Spedro struct long_ad um_root_icb;
73884fd684Spedro LIST_HEAD(udf_hash_lh, unode) *um_hashtbl;
749dc9bb81Sdlg SIPHASH_KEY um_hashkey;
75884fd684Spedro u_long um_hashsz;
76884fd684Spedro struct mutex um_hashmtx;
77884fd684Spedro int um_psecs;
78884fd684Spedro int um_stbl_len;
79884fd684Spedro struct udf_sparing_table *um_stbl;
80d9ac8608Spedro };
81d9ac8608Spedro
828eb7f8cbSpedro #define UDF_MNT_FIND_VAT 0x01 /* Indicates a VAT must be found */
838eb7f8cbSpedro #define UDF_MNT_USES_VAT 0x02 /* Indicates a VAT must be used */
84b077103dSkrw #define UDF_MNT_USES_META 0x04 /* Indicates we are using a Metadata partition*/
858eb7f8cbSpedro
8618ad5781Sderaadt #define VTOU(vp) ((struct unode *)((vp)->v_data))
8718ad5781Sderaadt
8818ad5781Sderaadt #ifdef _KERNEL
8918ad5781Sderaadt
90d9ac8608Spedro struct udf_dirstream {
91797916ccSpedro struct unode *node;
92170e22feSpedro struct umount *ump;
93d9ac8608Spedro struct buf *bp;
94d9ac8608Spedro uint8_t *data;
95d9ac8608Spedro uint8_t *buf;
96d9ac8608Spedro int fsize;
97d9ac8608Spedro int off;
98d9ac8608Spedro int this_off;
99d9ac8608Spedro int offset;
100d9ac8608Spedro int size;
101d9ac8608Spedro int error;
102d9ac8608Spedro int fid_fragment;
103d9ac8608Spedro };
104d9ac8608Spedro
105884fd684Spedro #define VFSTOUDFFS(mp) ((struct umount *)((mp)->mnt_data))
106d9ac8608Spedro
107d9ac8608Spedro /*
108d9ac8608Spedro * The block layer refers to things in terms of 512 byte blocks by default.
109d9ac8608Spedro * btodb() is expensive, so speed things up.
110c184c659Spedro * Can the block layer be forced to use a different block size?
111d9ac8608Spedro */
112d9ac8608Spedro #define RDSECTOR(devvp, sector, size, bp) \
1132f1d90baSmlarkin bread(devvp, \
1142f1d90baSmlarkin ((daddr_t)(sector) << ump->um_bshift) / DEV_BSIZE, size, bp)
115d9ac8608Spedro
116d9ac8608Spedro static __inline int
udf_readlblks(struct umount * ump,int sector,int size,struct buf ** bp)117170e22feSpedro udf_readlblks(struct umount *ump, int sector, int size, struct buf **bp)
118d9ac8608Spedro {
119170e22feSpedro return (RDSECTOR(ump->um_devvp, sector,
120170e22feSpedro (size + ump->um_bmask) & ~ump->um_bmask, bp));
121d9ac8608Spedro }
122d9ac8608Spedro
123d9ac8608Spedro /*
124d9ac8608Spedro * Produce a suitable file number from an ICB. The passed in ICB is expected
125d9ac8608Spedro * to be in little endian (meaning that it hasn't been swapped for big
126d9ac8608Spedro * endian machines yet).
127c184c659Spedro * If the fileno resolves to 0, we might be in big trouble.
128c184c659Spedro * Assumes the ICB is a long_ad. This struct is compatible with short_ad,
129d9ac8608Spedro * but not ext_ad.
130d9ac8608Spedro */
1310cad8b22Sguenther static __inline udfino_t
udf_getid(struct long_ad * icb)132d9ac8608Spedro udf_getid(struct long_ad *icb)
133d9ac8608Spedro {
134d9ac8608Spedro return (letoh32(icb->loc.lb_num));
135d9ac8608Spedro }
136d9ac8608Spedro
137d9ac8608Spedro int udf_allocv(struct mount *, struct vnode **, struct proc *);
1380cad8b22Sguenther int udf_hashlookup(struct umount *, udfino_t, int, struct vnode **);
139797916ccSpedro int udf_hashins(struct unode *);
140797916ccSpedro int udf_hashrem(struct unode *);
141d9ac8608Spedro int udf_checktag(struct desc_tag *, uint16_t);
142b6647e39Smiod
143b6647e39Smiod typedef uint16_t unicode_t;
14418ad5781Sderaadt
14518ad5781Sderaadt #endif /* _KERNEL */
14618ad5781Sderaadt
147