2022-07-22 14:46:29 +02:00
|
|
|
#include "devoptab_fsa.h"
|
|
|
|
#include "logger.h"
|
2024-06-03 14:25:45 +02:00
|
|
|
#include <cstdio>
|
2022-07-22 14:46:29 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
int __fsa_dirnext(struct _reent *r,
|
|
|
|
DIR_ITER *dirState,
|
|
|
|
char *filename,
|
|
|
|
struct stat *filestat) {
|
|
|
|
FSError status;
|
|
|
|
|
|
|
|
if (!dirState || !filename || !filestat) {
|
|
|
|
r->_errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto *deviceData = (FSADeviceData *) r->deviceData;
|
2022-09-04 19:42:48 +02:00
|
|
|
auto *dir = (__fsa_dir_t *) (dirState->dirStruct);
|
2022-07-22 14:46:29 +02:00
|
|
|
|
|
|
|
std::lock_guard<MutexWrapper> lock(dir->mutex);
|
2022-09-04 19:42:48 +02:00
|
|
|
memset(&dir->entry_data, 0, sizeof(dir->entry_data));
|
2022-07-22 14:46:29 +02:00
|
|
|
|
|
|
|
status = FSAReadDir(deviceData->clientHandle, dir->fd, &dir->entry_data);
|
|
|
|
if (status < 0) {
|
|
|
|
if (status != FS_ERROR_END_OF_DIR) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("FSAReadDir(0x%08X, 0x%08X, 0x%08X) (%s) failed: %s",
|
|
|
|
deviceData->clientHandle, dir->fd, &dir->entry_data, dir->name, FSAGetStatusStr(status));
|
|
|
|
}
|
|
|
|
r->_errno = __fsa_translate_error(status);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__fsa_translate_stat(&dir->entry_data.info, filestat);
|
|
|
|
|
2023-04-17 14:00:26 +02:00
|
|
|
if (snprintf(filename, NAME_MAX, "%s", dir->entry_data.name) >= NAME_MAX) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("snprintf filename result was truncated\n");
|
|
|
|
}
|
2022-07-22 14:46:29 +02:00
|
|
|
return 0;
|
|
|
|
}
|