3 * Mach Operating System
4 * Copyright (c) 1991,1990 Carnegie Mellon University
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie Mellon
25 * the rights to redistribute these changes.
28 * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms are permitted
32 * provided that the above copyright notice and this paragraph are
33 * duplicated in all such forms and that any documentation,
34 * advertising materials, and other materials related to such
35 * distribution and use acknowledge that the software was developed
36 * by the University of California, Berkeley. The name of the
37 * University may not be used to endorse or promote products derived
38 * from this software without specific prior written permission.
39 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
40 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
41 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
43 * @(#)dir.h 7.6 (Berkeley) 5/9/89
46 #ifndef _BOOT_UFS_DIR_H_
47 #define _BOOT_UFS_DIR_H_
50 * A directory consists of some number of blocks of DIRBLKSIZ
51 * bytes, where DIRBLKSIZ is chosen such that it can be transferred
52 * to disk in a single atomic operation (e.g. 512 bytes on most machines).
54 * Each DIRBLKSIZ byte block contains some number of directory entry
55 * structures, which are of variable length. Each directory entry has
56 * a struct direct at the front of it, containing its inode number,
57 * the length of the entry, and the length of the name contained in
58 * the entry. These are followed by the name padded to a 4 byte boundary
59 * with null bytes. All names are guaranteed null terminated.
60 * The maximum length of a name in a directory is MAXNAMLEN.
62 * The macro DIRSIZ(dp) gives the amount of space required to represent
63 * a directory entry. Free space in a directory is represented by
64 * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes
65 * in a directory block are claimed by the directory entries. This
66 * usually results in the last entry in a directory having a large
67 * dp->d_reclen. When entries are deleted from a directory, the
68 * space is returned to the previous entry in the same directory
69 * block by increasing its dp->d_reclen. If the first entry of
70 * a directory block is free, then its dp->d_ino is set to 0.
71 * Entries other than the first in a directory do not normally have
74 #define DIRBLKSIZ DEV_BSIZE
79 unsigned int d_ino; /* inode number of entry */
80 unsigned short d_reclen; /* length of this record */
81 unsigned short d_namlen; /* length of string in d_name */
82 char d_name[MAXNAMLEN + 1]; /* name with length <= MAXNAMLEN */
86 * The DIRSIZ macro gives the minimum record length which will hold
87 * the directory entry. This requires the amount of space in struct direct
88 * without the d_name field, plus enough space for the name with a terminating
89 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
93 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
97 * Template for manipulating directories.
98 * Should use struct direct's, but the name field
99 * is MAXNAMLEN - 1, and this just won't do.
103 unsigned int dot_ino;
106 char dot_name[4]; /* must be multiple of 4 */
107 unsigned int dotdot_ino;
110 char dotdot_name[4]; /* ditto */
115 * The following information should be obtained from <dirent.h>
116 * and is provided solely (and temporarily) for backward compatibility.
119 #define d_fileno d_ino /* compatibility with POSIX */
121 #define DEV_BSIZE 512
124 * Definitions for library routines operating on directories.
126 typedef struct _dirdesc
131 char dd_buf[DIRBLKSIZ];
135 #define dirfd(dirp) ((dirp)->dd_fd)
140 #endif /* not KERNEL */
141 #endif /* _BOOT_UFS_DIR_H_ */