xref: /OK3568_Linux_fs/kernel/fs/freevxfs/vxfs_dir.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2000-2001 Christoph Hellwig.
3*4882a593Smuzhiyun  * All rights reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
6*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
7*4882a593Smuzhiyun  * are met:
8*4882a593Smuzhiyun  * 1. Redistributions of source code must retain the above copyright
9*4882a593Smuzhiyun  *    notice, this list of conditions, and the following disclaimer,
10*4882a593Smuzhiyun  *    without modification.
11*4882a593Smuzhiyun  * 2. The name of the author may not be used to endorse or promote products
12*4882a593Smuzhiyun  *    derived from this software without specific prior written permission.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * Alternatively, this software may be distributed under the terms of the
15*4882a593Smuzhiyun  * GNU General Public License ("GPL").
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18*4882a593Smuzhiyun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*4882a593Smuzhiyun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*4882a593Smuzhiyun  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21*4882a593Smuzhiyun  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*4882a593Smuzhiyun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*4882a593Smuzhiyun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*4882a593Smuzhiyun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*4882a593Smuzhiyun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*4882a593Smuzhiyun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*4882a593Smuzhiyun  * SUCH DAMAGE.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun #ifndef _VXFS_DIR_H_
31*4882a593Smuzhiyun #define _VXFS_DIR_H_
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun  * Veritas filesystem driver - directory structure.
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * This file contains the definition of the vxfs directory format.
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /*
41*4882a593Smuzhiyun  * VxFS directory block header.
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  * This entry is the head of every filesystem block in a directory.
44*4882a593Smuzhiyun  * It is used for free space management and additionally includes
45*4882a593Smuzhiyun  * a hash for speeding up directory search (lookup).
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * The hash may be empty and in fact we do not use it all in the
48*4882a593Smuzhiyun  * Linux driver for now.
49*4882a593Smuzhiyun  */
50*4882a593Smuzhiyun struct vxfs_dirblk {
51*4882a593Smuzhiyun 	__fs16		d_free;		/* free space in dirblock */
52*4882a593Smuzhiyun 	__fs16		d_nhash;	/* no of hash chains */
53*4882a593Smuzhiyun 	__fs16		d_hash[1];	/* hash chain */
54*4882a593Smuzhiyun };
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun  * VXFS_NAMELEN is the maximum length of the d_name field
58*4882a593Smuzhiyun  *	of an VxFS directory entry.
59*4882a593Smuzhiyun  */
60*4882a593Smuzhiyun #define VXFS_NAMELEN	256
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /*
63*4882a593Smuzhiyun  * VxFS directory entry.
64*4882a593Smuzhiyun  */
65*4882a593Smuzhiyun struct vxfs_direct {
66*4882a593Smuzhiyun 	__fs32		d_ino;			/* inode number */
67*4882a593Smuzhiyun 	__fs16		d_reclen;		/* record length */
68*4882a593Smuzhiyun 	__fs16		d_namelen;		/* d_name length */
69*4882a593Smuzhiyun 	__fs16		d_hashnext;		/* next hash entry */
70*4882a593Smuzhiyun 	char		d_name[VXFS_NAMELEN];	/* name */
71*4882a593Smuzhiyun };
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /*
74*4882a593Smuzhiyun  * VXFS_DIRPAD defines the directory entry boundaries, is _must_ be
75*4882a593Smuzhiyun  *	a multiple of four.
76*4882a593Smuzhiyun  * VXFS_NAMEMIN is the length of a directory entry with a NULL d_name.
77*4882a593Smuzhiyun  * VXFS_DIRROUND is an internal macros that rounds a length to a value
78*4882a593Smuzhiyun  *	usable for directory sizes.
79*4882a593Smuzhiyun  * VXFS_DIRLEN calculates the directory entry size for an entry with
80*4882a593Smuzhiyun  *	a d_name with size len.
81*4882a593Smuzhiyun  */
82*4882a593Smuzhiyun #define VXFS_DIRPAD		4
83*4882a593Smuzhiyun #define VXFS_NAMEMIN		offsetof(struct vxfs_direct, d_name)
84*4882a593Smuzhiyun #define VXFS_DIRROUND(len)	((VXFS_DIRPAD + (len) - 1) & ~(VXFS_DIRPAD -1))
85*4882a593Smuzhiyun #define VXFS_DIRLEN(len)	(VXFS_DIRROUND(VXFS_NAMEMIN + (len)))
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun /*
88*4882a593Smuzhiyun  * VXFS_DIRBLKOV is the overhead of a specific dirblock.
89*4882a593Smuzhiyun  */
90*4882a593Smuzhiyun #define VXFS_DIRBLKOV(sbi, dbp)	\
91*4882a593Smuzhiyun 	((sizeof(short) * fs16_to_cpu(sbi, dbp->d_nhash)) + 4)
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun #endif /* _VXFS_DIR_H_ */
94