12#if defined(OS_USE_OS_APP_CONFIG_H)
13#include <cmsis-plus/os-app-config.h>
27#pragma clang diagnostic ignored "-Wc++98-compat"
28#elif defined(__GNUC__)
29#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
44#pragma GCC diagnostic push
46#pragma clang diagnostic ignored "-Wexit-time-destructors"
47#pragma clang diagnostic ignored "-Wglobal-constructors"
50 file_system::mounted_list file_system::mounted_list__;
52#pragma GCC diagnostic pop
54 file_system* file_system::mounted_root__;
62 mkdir (
const char* path, mode_t mode)
64#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
80 auto adjusted_path = path;
90 return fs->mkdir (adjusted_path, mode);
96#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
112 auto adjusted_path = path;
122 return fs->rmdir (adjusted_path);
128#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
133#pragma GCC diagnostic push
134#if defined(__clang__)
135#elif defined(__GNUC__)
136#pragma GCC diagnostic ignored "-Waggregate-return"
138 for (
auto&& fs : file_system::mounted_list__)
139#pragma GCC diagnostic pop
144 if (file_system::mounted_root__ !=
nullptr)
146 file_system::mounted_root__->sync ();
155 chmod (
const char* path, mode_t mode)
157#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
173 const char* adjusted_path = path;
182 return fs->chmod (adjusted_path, mode);
188#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
192 if ((path ==
nullptr) || (buf ==
nullptr))
204 const char* adjusted_path = path;
213 return fs->stat (adjusted_path, buf);
219#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
235 const char* adjusted_path = path;
250 return fs->truncate (adjusted_path, length);
254 rename (
const char* existing,
const char* _new)
256#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
257 trace::printf (
"%s(\"%s\",\"%s\")\n", __func__, existing, _new);
260 if ((existing ==
nullptr) || (_new ==
nullptr))
266 if ((*existing ==
'\0') || (*_new ==
'\0'))
272 auto adjusted_existing = existing;
273 auto adjusted_new = _new;
283 return fs->rename (adjusted_existing, adjusted_new);
289#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
305 auto adjusted_path = path;
314 return fs->unlink (adjusted_path);
320#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
324 if ((path ==
nullptr) || (
times ==
nullptr))
336 auto adjusted_path = path;
345 return fs->utime (adjusted_path,
times);
351#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
355 if ((path ==
nullptr) || (buf ==
nullptr))
367 auto adjusted_path = path;
376 return fs->statvfs (buf);
382#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
386 if (dirpath ==
nullptr)
392 if (*dirpath ==
'\0')
414 auto adjusted_path = dirpath;
428 dir = fs->opendir (adjusted_path);
441#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
453#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
454 trace::printf (
"file_system::%s(\"%s\")=%p\n", __func__, name_,
this);
456 deferred_files_list_.clear ();
457 deferred_directories_list_.clear ();
462#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
463 trace::printf (
"file_system::%s() @%p %s\n", __func__,
this, name_);
474 va_start (args, options);
475 int ret =
vmkfs (options, args);
484#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
485 trace::printf (
"file_system::%s(%u) @%p\n", __func__, options,
this);
488 if (mounted_path_ !=
nullptr)
508 va_start (args, flags);
509 int ret =
vmount (path, flags, args);
519#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
520 trace::printf (
"file_system::%s(\"%s\", %u) @%p\n", __func__,
521 path ? path :
"nullptr", flags,
this);
524 if (mounted_path_ !=
nullptr)
533#pragma GCC diagnostic push
534#if defined(__clang__)
535#elif defined(__GNUC__)
536#pragma GCC diagnostic ignored "-Waggregate-return"
538 for (
auto&& fs : mounted_list__)
539#pragma GCC diagnostic pop
542 if (std::strcmp (path, fs.mounted_path_) == 0)
552 char* p =
const_cast<char*
> (path);
555 if (strcmp (
"/", path) == 0)
571 mounted_root__ =
this;
576 mounted_list__.link (*
this);
577 mounted_path_ = path;
591#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
592 trace::printf (
"file_system::%s(%u) @%p\n", __func__, flags,
this);
595 mount_manager_links_.unlink ();
596 mounted_path_ =
nullptr;
598 if (
this == mounted_root__)
600 if (!mounted_list__.empty ())
606 mounted_root__ =
nullptr;
609 if (!
device ().is_opened ())
623 assert (path1 !=
nullptr);
624 assert (*path1 !=
nullptr);
626#pragma GCC diagnostic push
627#if defined(__clang__)
628#elif defined(__GNUC__)
629#pragma GCC diagnostic ignored "-Waggregate-return"
631 for (
auto&& fs : mounted_list__)
632#pragma GCC diagnostic pop
634 auto len = std::strlen (fs.mounted_path_);
637 if (std::strncmp (fs.mounted_path_, *path1, len) == 0)
639#pragma GCC diagnostic push
640#if defined(__clang__)
641#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
644 *path1 = (*path1 + len - 1);
645 while ((*path1)[1] ==
'/')
647 *path1 = (*path1 + 1);
650 if ((path2 !=
nullptr) && (*path2 !=
nullptr))
652 *path2 = (*path2 + len - 1);
653 while ((*path2)[1] ==
'/')
655 *path2 = (*path2 + 1);
658#pragma GCC diagnostic pop
665 if (mounted_root__ !=
nullptr)
667 return mounted_root__;
681 va_start (args, oflag);
691#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
692 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, oflag);
695 if (!
device ().is_opened ())
721#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
722 trace::printf (
"file_system::%s(\"%s\")\n", __func__, dirpath);
725 if (!
device ().is_opened ())
750#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
751 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, mode);
766 if (!
device ().is_opened ())
780#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
796 if (!
device ().is_opened ())
810#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
814 if (!
device ().is_opened ())
830#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
831 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, mode);
846 if (!
device ().is_opened ())
861#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
862 trace::printf (
"file_system::%s(\"%s\", %p)\n", __func__, path, buf);
865 if ((path ==
nullptr) || (buf ==
nullptr))
877 if (!
device ().is_opened ())
892#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
893 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, length);
908 if (!
device ().is_opened ())
923#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
924 trace::printf (
"file_system::%s(\"%s\",\"%s\")\n", __func__, existing,
928 if ((existing ==
nullptr) || (_new ==
nullptr))
934 if ((*existing ==
'\0') || (*_new ==
'\0'))
940 if (!
device ().is_opened ())
955#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
971 if (!
device ().is_opened ())
987#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
991 if ((path ==
nullptr) || (
times ==
nullptr))
1003 if (!
device ().is_opened ())
1012 if (
times ==
nullptr)
1016 tmp.actime = time (
nullptr);
1017 tmp.modtime = tmp.actime;
1031#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1035 if (!
device ().is_opened ())
1054#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1055 trace::printf (
"file_system_impl::%s()=%p\n", __func__,
this);
1061#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1062 trace::printf (
"file_system_impl::%s() @%p\n", __func__,
this);
static value_type * identify_device(const char *path)
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
file_system_impl(block_device &device)
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
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
int mount(const char *path=nullptr, unsigned int flags=0,...)
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)
file_system(file_system_impl &impl, const char *name)
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)
file_system_impl & impl(void) const
virtual int vmkfs(int options, std::va_list args)
virtual directory * opendir(const char *dirpath)
io * alloc_file_descriptor(void)
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)