Emmanuel Blot
unread,Feb 25, 2015, 12:20:55 PM2/25/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to min...@googlegroups.com
Hi,
I have a quick question about the use of this structure.
It is defined as:
struct dirent {
ino_t d_fileno; /* file number of entry */
uint16_t d_reclen; /* length of this record */
uint16_t d_namlen; /* length of string in d_name */
uint8_t d_type; /* file type, see below */
#if defined(_NETBSD_SOURCE)
#define MAXNAMLEN 511 /* must be kept in sync with NAME_MAX */
char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */
#else
char d_name[511 + 1]; /* name must be no longer than this */
#endif
};
However, in servers/vfs/path.c get_name(), the temporary buffer to
receive the directory entries is allocated as follows:
#define DIR_ENTRIES 8
#define DIR_ENTRY_SIZE (sizeof(struct dirent) + NAME_MAX)
char buf[DIR_ENTRY_SIZE * DIR_ENTRIES];
and in fs/mfs/read.c getdents():
#define GETDENTS_BUFSIZE (sizeof(struct dirent) + MFS_NAME_MAX + 1)
#define GETDENTS_ENTRIES 8
static char getdents_buf[GETDENTS_BUFSIZE * GETDENTS_ENTRIES];
with:
#define NAME_MAX 511
#define MFS_DIRSIZ 60
#define MFS_NAME_MAX MFS_DIRSIZ
while lib/libfsdriver/dentry.c fsdriver_dentry_add() use d_dname to
store the directory entry name as expected, but limits its size to
MAXNAMLEN, and use d_reclen to increase the buffer pointer.
The question is: what are the extra bytes allocated in the temporary
buffer for (NAME_MAX && MFS_NAME_MAX)?
It would look like a leftover of another structure that would have
been defined as:
struct dirent {
ino_t d_fileno; /* file number of entry */
uint16_t d_reclen; /* length of this record */
uint16_t d_namlen; /* length of string in d_name */
uint8_t d_type; /* file type, see below */
char d_name[]; /* variable size */
};
- or am I missing something obvious?
Thanks,
Manu