151a7b740SScott Long /*- 2*4d846d26SWarner 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 * $FreeBSD$ 2951a7b740SScott Long */ 3051a7b740SScott Long 31c9c0dc5bSScott Long #define UDF_HASHTBLSIZE 100 32c9c0dc5bSScott Long 3351a7b740SScott Long struct udf_node { 3451a7b740SScott Long struct vnode *i_vnode; 3551a7b740SScott Long struct udf_mnt *udfmp; 3651a7b740SScott Long ino_t hash_id; 3751a7b740SScott Long long diroff; 3851a7b740SScott Long struct file_entry *fentry; 3951a7b740SScott Long }; 4051a7b740SScott Long 4151a7b740SScott Long struct udf_mnt { 4251a7b740SScott Long int im_flags; 4351a7b740SScott Long struct mount *im_mountp; 44429c018aSPoul-Henning Kamp struct g_consumer *im_cp; 45429c018aSPoul-Henning Kamp struct bufobj *im_bo; 4689c9c53dSPoul-Henning Kamp struct cdev *im_dev; 4751a7b740SScott Long struct vnode *im_devvp; 4851a7b740SScott Long int bsize; 4951a7b740SScott Long int bshift; 5051a7b740SScott Long int bmask; 51c2d6947dSJeroen Ruigrok van der Werven uint32_t part_start; 52c2d6947dSJeroen Ruigrok van der Werven uint32_t part_len; 53c2d6947dSJeroen Ruigrok van der Werven uint64_t root_id; 5451a7b740SScott Long struct long_ad root_icb; 5551a7b740SScott Long int p_sectors; 5651a7b740SScott Long int s_table_entries; 5751a7b740SScott Long struct udf_sparing_table *s_table; 586565282cSScott Long void *im_d2l; /* disk->local iconv handle */ 596565282cSScott Long #if 0 606565282cSScott Long void *im_l2d; /* local->disk iconv handle */ 616565282cSScott Long #endif 6251a7b740SScott Long }; 6351a7b740SScott Long 641703656aSScott Long struct udf_dirstream { 651703656aSScott Long struct udf_node *node; 661703656aSScott Long struct udf_mnt *udfmp; 671703656aSScott Long struct buf *bp; 681703656aSScott Long uint8_t *data; 691703656aSScott Long uint8_t *buf; 701703656aSScott Long int fsize; 711703656aSScott Long int off; 721703656aSScott Long int this_off; 731703656aSScott Long int offset; 741703656aSScott Long int size; 751703656aSScott Long int error; 761703656aSScott Long int fid_fragment; 771703656aSScott Long }; 781703656aSScott Long 7910bcafe9SPawel Jakub Dawidek struct ifid { 8010bcafe9SPawel Jakub Dawidek u_short ifid_len; 8110bcafe9SPawel Jakub Dawidek u_short ifid_pad; 8210bcafe9SPawel Jakub Dawidek int ifid_ino; 8310bcafe9SPawel Jakub Dawidek long ifid_start; 8410bcafe9SPawel Jakub Dawidek }; 8510bcafe9SPawel Jakub Dawidek 8651a7b740SScott Long #define VFSTOUDFFS(mp) ((struct udf_mnt *)((mp)->mnt_data)) 8751a7b740SScott Long #define VTON(vp) ((struct udf_node *)((vp)->v_data)) 8851a7b740SScott Long 8951a7b740SScott Long /* 9051a7b740SScott Long * The block layer refers to things in terms of 512 byte blocks by default. 9151a7b740SScott Long * btodb() is expensive, so speed things up. 9251a7b740SScott Long * XXX Can the block layer be forced to use a different block size? 9351a7b740SScott Long */ 9451a7b740SScott Long #define RDSECTOR(devvp, sector, size, bp) \ 9551a7b740SScott Long bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp) 9651a7b740SScott Long 9751a7b740SScott Long MALLOC_DECLARE(M_UDFFENTRY); 9851a7b740SScott Long 9951a7b740SScott Long static __inline int 100b0c0fb59SAndriy Gapon udf_readdevblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp) 10151a7b740SScott Long { 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 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