12#ifndef CMSIS_PLUS_POSIX_IO_FILE_SYSTEM_H_
13#define CMSIS_PLUS_POSIX_IO_FILE_SYSTEM_H_
17#if defined(__cplusplus)
21#if defined(OS_USE_OS_APP_CONFIG_H)
22#include <cmsis-plus/os-app-config.h>
39#define FF_MOUNT_FLAGS_HAS_VOLUME (1)
43#pragma GCC diagnostic push
45#pragma clang diagnostic ignored "-Wc++98-compat"
61 class file_system_impl;
71 mkdir (
const char* path, mode_t mode);
74 rmdir (
const char* path);
83 chmod (
const char* path, mode_t mode);
86 stat (
const char* path,
struct stat* buf);
89 truncate (
const char* path, off_t length);
92 rename (
const char* existing,
const char* _new);
98 utime (
const char* path,
const utimbuf*
times);
121#pragma GCC diagnostic push
122#if defined(__clang__)
123#elif defined(__GNUC__)
124#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
125#pragma GCC diagnostic ignored "-Wsuggest-final-types"
136 mkdir (
const char* path, mode_t mode);
139 rmdir (
const char* path);
145 chmod (
const char* path, mode_t mode);
148 stat (
const char* path,
struct stat* buf);
151 truncate (
const char* path, off_t length);
154 rename (
const char* existing,
const char* _new);
157 unlink (
const char* path);
160 utime (
const char* path,
const utimbuf*
times);
210 mkfs (
int options, ...);
213 vmkfs (
int options, std::va_list args);
216 mount (
const char* path =
nullptr,
unsigned int flags = 0, ...);
231 vmount (
const char* path,
unsigned int flags, std::va_list args);
242 umount (
int unsigned flags = 0);
250 open (
const char* path =
nullptr,
int oflag = 0, ...);
253 vopen (
const char* path,
int oflag, std::va_list args);
263 mkdir (
const char* path, mode_t mode);
266 rmdir (
const char* path);
272 chmod (
const char* path, mode_t mode);
275 stat (
const char* path,
struct stat* buf);
278 truncate (
const char* path, off_t length);
281 rename (
const char* existing,
const char* _new);
284 unlink (
const char* path);
287 utime (
const char* path,
const utimbuf*
times);
310 &file::deferred_links_>;
314 &directory::deferred_links_>;
324 template <
typename T>
328 template <
typename T>
332 template <
typename T,
typename L>
336 template <
typename T,
typename L>
340 template <
typename T>
344 template <
typename T>
367 const char* name_ =
nullptr;
375 const char* mounted_path_ =
nullptr;
405 &file_system::mount_manager_links_>;
406 static mounted_list mounted_list__;
414#pragma GCC diagnostic pop
551#pragma GCC diagnostic push
552#if defined(__clang__)
553#elif defined(__GNUC__)
554#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
555#pragma GCC diagnostic ignored "-Wsuggest-final-types"
557 template <
typename T>
573 template <
typename... Args>
629#pragma GCC diagnostic pop
633#pragma GCC diagnostic push
634#if defined(__clang__)
635#elif defined(__GNUC__)
636#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
637#pragma GCC diagnostic ignored "-Wsuggest-final-types"
639 template <
typename T,
typename L>
656 template <
typename... Args>
704 vmount (
const char* path,
unsigned int flags,
705 std::va_list args)
override;
716 umount (
int unsigned flags = 0)
override;
721 vopen (
const char* path,
int oflag, std::va_list args)
override;
725 opendir (
const char* dirpath)
override;
730 mkdir (
const char* path, mode_t mode)
override;
733 rmdir (
const char* path)
override;
736 sync (
void)
override;
739 chmod (
const char* path, mode_t mode)
override;
742 stat (
const char* path,
struct stat* buf)
override;
745 truncate (
const char* path, off_t length)
override;
748 rename (
const char* existing,
const char* _new)
override;
751 unlink (
const char* path)
override;
754 utime (
const char* path,
const utimbuf*
times)
override;
781#pragma GCC diagnostic pop
801#pragma GCC diagnostic push
802#if defined(__clang__)
803#elif defined(__GNUC__)
804#pragma GCC diagnostic ignored "-Wuseless-cast"
813#pragma GCC diagnostic pop
824 deferred_files_list_.link (*fil);
830 deferred_directories_list_.link (*dir);
836 return deferred_files_list_;
842 return deferred_directories_list_;
845 template <
typename T>
853 if (deferred_files_list_.empty ())
855 fil =
new file_type (*
this);
859 fil =
static_cast<file_type*
> (deferred_files_list_.unlink_head ());
865 new (fil) file_type (*
this);
867 deallocate_files<file_type> ();
872 template <
typename T,
typename L>
880 if (deferred_files_list_.empty ())
882 fil =
new file_type (*
this, locker);
886 fil =
static_cast<file_type*
> (deferred_files_list_.unlink_head ());
892 new (fil) file_type (*
this, locker);
894 deallocate_files<file_type> ();
899 template <
typename T>
906 while (!deferred_files_list_.empty ())
909 =
static_cast<file_type*
> (deferred_files_list_.unlink_head ());
916 template <
typename T>
920 using directory_type = T;
924 if (deferred_directories_list_.empty ())
926 dir =
new directory_type (*
this);
930 dir =
static_cast<directory_type*
> (
931 deferred_directories_list_.unlink_head ());
934 dir->~directory_type ();
937 new (dir) directory_type (*
this);
939 deallocate_directories<directory_type> ();
944 template <
typename T,
typename L>
948 using directory_type = T;
952 if (deferred_directories_list_.empty ())
954 dir =
new directory_type (*
this, locker);
958 dir =
static_cast<directory_type*
> (
959 deferred_directories_list_.unlink_head ());
962 dir->~directory_type ();
965 new (dir) directory_type (*
this, locker);
967 deallocate_directories<directory_type> ();
972 template <
typename T>
976 using directory_type = T;
979 while (!deferred_directories_list_.empty ())
981 directory_type* d =
static_cast<directory_type*
> (
982 deferred_directories_list_.unlink_head ());
999 template <
typename T>
1000 template <
typename... Args>
1004 impl_instance_{
device,
std::forward<Args> (args)... }
1006#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1007 trace::printf (
"file_system_implementable::%s(\"%s\")=@%p\n", __func__,
1012#pragma GCC diagnostic push
1013#if defined(__clang__)
1014#elif defined(__GNUC__)
1015#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
1017 template <
typename T>
1020#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1021 trace::printf (
"file_system_implementable::%s() @%p %s\n", __func__,
1025#pragma GCC diagnostic pop
1027 template <
typename T>
1036 template <
typename T,
typename L>
1037 template <
typename... Args>
1043 impl_instance_{
device, locker,
std::forward<Args> (args)... }
1045#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1046 trace::printf (
"file_system_lockable::%s()=%p\n", __func__,
this);
1050#pragma GCC diagnostic push
1051#if defined(__clang__)
1052#elif defined(__GNUC__)
1053#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
1055 template <
typename T,
typename L>
1058#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1059 trace::printf (
"file_system_lockable::%s() @%p\n", __func__,
this);
1062#pragma GCC diagnostic pop
1066 template <
typename T,
typename L>
1071 std::lock_guard<L> lock{ impl_instance_.locker () };
1081 template <
typename T,
typename L>
1085 std::lock_guard<L> lock{ impl_instance_.locker () };
1092 template <
typename T,
typename L>
1097 std::lock_guard<L> lock{ impl_instance_.locker () };
1102 template <
typename T,
typename L>
1106 std::lock_guard<L> lock{ impl_instance_.locker () };
1113 template <
typename T,
typename L>
1117 std::lock_guard<L> lock{ impl_instance_.locker () };
1122 template <
typename T,
typename L>
1126 std::lock_guard<L> lock{ impl_instance_.locker () };
1131 template <
typename T,
typename L>
1135 std::lock_guard<L> lock{ impl_instance_.locker () };
1142 template <
typename T,
typename L>
1146 std::lock_guard<L> lock{ impl_instance_.locker () };
1151 template <
typename T,
typename L>
1155 std::lock_guard<L> lock{ impl_instance_.locker () };
1160 template <
typename T,
typename L>
1164 std::lock_guard<L> lock{ impl_instance_.locker () };
1169 template <
typename T,
typename L>
1173 std::lock_guard<L> lock{ impl_instance_.locker () };
1178 template <
typename T,
typename L>
1182 std::lock_guard<L> lock{ impl_instance_.locker () };
1188 template <
typename T,
typename L>
1191 const utimbuf*
times)
1193 std::lock_guard<L> lock{ impl_instance_.locker () };
1198 template <
typename T,
typename L>
1202 std::lock_guard<L> lock{ impl_instance_.locker () };
1207 template <
typename T,
typename L>
1218#pragma GCC diagnostic pop
virtual int do_rename(const char *existing, const char *_new)=0
virtual int do_mkdir(const char *path, mode_t mode)=0
virtual directory * do_opendir(file_system &fs, const char *dirname)=0
virtual int do_unlink(const char *path)=0
virtual int do_umount(unsigned int flags)=0
virtual void do_sync(void)=0
virtual int do_truncate(const char *path, off_t length)=0
virtual int do_vmkfs(int options, std::va_list args)=0
virtual int do_chmod(const char *path, mode_t mode)=0
block_device & device(void) const
virtual int do_vmount(unsigned int flags, std::va_list args)=0
virtual int do_utime(const char *path, const utimbuf *times)=0
virtual file * do_vopen(file_system &fs, const char *path, int oflag, std::va_list args)=0
virtual int do_stat(const char *path, struct stat *buf)=0
virtual ~file_system_impl()
virtual int do_statvfs(struct statvfs *buf)=0
virtual int do_rmdir(const char *path)=0
value_type & impl(void) const
virtual ~file_system_implementable() override
file_system_implementable(const char *name, block_device &device, Args &&... args)
virtual file * vopen(const char *path, int oflag, std::va_list args) override
virtual directory * opendir(const char *dirpath) override
virtual int utime(const char *path, const utimbuf *times) override
virtual int vmount(const char *path, unsigned int flags, std::va_list args) override
Mount file system.
virtual void sync(void) override
value_type & impl(void) const
file_system_lockable(const char *name, block_device &device, lockable_type &locker, Args &&... args)
virtual int stat(const char *path, struct stat *buf) override
virtual int mkdir(const char *path, mode_t mode) override
virtual int unlink(const char *path) override
virtual int chmod(const char *path, mode_t mode) override
virtual ~file_system_lockable() override
virtual int umount(int unsigned flags=0) override
Unmount file system.
virtual int truncate(const char *path, off_t length) override
virtual int rename(const char *existing, const char *_new) override
virtual int statvfs(struct statvfs *buf) override
virtual int rmdir(const char *path) override
int mount(const char *path=nullptr, unsigned int flags=0,...)
deferred_directories_list_t & deferred_directories_list(void)
virtual int truncate(const char *path, off_t length)
file * open(const char *path=nullptr, int oflag=0,...)
virtual int mkdir(const char *path, mode_t mode)
virtual int rename(const char *existing, const char *_new)
void add_deferred_directory(directory *dir)
T * allocate_directory(void)
block_device & device(void) const
virtual int unlink(const char *path)
virtual int statvfs(struct statvfs *buf)
virtual int utime(const char *path, const utimbuf *times)
virtual int stat(const char *path, struct stat *buf)
static file_system * identify_mounted(const char **path1, const char **path2=nullptr)
int mkfs(int options,...)
virtual int chmod(const char *path, mode_t mode)
virtual int vmount(const char *path, unsigned int flags, std::va_list args)
Mount file system.
virtual file * vopen(const char *path, int oflag, std::va_list args)
virtual int umount(int unsigned flags=0)
Unmount file system.
virtual int rmdir(const char *path)
deferred_files_list_t & deferred_files_list(void)
void add_deferred_file(file *fil)
const char * name(void) const
void deallocate_files(void)
file_system_impl & impl(void) const
const char * mounted_path(void)
virtual int vmkfs(int options, std::va_list args)
void deallocate_directories(void)
virtual directory * opendir(const char *dirpath)
The core of a double linked list, pointers to next, previous.
int printf(const char *format,...)
Write a formatted string to the trace device.
clock_t times(struct tms *buf)
int utime(const char *path, const utimbuf *times)
int unlink(const char *path)
int rmdir(const char *path)
int rename(const char *existing, const char *_new)
int stat(const char *path, struct stat *buf)
int chmod(const char *path, mode_t mode)
int truncate(const char *path, off_t length)
directory * opendir(const char *dirname)
Open directory.
int mkdir(const char *path, mode_t mode)