µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::posix::file_system_implementable< T > Class Template Reference

#include <file-system.h>

+ Inheritance diagram for os::posix::file_system_implementable< T >:

Public Types

using value_type = T
 

Public Member Functions

Constructors & Destructor
template<typename... Args>
 file_system_implementable (const char *name, block_device &device, Args &&... args)
 
virtual ~file_system_implementable () override
 
Public Member Functions
value_typeimpl (void) const
 

Public Member Functions

using deferred_files_list_t = utils::intrusive_list< file, utils::double_list_links, &file::deferred_links_ >
 
using deferred_directories_list_t = utils::intrusive_list< directory, utils::double_list_links, &directory::deferred_links_ >
 
int mkfs (int options,...)
 
virtual int vmkfs (int options, std::va_list args)
 
int mount (const char *path=nullptr, unsigned int flags=0,...)
 
virtual int vmount (const char *path, unsigned int flags, std::va_list args)
 Mount file system.
 
virtual int umount (int unsigned flags=0)
 Unmount file system.
 
fileopen (const char *path=nullptr, int oflag=0,...)
 
virtual filevopen (const char *path, int oflag, std::va_list args)
 
virtual directoryopendir (const char *dirpath)
 
virtual int mkdir (const char *path, mode_t mode)
 
virtual int rmdir (const char *path)
 
virtual void sync (void)
 
virtual int chmod (const char *path, mode_t mode)
 
virtual int stat (const char *path, struct stat *buf)
 
virtual int truncate (const char *path, off_t length)
 
virtual int rename (const char *existing, const char *_new)
 
virtual int unlink (const char *path)
 
virtual int utime (const char *path, const utimbuf *times)
 
virtual int statvfs (struct statvfs *buf)
 
const char * mounted_path (void)
 
const char * name (void) const
 
void add_deferred_file (file *fil)
 
void add_deferred_directory (directory *dir)
 
deferred_files_list_tdeferred_files_list (void)
 
deferred_directories_list_tdeferred_directories_list (void)
 
template<typename T >
T * allocate_file (void)
 
template<typename T , typename L >
T * allocate_file (L &locker)
 
template<typename T >
T * allocate_directory (void)
 
template<typename T , typename L >
T * allocate_directory (L &locker)
 
template<typename T >
void deallocate_files (void)
 
template<typename T >
void deallocate_directories (void)
 
block_devicedevice (void) const
 
static file_systemidentify_mounted (const char **path1, const char **path2=nullptr)
 

Detailed Description

template<typename T>
class os::posix::file_system_implementable< T >

Definition at line 558 of file file-system.h.

Member Typedef Documentation

◆ deferred_directories_list_t

Definition at line 312 of file file-system.h.

◆ deferred_files_list_t

Definition at line 308 of file file-system.h.

◆ value_type

template<typename T >
using os::posix::file_system_implementable< T >::value_type = T

Definition at line 563 of file file-system.h.

Constructor & Destructor Documentation

◆ file_system_implementable()

template<typename T >
template<typename... Args>
os::posix::file_system_implementable< T >::file_system_implementable ( const char *  name,
block_device device,
Args &&...  args 
)

Definition at line 1001 of file file-system.h.

1003 : file_system{ impl_instance_, name }, //
1004 impl_instance_{ device, std::forward<Args> (args)... }
1005 {
1006#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1007 trace::printf ("file_system_implementable::%s(\"%s\")=@%p\n", __func__,
1008 name_, this);
1009#endif
1010 }
file_system(file_system_impl &impl, const char *name)
block_device & device(void) const
const char * name(void) const
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References os::trace::printf().

◆ ~file_system_implementable()

template<typename T >
os::posix::file_system_implementable< T >::~file_system_implementable
overridevirtual

Definition at line 1018 of file file-system.h.

1019 {
1020#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1021 trace::printf ("file_system_implementable::%s() @%p %s\n", __func__,
1022 this, name_);
1023#endif
1024 }

