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