2011-02-21 14:13:55 +01:00
|
|
|
#ifndef _SYS_DIRENT_H_
|
|
|
|
#define _SYS_DIRENT_H_
|
|
|
|
|
2011-03-05 00:15:48 +01:00
|
|
|
#include <sys/cdefs.h>
|
2011-02-21 14:13:55 +01:00
|
|
|
#include <sys/featuretest.h>
|
2011-03-05 00:15:48 +01:00
|
|
|
#include <minix/dirent.h>
|
2011-02-21 14:13:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The dirent structure defines the format of directory entries returned by
|
|
|
|
* the getdents(2) system call.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct dirent { /* Largest entry (8 slots) */
|
|
|
|
ino_t d_ino; /* I-node number */
|
|
|
|
off_t d_off; /* Offset in directory */
|
|
|
|
unsigned short d_reclen; /* Length of this record */
|
|
|
|
char d_name[1]; /* Null terminated name */
|
|
|
|
};
|
|
|
|
|
2011-03-05 00:15:48 +01:00
|
|
|
#if defined(_NETBSD_SOURCE)
|
2011-09-30 12:18:10 +02:00
|
|
|
#define MAXNAMLEN 511
|
2011-03-05 00:15:48 +01:00
|
|
|
#define d_fileno d_ino
|
|
|
|
#endif
|
|
|
|
|
2011-02-21 14:13:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The _DIRENT_ALIGN macro returns the alignment of struct dirent. It
|
|
|
|
* is used to check for bogus pointers and to calculate in advance the
|
|
|
|
* memory required to store a dirent.
|
|
|
|
* Unfortunately Minix doesn't use any standard alignment in dirents
|
|
|
|
* at the moment, so, in order to calculate a safe dirent size, we add
|
|
|
|
* an arbitrary number of bytes to the structure (_DIRENT_PAD), and we
|
|
|
|
* set _DIRENT_ALIGN to zero to pass the pointers checks.
|
|
|
|
* Please, FIXME.
|
|
|
|
*/
|
|
|
|
#define _DIRENT_ALIGN(dp) 0
|
|
|
|
#define _DIRENT_PAD 64
|
|
|
|
/*
|
|
|
|
* The _DIRENT_NAMEOFF macro returns the offset of the d_name field in
|
|
|
|
* struct dirent
|
|
|
|
*/
|
|
|
|
#define _DIRENT_NAMEOFF(dp) \
|
|
|
|
((char *)(void *)&(dp)->d_name - (char *)(void *)dp)
|
|
|
|
/*
|
|
|
|
* The _DIRENT_RECLEN macro gives the minimum record length which will hold
|
|
|
|
* a name of size "namlen".
|
|
|
|
*/
|
|
|
|
#define _DIRENT_RECLEN(dp, namlen) \
|
|
|
|
((_DIRENT_NAMEOFF(dp) + (namlen) + 1 + _DIRENT_PAD + _DIRENT_ALIGN(dp)) & \
|
|
|
|
~_DIRENT_ALIGN(dp))
|
|
|
|
/*
|
|
|
|
* The _DIRENT_SIZE macro returns the minimum record length required for
|
|
|
|
* name name stored in the current record.
|
|
|
|
*/
|
|
|
|
#define _DIRENT_SIZE(dp) _DIRENT_RECLEN(dp, strlen(dp->d_name))
|
|
|
|
/*
|
|
|
|
* The _DIRENT_NEXT macro advances to the next dirent record.
|
|
|
|
*/
|
|
|
|
#define _DIRENT_NEXT(dp) ((void *)((char *)(void *)(dp) + (dp)->d_reclen))
|
|
|
|
/*
|
|
|
|
* The _DIRENT_MINSIZE returns the size of an empty (invalid) record.
|
|
|
|
*/
|
|
|
|
#define _DIRENT_MINSIZE(dp) _DIRENT_RECLEN(dp, 0)
|
|
|
|
|
|
|
|
#endif /* !_SYS_DIRENT_H_ */
|