13#ifndef CMSIS_PLUS_POSIX_IO_FILE_SYSTEM_H_
14#define CMSIS_PLUS_POSIX_IO_FILE_SYSTEM_H_
18#if defined(__cplusplus)
22#if defined(OS_USE_OS_APP_CONFIG_H)
23#include <cmsis-plus/os-app-config.h>
40#define FF_MOUNT_FLAGS_HAS_VOLUME (1)
44#pragma GCC diagnostic push
46#pragma clang diagnostic ignored "-Wc++98-compat"
62 class file_system_impl;
72 mkdir (
const char* path, mode_t mode);
75 rmdir (
const char* path);
84 chmod (
const char* path, mode_t mode);
87 stat (
const char* path,
struct stat* buf);
90 truncate (
const char* path, off_t length);
93 rename (
const char* existing,
const char* _new);
99 utime (
const char* path,
const utimbuf*
times);
122#pragma GCC diagnostic push
123#if defined(__clang__)
124#elif defined(__GNUC__)
125#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
126#pragma GCC diagnostic ignored "-Wsuggest-final-types"
137 mkdir (
const char* path, mode_t mode);
140 rmdir (
const char* path);
146 chmod (
const char* path, mode_t mode);
149 stat (
const char* path,
struct stat* buf);
152 truncate (
const char* path, off_t length);
155 rename (
const char* existing,
const char* _new);
158 unlink (
const char* path);
161 utime (
const char* path,
const utimbuf*
times);
212 mkfs (
int options, ...);
215 vmkfs (
int options, std::va_list args);
218 mount (
const char* path =
nullptr,
unsigned int flags = 0, ...);
233 vmount (
const char* path,
unsigned int flags, std::va_list args);
244 umount (
int unsigned flags = 0);
252 open (
const char* path =
nullptr,
int oflag = 0, ...);
255 vopen (
const char* path,
int oflag, std::va_list args);
265 mkdir (
const char* path, mode_t mode);
268 rmdir (
const char* path);
274 chmod (
const char* path, mode_t mode);
277 stat (
const char* path,
struct stat* buf);
280 truncate (
const char* path, off_t length);
283 rename (
const char* existing,
const char* _new);
286 unlink (
const char* path);
289 utime (
const char* path,
const utimbuf*
times);
333 template<
typename T,
typename L>
337 template<
typename T,
typename L>
369 const char* name_ =
nullptr;
377 const char* mounted_path_ =
nullptr;
409 static mounted_list mounted_list__;
417#pragma GCC diagnostic pop
478 std::va_list args) = 0;
541#pragma GCC diagnostic push
542#if defined(__clang__)
543#elif defined(__GNUC__)
544#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
545#pragma GCC diagnostic ignored "-Wsuggest-final-types"
565 template<
typename ... Args>
622#pragma GCC diagnostic pop
626#pragma GCC diagnostic push
627#if defined(__clang__)
628#elif defined(__GNUC__)
629#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
630#pragma GCC diagnostic ignored "-Wsuggest-final-types"
632 template<
typename T,
typename L>
651 template<
typename ... Args>
699 vmount (
const char* path,
unsigned int flags, std::va_list args)
711 umount (
int unsigned flags = 0)
override;
716 vopen (
const char* path,
int oflag, std::va_list args)
override;
720 opendir (
const char* dirpath)
override;
725 mkdir (
const char* path, mode_t mode)
override;
728 rmdir (
const char* path)
override;
731 sync (
void)
override;
734 chmod (
const char* path, mode_t mode)
override;
737 stat (
const char* path,
struct stat* buf)
override;
740 truncate (
const char* path, off_t length)
override;
743 rename (
const char* existing,
const char* _new)
override;
746 unlink (
const char* path)
override;
749 utime (
const char* path,
const utimbuf*
times)
override;
777#pragma GCC diagnostic pop
797#pragma GCC diagnostic push
798#if defined(__clang__)
799#elif defined(__GNUC__)
800#pragma GCC diagnostic ignored "-Wuseless-cast"
809#pragma GCC diagnostic pop
820 deferred_files_list_.link (*fil);
826 deferred_directories_list_.link (*dir);
832 return deferred_files_list_;
838 return deferred_directories_list_;
849 if (deferred_files_list_.empty ())
851 fil =
new file_type (*
this);
855 fil =
static_cast<file_type*
> (deferred_files_list_.unlink_head ());
861 new (fil) file_type (*
this);
863 deallocate_files<file_type> ();
868 template<
typename T,
typename L>
876 if (deferred_files_list_.empty ())
878 fil =
new file_type (*
this, locker);
882 fil =
static_cast<file_type*
> (deferred_files_list_.unlink_head ());
888 new (fil) file_type (*
this, locker);
890 deallocate_files<file_type> ();
902 while (!deferred_files_list_.empty ())
905 static_cast<file_type*
> (deferred_files_list_.unlink_head ());
916 using directory_type = T;
920 if (deferred_directories_list_.empty ())
922 dir =
new directory_type (*
this);
927 static_cast<directory_type*
> (deferred_directories_list_.unlink_head ());
930 dir->~directory_type ();
933 new (dir) directory_type (*
this);
935 deallocate_directories<directory_type> ();
940 template<
typename T,
typename L>
944 using directory_type = T;
948 if (deferred_directories_list_.empty ())
950 dir =
new directory_type (*
this, locker);
955 static_cast<directory_type*
> (deferred_directories_list_.unlink_head ());
958 dir->~directory_type ();
961 new (dir) directory_type (*
this, locker);
963 deallocate_directories<directory_type> ();
972 using directory_type = T;
975 while (!deferred_directories_list_.empty ())
978 static_cast<directory_type*
> (deferred_directories_list_.unlink_head ());
996 template<
typename ... Args>
1000 { impl_instance_,
name },
1002 {
device, std::forward<Args>(args)... }
1004#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1005 trace::printf (
"file_system_implementable::%s(\"%s\")=@%p\n",
1006 __func__, name_,
this);
1010#pragma GCC diagnostic push
1011#if defined(__clang__)
1012#elif defined(__GNUC__)
1013#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
1015 template<
typename T>
1018#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1019 trace::printf (
"file_system_implementable::%s() @%p %s\n", __func__,
1023#pragma GCC diagnostic pop
1025 template<
typename T>
1034 template<
typename T,
typename L>
1035 template<
typename ... Args>
1041 { impl_instance_,
name },
1043 {
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
1072 { impl_instance_.locker () };
1082 template<
typename T,
typename L>
1086 std::lock_guard<L> lock
1087 { impl_instance_.locker () };
1094 template<
typename T,
typename L>
1099 std::lock_guard<L> lock
1100 { impl_instance_.locker () };
1105 template<
typename T,
typename L>
1109 std::lock_guard<L> lock
1110 { impl_instance_.locker () };
1117 template<
typename T,
typename L>
1121 std::lock_guard<L> lock
1122 { impl_instance_.locker () };
1127 template<
typename T,
typename L>
1131 std::lock_guard<L> lock
1132 { impl_instance_.locker () };
1137 template<
typename T,
typename L>
1141 std::lock_guard<L> lock
1142 { impl_instance_.locker () };
1149 template<
typename T,
typename L>
1153 std::lock_guard<L> lock
1154 { impl_instance_.locker () };
1159 template<
typename T,
typename L>
1163 std::lock_guard<L> lock
1164 { impl_instance_.locker () };
1169 template<
typename T,
typename L>
1173 std::lock_guard<L> lock
1174 { impl_instance_.locker () };
1179 template<
typename T,
typename L>
1184 std::lock_guard<L> lock
1185 { impl_instance_.locker () };
1190 template<
typename T,
typename L>
1194 std::lock_guard<L> lock
1195 { impl_instance_.locker () };
1201 template<
typename T,
typename L>
1204 const utimbuf*
times)
1206 std::lock_guard<L> lock
1207 { impl_instance_.locker () };
1212 template<
typename T,
typename L>
1216 std::lock_guard<L> lock
1217 { impl_instance_.locker () };
1222 template<
typename T,
typename L>
1233#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)