References os::trace::printf().

Member Function Documentation

◆ add_deferred_directory()

void os::posix::file_system::add_deferred_directory ( directory dir)
inlineinherited

Definition at line 828 of file file-system.h.

829 {
830 deferred_directories_list_.link (*dir);
831 }

Referenced by os::posix::directory::close().

◆ add_deferred_file()

void os::posix::file_system::add_deferred_file ( file fil)
inlineinherited

Definition at line 822 of file file-system.h.

823 {
824 deferred_files_list_.link (*fil);
825 }

Referenced by os::posix::file::close().

◆ allocate_directory() [1/2]

template<typename T , typename L >
T * os::posix::file_system::allocate_directory ( L &  locker)
inherited

Definition at line 946 of file file-system.h.

947 {
948 using directory_type = T;
949
950 directory_type* dir;
951
952 if (deferred_directories_list_.empty ())
953 {
954 dir = new directory_type (*this, locker);
955 }
956 else
957 {
958 dir = static_cast<directory_type*> (
959 deferred_directories_list_.unlink_head ());
960
961 // Call the constructor before reusing the object,
962 dir->~directory_type ();
963
964 // Placement new, run only the constructor.
965 new (dir) directory_type (*this, locker);
966
967 deallocate_directories<directory_type> ();
968 }
969 return dir;
970 }

◆ allocate_directory() [2/2]

template<typename T >
T * os::posix::file_system::allocate_directory ( void  )
inherited

Definition at line 918 of file file-system.h.

919 {
920 using directory_type = T;
921
922 directory_type* dir;
923
924 if (deferred_directories_list_.empty ())
925 {
926 dir = new directory_type (*this);
927 }
928 else
929 {
930 dir = static_cast<directory_type*> (
931 deferred_directories_list_.unlink_head ());
932
933 // Call the constructor before reusing the object,
934 dir->~directory_type ();
935
936 // Placement new, run only the constructor.
937 new (dir) directory_type (*this);
938
939 deallocate_directories<directory_type> ();
940 }
941 return dir;
942 }

◆ allocate_file() [1/2]

template<typename T , typename L >
T * os::posix::file_system::allocate_file ( L &  locker)
inherited

Definition at line 874 of file file-system.h.

875 {
876 using file_type = T;
877
878 file_type* fil;
879
880 if (deferred_files_list_.empty ())
881 {
882 fil = new file_type (*this, locker);
883 }
884 else
885 {
886 fil = static_cast<file_type*> (deferred_files_list_.unlink_head ());
887
888 // Call the constructor before reusing the object,
889 fil->~file_type ();
890
891 // Placement new, run only the constructor.
892 new (fil) file_type (*this, locker);
893
894 deallocate_files<file_type> ();
895 }
896 return fil;
897 }

◆ allocate_file() [2/2]

template<typename T >
T * os::posix::file_system::allocate_file ( void  )
inherited

Definition at line 847 of file file-system.h.

848 {
849 using file_type = T;
850
851 file_type* fil;
852
853 if (deferred_files_list_.empty ())
854 {
855 fil = new file_type (*this);
856 }
857 else
858 {
859 fil = static_cast<file_type*> (deferred_files_list_.unlink_head ());
860
861 // Call the constructor before reusing the object,
862 fil->~file_type ();
863
864 // Placement new, run only the constructor.
865 new (fil) file_type (*this);
866
867 deallocate_files<file_type> ();
868 }
869 return fil;
870 }

◆ chmod()

int os::posix::file_system::chmod ( const char *  path,
mode_t  mode 
)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 828 of file file-system.cpp.

829 {
830#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
831 trace::printf ("file_system::%s(\"%s\", %u)\n", __func__, path, mode);
832#endif
833
834 if (path == nullptr)
835 {
836 errno = EFAULT;
837 return -1;
838 }
839
840 if (*path == '\0')
841 {
842 errno = ENOENT;
843 return -1;
844 }
845
846 if (!device ().is_opened ())
847 {
848 errno = EBADF; // Not opened.
849 return -1;
850 }
851
852 errno = 0;
853
854 // Execute the implementation specific code.
855 return impl ().do_chmod (path, mode);
856 }
virtual int do_chmod(const char *path, mode_t mode)=0
file_system_impl & impl(void) const

