KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
dirent.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dirent.h
4 Copyright (C) 2003 Megan Potter
5 Copyright (C) 2024 Falco Girgis
6
7*/
8
9/** \file dirent.h
10 \brief Directory entry functionality.
11 \ingroup vfs_posix
12
13 This partially implements the standard POSIX dirent.h functionality.
14
15 \author Megan Potter
16 \author Falco Girgis
17*/
18
19#ifndef __SYS_DIRENT_H
20#define __SYS_DIRENT_H
21
22#include <sys/cdefs.h>
23
24__BEGIN_DECLS
25
26#include <unistd.h>
27#include <stdint.h>
28#include <kos/fs.h>
29#include <kos/limits.h>
30
31/** \addtogroup vfs_posix
32 @{
33*/
34
35/** \name Directory File Types
36 \brief POSIX file types for dirent::d_type
37
38 \remark
39 These directory entry types are not part of the POSIX specifican per-se,
40 but are used by BSD and glibc.
41
42 \todo Ensure each VFS driver maps its directory types accordingly
43
44 @{
45*/
46#define DT_UNKNOWN 0 /**< \brief Unknown */
47#define DT_FIFO 1 /**< \brief Named Pipe or FIFO */
48#define DT_CHR 2 /**< \brief Character Device */
49#define DT_DIR 4 /**< \brief Directory */
50#define DT_BLK 6 /**< \brief Block Device */
51#define DT_REG 8 /**< \brief Regular File */
52#define DT_LNK 10 /**< \brief Symbolic Link */
53#define DT_SOCK 12 /**< \brief Local-Domain Socket */
54#define DT_WHT 14 /**< \brief Whiteout (ignored) */
55/** @} */
56
57/** \brief POSIX directory entry structure.
58
59 This structure contains information about a single entry in a directory in
60 the VFS.
61 */
62struct dirent {
63 int d_ino; /**< \brief File unique identifier */
64 off_t d_off; /**< \brief File offset */
65 uint16_t d_reclen; /**< \brief Record length */
66 uint8_t d_type; /**< \brief File type */
67 /** \brief File name
68
69 \warning
70 This field is a flexible array member, which means the structure
71 requires manual over-allocation to reserve storage for this string.
72 \note
73 This allows us to optimize our memory usage by only allocating
74 exactly as many bytes as the string is long for this field.
75 */
76 char d_name[];
77};
78
79/** \brief Type representing a directory stream.
80
81 This type represents a directory stream and is used by the directory reading
82 functions to trace their position in the directory.
83
84 \note
85 The end of this structure is providing extra fixed storage for its inner
86 d_ent.d_name[] FAM, hence the unionization of the d_ent structure along
87 with a d_name[NAME_MAX] extension.
88*/
89typedef struct {
90 /** \brief File descriptor for the directory */
92 /** \brief Union of dirent + extended dirent required for C++ */
93 union {
94 /** \brief Current directory entry */
95 struct dirent d_ent;
96 /** \brief Extended dirent structure with name storage */
97 struct {
98 /** \brief Current directory entry (alias) */
99 struct dirent d_ent2;
100 /** \brief Storage for d_ent::d_name[] FAM */
101 char d_name[NAME_MAX + 1];
102 };
103 };
104} DIR;
105
106/* The following functions that will be defined in <dirent.h> are not currently
107 implemented in KOS:
108
109 DIR *fdopendir(int);
110 readdir_r(DIR *__restrict, struct dirent *__restrict,
111 struct dirent **__restrict);
112 void _seekdir(DIR *, long);
113 void seekdir(DIR *, long);
114 long telldir(DIR *);
115 int scandirat(int, const char *, struct dirent ***,
116 int (*) (const struct dirent *), int (*) (const struct dirent **,
117 const struct dirent **));
118 int versionsort(const struct dirent **, const struct dirent **);
119 ssize_t posix_getdents(int, void *, size_t, int);
120*/
121
122/** @} */
123
124__END_DECLS
125
126#endif
Virtual filesystem support.
#define NAME_MAX
Max filename length.
Definition limits.h:25
int file_t
File descriptor type.
Definition fs.h:94
Limits.
Type representing a directory stream.
Definition dirent.h:89
file_t fd
File descriptor for the directory.
Definition dirent.h:91
POSIX directory entry structure.
Definition dirent.h:62
char d_name[]
File name.
Definition dirent.h:76
uint16_t d_reclen
Record length.
Definition dirent.h:65
uint8_t d_type
File type.
Definition dirent.h:66
int d_ino
File unique identifier.
Definition dirent.h:63
off_t d_off
File offset.
Definition dirent.h:64