28#ifndef CMSIS_PLUS_POSIX_IO_FILE_SYSTEM_H_
29#define CMSIS_PLUS_POSIX_IO_FILE_SYSTEM_H_
33#if defined(__cplusplus)
37#if defined(OS_USE_OS_APP_CONFIG_H)
38#include <cmsis-plus/os-app-config.h>
55#define FF_MOUNT_FLAGS_HAS_VOLUME (1)
59#pragma GCC diagnostic push
62#pragma clang diagnostic ignored "-Wc++98-compat"
78 class file_system_impl;
88 mkdir (
const char* path, mode_t mode);
91 rmdir (
const char* path);
100 chmod (
const char* path, mode_t mode);
103 stat (
const char* path,
struct stat* buf);
106 truncate (
const char* path, off_t length);
109 rename (
const char* existing,
const char* _new);
112 unlink (
const char* path);
115 utime (
const char* path,
const struct utimbuf*
times);
147 mkdir (
const char* path, mode_t mode);
150 rmdir (
const char* path);
156 chmod (
const char* path, mode_t mode);
159 stat (
const char* path,
struct stat* buf);
162 truncate (
const char* path, off_t length);
165 rename (
const char* existing,
const char* _new);
168 unlink (
const char* path);
171 utime (
const char* path,
const struct utimbuf*
times);
222 mkfs (
int options, ...);
225 vmkfs (
int options, std::va_list args);
228 mount (
const char* path =
nullptr,
unsigned int flags = 0, ...);
243 vmount (
const char* path,
unsigned int flags, std::va_list args);
254 umount (
int unsigned flags = 0);
262 open (
const char* path =
nullptr,
int oflag = 0, ...);
265 vopen (
const char* path,
int oflag, std::va_list args);
275 mkdir (
const char* path, mode_t mode);
278 rmdir (
const char* path);
284 chmod (
const char* path, mode_t mode);
287 stat (
const char* path,
struct stat* buf);
290 truncate (
const char* path, off_t length);
293 rename (
const char* existing,
const char* _new);
296 unlink (
const char* path);
299 utime (
const char* path,
const struct utimbuf*
times);
343 template<
typename T,
typename L>
347 template<
typename T,
typename L>
379 const char* name_ =
nullptr;
387 const char* mounted_path_ =
nullptr;
419 static mounted_list mounted_list__;
487 std::va_list args) = 0;
568 template<
typename ... Args>
628 template<
typename T,
typename L>
647 template<
typename ... Args>
695 vmount (
const char* path,
unsigned int flags, std::va_list args)
707 umount (
int unsigned flags = 0)
override;
712 vopen (
const char* path,
int oflag, std::va_list args)
override;
716 opendir (
const char* dirpath)
override;
721 mkdir (
const char* path, mode_t mode)
override;
724 rmdir (
const char* path)
override;
727 sync (
void)
override;
730 chmod (
const char* path, mode_t mode)
override;
733 stat (
const char* path,
struct stat* buf)
override;
736 truncate (
const char* path, off_t length)
override;
739 rename (
const char* existing,
const char* _new)
override;
742 unlink (
const char* path)
override;
745 utime (
const char* path,
const struct utimbuf*
times)
override;
807 deferred_files_list_.link (*fil);
813 deferred_directories_list_.link (*dir);
819 return deferred_files_list_;
825 return deferred_directories_list_;
836 if (deferred_files_list_.empty ())
838 fil =
new file_type (*
this);
842 fil =
static_cast<file_type*
> (deferred_files_list_.unlink_head ());
848 new (fil) file_type (*
this);
850 deallocate_files<file_type> ();
855 template<
typename T,
typename L>
863 if (deferred_files_list_.empty ())
865 fil =
new file_type (*
this, locker);
869 fil =
static_cast<file_type*
> (deferred_files_list_.unlink_head ());
875 new (fil) file_type (*
this, locker);
877 deallocate_files<file_type> ();
889 while (!deferred_files_list_.empty ())
892 static_cast<file_type*
> (deferred_files_list_.unlink_head ());
903 using directory_type = T;
907 if (deferred_directories_list_.empty ())
909 dir =
new directory_type (*
this);
914 static_cast<directory_type*
> (deferred_directories_list_.unlink_head ());
917 dir->~directory_type ();
920 new (dir) directory_type (*
this);
922 deallocate_directories<directory_type> ();
927 template<
typename T,
typename L>
931 using directory_type = T;
935 if (deferred_directories_list_.empty ())
937 dir =
new directory_type (*
this, locker);
942 static_cast<directory_type*
> (deferred_directories_list_.unlink_head ());
945 dir->~directory_type ();
948 new (dir) directory_type (*
this, locker);
950 deallocate_directories<directory_type> ();
959 using directory_type = T;
962 while (!deferred_directories_list_.empty ())
965 static_cast<directory_type*
> (deferred_directories_list_.unlink_head ());
983 template<
typename ... Args>
987 { impl_instance_,
name },
989 {
device, std::forward<Args>(args)... }
991#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
992 trace::printf (
"file_system_implementable::%s(\"%s\")=@%p\n",
993 __func__, name_,
this);
1000#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1001 trace::printf (
"file_system_implementable::%s() @%p %s\n", __func__,
1006 template<
typename T>
1015 template<
typename T,
typename L>
1016 template<
typename ... Args>
1022 { impl_instance_,
name },
1024 {
device, locker, std::forward<Args>(args)... }
1026#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1027 trace::printf (
"file_system_lockable::%s()=%p\n", __func__,
this);
1031 template<
typename T,
typename L>
1034#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1035 trace::printf (
"file_system_lockable::%s() @%p\n", __func__,
this);
1041 template<
typename T,
typename L>
1046 std::lock_guard<L> lock
1047 { impl_instance_.locker () };
1057 template<
typename T,
typename L>
1061 std::lock_guard<L> lock
1062 { impl_instance_.locker () };
1069 template<
typename T,
typename L>
1074 std::lock_guard<L> lock
1075 { impl_instance_.locker () };
1080 template<
typename T,
typename L>
1084 std::lock_guard<L> lock
1085 { impl_instance_.locker () };
1092 template<
typename T,
typename L>
1096 std::lock_guard<L> lock
1097 { impl_instance_.locker () };
1102 template<
typename T,
typename L>
1106 std::lock_guard<L> lock
1107 { impl_instance_.locker () };
1112 template<
typename T,
typename L>
1116 std::lock_guard<L> lock
1117 { impl_instance_.locker () };
1124 template<
typename T,
typename L>
1128 std::lock_guard<L> lock
1129 { impl_instance_.locker () };
1134 template<
typename T,
typename L>
1138 std::lock_guard<L> lock
1139 { impl_instance_.locker () };
1144 template<
typename T,
typename L>
1148 std::lock_guard<L> lock
1149 { impl_instance_.locker () };
1154 template<
typename T,
typename L>
1159 std::lock_guard<L> lock
1160 { impl_instance_.locker () };
1165 template<
typename T,
typename L>
1169 std::lock_guard<L> lock
1170 { impl_instance_.locker () };
1176 template<
typename T,
typename L>
1179 const struct utimbuf*
times)
1181 std::lock_guard<L> lock
1182 { impl_instance_.locker () };
1187 template<
typename T,
typename L>
1191 std::lock_guard<L> lock
1192 { impl_instance_.locker () };
1197 template<
typename T,
typename L>
1208#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 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_stat(const char *path, struct stat *buf)=0
virtual ~file_system_impl()
virtual file * do_vopen(class file_system &fs, const char *path, int oflag, std::va_list args)=0
virtual directory * do_opendir(class file_system &fs, const char *dirname)=0
virtual int do_statvfs(struct statvfs *buf)=0
virtual int do_utime(const char *path, const struct utimbuf *times)=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 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 utime(const char *path, const struct utimbuf *times) 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)
virtual int utime(const char *path, const struct utimbuf *times)
block_device & device(void) const
virtual int unlink(const char *path)
virtual int statvfs(struct statvfs *buf)
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 unlink(const char *path)
int utime(const char *path, const struct utimbuf *times)
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)