Introduce a utility function for moving to the next dirent in read_dir.
This takes care of making sure the dirent buffer is properly aligned, which it needs to be on some platforms (SPARC, ARM, etc.) Change-Id: I9a6352b1e654c090a200770d51f96511ee024a99
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022, Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef FS_OPS_SUPPORT_H
|
||||||
|
#define FS_OPS_SUPPORT_H
|
||||||
|
|
||||||
|
#ifndef FS_SHELL
|
||||||
|
# include <kernel.h>
|
||||||
|
# include <kernel/debug.h>
|
||||||
|
# include <dirent.h>
|
||||||
|
#else
|
||||||
|
# include "fssh_kernel_priv.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static struct dirent*
|
||||||
|
next_dirent(struct dirent* dirent, size_t nameLength, size_t& bufferRemaining)
|
||||||
|
{
|
||||||
|
const size_t reclen = offsetof(struct dirent, d_name) + nameLength + 1;
|
||||||
|
ASSERT(reclen <= bufferRemaining);
|
||||||
|
dirent->d_reclen = reclen;
|
||||||
|
|
||||||
|
const size_t roundedReclen = ROUNDUP(reclen, alignof(struct dirent));
|
||||||
|
if (roundedReclen >= bufferRemaining) {
|
||||||
|
bufferRemaining -= reclen;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
dirent->d_reclen = roundedReclen;
|
||||||
|
bufferRemaining -= roundedReclen;
|
||||||
|
|
||||||
|
return (struct dirent*)((uint8*)dirent + roundedReclen);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FS_OPS_SUPPORT_H
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
#include "bfs_control.h"
|
#include "bfs_control.h"
|
||||||
#include "bfs_disk_system.h"
|
#include "bfs_disk_system.h"
|
||||||
|
|
||||||
|
#include <file_systems/fs_ops_support.h>
|
||||||
|
|
||||||
// TODO: temporary solution as long as there is no public I/O requests API
|
// TODO: temporary solution as long as there is no public I/O requests API
|
||||||
#ifndef FS_SHELL
|
#ifndef FS_SHELL
|
||||||
# include <io_requests.h>
|
# include <io_requests.h>
|
||||||
@@ -1755,14 +1757,10 @@ bfs_read_dir(fs_volume* _volume, fs_vnode* _node, void* _cookie,
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
RETURN_ERROR(status);
|
RETURN_ERROR(status);
|
||||||
|
|
||||||
ASSERT(length < nameBufferSize);
|
|
||||||
|
|
||||||
dirent->d_dev = volume->ID();
|
dirent->d_dev = volume->ID();
|
||||||
dirent->d_ino = id;
|
dirent->d_ino = id;
|
||||||
dirent->d_reclen = offsetof(struct dirent, d_name) + length + 1;
|
|
||||||
|
|
||||||
bufferSize -= dirent->d_reclen;
|
dirent = next_dirent(dirent, length, bufferSize);
|
||||||
dirent = (struct dirent*)((uint8*)dirent + dirent->d_reclen);
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user