151a7b740SScott Long /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3d63027b6SPedro F. Giffuni *
451a7b740SScott Long * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
551a7b740SScott Long * All rights reserved.
651a7b740SScott Long *
751a7b740SScott Long * Redistribution and use in source and binary forms, with or without
851a7b740SScott Long * modification, are permitted provided that the following conditions
951a7b740SScott Long * are met:
1051a7b740SScott Long * 1. Redistributions of source code must retain the above copyright
1151a7b740SScott Long * notice, this list of conditions and the following disclaimer.
1251a7b740SScott Long * 2. Redistributions in binary form must reproduce the above copyright
1351a7b740SScott Long * notice, this list of conditions and the following disclaimer in the
1451a7b740SScott Long * documentation and/or other materials provided with the distribution.
1551a7b740SScott Long *
1651a7b740SScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1751a7b740SScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1851a7b740SScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1951a7b740SScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2051a7b740SScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2151a7b740SScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2251a7b740SScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2351a7b740SScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2451a7b740SScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2551a7b740SScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2651a7b740SScott Long * SUCH DAMAGE.
2751a7b740SScott Long */
2851a7b740SScott Long
29c9c0dc5bSScott Long #define UDF_HASHTBLSIZE 100
30c9c0dc5bSScott Long
3151a7b740SScott Long struct udf_node {
3251a7b740SScott Long struct vnode *i_vnode;
3351a7b740SScott Long struct udf_mnt *udfmp;
3451a7b740SScott Long ino_t hash_id;
3551a7b740SScott Long long diroff;
3651a7b740SScott Long struct file_entry *fentry;
3751a7b740SScott Long };
3851a7b740SScott Long
3951a7b740SScott Long struct udf_mnt {
4051a7b740SScott Long int im_flags;
4151a7b740SScott Long struct mount *im_mountp;
42429c018aSPoul-Henning Kamp struct g_consumer *im_cp;
43429c018aSPoul-Henning Kamp struct bufobj *im_bo;
4489c9c53dSPoul-Henning Kamp struct cdev *im_dev;
4551a7b740SScott Long struct vnode *im_devvp;
4651a7b740SScott Long int bsize;
4751a7b740SScott Long int bshift;
4851a7b740SScott Long int bmask;
49c2d6947dSJeroen Ruigrok van der Werven uint32_t part_start;
50c2d6947dSJeroen Ruigrok van der Werven uint32_t part_len;
51c2d6947dSJeroen Ruigrok van der Werven uint64_t root_id;
5251a7b740SScott Long struct long_ad root_icb;
5351a7b740SScott Long int p_sectors;
5451a7b740SScott Long int s_table_entries;
5551a7b740SScott Long struct udf_sparing_table *s_table;
566565282cSScott Long void *im_d2l; /* disk->local iconv handle */
576565282cSScott Long #if 0
586565282cSScott Long void *im_l2d; /* local->disk iconv handle */
596565282cSScott Long #endif
6051a7b740SScott Long };
6151a7b740SScott Long
621703656aSScott Long struct udf_dirstream {
631703656aSScott Long struct udf_node *node;
641703656aSScott Long struct udf_mnt *udfmp;
651703656aSScott Long struct buf *bp;
661703656aSScott Long uint8_t *data;
671703656aSScott Long uint8_t *buf;
681703656aSScott Long int fsize;
691703656aSScott Long int off;
701703656aSScott Long int this_off;
711703656aSScott Long int offset;
721703656aSScott Long int size;
731703656aSScott Long int error;
741703656aSScott Long int fid_fragment;
751703656aSScott Long };
761703656aSScott Long
7710bcafe9SPawel Jakub Dawidek struct ifid {
7810bcafe9SPawel Jakub Dawidek u_short ifid_len;
7910bcafe9SPawel Jakub Dawidek u_short ifid_pad;
8010bcafe9SPawel Jakub Dawidek int ifid_ino;
8110bcafe9SPawel Jakub Dawidek long ifid_start;
8210bcafe9SPawel Jakub Dawidek };
8310bcafe9SPawel Jakub Dawidek
8451a7b740SScott Long #define VFSTOUDFFS(mp) ((struct udf_mnt *)((mp)->mnt_data))
8551a7b740SScott Long #define VTON(vp) ((struct udf_node *)((vp)->v_data))
8651a7b740SScott Long
8751a7b740SScott Long /*
8851a7b740SScott Long * The block layer refers to things in terms of 512 byte blocks by default.
8951a7b740SScott Long * btodb() is expensive, so speed things up.
9051a7b740SScott Long * XXX Can the block layer be forced to use a different block size?
9151a7b740SScott Long */
9251a7b740SScott Long #define RDSECTOR(devvp, sector, size, bp) \
9351a7b740SScott Long bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp)
9451a7b740SScott Long
9551a7b740SScott Long MALLOC_DECLARE(M_UDFFENTRY);
9651a7b740SScott Long
9751a7b740SScott Long static __inline int
udf_readdevblks(struct udf_mnt * udfmp,daddr_t sector,int size,struct buf ** bp)98*c70e6150SJohn Baldwin udf_readdevblks(struct udf_mnt *udfmp, daddr_t sector, int size, struct buf **bp)
9951a7b740SScott Long {
100*c70e6150SJohn Baldwin if (size < 0 || size + udfmp->bmask < size)
101*c70e6150SJohn Baldwin return (ERANGE);
102185416b4SScott Long return (RDSECTOR(udfmp->im_devvp, sector,
103185416b4SScott Long (size + udfmp->bmask) & ~udfmp->bmask, bp));
10451a7b740SScott Long }
10551a7b740SScott Long
10651a7b740SScott Long /*
10789ec2c3cSScott Long * Produce a suitable file number from an ICB. The passed in ICB is expected
10889ec2c3cSScott Long * to be in little endian (meaning that it hasn't been swapped for big
10989ec2c3cSScott Long * endian machines yet).
11051a7b740SScott Long * XXX If the fileno resolves to 0, we might be in big trouble.
11151a7b740SScott Long * XXX Assumes the ICB is a long_ad. This struct is compatible with short_ad,
11251a7b740SScott Long * but not ext_ad.
11351a7b740SScott Long */
114185416b4SScott Long static __inline ino_t
udf_getid(struct long_ad * icb)11551a7b740SScott Long udf_getid(struct long_ad *icb)
11651a7b740SScott Long {
11789ec2c3cSScott Long return (le32toh(icb->loc.lb_num));
11851a7b740SScott Long }
11951a7b740SScott Long
12051a7b740SScott Long int udf_allocv(struct mount *, struct vnode **, struct thread *);
121c2d6947dSJeroen Ruigrok van der Werven int udf_checktag(struct desc_tag *, uint16_t);
12251a7b740SScott Long int udf_vget(struct mount *, ino_t, int, struct vnode **);
12351a7b740SScott Long
12451a7b740SScott Long extern uma_zone_t udf_zone_trans;
12551a7b740SScott Long extern uma_zone_t udf_zone_node;
1261703656aSScott Long extern uma_zone_t udf_zone_ds;
12761e69c80SJohn Baldwin
12861e69c80SJohn Baldwin extern struct vop_vector udf_fifoops;
129