dir.5

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 5 代码 · 共 88 行

5
88
字号
.\" SCCSID: @(#)dir.5	8.1	9/11/90.TH dir 5 .SH Namedir \- format of directories.SH Syntax.B #include <sys/types.h>.br.B #include <sys/dir.h>.SH Description.NXR "dir keyword" .NXR "directory" "file format"A directory behaves exactly like an ordinary file, except that nouser may write into a directory.The fact that a file is a directory is indicated bya bit in the flag word of its i-node entry.  For furtherinformation, see .MS fs 5 .The structure of a directory entry is given in the include file..PPA directory consists of some number of blocks of DIRBLKSIZbytes, where DIRBLKSIZ is chosen such that it can be transferredto disk in a single atomic operation (for example, 512 bytes on most machines)..PPEach DIRBLKSIZ byte block contains some number of directory entrystructures, which are of variable length.  Each directory entry hasa struct direct at the front of it, containing its inode number,the length of the entry, and the length of the name contained inthe entry.  These are followed by the name padded to a 4-byte boundarywith null bytes.  All names are guaranteed null terminated.The maximum length of a name in a directory is MAXNAMLEN..PPThe macro DIRSIZ(dp) gives the amount of space required to representa directory entry.  Free space in a directory is represented byentries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytesin a directory block are claimed by the directory entries.  Thisaction usually results in the last entry in a directory having a large.brdp->d_reclen.  When entries are deleted from a directory, thespace is returned to the previous entry in the same directoryblock by increasing its dp->d_reclen.  If the first entry ofdirectory block is free, then its dp->d_ino is set to 0.Entries other than the first in a directory do not normally havedp->d_ino set to 0..EX#ifdef KERNEL#define DIRBLKSIZ DEV_BSIZE#else#define	DIRBLKSIZ 512#endif#define MAXNAMLEN 255.EE.PPThe DIRSIZ macro gives the minimum record length that will holdthe directory entry.  This requires the amount of space in struct directwithout the d_name field, plus enough space for the name with a terminatingnull byte (dp->d_namlen+1), rounded up to a 4-byte boundary..EX#undef DIRSIZ#define DIRSIZ(dp) \e    ((sizeof (struct direct) - (MAXNAMLEN+1)) + \e    (((dp)->d_namlen+1 + 3) &~ 3))struct	direct {	u_long	d_ino;	short	d_reclen;	short	d_namlen;	char	d_name[MAXNAMLEN + 1];	/* typically shorter */};struct _dirdesc {	int	dd_fd;	long	dd_loc;	long	dd_size;	char	dd_buf[DIRBLKSIZ];};.EE.PPBy convention, the first two entries in each directoryare for dot (.) and dot dot (..).  The first is an entry for thedirectory itself.  The second is for the parent directory.The meaning of `..' is modified for the root directoryof the master file system (\*(lq/\*(rq),where dot dot has the same meaning as dot..SH See Alsofs(5)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?