13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
28#pragma clang diagnostic ignored "-Wc++98-compat"
29#elif defined(__GNUC__)
30#pragma GCC diagnostic ignored "-Wsuggest-final-methods"
45#pragma GCC diagnostic push
47#pragma clang diagnostic ignored "-Wexit-time-destructors"
48#pragma clang diagnostic ignored "-Wglobal-constructors"
51 file_system::mounted_list file_system::mounted_list__;
53#pragma GCC diagnostic pop
55 file_system* file_system::mounted_root__;
63 mkdir (
const char* path, mode_t mode)
65#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
81 auto adjusted_path = path;
91 return fs->mkdir (adjusted_path, mode);
97#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
113 auto adjusted_path = path;
123 return fs->rmdir (adjusted_path);
129#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
134#pragma GCC diagnostic push
135#if defined(__clang__)
136#elif defined(__GNUC__)
137#pragma GCC diagnostic ignored "-Waggregate-return"
139 for (
auto&& fs : file_system::mounted_list__)
140#pragma GCC diagnostic pop
145 if (file_system::mounted_root__ !=
nullptr)
147 file_system::mounted_root__->sync ();
156 chmod (
const char* path, mode_t mode)
158#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
174 const char* adjusted_path = path;
183 return fs->chmod (adjusted_path, mode);
189#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
193 if ((path ==
nullptr) || (buf ==
nullptr))
205 const char* adjusted_path = path;
214 return fs->stat (adjusted_path, buf);
220#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
236 const char* adjusted_path = path;
251 return fs->truncate (adjusted_path, length);
255 rename (
const char* existing,
const char* _new)
257#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
258 trace::printf (
"%s(\"%s\",\"%s\")\n", __func__, existing, _new);
261 if ((existing ==
nullptr) || (_new ==
nullptr))
267 if ((*existing ==
'\0') || (*_new ==
'\0'))
273 auto adjusted_existing = existing;
274 auto adjusted_new = _new;
284 return fs->rename (adjusted_existing, adjusted_new);
290#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
306 auto adjusted_path = path;
315 return fs->unlink (adjusted_path);
321#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
325 if ((path ==
nullptr) || (
times ==
nullptr))
337 auto adjusted_path = path;
346 return fs->utime (adjusted_path,
times);
352#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
356 if ((path ==
nullptr) || (buf ==
nullptr))
368 auto adjusted_path = path;
377 return fs->statvfs (buf);
383#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
387 if (dirpath ==
nullptr)
393 if (*dirpath ==
'\0')
415 auto adjusted_path = dirpath;
429 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)
640 *path1 = (*path1 + len - 1);
641 while ((*path1)[1] ==
'/')
643 *path1 = (*path1 + 1);
646 if ((path2 !=
nullptr) && (*path2 !=
nullptr))
648 *path2 = (*path2 + len - 1);
649 while ((*path2)[1] ==
'/')
651 *path2 = (*path2 + 1);
660 if (mounted_root__ !=
nullptr)
662 return mounted_root__;
676 va_start(args, oflag);
686#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
687 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, oflag);
690 if (!
device ().is_opened ())
716#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
717 trace::printf (
"file_system::%s(\"%s\")\n", __func__, dirpath);
720 if (!
device ().is_opened ())
745#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
746 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, mode);
761 if (!
device ().is_opened ())
775#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
791 if (!
device ().is_opened ())
805#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
809 if (!
device ().is_opened ())
825#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
826 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, mode);
841 if (!
device ().is_opened ())
856#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
857 trace::printf (
"file_system::%s(\"%s\", %p)\n", __func__, path, buf);
860 if ((path ==
nullptr) || (buf ==
nullptr))
872 if (!
device ().is_opened ())
887#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
888 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, length);
903 if (!
device ().is_opened ())
918#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
919 trace::printf (
"file_system::%s(\"%s\",\"%s\")\n", __func__, existing,
923 if ((existing ==
nullptr) || (_new ==
nullptr))
929 if ((*existing ==
'\0') || (*_new ==
'\0'))
935 if (!
device ().is_opened ())
950#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
966 if (!
device ().is_opened ())
982#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
986 if ((path ==
nullptr) || (
times ==
nullptr))
998 if (!
device ().is_opened ())
1007 if (
times ==
nullptr)
1011 tmp.actime = time (
nullptr);
1012 tmp.modtime = tmp.actime;
1026#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1030 if (!
device ().is_opened ())
1049#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1050 trace::printf (
"file_system_impl::%s()=%p\n", __func__,
this);
1056#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1057 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)