posix: options: fs: separate file_system_r to its own file
Move the functionality of POSIX_FILE_SYSTEM_R to its own compilation unit and remove the unnecessary dependency on POSIX_FILE_SYSTEM. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
parent
fc860e1010
commit
bc5aff3582
8 changed files with 77 additions and 44 deletions
|
@ -71,6 +71,10 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_FILE_SYSTEM)
|
|||
zephyr_library_sources_ifdef(CONFIG_POSIX_FILE_SYSTEM fs.c)
|
||||
endif()
|
||||
|
||||
if (NOT CONFIG_TC_PROVIDES_POSIX_FILE_SYSTEM_R)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_FILE_SYSTEM_R file_system_r.c)
|
||||
endif()
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_FSYNC fsync.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_MEMLOCK mlockall.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POSIX_MEMLOCK_RANGE mlock.c)
|
||||
|
|
|
@ -14,6 +14,7 @@ rsource "Kconfig.c_lang_r"
|
|||
rsource "Kconfig.c_lib_ext"
|
||||
rsource "Kconfig.device_io"
|
||||
rsource "Kconfig.fd_mgmt"
|
||||
rsource "Kconfig.file_system_r"
|
||||
rsource "Kconfig.fs"
|
||||
rsource "Kconfig.mem"
|
||||
rsource "Kconfig.mqueue"
|
||||
|
|
14
lib/posix/options/Kconfig.file_system_r
Normal file
14
lib/posix/options/Kconfig.file_system_r
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Copyright (c) 2018 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config POSIX_FILE_SYSTEM_R
|
||||
bool "Thread-Safe File System"
|
||||
select FILE_SYSTEM
|
||||
select FDTABLE
|
||||
help
|
||||
Select 'y' here and Zephyr will provide an implementation of the POSIX_FILE_SYSTEM_R
|
||||
Option Group, consisting of readdir_r().
|
||||
|
||||
For more informnation, please see
|
||||
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
|
|
@ -17,13 +17,4 @@ config POSIX_FILE_SYSTEM_ALIAS_FSTAT
|
|||
help
|
||||
When selected via Kconfig, Zephyr will provide an alias for fstat() as _fstat().
|
||||
|
||||
config POSIX_FILE_SYSTEM_R
|
||||
bool "Thread-Safe File System"
|
||||
help
|
||||
Select 'y' here and Zephyr will provide an implementation of the POSIX_FILE_SYSTEM_R
|
||||
Option Group, consisting of readdir_r().
|
||||
|
||||
For more informnation, please see
|
||||
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
|
||||
|
||||
endif # POSIX_FILE_SYSTEM
|
||||
|
|
|
@ -156,7 +156,7 @@ config POSIX_THREAD_PRIO_PROTECT
|
|||
|
||||
config POSIX_THREAD_SAFE_FUNCTIONS
|
||||
bool "POSIX thread-safe functions"
|
||||
select POSIX_FILE_SYSTEM_R if POSIX_FILE_SYSTEM
|
||||
select POSIX_FILE_SYSTEM_R
|
||||
select POSIX_C_LANG_SUPPORT_R
|
||||
help
|
||||
Select 'y' here to enable POSIX thread-safe functions including asctime_r(), ctime_r(),
|
||||
|
|
56
lib/posix/options/file_system_r.c
Normal file
56
lib/posix/options/file_system_r.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Tenstorrent AI ULC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#undef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include "fs_priv.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <zephyr/fs/fs.h>
|
||||
#include <zephyr/posix/posix_features.h>
|
||||
#include <zephyr/posix/dirent.h>
|
||||
|
||||
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
|
||||
{
|
||||
int rc;
|
||||
struct fs_dirent de;
|
||||
struct posix_fs_desc *const ptr = dirp;
|
||||
|
||||
if (result == NULL) {
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (entry == NULL) {
|
||||
*result = NULL;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
if (dirp == NULL) {
|
||||
*result = NULL;
|
||||
return EBADF;
|
||||
}
|
||||
|
||||
rc = fs_readdir(&ptr->dir, &de);
|
||||
if (rc < 0) {
|
||||
*result = NULL;
|
||||
return -rc;
|
||||
}
|
||||
|
||||
strncpy(entry->d_name, de.name, MIN(sizeof(entry->d_name), sizeof(de.name)));
|
||||
entry->d_name[sizeof(entry->d_name) - 1] = '\0';
|
||||
|
||||
if (entry->d_name[0] == '\0') {
|
||||
*result = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*result = entry;
|
||||
return 0;
|
||||
}
|
|
@ -331,40 +331,6 @@ struct dirent *readdir(DIR *dirp)
|
|||
return &pdirent;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_POSIX_FILE_SYSTEM_R
|
||||
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
|
||||
{
|
||||
struct dirent *dir;
|
||||
|
||||
errno = 0;
|
||||
|
||||
dir = readdir(dirp);
|
||||
if (dir == NULL) {
|
||||
int error = errno;
|
||||
|
||||
if (error != 0) {
|
||||
if (result != NULL) {
|
||||
*result = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry != NULL) {
|
||||
memcpy(entry, dir, sizeof(struct dirent));
|
||||
}
|
||||
|
||||
if (result != NULL) {
|
||||
*result = entry;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_POSIX_FILE_SYSTEM_R */
|
||||
|
||||
/**
|
||||
* @brief Rename a file.
|
||||
*
|
||||
|
|
|
@ -3,6 +3,7 @@ CONFIG_LOG=y
|
|||
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||
CONFIG_POSIX_API=y
|
||||
CONFIG_POSIX_FILE_SYSTEM=y
|
||||
CONFIG_POSIX_FILE_SYSTEM_R=y
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_MAIN_STACK_SIZE=4096
|
||||
CONFIG_ZTEST_STACK_SIZE=2048
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue