xref: /csrg-svn/usr.bin/uucp/port/LIBNDIR/ndir.h (revision 62387)
1*48662Sbostic /*	ndir.h	4.4	82/07/25	*/
2*48662Sbostic 
3*48662Sbostic /*
4*48662Sbostic  * Change notice (rti!trt):  To be compatible with non-bsd systems:
5*48662Sbostic  * #defines for u_short, u_long, and void added.
6*48662Sbostic  */
7*48662Sbostic 
8*48662Sbostic #define	u_short	unsigned short
9*48662Sbostic #define	u_long	long
10*48662Sbostic #define	void
11*48662Sbostic 
12*48662Sbostic /*
13*48662Sbostic  * A directory consists of some number of blocks of DIRBLKSIZ
14*48662Sbostic  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
15*48662Sbostic  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
16*48662Sbostic  *
17*48662Sbostic  * Each DIRBLKSIZ byte block contains some number of directory entry
18*48662Sbostic  * structures, which are of variable length.  Each directory entry has
19*48662Sbostic  * a struct direct at the front of it, containing its inode number,
20*48662Sbostic  * the length of the entry, and the length of the name contained in
21*48662Sbostic  * the entry.  These are followed by the name padded to a 4 byte boundary
22*48662Sbostic  * with null bytes.  All names are guaranteed null terminated.
23*48662Sbostic  * The maximum length of a name in a directory is MAXNAMLEN.
24*48662Sbostic  *
25*48662Sbostic  * The macro DIRSIZ(dp) gives the amount of space required to represent
26*48662Sbostic  * a directory entry.  Free space in a directory is represented by
27*48662Sbostic  * entries which have dp->d_reclen >= DIRSIZ(dp).  All DIRBLKSIZ bytes
28*48662Sbostic  * in a directory block are claimed by the directory entries.  This
29*48662Sbostic  * usually results in the last entry in a directory having a large
30*48662Sbostic  * dp->d_reclen.  When entries are deleted from a directory, the
31*48662Sbostic  * space is returned to the previous entry in the same directory
32*48662Sbostic  * block by increasing its dp->d_reclen.  If the first entry of
33*48662Sbostic  * a directory block is free, then its dp->d_ino is set to 0.
34*48662Sbostic  * Entries other than the first in a directory do not normally have
35*48662Sbostic  * dp->d_ino set to 0.
36*48662Sbostic  */
37*48662Sbostic #define DIRBLKSIZ	512
38*48662Sbostic #define	MAXNAMLEN	255
39*48662Sbostic 
40*48662Sbostic struct	direct {
41*48662Sbostic 	u_long	d_ino;			/* inode number of entry */
42*48662Sbostic 	u_short	d_reclen;		/* length of this record */
43*48662Sbostic 	u_short	d_namlen;		/* length of string in d_name */
44*48662Sbostic 	char	d_name[MAXNAMLEN + 1];	/* name must be no longer than this */
45*48662Sbostic };
46*48662Sbostic 
47*48662Sbostic /*
48*48662Sbostic  * The DIRSIZ macro gives the minimum record length which will hold
49*48662Sbostic  * the directory entry.  This requires the amount of space in struct direct
50*48662Sbostic  * without the d_name field, plus enough space for the name with a terminating
51*48662Sbostic  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
52*48662Sbostic  */
53*48662Sbostic #undef DIRSIZ
54*48662Sbostic #define DIRSIZ(dp) \
55*48662Sbostic     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
56*48662Sbostic 
57*48662Sbostic #ifndef KERNEL
58*48662Sbostic /*
59*48662Sbostic  * Definitions for library routines operating on directories.
60*48662Sbostic  */
61*48662Sbostic typedef struct _dirdesc {
62*48662Sbostic 	int	dd_fd;
63*48662Sbostic 	long	dd_loc;
64*48662Sbostic 	long	dd_size;
65*48662Sbostic 	char	dd_buf[DIRBLKSIZ];
66*48662Sbostic } DIR;
67*48662Sbostic #ifndef NULL
68*48662Sbostic #define NULL 0
69*48662Sbostic #endif
70*48662Sbostic extern	DIR *opendir();
71*48662Sbostic extern	struct direct *readdir();
72*48662Sbostic extern	long telldir();
73*48662Sbostic extern	void seekdir();
74*48662Sbostic #define rewinddir(dirp)	seekdir((dirp), (long)0)
75*48662Sbostic extern	void closedir();
76*48662Sbostic #endif KERNEL
77