xref: /titanic_51/usr/src/grub/grub-0.97/stage2/dir.h (revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809)
1 
2 /*
3  * Mach Operating System
4  * Copyright (c) 1991,1990 Carnegie Mellon University
5  * All Rights Reserved.
6  *
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.
12  *
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.
16  *
17  * Carnegie Mellon requests users of this software to return to
18  *
19  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
20  *  School of Computer Science
21  *  Carnegie Mellon University
22  *  Pittsburgh PA 15213-3890
23  *
24  * any improvements or extensions that they make and grant Carnegie Mellon
25  * the rights to redistribute these changes.
26  */
27 /*
28  * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
29  * All rights reserved.
30  *
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.
42  *
43  *	@(#)dir.h	7.6 (Berkeley) 5/9/89
44  */
45 
46 #ifndef _BOOT_UFS_DIR_H_
47 #define	_BOOT_UFS_DIR_H_
48 
49 /*
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).
53  *
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.
61  *
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
72  * dp->d_ino set to 0.
73  */
74 #define DIRBLKSIZ	DEV_BSIZE
75 #define	MAXNAMLEN	255
76 
77 struct direct
78   {
79     u_int d_ino;		/* inode number of entry */
80     u_short d_reclen;		/* length of this record */
81     u_short d_namlen;		/* length of string in d_name */
82     char d_name[MAXNAMLEN + 1];	/* name with length <= MAXNAMLEN */
83   };
84 
85 /*
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.
90  */
91 #undef DIRSIZ
92 #define DIRSIZ(dp) \
93     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
94 
95 #ifdef KERNEL
96 /*
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.
100  */
101 struct dirtemplate
102   {
103     u_int dot_ino;
104     short dot_reclen;
105     short dot_namlen;
106     char dot_name[4];		/* must be multiple of 4 */
107     u_int dotdot_ino;
108     short dotdot_reclen;
109     short dotdot_namlen;
110     char dotdot_name[4];	/* ditto */
111   };
112 #endif
113 
114 /*
115  * The following information should be obtained from <dirent.h>
116  * and is provided solely (and temporarily) for backward compatibility.
117  */
118 #ifndef KERNEL
119 #define d_fileno d_ino		/* compatibility with POSIX */
120 #ifndef DEV_BSIZE
121 #define	DEV_BSIZE	512
122 #endif
123 /*
124  * Definitions for library routines operating on directories.
125  */
126 typedef struct _dirdesc
127   {
128     int dd_fd;
129     int dd_loc;
130     int dd_size;
131     char dd_buf[DIRBLKSIZ];
132   }
133 DIR;
134 
135 #define dirfd(dirp)	((dirp)->dd_fd)
136 
137 #ifndef NULL
138 #define NULL 0
139 #endif
140 extern DIR *opendir ();
141 extern struct direct *readdir ();
142 extern int telldir ();
143 extern void seekdir ();
144 #define rewinddir(dirp)	seekdir((dirp), (long)0)
145 extern void closedir ();
146 #endif /* not KERNEL */
147 #endif /* _BOOT_UFS_DIR_H_ */
148