Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/dirent.h
Show All 30 Lines | |||||
*/ | */ | ||||
#ifndef _SYS_DIRENT_H_ | #ifndef _SYS_DIRENT_H_ | ||||
#define _SYS_DIRENT_H_ | #define _SYS_DIRENT_H_ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
#include <sys/_types.h> | #include <sys/_types.h> | ||||
#ifndef _INO_T_DECLARED | |||||
typedef __ino_t ino_t; | |||||
#define _INO_T_DECLARED | |||||
#endif | |||||
#ifndef _OFF_T_DECLARED | |||||
typedef __off_t off_t; | |||||
#define _OFF_T_DECLARED | |||||
#endif | |||||
/* | /* | ||||
* 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 an 8 | ||||
wblock: s/a 8/an 8/ | |||||
* 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 padding between the last member of the header (d_namelen) and | |||||
* d_name avoids ABI padding at the end of dirent on LP64 architectures. | |||||
* There is code depending on d_name being last. Also, retaining this | |||||
* padding on ILP32 architectures simplifies the 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 */ | ||||
__uint32_t d_pad0; | |||||
#if __BSD_VISIBLE | #if __BSD_VISIBLE | ||||
#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 | #else | ||||
char d_name[255 + 1]; /* name must be no longer than this */ | char d_name[255 + 1]; /* name must be no longer than this */ | ||||
#endif | #endif | ||||
}; | }; | ||||
#if defined(_WANT_FREEBSD11_DIRENT) || defined(_KERNEL) | |||||
struct freebsd11_dirent { | |||||
__uint32_t d_fileno; /* file number of entry */ | |||||
__uint16_t d_reclen; /* length of this record */ | |||||
__uint8_t d_type; /* file type, see below */ | |||||
__uint8_t d_namlen; /* length of string in d_name */ | |||||
char d_name[255 + 1]; /* name must be no longer than this */ | |||||
}; | |||||
#endif /* _WANT_FREEBSD11_DIRENT || _KERNEL */ | |||||
#if __BSD_VISIBLE | #if __BSD_VISIBLE | ||||
/* | /* | ||||
* 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 returns 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 | * XXX although this macro is in the implementation namespace, it requires | ||||
* a manifest constant that is not. | * 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 */ | #endif /* __BSD_VISIBLE */ | ||||
Not Done Inline ActionsIs this a bit of a rehash of other headers? ngie: Is this a bit of a rehash of other headers? | |||||
#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_ */ |
s/a 8/an 8/