Home | History | Annotate | Line # | Download | only in ext2fs
ext2fs_dir.h revision 1.3
      1  1.3    bouyer /*	$NetBSD: ext2fs_dir.h,v 1.3 2000/01/26 16:21:33 bouyer Exp $	*/
      2  1.1    bouyer 
      3  1.1    bouyer /*
      4  1.1    bouyer  * Copyright (c) 1997 Manuel Bouyer.
      5  1.1    bouyer  * Copyright (c) 1982, 1986, 1989, 1993
      6  1.1    bouyer  *	The Regents of the University of California.  All rights reserved.
      7  1.1    bouyer  * (c) UNIX System Laboratories, Inc.
      8  1.1    bouyer  * All or some portions of this file are derived from material licensed
      9  1.1    bouyer  * to the University of California by American Telephone and Telegraph
     10  1.1    bouyer  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     11  1.1    bouyer  * the permission of UNIX System Laboratories, Inc.
     12  1.1    bouyer  *
     13  1.1    bouyer  * Redistribution and use in source and binary forms, with or without
     14  1.1    bouyer  * modification, are permitted provided that the following conditions
     15  1.1    bouyer  * are met:
     16  1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     17  1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     18  1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     20  1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     21  1.1    bouyer  * 3. All advertising materials mentioning features or use of this software
     22  1.1    bouyer  *    must display the following acknowledgement:
     23  1.1    bouyer  *	This product includes software developed by the University of
     24  1.1    bouyer  *	California, Berkeley and its contributors.
     25  1.1    bouyer  * 4. Neither the name of the University nor the names of its contributors
     26  1.1    bouyer  *    may be used to endorse or promote products derived from this software
     27  1.1    bouyer  *    without specific prior written permission.
     28  1.1    bouyer  *
     29  1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30  1.1    bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31  1.1    bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  1.1    bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33  1.1    bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34  1.1    bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     35  1.1    bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     36  1.1    bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     37  1.1    bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     38  1.1    bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     39  1.1    bouyer  * SUCH DAMAGE.
     40  1.1    bouyer  *
     41  1.1    bouyer  *	@(#)dir.h	8.4 (Berkeley) 8/10/94
     42  1.1    bouyer  * Modified for ext2fs by Manuel Bouyer.
     43  1.1    bouyer  */
     44  1.1    bouyer 
     45  1.1    bouyer #ifndef _EXT2FS_DIR_H_
     46  1.1    bouyer #define	_EXT2FS_DIR_H_
     47  1.1    bouyer 
     48  1.1    bouyer /*
     49  1.1    bouyer  * Theoretically, directories can be more than 2Gb in length, however, in
     50  1.1    bouyer  * practice this seems unlikely. So, we define the type doff_t as a 32-bit
     51  1.1    bouyer  * quantity to keep down the cost of doing lookup on a 32-bit machine.
     52  1.2  christos  */
     53  1.1    bouyer #define	doff_t		int32_t
     54  1.1    bouyer #define	EXT2FS_MAXDIRSIZE	(0x7fffffff)
     55  1.1    bouyer 
     56  1.1    bouyer /*
     57  1.1    bouyer  * A directory consists of some number of blocks of e2fs_bsize bytes.
     58  1.1    bouyer  *
     59  1.1    bouyer  * Each block contains some number of directory entry
     60  1.1    bouyer  * structures, which are of variable length.  Each directory entry has
     61  1.1    bouyer  * a struct direct at the front of it, containing its inode number,
     62  1.1    bouyer  * the length of the entry, and the length of the name contained in
     63  1.1    bouyer  * the entry.  These are followed by the name padded to a 4 byte boundary
     64  1.1    bouyer  * with null bytes.  All names are guaranteed null terminated.
     65  1.1    bouyer  * The maximum length of a name in a directory is EXT2FS_MAXNAMLEN.
     66  1.1    bouyer  *
     67  1.1    bouyer  * The macro EXT2FS_DIRSIZ(fmt, dp) gives the amount of space required to
     68  1.1    bouyer  * represent a directory entry.  Free space in a directory is represented by
     69  1.1    bouyer  * entries which have dp->e2d_reclen > DIRSIZ(fmt, dp).  All d2fs_bsize bytes
     70  1.1    bouyer  * in a directory block are claimed by the directory entries.  This
     71  1.1    bouyer  * usually results in the last entry in a directory having a large
     72  1.1    bouyer  * dp->e2d_reclen.  When entries are deleted from a directory, the
     73  1.1    bouyer  * space is returned to the previous entry in the same directory
     74  1.1    bouyer  * block by increasing its dp->e2d_reclen.  If the first entry of
     75  1.1    bouyer  * a directory block is free, then its dp->e2d_ino is set to 0.
     76  1.1    bouyer  * Entries other than the first in a directory do not normally have
     77  1.1    bouyer  * dp->e2d_ino set to 0.
     78  1.3    bouyer  * Ext2 rev 0 has a 16 bits e2d_namlen. For Ext2 vev 1 this has been split
     79  1.3    bouyer  * into a 8 bits e2d_namlen and 8 bits e2d_type (looks like ffs, isnt't it ? :)
     80  1.3    bouyer  * It's safe to use this for rev 0 as well because all ext2 are little-endian.
     81  1.1    bouyer  */
     82  1.1    bouyer 
     83  1.1    bouyer #define	EXT2FS_MAXNAMLEN	255
     84  1.1    bouyer 
     85  1.1    bouyer struct	ext2fs_direct {
     86  1.1    bouyer 	u_int32_t e2d_ino;		/* inode number of entry */
     87  1.1    bouyer 	u_int16_t e2d_reclen;		/* length of this record */
     88  1.3    bouyer 	u_int8_t e2d_namlen;		/* length of string in d_name */
     89  1.3    bouyer 	u_int8_t e2d_type;		/* file type */
     90  1.1    bouyer 	char	  e2d_name[EXT2FS_MAXNAMLEN];/* name with length <= EXT2FS_MAXNAMLEN */
     91  1.1    bouyer };
     92  1.1    bouyer 
     93  1.1    bouyer /*
     94  1.1    bouyer  * The EXT2FS_DIRSIZ macro gives the minimum record length which will hold
     95  1.1    bouyer  * the directory entryfor a name len "len" (without the terminating null byte).
     96  1.1    bouyer  * This requires the amount of space in struct direct
     97  1.1    bouyer  * without the d_name field, plus enough space for the name without a
     98  1.1    bouyer  * terminating null byte, rounded up to a 4 byte boundary.
     99  1.1    bouyer  */
    100  1.1    bouyer #define EXT2FS_DIRSIZ(len) \
    101  1.1    bouyer    (( 8 + len + 3) &~ 3)
    102  1.1    bouyer 
    103  1.1    bouyer /*
    104  1.1    bouyer  * Template for manipulating directories.  Should use struct direct's,
    105  1.1    bouyer  * but the name field is EXT2FS_MAXNAMLEN - 1, and this just won't do.
    106  1.1    bouyer  */
    107  1.1    bouyer struct ext2fs_dirtemplate {
    108  1.1    bouyer 	u_int32_t	dot_ino;
    109  1.1    bouyer 	int16_t		dot_reclen;
    110  1.3    bouyer 	u_int8_t	dot_namlen;
    111  1.3    bouyer 	u_int8_t	dot_type;
    112  1.1    bouyer 	char		dot_name[4];	/* must be multiple of 4 */
    113  1.1    bouyer 	u_int32_t	dotdot_ino;
    114  1.1    bouyer 	int16_t		dotdot_reclen;
    115  1.3    bouyer 	u_int8_t	dotdot_namlen;
    116  1.3    bouyer 	u_int8_t	dotdot_type;
    117  1.1    bouyer 	char		dotdot_name[4];	/* ditto */
    118  1.1    bouyer };
    119  1.1    bouyer 
    120  1.1    bouyer #endif /* !_EXT2FS_DIR_H_ */
    121