xref: /freebsd/sys/fs/udf/udf.h (revision c2d6947d145d27177ec124f74b1e58fb237c6e0b)
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 
2951a7b740SScott Long struct udf_node {
3051a7b740SScott Long 	TAILQ_ENTRY(udf_node)	tq;
3151a7b740SScott Long 	struct vnode	*i_vnode;
3251a7b740SScott Long 	struct vnode	*i_devvp;
3351a7b740SScott Long 	struct udf_mnt	*udfmp;
3451a7b740SScott Long 	dev_t		i_dev;
3551a7b740SScott Long 	ino_t		hash_id;
3651a7b740SScott Long 	long		diroff;
3751a7b740SScott Long 	struct file_entry *fentry;
3851a7b740SScott Long };
3951a7b740SScott Long 
4051a7b740SScott Long struct udf_mnt {
4151a7b740SScott Long 	int			im_flags;
4251a7b740SScott Long 	struct mount		*im_mountp;
4351a7b740SScott Long 	dev_t			im_dev;
4451a7b740SScott Long 	struct vnode		*im_devvp;
4551a7b740SScott Long 	int			bsize;
4651a7b740SScott Long 	int			bshift;
4751a7b740SScott Long 	int			bmask;
48c2d6947dSJeroen Ruigrok van der Werven 	uint32_t		part_start;
49c2d6947dSJeroen Ruigrok van der Werven 	uint32_t		part_len;
50c2d6947dSJeroen Ruigrok van der Werven 	uint64_t		root_id;
5151a7b740SScott Long 	struct vnode		*root_vp;
5251a7b740SScott Long 	struct long_ad		root_icb;
5351a7b740SScott Long 	TAILQ_HEAD(, udf_node)	udf_tqh;
5451a7b740SScott Long 	struct mtx		hash_mtx;
5551a7b740SScott Long 	int			p_sectors;
5651a7b740SScott Long 	int			s_table_entries;
5751a7b740SScott Long 	struct udf_sparing_table *s_table;
5851a7b740SScott Long };
5951a7b740SScott Long 
6051a7b740SScott Long #define	VFSTOUDFFS(mp)	((struct udf_mnt *)((mp)->mnt_data))
6151a7b740SScott Long #define	VTON(vp)	((struct udf_node *)((vp)->v_data))
6251a7b740SScott Long 
6351a7b740SScott Long /*
6451a7b740SScott Long  * The block layer refers to things in terms of 512 byte blocks by default.
6551a7b740SScott Long  * btodb() is expensive, so speed things up.
6651a7b740SScott Long  * XXX Can the block layer be forced to use a different block size?
6751a7b740SScott Long  */
6851a7b740SScott Long #define	RDSECTOR(devvp, sector, size, bp) \
6951a7b740SScott Long 	bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp)
7051a7b740SScott Long 
7151a7b740SScott Long MALLOC_DECLARE(M_UDFFENTRY);
7251a7b740SScott Long 
7351a7b740SScott Long static __inline int
7451a7b740SScott Long udf_readlblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp)
7551a7b740SScott Long {
7651a7b740SScott Long 	return (bread(udfmp->im_devvp, sector << (udfmp->bshift - DEV_BSHIFT),
7751a7b740SScott Long 		      (size + udfmp->bmask) & ~udfmp->bmask, NOCRED, bp));
7851a7b740SScott Long }
7951a7b740SScott Long 
8051a7b740SScott Long static __inline int
8151a7b740SScott Long udf_readalblks(struct udf_mnt *udfmp, int lsector, int size, struct buf **bp)
8251a7b740SScott Long {
8351a7b740SScott Long 	daddr_t rablock, lblk;
8451a7b740SScott Long 	int rasize;
8551a7b740SScott Long 
8651a7b740SScott Long 	lblk = (lsector + udfmp->part_start) << (udfmp->bshift - DEV_BSHIFT);
8751a7b740SScott Long 	rablock = (lblk + 1) << udfmp->bshift;
8851a7b740SScott Long 	rasize = size;
8951a7b740SScott Long 
9051a7b740SScott Long 	return (breadn(udfmp->im_devvp, lblk,
9151a7b740SScott Long 		       (size + udfmp->bmask) & ~udfmp->bmask,
9251a7b740SScott Long 		       &rablock, &rasize, 1,  NOCRED, bp));
9351a7b740SScott Long }
9451a7b740SScott Long 
9551a7b740SScott Long /*
9651a7b740SScott Long  * Produce a suitable file number from an ICB.
9751a7b740SScott Long  * XXX If the fileno resolves to 0, we might be in big trouble.
9851a7b740SScott Long  * XXX Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
9951a7b740SScott Long  *     but not ext_ad.
10051a7b740SScott Long  */
10151a7b740SScott Long static ino_t
10251a7b740SScott Long udf_getid(struct long_ad *icb)
10351a7b740SScott Long {
10451a7b740SScott Long 	return (icb->loc.lb_num);
10551a7b740SScott Long }
10651a7b740SScott Long 
10751a7b740SScott Long int udf_allocv(struct mount *, struct vnode **, struct thread *);
10851a7b740SScott Long int udf_hashlookup(struct udf_mnt *, ino_t, int, struct vnode **);
10951a7b740SScott Long int udf_hashins(struct udf_node *);
11051a7b740SScott Long int udf_hashrem(struct udf_node *);
111c2d6947dSJeroen Ruigrok van der Werven int udf_checktag(struct desc_tag *, uint16_t);
11251a7b740SScott Long int udf_vget(struct mount *, ino_t, int, struct vnode **);
11351a7b740SScott Long 
11451a7b740SScott Long extern uma_zone_t udf_zone_trans;
11551a7b740SScott Long extern uma_zone_t udf_zone_node;
116