151a7b740SScott Long /*- 251a7b740SScott Long * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org> 351a7b740SScott Long * All rights reserved. 451a7b740SScott Long * 551a7b740SScott Long * Redistribution and use in source and binary forms, with or without 651a7b740SScott Long * modification, are permitted provided that the following conditions 751a7b740SScott Long * are met: 851a7b740SScott Long * 1. Redistributions of source code must retain the above copyright 951a7b740SScott Long * notice, this list of conditions and the following disclaimer. 1051a7b740SScott Long * 2. Redistributions in binary form must reproduce the above copyright 1151a7b740SScott Long * notice, this list of conditions and the following disclaimer in the 1251a7b740SScott Long * documentation and/or other materials provided with the distribution. 1351a7b740SScott Long * 1451a7b740SScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1551a7b740SScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1651a7b740SScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1751a7b740SScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1851a7b740SScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1951a7b740SScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2051a7b740SScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2151a7b740SScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2251a7b740SScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2351a7b740SScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2451a7b740SScott Long * SUCH DAMAGE. 2551a7b740SScott Long * 2651a7b740SScott Long * $FreeBSD$ 2751a7b740SScott Long */ 2851a7b740SScott Long 29c9c0dc5bSScott Long #define UDF_HASHTBLSIZE 100 30c9c0dc5bSScott Long 3151a7b740SScott Long struct udf_node { 32c9c0dc5bSScott Long LIST_ENTRY(udf_node) le; 3351a7b740SScott Long struct vnode *i_vnode; 3451a7b740SScott Long struct vnode *i_devvp; 3551a7b740SScott Long struct udf_mnt *udfmp; 3651a7b740SScott Long dev_t i_dev; 3751a7b740SScott Long ino_t hash_id; 3851a7b740SScott Long long diroff; 3951a7b740SScott Long struct file_entry *fentry; 4051a7b740SScott Long }; 4151a7b740SScott Long 4251a7b740SScott Long struct udf_mnt { 4351a7b740SScott Long int im_flags; 4451a7b740SScott Long struct mount *im_mountp; 4551a7b740SScott Long dev_t im_dev; 4651a7b740SScott Long struct vnode *im_devvp; 4751a7b740SScott Long int bsize; 4851a7b740SScott Long int bshift; 4951a7b740SScott Long int bmask; 50c2d6947dSJeroen Ruigrok van der Werven uint32_t part_start; 51c2d6947dSJeroen Ruigrok van der Werven uint32_t part_len; 52c2d6947dSJeroen Ruigrok van der Werven uint64_t root_id; 5351a7b740SScott Long struct vnode *root_vp; 5451a7b740SScott Long struct long_ad root_icb; 55c9c0dc5bSScott Long LIST_HEAD(udf_hash_lh, udf_node) *hashtbl; 56c9c0dc5bSScott Long u_long hashsz; 5751a7b740SScott Long struct mtx hash_mtx; 5851a7b740SScott Long int p_sectors; 5951a7b740SScott Long int s_table_entries; 6051a7b740SScott Long struct udf_sparing_table *s_table; 6151a7b740SScott Long }; 6251a7b740SScott Long 631703656aSScott Long struct udf_dirstream { 641703656aSScott Long struct udf_node *node; 651703656aSScott Long struct udf_mnt *udfmp; 661703656aSScott Long struct buf *bp; 671703656aSScott Long uint8_t *data; 681703656aSScott Long uint8_t *buf; 691703656aSScott Long int fsize; 701703656aSScott Long int off; 711703656aSScott Long int this_off; 721703656aSScott Long int offset; 731703656aSScott Long int size; 741703656aSScott Long int error; 751703656aSScott Long int fid_fragment; 761703656aSScott Long }; 771703656aSScott Long 7851a7b740SScott Long #define VFSTOUDFFS(mp) ((struct udf_mnt *)((mp)->mnt_data)) 7951a7b740SScott Long #define VTON(vp) ((struct udf_node *)((vp)->v_data)) 8051a7b740SScott Long 8151a7b740SScott Long /* 8251a7b740SScott Long * The block layer refers to things in terms of 512 byte blocks by default. 8351a7b740SScott Long * btodb() is expensive, so speed things up. 8451a7b740SScott Long * XXX Can the block layer be forced to use a different block size? 8551a7b740SScott Long */ 8651a7b740SScott Long #define RDSECTOR(devvp, sector, size, bp) \ 8751a7b740SScott Long bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp) 8851a7b740SScott Long 8951a7b740SScott Long MALLOC_DECLARE(M_UDFFENTRY); 9051a7b740SScott Long 9151a7b740SScott Long static __inline int 9251a7b740SScott Long udf_readlblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp) 9351a7b740SScott Long { 9451a7b740SScott Long return (bread(udfmp->im_devvp, sector << (udfmp->bshift - DEV_BSHIFT), 9551a7b740SScott Long (size + udfmp->bmask) & ~udfmp->bmask, NOCRED, bp)); 9651a7b740SScott Long } 9751a7b740SScott Long 9851a7b740SScott Long static __inline int 9951a7b740SScott Long udf_readalblks(struct udf_mnt *udfmp, int lsector, int size, struct buf **bp) 10051a7b740SScott Long { 10151a7b740SScott Long daddr_t rablock, lblk; 10251a7b740SScott Long int rasize; 10351a7b740SScott Long 10451a7b740SScott Long lblk = (lsector + udfmp->part_start) << (udfmp->bshift - DEV_BSHIFT); 10551a7b740SScott Long rablock = (lblk + 1) << udfmp->bshift; 10651a7b740SScott Long rasize = size; 10751a7b740SScott Long 10851a7b740SScott Long return (breadn(udfmp->im_devvp, lblk, 10951a7b740SScott Long (size + udfmp->bmask) & ~udfmp->bmask, 11051a7b740SScott Long &rablock, &rasize, 1, NOCRED, bp)); 11151a7b740SScott Long } 11251a7b740SScott Long 11351a7b740SScott Long /* 11451a7b740SScott Long * Produce a suitable file number from an ICB. 11551a7b740SScott Long * XXX If the fileno resolves to 0, we might be in big trouble. 11651a7b740SScott Long * XXX Assumes the ICB is a long_ad. This struct is compatible with short_ad, 11751a7b740SScott Long * but not ext_ad. 11851a7b740SScott Long */ 11951a7b740SScott Long static ino_t 12051a7b740SScott Long udf_getid(struct long_ad *icb) 12151a7b740SScott Long { 12251a7b740SScott Long return (icb->loc.lb_num); 12351a7b740SScott Long } 12451a7b740SScott Long 12551a7b740SScott Long int udf_allocv(struct mount *, struct vnode **, struct thread *); 12651a7b740SScott Long int udf_hashlookup(struct udf_mnt *, ino_t, int, struct vnode **); 12751a7b740SScott Long int udf_hashins(struct udf_node *); 12851a7b740SScott Long int udf_hashrem(struct udf_node *); 129c2d6947dSJeroen Ruigrok van der Werven int udf_checktag(struct desc_tag *, uint16_t); 13051a7b740SScott Long int udf_vget(struct mount *, ino_t, int, struct vnode **); 13151a7b740SScott Long 13251a7b740SScott Long extern uma_zone_t udf_zone_trans; 13351a7b740SScott Long extern uma_zone_t udf_zone_node; 1341703656aSScott Long extern uma_zone_t udf_zone_ds; 135