xref: /titanic_50/usr/src/uts/common/sys/fs/ufs_fsdir.h (revision e07d9cb85217949d497b02d7211de8a197d2f2eb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #ifndef	_SYS_FS_UFS_FSDIR_H
41 #define	_SYS_FS_UFS_FSDIR_H
42 
43 #pragma ident	"%Z%%M%	%I%	%E% SMI"
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 /*
50  * A directory consists of some number of blocks of DIRBLKSIZ
51  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
52  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
53  *
54  * Each DIRBLKSIZ byte block contains some number of directory entry
55  * structures, which are of variable length.  Each directory entry has
56  * a struct direct at the front of it, containing its inode number,
57  * the length of the entry, and the length of the name contained in
58  * the entry.  These are followed by the name padded to a 4 byte boundary
59  * with null bytes.  All names are guaranteed null terminated.
60  * The maximum length of a name in a directory is MAXNAMLEN.
61  *
62  * The macro DIRSIZ(dp) gives the amount of space required to represent
63  * a directory entry.  Free space in a directory is represented by
64  * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
65  * in a directory block are claimed by the directory entries.  This
66  * usually results in the last entry in a directory having a large
67  * dp->d_reclen.  When entries are deleted from a directory, the
68  * space is returned to the previous entry in the same directory
69  * block by increasing its dp->d_reclen.  If the first entry of
70  * a directory block is free, then its dp->d_ino is set to 0.
71  * Entries other than the first in a directory do not normally have
72  * dp->d_ino set to 0.
73  */
74 #define	DIRBLKSIZ	DEV_BSIZE
75 #define	MAXNAMLEN	255
76 
77 struct	direct {
78 	uint32_t	d_ino;		/* inode number of entry */
79 	ushort_t	d_reclen;	/* length of this record */
80 	ushort_t	d_namlen;	/* length of string in d_name */
81 	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
82 };
83 
84 /*
85  * The DIRSIZ macro gives the minimum record length which will hold
86  * the directory entry.  This requires the amount of space in struct direct
87  * without the d_name field, plus enough space for the name with a terminating
88  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
89  */
90 #undef DIRSIZ
91 #define	DIRSIZ(dp) \
92 	((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1+3) &~ 3))
93 
94 #ifdef _KERNEL
95 /*
96  * Template for manipulating directories.
97  * Should use struct direct's, but the name field
98  * is MAXNAMLEN - 1, and this just won't do.
99  */
100 struct dirtemplate {
101 	uint32_t	dot_ino;
102 	short		dot_reclen;
103 	short		dot_namlen;
104 	char		dot_name[4];		/* must be multiple of 4 */
105 	uint32_t	dotdot_ino;
106 	short		dotdot_reclen;
107 	short		dotdot_namlen;
108 	char		dotdot_name[4];		/* ditto */
109 };
110 #endif
111 
112 #ifdef	__cplusplus
113 }
114 #endif
115 
116 #endif	/* _SYS_FS_UFS_FSDIR_H */
117