Adjust all struct dirent creations (again), this time to use offsetof().

The dirent struct is not packed, so offsetof(dirent, d_name) != sizeof(dirent).
Thus in order not to waste the alignment bytes (which are significant,
on x86_64 at least, sizeof(dirent)==32, but offsetof(...)=26.)

This is also the most portable way to handle things, and should
work just fine in cross-platform code that has a non-zero-sized d_name.
This commit is contained in:
Augustin Cavalier
2021-12-01 17:05:40 -05:00
parent ba0e4a83e5
commit 711e2dc05b
31 changed files with 66 additions and 66 deletions
@@ -1737,7 +1737,7 @@ bfs_read_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
while (count < maxCount && bufferSize > sizeof(struct dirent)) {
ino_t id;
uint16 length;
size_t nameBufferSize = bufferSize - sizeof(struct dirent);
size_t nameBufferSize = bufferSize - offsetof(struct dirent, d_name);
status_t status = iterator->GetNextEntry(dirent->d_name, &length,
nameBufferSize, &id);
@@ -1759,7 +1759,7 @@ bfs_read_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
dirent->d_dev = volume->ID();
dirent->d_ino = id;
dirent->d_reclen = sizeof(struct dirent) + length + 1;
dirent->d_reclen = offsetof(struct dirent, d_name) + length + 1;
bufferSize -= dirent->d_reclen;
dirent = (struct dirent*)((uint8*)dirent + dirent->d_reclen);
@@ -1867,7 +1867,7 @@ bfs_read_attr_dir(fs_volume* _volume, fs_vnode* node, void* _cookie,
Volume* volume = (Volume*)_volume->private_volume;
dirent->d_dev = volume->ID();
dirent->d_reclen = sizeof(struct dirent) + length + 1;
dirent->d_reclen = offsetof(struct dirent, d_name) + length + 1;
*_num = 1;
return B_OK;