194663Sscottl/*-
294663Sscottl * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
394663Sscottl * All rights reserved.
494663Sscottl *
594663Sscottl * Redistribution and use in source and binary forms, with or without
694663Sscottl * modification, are permitted provided that the following conditions
794663Sscottl * are met:
894663Sscottl * 1. Redistributions of source code must retain the above copyright
994663Sscottl *    notice, this list of conditions and the following disclaimer.
1094663Sscottl * 2. Redistributions in binary form must reproduce the above copyright
1194663Sscottl *    notice, this list of conditions and the following disclaimer in the
1294663Sscottl *    documentation and/or other materials provided with the distribution.
1394663Sscottl *
1494663Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1594663Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1694663Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1794663Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1894663Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1994663Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2094663Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2194663Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2294663Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2394663Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2494663Sscottl * SUCH DAMAGE.
2594663Sscottl *
2694663Sscottl * $FreeBSD$
2794663Sscottl */
2894663Sscottl
29114632Sscottl#define UDF_HASHTBLSIZE 100
30114632Sscottl
3194663Sscottlstruct udf_node {
3294663Sscottl	struct vnode	*i_vnode;
3394663Sscottl	struct udf_mnt	*udfmp;
3494663Sscottl	ino_t		hash_id;
3594663Sscottl	long		diroff;
3694663Sscottl	struct file_entry *fentry;
3794663Sscottl};
3894663Sscottl
3994663Sscottlstruct udf_mnt {
4094663Sscottl	int			im_flags;
4194663Sscottl	struct mount		*im_mountp;
42137037Sphk	struct g_consumer	*im_cp;
43137037Sphk	struct bufobj		*im_bo;
44130585Sphk	struct cdev *im_dev;
4594663Sscottl	struct vnode		*im_devvp;
4694663Sscottl	int			bsize;
4794663Sscottl	int			bshift;
4894663Sscottl	int			bmask;
4994795Sasmodai	uint32_t		part_start;
5094795Sasmodai	uint32_t		part_len;
5194795Sasmodai	uint64_t		root_id;
5294663Sscottl	struct long_ad		root_icb;
5394663Sscottl	int			p_sectors;
5494663Sscottl	int			s_table_entries;
5594663Sscottl	struct udf_sparing_table *s_table;
56122102Sscottl	void			*im_d2l;	/* disk->local iconv handle */
57122102Sscottl#if 0
58122102Sscottl	void			*im_l2d;	/* local->disk iconv handle */
59122102Sscottl#endif
6094663Sscottl};
6194663Sscottl
62101890Sscottlstruct udf_dirstream {
63101890Sscottl	struct udf_node	*node;
64101890Sscottl	struct udf_mnt	*udfmp;
65101890Sscottl	struct buf	*bp;
66101890Sscottl	uint8_t		*data;
67101890Sscottl	uint8_t		*buf;
68101890Sscottl	int		fsize;
69101890Sscottl	int		off;
70101890Sscottl	int		this_off;
71101890Sscottl	int		offset;
72101890Sscottl	int		size;
73101890Sscottl	int		error;
74101890Sscottl	int		fid_fragment;
75101890Sscottl};
76101890Sscottl
77166774Spjdstruct ifid {
78166774Spjd	u_short	ifid_len;
79166774Spjd	u_short	ifid_pad;
80166774Spjd	int	ifid_ino;
81166774Spjd	long	ifid_start;
82166774Spjd};
83166774Spjd
8494663Sscottl#define	VFSTOUDFFS(mp)	((struct udf_mnt *)((mp)->mnt_data))
8594663Sscottl#define	VTON(vp)	((struct udf_node *)((vp)->v_data))
8694663Sscottl
8794663Sscottl/*
8894663Sscottl * The block layer refers to things in terms of 512 byte blocks by default.
8994663Sscottl * btodb() is expensive, so speed things up.
9094663Sscottl * XXX Can the block layer be forced to use a different block size?
9194663Sscottl */
9294663Sscottl#define	RDSECTOR(devvp, sector, size, bp) \
9394663Sscottl	bread(devvp, sector << (udfmp->bshift - DEV_BSHIFT), size, NOCRED, bp)
9494663Sscottl
9594663SscottlMALLOC_DECLARE(M_UDFFENTRY);
9694663Sscottl
9794663Sscottlstatic __inline int
98189082Savgudf_readdevblks(struct udf_mnt *udfmp, int sector, int size, struct buf **bp)
9994663Sscottl{
100114652Sscottl	return (RDSECTOR(udfmp->im_devvp, sector,
101114652Sscottl			 (size + udfmp->bmask) & ~udfmp->bmask, bp));
10294663Sscottl}
10394663Sscottl
10494663Sscottl/*
105130986Sscottl * Produce a suitable file number from an ICB.  The passed in ICB is expected
106130986Sscottl * to be in little endian (meaning that it hasn't been swapped for big
107130986Sscottl * endian machines yet).
10894663Sscottl * XXX If the fileno resolves to 0, we might be in big trouble.
10994663Sscottl * XXX Assumes the ICB is a long_ad.  This struct is compatible with short_ad,
11094663Sscottl *     but not ext_ad.
11194663Sscottl */
112114652Sscottlstatic __inline ino_t
11394663Sscottludf_getid(struct long_ad *icb)
11494663Sscottl{
115130986Sscottl	return (le32toh(icb->loc.lb_num));
11694663Sscottl}
11794663Sscottl
11894663Sscottlint udf_allocv(struct mount *, struct vnode **, struct thread *);
11994795Sasmodaiint udf_checktag(struct desc_tag *, uint16_t);
12094663Sscottlint udf_vget(struct mount *, ino_t, int, struct vnode **);
12194663Sscottl
12294663Sscottlextern uma_zone_t udf_zone_trans;
12394663Sscottlextern uma_zone_t udf_zone_node;
124101890Sscottlextern uma_zone_t udf_zone_ds;
125188245Sjhb
126188245Sjhbextern struct vop_vector udf_fifoops;
127