summaryrefslogtreecommitdiff
path: root/StdLib/Include/sys/dirent.h
diff options
context:
space:
mode:
authordarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>2011-11-02 19:24:19 +0000
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>2011-11-02 19:24:19 +0000
commitd711a4860afcfecb23de8ea178acf2ae58650b2f (patch)
tree18ccf94d056bbe6b100b31be2b03bcf510873772 /StdLib/Include/sys/dirent.h
parent77c9e7473c19f324a737b362444461d97565a4e6 (diff)
downloadedk2-platforms-d711a4860afcfecb23de8ea178acf2ae58650b2f.tar.xz
StdLib: Add directory access functions to PosixLib.
Update <dirent.h> and <sys/dirent.h> to latest version. Enable the tempnam function. Fix assignments within predicate expressions so that it is clear where assignment is intended and where comparison occurs. Remove internal.h and DirFunctions.c with its non-portable opendir, closedir, and readdir functions. Add modified versions of the NetBSD opendir, closedir, and readdir functions. Fix the declaration of stat() to be standards compliant and consistent with code. Clean up indentation and declarations of non-existent objects. Signed-off-by: darylm503 Reviewed-by: lgrosenb Reviewed-by: lpleahy Reviewed-by: jljusten git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12649 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'StdLib/Include/sys/dirent.h')
-rw-r--r--StdLib/Include/sys/dirent.h66
1 files changed, 56 insertions, 10 deletions
diff --git a/StdLib/Include/sys/dirent.h b/StdLib/Include/sys/dirent.h
index 14c67ae128..64b46e4d46 100644
--- a/StdLib/Include/sys/dirent.h
+++ b/StdLib/Include/sys/dirent.h
@@ -59,18 +59,22 @@
*
* All names are wide characters and are guaranteed to be null terminated.
* The maximum length of a name in a directory is MAXNAMLEN.
+ *
+ * This structure is identical to the EFI_FILE_INFO structure. A new
+ * structure is declared because one must be able to refer to it
+ * as struct dirent.
*/
struct dirent {
- UINT64 Size; // Size of this dirent structure instance,
- // including the Null-terminated FileName string.
- UINT64 FileSize; // The size of the file in bytes.
- UINT64 PhysicalSize; // The amount of physical space the file consumes
- // on the file system volume.
- UINT64 Attribute; // The time the file was created.
- struct timespec CreateTime; // The time when the file was last accessed.
- struct timespec LastAccessTime; // The time when the file's contents were last modified.
- struct timespec ModificationTime; // The attribute bits for the file. See below.
- CHAR16 FileName[1]; // The Null-terminated name of the file.
+ UINT64 Size; // (d_reclen) Size of this dirent structure instance,
+ // including the Null-terminated FileName string.
+ UINT64 FileSize; // The size of the file in bytes.
+ UINT64 PhysicalSize; // The amount of physical space the file consumes
+ // on the file system volume.
+ struct timespec CreateTime; // The time the file was created.
+ struct timespec LastAccessTime; // The time when the file was last accessed.
+ struct timespec ModificationTime; // The time when the file's contents were last modified.
+ UINT64 Attribute; // (d_type) The attribute bits for the file. See below.
+ CHAR16 FileName[1]; // (d_name) The Null-terminated name of the file.
};
/*
@@ -88,4 +92,46 @@ struct dirent {
#define DT_SOCKET 0x0000000000030000 // File attaches to a socket
#define DT_VALID_ATTR 0x0000000000030037 // Mask for valid attribute bits
+/*
+ * The _DIRENT_ALIGN macro returns the alignment of struct dirent.
+ * struct dirent uses 8.
+ */
+#define _DIRENT_ALIGN(dp) (sizeof((dp)->Size) - 1)
+
+/*
+ * The _DIRENT_NAMEOFF macro returns the offset of the d_name field in
+ * struct dirent
+ */
+#define _DIRENT_NAMEOFF(dp) \
+ ((char *)(void *)&(dp)->FileName - (char *)(void *)dp)
+
+/*
+ * The _DIRENT_RECLEN macro gives the minimum record length which will hold
+ * a name of size "namlen". This requires the amount of space in struct dirent
+ * without the d_name field, plus enough space for the name with a terminating
+ * null byte (namlen+1), rounded up to a the appropriate byte boundary.
+ */
+#define _DIRENT_RECLEN(dp, namlen) \
+ ((_DIRENT_NAMEOFF(dp) + (namlen) + 1 + _DIRENT_ALIGN(dp)) & \
+ ~_DIRENT_ALIGN(dp))
+
+#define _DIRENT_NAMELEN(dp) \
+ ((dp)->Size - _DIRENT_NAMEOFF(dp) - 1)
+
+/*
+ * 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, _DIRENT_NAMELEN(dp))
+
+/*
+ * The _DIRENT_NEXT macro advances to the next dirent record.
+ */
+#define _DIRENT_NEXT(dp) ((void *)((char *)(void *)(dp) + (dp)->Size))
+
+/*
+ * The _DIRENT_MINSIZE returns the size of an empty (invalid) record.
+ */
+#define _DIRENT_MINSIZE(dp) _DIRENT_RECLEN(dp, 0)
+
#endif /* !_SYS_DIRENT_H_ */