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 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /* 48 * A directory consists of some number of blocks of DIRBLKSIZ 49 * bytes, where DIRBLKSIZ is chosen such that it can be transferred 50 * to disk in a single atomic operation (e.g. 512 bytes on most machines). 51 * 52 * Each DIRBLKSIZ byte block contains some number of directory entry 53 * structures, which are of variable length. Each directory entry has 54 * a struct direct at the front of it, containing its inode number, 55 * the length of the entry, and the length of the name contained in 56 * the entry. These are followed by the name padded to a 4 byte boundary 57 * with null bytes. All names are guaranteed null terminated. 58 * The maximum length of a name in a directory is MAXNAMLEN. 59 * 60 * The macro DIRSIZ(dp) gives the amount of space required to represent 61 * a directory entry. Free space in a directory is represented by 62 * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes 63 * in a directory block are claimed by the directory entries. This 64 * usually results in the last entry in a directory having a large 65 * dp->d_reclen. When entries are deleted from a directory, the 66 * space is returned to the previous entry in the same directory 67 * block by increasing its dp->d_reclen. If the first entry of 68 * a directory block is free, then its dp->d_ino is set to 0. 69 * Entries other than the first in a directory do not normally have 70 * dp->d_ino set to 0. 71 */ 72 #define DIRBLKSIZ DEV_BSIZE 73 #define MAXNAMLEN 255 74 75 struct direct { 76 uint32_t d_ino; /* inode number of entry */ 77 ushort_t d_reclen; /* length of this record */ 78 ushort_t d_namlen; /* length of string in d_name */ 79 char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ 80 }; 81 82 /* 83 * The DIRSIZ macro gives the minimum record length which will hold 84 * the directory entry. This requires the amount of space in struct direct 85 * without the d_name field, plus enough space for the name with a terminating 86 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. 87 */ 88 #undef DIRSIZ 89 #define DIRSIZ(dp) \ 90 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1+3) &~ 3)) 91 92 #ifdef _KERNEL 93 /* 94 * Template for manipulating directories. 95 * Should use struct direct's, but the name field 96 * is MAXNAMLEN - 1, and this just won't do. 97 */ 98 struct dirtemplate { 99 uint32_t dot_ino; 100 short dot_reclen; 101 short dot_namlen; 102 char dot_name[4]; /* must be multiple of 4 */ 103 uint32_t dotdot_ino; 104 short dotdot_reclen; 105 short dotdot_namlen; 106 char dotdot_name[4]; /* ditto */ 107 }; 108 #endif 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif /* _SYS_FS_UFS_FSDIR_H */ 115