39#pragma clang diagnostic ignored "-Wc++98-compat"
54#pragma GCC diagnostic push
56#pragma clang diagnostic ignored "-Wexit-time-destructors"
57#pragma clang diagnostic ignored "-Wglobal-constructors"
60 file_system::mounted_list file_system::mounted_list__;
62#pragma GCC diagnostic pop
64 class file_system* file_system::mounted_root__;
72 mkdir (
const char* path, mode_t mode)
74#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
90 auto adjusted_path = path;
100 return fs->mkdir (adjusted_path, mode);
106#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
122 auto adjusted_path = path;
132 return fs->rmdir (adjusted_path);
138#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
143 for (
auto&& fs : file_system::mounted_list__)
148 if (file_system::mounted_root__ !=
nullptr)
150 file_system::mounted_root__->sync ();
159 chmod (
const char* path, mode_t mode)
161#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
177 const char* adjusted_path = path;
186 return fs->chmod (adjusted_path, mode);
192#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
196 if ((path ==
nullptr) || (buf ==
nullptr))
208 const char* adjusted_path = path;
217 return fs->stat (adjusted_path, buf);
223#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
239 const char* adjusted_path = path;
254 return fs->truncate (adjusted_path, length);
258 rename (
const char* existing,
const char* _new)
260#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
261 trace::printf (
"%s(\"%s\",\"%s\")\n", __func__, existing, _new);
264 if ((existing ==
nullptr) || (_new ==
nullptr))
270 if ((*existing ==
'\0') || (*_new ==
'\0'))
276 auto adjusted_existing = existing;
277 auto adjusted_new = _new;
287 return fs->rename (adjusted_existing, adjusted_new);
293#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
309 auto adjusted_path = path;
318 return fs->unlink (adjusted_path);
324#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
328 if ((path ==
nullptr) || (
times ==
nullptr))
340 auto adjusted_path = path;
349 return fs->utime (adjusted_path,
times);
355#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
359 if ((path ==
nullptr) || (buf ==
nullptr))
371 auto adjusted_path = path;
380 return fs->statvfs (buf);
386#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
390 if (dirpath ==
nullptr)
396 if (*dirpath ==
'\0')
418 auto adjusted_path = dirpath;
432 dir = fs->opendir (adjusted_path);
444#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
456#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
457 trace::printf (
"file_system::%s(\"%s\")=%p\n", __func__, name_,
this);
459 deferred_files_list_.clear ();
460 deferred_directories_list_.clear ();
465#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
466 trace::printf (
"file_system::%s() @%p %s\n", __func__,
this, name_);
477 va_start(args, options);
478 int ret =
vmkfs (options, args);
487#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
488 trace::printf (
"file_system::%s(%u) @%p\n", __func__, options,
this);
491 if (mounted_path_ !=
nullptr)
511 va_start(args, flags);
512 int ret =
vmount (path, flags, args);
522#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
523 trace::printf (
"file_system::%s(\"%s\", %u) @%p\n", __func__,
524 path ? path :
"nullptr", flags,
this);
527 if (mounted_path_ !=
nullptr)
536 for (
auto&& fs : mounted_list__)
539 if (std::strcmp (path, fs.mounted_path_) == 0)
549 char* p =
const_cast<char*
> (path);
552 if (strcmp (
"/", path) == 0)
568 mounted_root__ =
this;
573 mounted_list__.link (*
this);
574 mounted_path_ = path;
588#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
589 trace::printf (
"file_system::%s(%u) @%p\n", __func__, flags,
this);
592 mount_manager_links_.unlink ();
593 mounted_path_ =
nullptr;
595 if (
this == mounted_root__)
597 if (!mounted_list__.empty ())
603 mounted_root__ =
nullptr;
606 if (!
device ().is_opened ())
620 assert(path1 !=
nullptr);
621 assert(*path1 !=
nullptr);
623 for (
auto&& fs : mounted_list__)
625 auto len = std::strlen (fs.mounted_path_);
628 if (std::strncmp (fs.mounted_path_, *path1, len) == 0)
631 *path1 = (*path1 + len - 1);
632 while ((*path1)[1] ==
'/')
634 *path1 = (*path1 + 1);
637 if ((path2 !=
nullptr) && (*path2 !=
nullptr))
639 *path2 = (*path2 + len - 1);
640 while ((*path2)[1] ==
'/')
642 *path2 = (*path2 + 1);
651 if (mounted_root__ !=
nullptr)
653 return mounted_root__;
667 va_start(args, oflag);
677#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
678 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, oflag);
681 if (!
device ().is_opened ())
707#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
708 trace::printf (
"file_system::%s(\"%s\")\n", __func__, dirpath);
711 if (!
device ().is_opened ())
736#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
737 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, mode);
752 if (!
device ().is_opened ())
766#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
782 if (!
device ().is_opened ())
796#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
800 if (!
device ().is_opened ())
816#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
817 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, mode);
832 if (!
device ().is_opened ())
847#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
848 trace::printf (
"file_system::%s(\"%s\", %p)\n", __func__, path, buf);
851 if ((path ==
nullptr) || (buf ==
nullptr))
863 if (!
device ().is_opened ())
878#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
879 trace::printf (
"file_system::%s(\"%s\", %u)\n", __func__, path, length);
894 if (!
device ().is_opened ())
909#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
910 trace::printf (
"file_system::%s(\"%s\",\"%s\")\n", __func__, existing,
914 if ((existing ==
nullptr) || (_new ==
nullptr))
920 if ((*existing ==
'\0') || (*_new ==
'\0'))
926 if (!
device ().is_opened ())
941#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
957 if (!
device ().is_opened ())
973#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
977 if ((path ==
nullptr) || (
times ==
nullptr))
989 if (!
device ().is_opened ())
998 if (
times ==
nullptr)
1002 tmp.actime = time (
nullptr);
1003 tmp.modtime = tmp.actime;
1017#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1021 if (!
device ().is_opened ())
1040#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1041 trace::printf (
"file_system_impl::%s()=%p\n", __func__,
this);
1047#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1048 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 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_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
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 utime(const char *path, const struct utimbuf *times)
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)
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 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)