openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

dir.h (5906B)


      1 /* $Id: //depot/blt/srv/vfs/drivers/ffs/dir.h#1 $ */
      2 /* OpenBSD: dir.h,v 1.6 1997/05/30 08:34:56 downsj Exp */
      3 /* NetBSD: dir.h,v 1.8 1996/03/09 19:42:41 scottr Exp */
      4 
      5 /*
      6  * Copyright (c) 1982, 1986, 1989, 1993
      7  *     The Regents of the University of California.  All rights reserved.
      8  * (c) UNIX System Laboratories, Inc.
      9  * All or some portions of this file are derived from material licensed
     10  * to the University of California by American Telephone and Telegraph
     11  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     12  * the permission of UNIX System Laboratories, Inc.
     13  *
     14  * Redistribution and use in source and binary forms, with or without
     15  * modification, are permitted provided that the following conditions
     16  * are met:
     17  * 1. Redistributions of source code must retain the above copyright
     18  *    notice, this list of conditions and the following disclaimer.
     19  * 2. Redistributions in binary form must reproduce the above copyright
     20  *    notice, this list of conditions and the following disclaimer in the
     21  *    documentation and/or other materials provided with the distribution.
     22  * 3. All advertising materials mentioning features or use of this software
     23  *    must display the following acknowledgement:
     24  *        This product includes software developed by the University of
     25  *        California, Berkeley and its contributors.
     26  * 4. Neither the name of the University nor the names of its contributors
     27  *    may be used to endorse or promote products derived from this software
     28  *    without specific prior written permission.
     29  *
     30  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     40  * SUCH DAMAGE.
     41  *
     42  * @(#)dir.h 8.4 (Berkeley) 8/10/94
     43  */
     44 
     45 #ifndef DIR_H
     46 #define	DIR_H
     47 
     48 /*
     49  * Theoretically, directories can be more than 2Gb in length, however, in
     50  * practice this seems unlikely. So, we define the type doff_t as a 32-bit
     51  * quantity to keep down the cost of doing lookup on a 32-bit machine.
     52 */
     53 #define	doff_t		int32
     54 #define	MAXDIRSIZE	(0x7fffffff)
     55 
     56 /*
     57  * A directory consists of some number of blocks of DIRBLKSIZE
     58  * bytes, where DIRBLKSIZE is chosen such that it can be transferred
     59  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
     60  *
     61  * Each DIRBLKSIZE byte block contains some number of directory entry
     62  * structures, which are of variable length.  Each directory entry has
     63  * a struct direct at the front of it, containing its inode number,
     64  * the length of the entry, and the length of the name contained in
     65  * the entry.  These are followed by the name padded to a 4 byte boundary
     66  * with null bytes.  All names are guaranteed null terminated.
     67  * The maximum length of a name in a directory is MAXNAMLEN.
     68  *
     69  * The macro DIRSIZ(fmt, dp) gives the amount of space required to represent
     70  * a directory entry.  Free space in a directory is represented by
     71  * entries which have dp->d_reclen > DIRSIZ(fmt, dp).  All DIRBLKSIZE bytes
     72  * in a directory block are claimed by the directory entries.  This
     73  * usually results in the last entry in a directory having a large
     74  * dp->d_reclen.  When entries are deleted from a directory, the
     75  * space is returned to the previous entry in the same directory
     76  * block by increasing its dp->d_reclen.  If the first entry of
     77  * a directory block is free, then its dp->d_ino is set to 0.
     78  * Entries other than the first in a directory do not normally have
     79  * dp->d_ino set to 0.
     80  */
     81 #ifndef DIRBLKSIZE
     82 #define DIRBLKSIZE	DEV_BSIZE
     83 #endif
     84 #define	MAXNAMLEN	255
     85 
     86 struct	ffs_direct {
     87 	uint32 d_ino;		/* inode number of entry */
     88 	uint16 d_reclen;		/* length of this record */
     89 	uint8  d_type; 		/* file type, see below */
     90 	uint8  d_namlen;		/* length of string in d_name */
     91 	char	  d_name[MAXNAMLEN + 1];/* name with length <= MAXNAMLEN */
     92 };
     93 
     94 /*
     95  * File types
     96  */
     97 #define	DT_UNKNOWN	 0
     98 #define	DT_FIFO		 1
     99 #define	DT_CHR		 2
    100 #define	DT_DIR		 4
    101 #define	DT_BLK		 6
    102 #define	DT_REG		 8
    103 #define	DT_LNK		10
    104 #define	DT_SOCK		12
    105 #define	DT_WHT		14
    106 
    107 /*
    108  * Convert between stat structure types and directory types.
    109  */
    110 #define	IFTODT(mode)	(((mode) & 0170000) >> 12)
    111 #define	DTTOIF(dirtype)	((dirtype) << 12)
    112 
    113 /*
    114  * The DIRSIZ macro gives the minimum record length which will hold
    115  * the directory entry.  This requires the amount of space in struct direct
    116  * without the d_name field, plus enough space for the name with a terminating
    117  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
    118  */
    119 #if (BYTE_ORDER == LITTLE_ENDIAN)
    120 #define DIRSIZ(oldfmt, dp) \
    121     ((oldfmt) ? \
    122     ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_type+1 + 3) &~ 3)) : \
    123     ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)))
    124 #else
    125 #define DIRSIZ(oldfmt, dp) \
    126     ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
    127 #endif
    128 #define OLDDIRFMT	1
    129 #define NEWDIRFMT	0
    130 
    131 /*
    132  * Template for manipulating directories.  Should use struct direct's,
    133  * but the name field is MAXNAMLEN - 1, and this just won't do.
    134  */
    135 struct dirtemplate {
    136 	uint32	dot_ino;
    137 	int16		dot_reclen;
    138 	uint8	dot_type;
    139 	uint8	dot_namlen;
    140 	char		dot_name[4];	/* must be multiple of 4 */
    141 	uint32	dotdot_ino;
    142 	int16		dotdot_reclen;
    143 	uint8	dotdot_type;
    144 	uint8	dotdot_namlen;
    145 	char		dotdot_name[4];	/* ditto */
    146 };
    147 
    148 #endif
    149