Changeset View
Changeset View
Standalone View
Standalone View
head/share/man/man5/dir.5
Show All 22 Lines | |||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
.\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
.\" | .\" | ||||
.\" @(#)dir.5 8.3 (Berkeley) 4/19/94 | .\" @(#)dir.5 8.3 (Berkeley) 4/19/94 | ||||
.\" $FreeBSD$ | .\" $FreeBSD$ | ||||
.\" | .\" | ||||
.Dd April 19, 1994 | .Dd February 13, 2017 | ||||
.Dt DIR 5 | .Dt DIR 5 | ||||
.Os | .Os | ||||
.Sh NAME | .Sh NAME | ||||
.Nm dir , | .Nm dir , | ||||
.Nm dirent | .Nm dirent | ||||
.Nd directory file format | .Nd directory file format | ||||
.Sh SYNOPSIS | .Sh SYNOPSIS | ||||
.In dirent.h | .In dirent.h | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
* The dirent structure defines the format of directory entries returned by | * The dirent structure defines the format of directory entries returned by | ||||
* the getdirentries(2) system call. | * the getdirentries(2) system call. | ||||
* | * | ||||
* A directory entry has a struct dirent at the front of it, containing its | * A directory entry has a struct dirent at the front of it, containing its | ||||
* inode number, the length of the entry, and the length of the name | * inode number, the length of the entry, and the length of the name | ||||
* contained in the entry. These are followed by the name padded to a 4 | * contained in the entry. These are followed by the name padded to a 4 | ||||
* byte boundary with null bytes. All names are guaranteed null terminated. | * byte boundary with null bytes. All names are guaranteed null terminated. | ||||
* The maximum length of a name in a directory is MAXNAMLEN. | * The maximum length of a name in a directory is MAXNAMLEN. | ||||
* Explicit pad is added between the last member of the header and | |||||
* d_name, to avoid having the ABI padding in the end of dirent on | |||||
* LP64 arches. There is code depending on d_name being last. Also, | |||||
* keeping this pad for ILP32 architectures simplifies compat32 layer. | |||||
*/ | */ | ||||
struct dirent { | struct dirent { | ||||
__uint32_t d_fileno; /* file number of entry */ | ino_t d_fileno; /* file number of entry */ | ||||
off_t d_off; /* directory offset of entry */ | |||||
__uint16_t d_reclen; /* length of this record */ | __uint16_t d_reclen; /* length of this record */ | ||||
__uint8_t d_type; /* file type, see below */ | __uint8_t d_type; /* file type, see below */ | ||||
__uint8_t d_namlen; /* length of string in d_name */ | __uint8_t d_namlen; /* length of string in d_name */ | ||||
#ifdef _POSIX_SOURCE | __uint32_t d_pad0; | ||||
char d_name[255 + 1]; /* name must be no longer than this */ | #if __BSD_VISIBLE | ||||
#else | |||||
#define MAXNAMLEN 255 | #define MAXNAMLEN 255 | ||||
char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ | char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ | ||||
#else | |||||
char d_name[255 + 1]; /* name must be no longer than this */ | |||||
#endif | #endif | ||||
}; | }; | ||||
/* | /* | ||||
* File types | * File types | ||||
*/ | */ | ||||
#define DT_UNKNOWN 0 | #define DT_UNKNOWN 0 | ||||
#define DT_FIFO 1 | #define DT_FIFO 1 | ||||
#define DT_CHR 2 | #define DT_CHR 2 | ||||
#define DT_DIR 4 | #define DT_DIR 4 | ||||
#define DT_BLK 6 | #define DT_BLK 6 | ||||
#define DT_REG 8 | #define DT_REG 8 | ||||
#define DT_LNK 10 | #define DT_LNK 10 | ||||
#define DT_SOCK 12 | #define DT_SOCK 12 | ||||
#define DT_WHT 14 | #define DT_WHT 14 | ||||
/* | /* | ||||
* Convert between stat structure types and directory types. | * Convert between stat structure types and directory types. | ||||
*/ | */ | ||||
#define IFTODT(mode) (((mode) & 0170000) >> 12) | #define IFTODT(mode) (((mode) & 0170000) >> 12) | ||||
#define DTTOIF(dirtype) ((dirtype) << 12) | #define DTTOIF(dirtype) ((dirtype) << 12) | ||||
/* | /* | ||||
* The _GENERIC_DIRSIZ macro gives the minimum record length which will hold | * The _GENERIC_DIRSIZ macro gives the minimum record length which will hold | ||||
* the directory entry. This requires the amount of space in struct direct | * the directory entry. This returns the amount of space in struct direct | ||||
* without the d_name field, plus enough space for the name with a terminating | * without the d_name field, plus enough space for the name with a terminating | ||||
* null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. | * null byte (dp->d_namlen+1), rounded up to a 8 byte boundary. | ||||
* | |||||
* XXX although this macro is in the implementation namespace, it requires | |||||
* a manifest constant that is not. | |||||
*/ | */ | ||||
#define _GENERIC_DIRSIZ(dp) \ | #define _GENERIC_DIRLEN(namlen) \ | ||||
((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) | ((__offsetof(struct dirent, d_name) + (namlen) + 1 + 7) & ~7) | ||||
#define _GENERIC_DIRSIZ(dp) _GENERIC_DIRLEN((dp)->d_namlen) | |||||
#endif /* __BSD_VISIBLE */ | |||||
#ifdef _KERNEL | #ifdef _KERNEL | ||||
#define GENERIC_DIRSIZ(dp) _GENERIC_DIRSIZ(dp) | #define GENERIC_DIRSIZ(dp) _GENERIC_DIRSIZ(dp) | ||||
#endif | #endif | ||||
#endif /* !_SYS_DIRENT_H_ */ | #endif /* !_SYS_DIRENT_H_ */ | ||||
.Ed | .Ed | ||||
.Sh SEE ALSO | .Sh SEE ALSO | ||||
Show All 11 Lines |