xref: /illumos-gate/usr/src/uts/common/sys/fs/ufs_fsdir.h (revision 79397983)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28b4203d75SMarcel Telka /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifndef	_SYS_FS_UFS_FSDIR_H
417c478bd9Sstevel@tonic-gate #define	_SYS_FS_UFS_FSDIR_H
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * A directory consists of some number of blocks of DIRBLKSIZ
497c478bd9Sstevel@tonic-gate  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
507c478bd9Sstevel@tonic-gate  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * Each DIRBLKSIZ byte block contains some number of directory entry
537c478bd9Sstevel@tonic-gate  * structures, which are of variable length.  Each directory entry has
547c478bd9Sstevel@tonic-gate  * a struct direct at the front of it, containing its inode number,
557c478bd9Sstevel@tonic-gate  * the length of the entry, and the length of the name contained in
567c478bd9Sstevel@tonic-gate  * the entry.  These are followed by the name padded to a 4 byte boundary
577c478bd9Sstevel@tonic-gate  * with null bytes.  All names are guaranteed null terminated.
587c478bd9Sstevel@tonic-gate  * The maximum length of a name in a directory is MAXNAMLEN.
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * The macro DIRSIZ(dp) gives the amount of space required to represent
617c478bd9Sstevel@tonic-gate  * a directory entry.  Free space in a directory is represented by
627c478bd9Sstevel@tonic-gate  * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
637c478bd9Sstevel@tonic-gate  * in a directory block are claimed by the directory entries.  This
647c478bd9Sstevel@tonic-gate  * usually results in the last entry in a directory having a large
657c478bd9Sstevel@tonic-gate  * dp->d_reclen.  When entries are deleted from a directory, the
667c478bd9Sstevel@tonic-gate  * space is returned to the previous entry in the same directory
677c478bd9Sstevel@tonic-gate  * block by increasing its dp->d_reclen.  If the first entry of
687c478bd9Sstevel@tonic-gate  * a directory block is free, then its dp->d_ino is set to 0.
697c478bd9Sstevel@tonic-gate  * Entries other than the first in a directory do not normally have
707c478bd9Sstevel@tonic-gate  * dp->d_ino set to 0.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	DIRBLKSIZ	DEV_BSIZE
737c478bd9Sstevel@tonic-gate #define	MAXNAMLEN	255
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate struct	direct {
767c478bd9Sstevel@tonic-gate 	uint32_t	d_ino;		/* inode number of entry */
777c478bd9Sstevel@tonic-gate 	ushort_t	d_reclen;	/* length of this record */
787c478bd9Sstevel@tonic-gate 	ushort_t	d_namlen;	/* length of string in d_name */
797c478bd9Sstevel@tonic-gate 	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
807c478bd9Sstevel@tonic-gate };
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * The DIRSIZ macro gives the minimum record length which will hold
847c478bd9Sstevel@tonic-gate  * the directory entry.  This requires the amount of space in struct direct
857c478bd9Sstevel@tonic-gate  * without the d_name field, plus enough space for the name with a terminating
867c478bd9Sstevel@tonic-gate  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate #undef DIRSIZ
897c478bd9Sstevel@tonic-gate #define	DIRSIZ(dp) \
907c478bd9Sstevel@tonic-gate 	((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1+3) &~ 3))
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #ifdef _KERNEL
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Template for manipulating directories.
957c478bd9Sstevel@tonic-gate  * Should use struct direct's, but the name field
967c478bd9Sstevel@tonic-gate  * is MAXNAMLEN - 1, and this just won't do.
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate struct dirtemplate {
997c478bd9Sstevel@tonic-gate 	uint32_t	dot_ino;
1007c478bd9Sstevel@tonic-gate 	short		dot_reclen;
1017c478bd9Sstevel@tonic-gate 	short		dot_namlen;
1027c478bd9Sstevel@tonic-gate 	char		dot_name[4];		/* must be multiple of 4 */
1037c478bd9Sstevel@tonic-gate 	uint32_t	dotdot_ino;
1047c478bd9Sstevel@tonic-gate 	short		dotdot_reclen;
1057c478bd9Sstevel@tonic-gate 	short		dotdot_namlen;
1067c478bd9Sstevel@tonic-gate 	char		dotdot_name[4];		/* ditto */
1077c478bd9Sstevel@tonic-gate };
108*79397983SToomas Soome 
109*79397983SToomas Soome /*
110*79397983SToomas Soome  * Reduced structure for manipulating directories.
111*79397983SToomas Soome  * Note, we are using __packed here to ensure the size of structure
112*79397983SToomas Soome  * without changing the alignment.
113*79397983SToomas Soome  */
114*79397983SToomas Soome struct tmp_dir {
115*79397983SToomas Soome 	uint32_t	d_ino;		/* inode number of entry */
116*79397983SToomas Soome 	ushort_t	d_reclen;	/* length of this record */
117*79397983SToomas Soome 	ushort_t	d_namlen;	/* length of string in d_name */
118*79397983SToomas Soome 	char		d_name[4];	/* name must be no longer than this */
119*79397983SToomas Soome } __packed;
120*79397983SToomas Soome 
1217c478bd9Sstevel@tonic-gate #endif
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate #endif
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_UFS_FSDIR_H */
128