References os::posix::file_system_impl::do_chmod(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::chmod().

◆ deallocate_directories()

template<typename T >
void os::posix::file_system::deallocate_directories ( void  )
inherited

Definition at line 974 of file file-system.h.

975 {
976 using directory_type = T;
977
978 // Deallocate all remaining elements in the list.
979 while (!deferred_directories_list_.empty ())
980 {
981 directory_type* d = static_cast<directory_type*> (
982 deferred_directories_list_.unlink_head ());
983
984 // Call the destructor and the deallocator.
985 delete d;
986 }
987 }

◆ deallocate_files()

template<typename T >
void os::posix::file_system::deallocate_files ( void  )
inherited

Definition at line 901 of file file-system.h.

902 {
903 using file_type = T;
904
905 // Deallocate all remaining elements in the list.
906 while (!deferred_files_list_.empty ())
907 {
908 file_type* f
909 = static_cast<file_type*> (deferred_files_list_.unlink_head ());
910
911 // Call the destructor and the deallocator.
912 delete f;
913 }
914 }

◆ deferred_directories_list()

file_system::deferred_directories_list_t & os::posix::file_system::deferred_directories_list ( void  )
inlineinherited

Definition at line 840 of file file-system.h.

841 {
842 return deferred_directories_list_;
843 }

◆ deferred_files_list()

file_system::deferred_files_list_t & os::posix::file_system::deferred_files_list ( void  )
inlineinherited

Definition at line 834 of file file-system.h.

835 {
836 return deferred_files_list_;
837 }

◆ device()

block_device & os::posix::file_system::device ( void  ) const
inlineinherited

Definition at line 816 of file file-system.h.

817 {
818 return impl ().device ();
819 }
block_device & device(void) const

References os::posix::file_system_impl::device(), and os::posix::file_system::impl().

◆ identify_mounted()

file_system * os::posix::file_system::identify_mounted ( const char **  path1,
const char **  path2 = nullptr 
)
staticinherited

Definition at line 621 of file file-system.cpp.

622 {
623 assert (path1 != nullptr);
624 assert (*path1 != nullptr);
625
626#pragma GCC diagnostic push
627#if defined(__clang__)
628#elif defined(__GNUC__)
629#pragma GCC diagnostic ignored "-Waggregate-return"
630#endif
631 for (auto&& fs : mounted_list__)
632#pragma GCC diagnostic pop
633 {
634 auto len = std::strlen (fs.mounted_path_);
635
636 // Check if path1 starts with the mounted path.
637 if (std::strncmp (fs.mounted_path_, *path1, len) == 0)
638 {
639#pragma GCC diagnostic push
640#if defined(__clang__)
641#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
642#endif
643 // If so, adjust paths to skip over prefix, but keep '/'.
644 *path1 = (*path1 + len - 1);
645 while ((*path1)[1] == '/')
646 {
647 *path1 = (*path1 + 1);
648 }
649
650 if ((path2 != nullptr) && (*path2 != nullptr))
651 {
652 *path2 = (*path2 + len - 1);
653 while ((*path2)[1] == '/')
654 {
655 *path2 = (*path2 + 1);
656 }
657 }
658#pragma GCC diagnostic pop
659
660 return &fs;
661 }
662 }
663
664 // If root file system defined, return it.
665 if (mounted_root__ != nullptr)
666 {
667 return mounted_root__;
668 }
669
670 // Not found.
671 return nullptr;
672 }

Referenced by os::posix::chmod(), os::posix::mkdir(), os::posix::opendir(), os::posix::rename(), os::posix::rmdir(), os::posix::stat(), os::posix::statvfs(), os::posix::truncate(), os::posix::unlink(), os::posix::utime(), and os::posix::vopen().

◆ impl()

template<typename T >
file_system_implementable< T >::value_type & os::posix::file_system_implementable< T >::impl ( void  ) const

Definition at line 1029 of file file-system.h.

1030 {
1031 return static_cast<value_type&> (impl_);
1032 }

◆ mkdir()

int os::posix::file_system::mkdir ( const char *  path,
mode_t  mode 
)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 748 of file file-system.cpp.

749 {
750#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
751 trace::printf ("file_system::%s(\"%s\", %u)\n", __func__, path, mode);
752#endif
753
754 if (path == nullptr)
755 {
756 errno = EFAULT;
757 return -1;
758 }
759
760 if (*path == '\0')
761 {
762 errno = ENOENT;
763 return -1;
764 }
765
766 if (!device ().is_opened ())
767 {
768 errno = EBADF; // Not opened.
769 return -1;
770 }
771
772 errno = 0;
773
774 return impl ().do_mkdir (path, mode);
775 }
virtual int do_mkdir(const char *path, mode_t mode)=0

References os::posix::file_system_impl::do_mkdir(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::mkdir().

◆ mkfs()

int os::posix::file_system::mkfs ( int  options,
  ... 
)
inherited

Definition at line 470 of file file-system.cpp.

471 {
472 // Forward to the variadic version of the function.
473 std::va_list args;
474 va_start (args, options);
475 int ret = vmkfs (options, args);
476 va_end (args);
477
478 return ret;
479 }
virtual int vmkfs(int options, std::va_list args)

References os::posix::file_system::vmkfs().

◆ mount()

int os::posix::file_system::mount ( const char *  path = nullptr,
unsigned int  flags = 0,
  ... 
)
inherited

Definition at line 504 of file file-system.cpp.

505 {
506 // Forward to the variadic version of the function.
507 std::va_list args;
508 va_start (args, flags);
509 int ret = vmount (path, flags, args);
510 va_end (args);
511
512 return ret;
513 }
virtual int vmount(const char *path, unsigned int flags, std::va_list args)
Mount file system.

References os::posix::file_system::vmount().

◆ mounted_path()

const char * os::posix::file_system::mounted_path ( void  )
inherited

◆ name()

const char * os::posix::file_system::name ( void  ) const
inlineinherited

Definition at line 796 of file file-system.h.

797 {
798 return name_;
799 }

◆ open()

file * os::posix::file_system::open ( const char *  path = nullptr,
int  oflag = 0,
  ... 
)
inherited

Definition at line 677 of file file-system.cpp.

678 {
679 // Forward to the variadic version of the function.
680 std::va_list args;
681 va_start (args, oflag);
682 file* ret = vopen (path, oflag, args);
683 va_end (args);
684
685 return ret;
686 }
virtual file * vopen(const char *path, int oflag, std::va_list args)

References os::posix::file_system::vopen().

◆ opendir()

directory * os::posix::file_system::opendir ( const char *  dirpath)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 719 of file file-system.cpp.

720 {
721#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
722 trace::printf ("file_system::%s(\"%s\")\n", __func__, dirpath);
723#endif
724
725 if (!device ().is_opened ())
726 {
727 errno = EBADF; // Not opened.
728 return nullptr;
729 }
730
731 errno = 0;
732
733 // Execute the dir specific implementation code.
734 // Allocation is done by the implementation, where
735 // the size is known.
736 directory* dir = impl ().do_opendir (*this, dirpath);
737 if (dir == nullptr)
738 {
739 return nullptr;
740 }
741
742 return dir;
743 }
virtual directory * do_opendir(file_system &fs, const char *dirname)=0

References os::posix::file_system_impl::do_opendir(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::opendir().

◆ rename()

int os::posix::file_system::rename ( const char *  existing,
const char *  _new 
)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 921 of file file-system.cpp.

922 {
923#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
924 trace::printf ("file_system::%s(\"%s\",\"%s\")\n", __func__, existing,
925 _new);
926#endif
927
928 if ((existing == nullptr) || (_new == nullptr))
929 {
930 errno = EFAULT;
931 return -1;
932 }
933
934 if ((*existing == '\0') || (*_new == '\0'))
935 {
936 errno = ENOENT;
937 return -1;
938 }
939
940 if (!device ().is_opened ())
941 {
942 errno = EBADF; // Not opened.
943 return -1;
944 }
945
946 errno = 0;
947
948 // Execute the implementation specific code.
949 return impl ().do_rename (existing, _new);
950 }
virtual int do_rename(const char *existing, const char *_new)=0

References os::posix::file_system_impl::do_rename(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::rename().

◆ rmdir()

int os::posix::file_system::rmdir ( const char *  path)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 778 of file file-system.cpp.

779 {
780#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
781 trace::printf ("file_system::%s(\"%s\")\n", __func__, path);
782#endif
783
784 if (path == nullptr)
785 {
786 errno = EFAULT;
787 return -1;
788 }
789
790 if (*path == '\0')
791 {
792 errno = ENOENT;
793 return -1;
794 }
795
796 if (!device ().is_opened ())
797 {
798 errno = EBADF; // Not opened.
799 return -1;
800 }
801
802 errno = 0;
803
804 return impl ().do_rmdir (path);
805 }
virtual int do_rmdir(const char *path)=0

References os::posix::file_system_impl::do_rmdir(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::rmdir().

◆ stat()

int os::posix::file_system::stat ( const char *  path,
struct stat *  buf 
)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 859 of file file-system.cpp.

860 {
861#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
862 trace::printf ("file_system::%s(\"%s\", %p)\n", __func__, path, buf);
863#endif
864
865 if ((path == nullptr) || (buf == nullptr))
866 {
867 errno = EFAULT;
868 return -1;
869 }
870
871 if (*path == '\0')
872 {
873 errno = ENOENT;
874 return -1;
875 }
876
877 if (!device ().is_opened ())
878 {
879 errno = EBADF; // Not opened.
880 return -1;
881 }
882
883 errno = 0;
884
885 // Execute the implementation specific code.
886 return impl ().do_stat (path, buf);
887 }
virtual int do_stat(const char *path, struct stat *buf)=0

References os::posix::file_system_impl::do_stat(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::stat().

◆ statvfs()

int os::posix::file_system::statvfs ( struct statvfs buf)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 1029 of file file-system.cpp.

1030 {
1031#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1032 trace::printf ("file_system::%s(%p)\n", __func__, buf);
1033#endif
1034
1035 if (!device ().is_opened ())
1036 {
1037 errno = EBADF; // Not opened.
1038 return -1;
1039 }
1040
1041 return impl ().do_statvfs (buf);
1042 }
virtual int do_statvfs(struct statvfs *buf)=0

References os::posix::file_system_impl::do_statvfs(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file::fstatvfs(), and os::posix::file_system_lockable< T, L >::statvfs().

◆ sync()

void os::posix::file_system::sync ( void  )
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 808 of file file-system.cpp.

809 {
810#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
811 trace::printf ("file_system::%s() @%p\n", __func__, this);
812#endif
813
814 if (!device ().is_opened ())
815 {
816 errno = EBADF; // Not opened.
817 return;
818 }
819
820 errno = 0;
821
822 impl ().do_sync ();
823 }
virtual void do_sync(void)=0

References os::posix::file_system_impl::do_sync(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::sync().

◆ truncate()

int os::posix::file_system::truncate ( const char *  path,
off_t  length 
)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 890 of file file-system.cpp.

891 {
892#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
893 trace::printf ("file_system::%s(\"%s\", %u)\n", __func__, path, length);
894#endif
895
896 if (path == nullptr)
897 {
898 errno = EFAULT;
899 return -1;
900 }
901
902 if (*path == '\0')
903 {
904 errno = ENOENT;
905 return -1;
906 }
907
908 if (!device ().is_opened ())
909 {
910 errno = EBADF; // Not opened.
911 return -1;
912 }
913
914 errno = 0;
915
916 // Execute the implementation specific code.
917 return impl ().do_truncate (path, length);
918 }
virtual int do_truncate(const char *path, off_t length)=0

References os::posix::file_system_impl::do_truncate(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::truncate().

◆ umount()

int os::posix::file_system::umount ( int unsigned  flags = 0)
virtualinherited
Parameters
flagsFile system specific flags.
Return values
0if successful,
-1otherwise and the variable errno is set to indicate the error.

The root file system must be unmounted last, it cannot be unmounted if other mount points exists.

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 589 of file file-system.cpp.

590 {
591#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
592 trace::printf ("file_system::%s(%u) @%p\n", __func__, flags, this);
593#endif
594
595 mount_manager_links_.unlink ();
596 mounted_path_ = nullptr;
597
598 if (this == mounted_root__)
599 {
600 if (!mounted_list__.empty ())
601 {
602 errno = EBUSY;
603 return -1;
604 }
605
606 mounted_root__ = nullptr;
607 }
608
609 if (!device ().is_opened ())
610 {
611 errno = EBADF; // Not opened.
612 return -1;
613 }
614
615 impl ().do_sync ();
616 int ret = impl ().do_umount (flags);
617 return ret;
618 }
virtual int do_umount(unsigned int flags)=0

References os::posix::file_system_impl::do_sync(), os::posix::file_system_impl::do_umount(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::umount().

◆ unlink()

int os::posix::file_system::unlink ( const char *  path)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 953 of file file-system.cpp.

954 {
955#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
956 trace::printf ("file_system::%s(\"%s\")\n", __func__, path);
957#endif
958
959 if (path == nullptr)
960 {
961 errno = EFAULT;
962 return -1;
963 }
964
965 if (*path == '\0')
966 {
967 errno = ENOENT;
968 return -1;
969 }
970
971 if (!device ().is_opened ())
972 {
973 errno = EBADF; // Not opened.
974 return -1;
975 }
976
977 errno = 0;
978
979 // Execute the implementation specific code.
980 return impl ().do_unlink (path);
981 }
virtual int do_unlink(const char *path)=0

References os::posix::file_system_impl::do_unlink(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system_lockable< T, L >::unlink().

◆ utime()

int os::posix::file_system::utime ( const char *  path,
const utimbuf *  times 
)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 985 of file file-system.cpp.

986 {
987#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
988 trace::printf ("file_system::%s(\"%s\", %p)\n", __func__, path, times);
989#endif
990
991 if ((path == nullptr) || (times == nullptr))
992 {
993 errno = EFAULT;
994 return -1;
995 }
996
997 if (*path == '\0')
998 {
999 errno = ENOENT;
1000 return -1;
1001 }
1002
1003 if (!device ().is_opened ())
1004 {
1005 errno = EBADF; // Not opened.
1006 return -1;
1007 }
1008
1009 errno = 0;
1010
1011 /* struct */ utimbuf tmp;
1012 if (times == nullptr)
1013 {
1014 // If times is a null pointer, the access and modification times
1015 // of the file shall be set to the current time.
1016 tmp.actime = time (nullptr);
1017 tmp.modtime = tmp.actime;
1018 return impl ().do_utime (path, &tmp);
1019 }
1020 else
1021 {
1022 // Execute the implementation specific code.
1023 return impl ().do_utime (path, times);
1024 }
1025 }
virtual int do_utime(const char *path, const utimbuf *times)=0
clock_t times(struct tms *buf)

References os::posix::file_system_impl::do_utime(), os::posix::file_system::impl(), os::trace::printf(), and times().

Referenced by os::posix::file_system_lockable< T, L >::utime().

◆ vmkfs()

int os::posix::file_system::vmkfs ( int  options,
std::va_list  args 
)
virtualinherited

Definition at line 482 of file file-system.cpp.

483 {
484#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
485 trace::printf ("file_system::%s(%u) @%p\n", __func__, options, this);
486#endif
487
488 if (mounted_path_ != nullptr)
489 {
490 // File system already mounted.
491 errno = EBUSY;
492 return -1;
493 }
494
495 errno = 0;
496
497 int ret;
498 ret = impl ().do_vmkfs (options, args);
499
500 return ret;
501 }
virtual int do_vmkfs(int options, std::va_list args)=0

References os::posix::file_system_impl::do_vmkfs(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system::mkfs().

◆ vmount()

int os::posix::file_system::vmount ( const char *  path,
unsigned int  flags,
std::va_list  args 
)
virtualinherited
Parameters
pathPath, terminated in /. If / or nullptr, the file system is mounted as root, i.e. the default if no other mount point matches.
flagsFile system specific flags.
argsOptional arguments.
Return values
0if successful,
-1otherwise and the variable errno is set to indicate the error.

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 516 of file file-system.cpp.

518 {
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);
522#endif
523
524 if (mounted_path_ != nullptr)
525 {
526 // File system already mounted.
527 errno = EBUSY;
528 return -1;
529 }
530
531 if (path != nullptr)
532 {
533#pragma GCC diagnostic push
534#if defined(__clang__)
535#elif defined(__GNUC__)
536#pragma GCC diagnostic ignored "-Waggregate-return"
537#endif
538 for (auto&& fs : mounted_list__)
539#pragma GCC diagnostic pop
540 {
541 // Validate the device name by checking duplicates.
542 if (std::strcmp (path, fs.mounted_path_) == 0)
543 {
544 trace::printf ("Path \"%s\" already mounted.", path);
545
546 errno = EBUSY;
547 return -1;
548 }
549 }
550 }
551
552 char* p = const_cast<char*> (path);
553 if (p != nullptr)
554 {
555 if (strcmp ("/", path) == 0)
556 {
557 p = nullptr;
558 }
559 }
560
561 errno = 0;
562
563 int ret = impl ().do_vmount (flags, args);
564 if (ret < 0)
565 {
566 return -1;
567 }
568
569 if (p == nullptr)
570 {
571 mounted_root__ = this;
572 mounted_path_ = "/";
573 }
574 else
575 {
576 mounted_list__.link (*this);
577 mounted_path_ = path;
578 }
579
580 return 0;
581 }
virtual int do_vmount(unsigned int flags, std::va_list args)=0

References os::posix::file_system_impl::do_vmount(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system::mount(), and os::posix::file_system_lockable< T, L >::vmount().

◆ vopen()

file * os::posix::file_system::vopen ( const char *  path,
int  oflag,
std::va_list  args 
)
virtualinherited

Reimplemented in os::posix::file_system_lockable< T, L >.

Definition at line 689 of file file-system.cpp.

690 {
691#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
692 trace::printf ("file_system::%s(\"%s\", %u)\n", __func__, path, oflag);
693#endif
694
695 if (!device ().is_opened ())
696 {
697 errno = EBADF; // Not opened.
698 return nullptr;
699 }
700
701 errno = 0;
702
703 // Execute the file specific implementation code.
704 // Allocation is done by the implementation, where
705 // the size is known.
706 file* fil = impl ().do_vopen (*this, path, oflag, args);
707 if (fil == nullptr)
708 {
709 return nullptr;
710 }
711
712 // If successful, allocate a file descriptor.
713 fil->alloc_file_descriptor ();
714
715 return fil;
716 }
virtual file * do_vopen(file_system &fs, const char *path, int oflag, std::va_list args)=0
io * alloc_file_descriptor(void)
Definition io.cpp:189

References os::posix::io::alloc_file_descriptor(), os::posix::file_system_impl::do_vopen(), os::posix::file_system::impl(), and os::trace::printf().

Referenced by os::posix::file_system::open(), and os::posix::file_system_lockable< T, L >::vopen().


The documentation for this class was generated from the following file: