xref: /freebsd/sys/fs/udf/udf.h (revision 10bcafe9abdb866e20e561bf567f15c0a06a0114)
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 {
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
9851a7b740SScott Long udf_readlblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp)
9951a7b740SScott Long {
100185416b4SScott Long 	return (RDSECTOR(udfmp->im_devvp, sector,
101185416b4SScott Long 			 (size + udfmp->bmask) & ~udfmp->bmask, bp));
10251a7b740SScott Long }
10351a7b740SScott Long 
10451a7b740SScott Long static __inline int
10551a7b740SScott Long udf_readalblks(struct udf_mnt *udfmp, int lsector, int size, struct buf **bp)
10651a7b740SScott Long {
10751a7b740SScott Long 	daddr_t rablock, lblk;
10851a7b740SScott Long 	int rasize;
10951a7b740SScott Long 
11051a7b740SScott Long 	lblk = (lsector + udfmp->part_start) << (udfmp->bshift - DEV_BSHIFT);
11151a7b740SScott Long 	rablock = (lblk + 1) << udfmp->bshift;
11251a7b740SScott Long 	rasize = size;
11351a7b740SScott Long 
11451a7b740SScott Long 	return (breadn(udfmp->im_devvp, lblk,
11551a7b740SScott Long 		       (size + udfmp->bmask) & ~udfmp->bmask,
11651a7b740SScott Long 		       &rablock, &rasize, 1,  NOCRED, bp));
11751a7b740SScott Long }
11851a7b740SScott Long 
11951a7b740SScott Long /*
12089ec2c3cSScott Long  * Produce a suitable file number from an ICB.  The passed in ICB is expected
12189ec2c3cSScott Long  * to be in little endian (meaning that it hasn't been swapped for big
12289ec2c3cSScott Long  * endian machines yet).
12351a7b740SScott Long  * XXX If the fileno resolves to 0, we might be in big trouble.
12451a7b740SScott Long  * XXX Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
12551a7b740SScott Long  *     but not ext_ad.
12651a7b740SScott Long  */
127185416b4SScott Long static __inline ino_t
12851a7b740SScott Long udf_getid(struct long_ad *icb)
12951a7b740SScott Long {
13089ec2c3cSScott Long 	return (le32toh(icb->loc.lb_num));
13151a7b740SScott Long }
13251a7b740SScott Long 
13351a7b740SScott Long int udf_allocv(struct mount *, struct vnode **, struct thread *);
134c2d6947dSJeroen Ruigrok van der Werven int udf_checktag(struct desc_tag *, uint16_t);
13551a7b740SScott Long int udf_vget(struct mount *, ino_t, int, struct vnode **);
13651a7b740SScott Long 
13751a7b740SScott Long extern uma_zone_t udf_zone_trans;
13851a7b740SScott Long extern uma_zone_t udf_zone_node;
1391703656aSScott Long extern uma_zone_t udf_zone_ds;
140