1 /*- 2 * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #define UDF_HASHTBLSIZE 100 30 31 struct udf_node { 32 LIST_ENTRY(udf_node) le; 33 struct vnode *i_vnode; 34 struct vnode *i_devvp; 35 struct udf_mnt *udfmp; 36 struct cdev *i_dev; 37 ino_t hash_id; 38 long diroff; 39 struct file_entry *fentry; 40 }; 41 42 struct udf_mnt { 43 int im_flags; 44 struct mount *im_mountp; 45 struct g_consumer *im_cp; 46 struct bufobj *im_bo; 47 struct cdev *im_dev; 48 struct vnode *im_devvp; 49 int bsize; 50 int bshift; 51 int bmask; 52 uint32_t part_start; 53 uint32_t part_len; 54 uint64_t root_id; 55 struct long_ad root_icb; 56 LIST_HEAD(udf_hash_lh, udf_node) *hashtbl; 57 u_long hashsz; 58 struct mtx hash_mtx; 59 int p_sectors; 60 int s_table_entries; 61 struct udf_sparing_table *s_table; 62 void *im_d2l; /* disk->local iconv handle */ 63 #if 0 64 void *im_l2d; /* local->disk iconv handle */ 65 #endif 66 }; 67 68 struct udf_dirstream { 69 struct udf_node *node; 70 struct udf_mnt *udfmp; 71 struct buf *bp; 72 uint8_t *data; 73 uint8_t *buf; 74 int fsize; 75 int off; 76 int this_off; 77 int offset; 78 int size; 79 int error; 80 int fid_fragment; 81 }; 82 83 #define VFSTOUDFFS(mp) ((struct udf_mnt *)((mp)->mnt_data)) 84 #define VTON(vp) ((struct udf_node *)((vp)->v_data)) 85 86 /* 87 * The block layer refers to things in terms of 512 byte blocks by default. 88 * btodb() is expensive, so speed things up. 89 * XXX Can the block layer be forced to use a different block size? 90 */ 91 #define RDSECTOR(devvp, sector, size, bp) \ 92 bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp) 93 94 MALLOC_DECLARE(M_UDFFENTRY); 95 96 static __inline int 97 udf_readlblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp) 98 { 99 return (RDSECTOR(udfmp->im_devvp, sector, 100 (size + udfmp->bmask) & ~udfmp->bmask, bp)); 101 } 102 103 static __inline int 104 udf_readalblks(struct udf_mnt *udfmp, int lsector, int size, struct buf **bp) 105 { 106 daddr_t rablock, lblk; 107 int rasize; 108 109 lblk = (lsector + udfmp->part_start) << (udfmp->bshift - DEV_BSHIFT); 110 rablock = (lblk + 1) << udfmp->bshift; 111 rasize = size; 112 113 return (breadn(udfmp->im_devvp, lblk, 114 (size + udfmp->bmask) & ~udfmp->bmask, 115 &rablock, &rasize, 1, NOCRED, bp)); 116 } 117 118 /* 119 * Produce a suitable file number from an ICB. The passed in ICB is expected 120 * to be in little endian (meaning that it hasn't been swapped for big 121 * endian machines yet). 122 * XXX If the fileno resolves to 0, we might be in big trouble. 123 * XXX Assumes the ICB is a long_ad. This struct is compatible with short_ad, 124 * but not ext_ad. 125 */ 126 static __inline ino_t 127 udf_getid(struct long_ad *icb) 128 { 129 return (le32toh(icb->loc.lb_num)); 130 } 131 132 int udf_allocv(struct mount *, struct vnode **, struct thread *); 133 int udf_hashlookup(struct udf_mnt *, ino_t, int, struct vnode **); 134 int udf_hashins(struct udf_node *); 135 int udf_hashrem(struct udf_node *); 136 int udf_checktag(struct desc_tag *, uint16_t); 137 int udf_vget(struct mount *, ino_t, int, struct vnode **); 138 139 extern uma_zone_t udf_zone_trans; 140 extern uma_zone_t udf_zone_node; 141 extern uma_zone_t udf_zone_ds; 142