µ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_lockable< T, L > Class Template Reference

#include <file-system.h>

+ Inheritance diagram for os::posix::file_system_lockable< T, L >:

Public Types

using lockable_type = L
 
using value_type = T
 

Public Member Functions

Constructors & Destructor
template<typename... Args>
 file_system_lockable (const char *name, block_device &device, lockable_type &locker, Args &&... args)
 
virtual ~file_system_lockable () override
 
Public Member Functions
virtual int vmount (const char *path, unsigned int flags, std::va_list args) override
 Mount file system.
 
virtual int umount (int unsigned flags=0) override
 Unmount file system.
 
virtual filevopen (const char *path, int oflag, std::va_list args) override
 
virtual directoryopendir (const char *dirpath) override
 
virtual int mkdir (const char *path, mode_t mode) override
 
virtual int rmdir (const char *path) override
 
virtual void sync (void) override
 
virtual int chmod (const char *path, mode_t mode) override
 
virtual int stat (const char *path, struct stat *buf) override
 
virtual int truncate (const char *path, off_t length) override
 
virtual int rename (const char *existing, const char *_new) override
 
virtual int unlink (const char *path) override
 
virtual int utime (const char *path, const utimbuf *times) override
 
virtual int statvfs (struct statvfs *buf) override
 
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,...)
 
fileopen (const char *path=nullptr, int oflag=0,...)
 
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, typename L>
class os::posix::file_system_lockable< T, L >

Definition at line 640 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.

◆ lockable_type

template<typename T , typename L >
using os::posix::file_system_lockable< T, L >::lockable_type = L

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

◆ value_type

template<typename T , typename L >
using os::posix::file_system_lockable< T, L >::value_type = T

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

Constructor & Destructor Documentation

◆ file_system_lockable()

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

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

1042 : file_system{ impl_instance_, name }, //
1043 impl_instance_{ device, locker, std::forward<Args> (args)... }
1044 {
1045#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1046 trace::printf ("file_system_lockable::%s()=%p\n", __func__, this);
1047#endif
1048 }
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_lockable()

template<typename T , typename L >
os::posix::file_system_lockable< T, L >::~file_system_lockable
overridevirtual

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

1057 {
1058#if defined(OS_TRACE_POSIX_IO_FILE_SYSTEM)
1059 trace::printf ("file_system_lockable::%s() @%p\n", __func__, this);
1060#endif
1061 }

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()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::chmod ( const char *  path,
mode_t  mode 
)
overridevirtual

Reimplemented from os::posix::file_system.

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

1145 {
1146 std::lock_guard<L> lock{ impl_instance_.locker () };
1147
1148 return file_system::chmod (path, mode);
1149 }
virtual int chmod(const char *path, mode_t mode)
port::scheduler::state_t lock(void)

References os::posix::file_system::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
file_system_impl & impl(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 , typename L >
file_system_lockable< T, L >::value_type & os::posix::file_system_lockable< T, L >::impl ( void  ) const

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

1210 {
1211 return static_cast<value_type&> (impl_);
1212 }

◆ mkdir()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::mkdir ( const char *  path,
mode_t  mode 
)
overridevirtual

Reimplemented from os::posix::file_system.

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

1116 {
1117 std::lock_guard<L> lock{ impl_instance_.locker () };
1118
1119 return file_system::mkdir (path, mode);
1120 }
virtual int mkdir(const char *path, mode_t mode)

References os::posix::file_system::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()

template<typename T , typename L >
directory * os::posix::file_system_lockable< T, L >::opendir ( const char *  dirpath)
overridevirtual

Reimplemented from os::posix::file_system.

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

1105 {
1106 std::lock_guard<L> lock{ impl_instance_.locker () };
1107
1108 return file_system::opendir (dirpath);
1109 }
virtual directory * opendir(const char *dirpath)

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

◆ rename()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::rename ( const char *  existing,
const char *  _new 
)
overridevirtual

Reimplemented from os::posix::file_system.

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

1172 {
1173 std::lock_guard<L> lock{ impl_instance_.locker () };
1174
1175 return file_system::rename (existing, _new);
1176 }
virtual int rename(const char *existing, const char *_new)

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

◆ rmdir()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::rmdir ( const char *  path)
overridevirtual

Reimplemented from os::posix::file_system.

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

1125 {
1126 std::lock_guard<L> lock{ impl_instance_.locker () };
1127
1128 return file_system::rmdir (path);
1129 }
virtual int rmdir(const char *path)

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

◆ stat()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::stat ( const char *  path,
struct stat *  buf 
)
overridevirtual

Reimplemented from os::posix::file_system.

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

1154 {
1155 std::lock_guard<L> lock{ impl_instance_.locker () };
1156
1157 return file_system::stat (path, buf);
1158 }
virtual int stat(const char *path, struct stat *buf)

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

◆ statvfs()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::statvfs ( struct statvfs buf)
overridevirtual

Reimplemented from os::posix::file_system.

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

1201 {
1202 std::lock_guard<L> lock{ impl_instance_.locker () };
1203
1204 return file_system::statvfs (buf);
1205 }
virtual int statvfs(struct statvfs *buf)

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

◆ sync()

template<typename T , typename L >
void os::posix::file_system_lockable< T, L >::sync ( void  )
overridevirtual

Reimplemented from os::posix::file_system.

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

1134 {
1135 std::lock_guard<L> lock{ impl_instance_.locker () };
1136
1137 return file_system::sync ();
1138 }
virtual void sync(void)

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

◆ truncate()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::truncate ( const char *  path,
off_t  length 
)
overridevirtual

Reimplemented from os::posix::file_system.

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

1163 {
1164 std::lock_guard<L> lock{ impl_instance_.locker () };
1165
1166 return file_system::truncate (path, length);
1167 }
virtual int truncate(const char *path, off_t length)

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

◆ umount()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::umount ( int unsigned  flags = 0)
overridevirtual
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 from os::posix::file_system.

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

1084 {
1085 std::lock_guard<L> lock{ impl_instance_.locker () };
1086
1087 return file_system::umount (flags);
1088 }
virtual int umount(int unsigned flags=0)
Unmount file system.

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

◆ unlink()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::unlink ( const char *  path)
overridevirtual

Reimplemented from os::posix::file_system.

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

1181 {
1182 std::lock_guard<L> lock{ impl_instance_.locker () };
1183
1184 return file_system::unlink (path);
1185 }
virtual int unlink(const char *path)

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

◆ utime()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::utime ( const char *  path,
const utimbuf *  times 
)
overridevirtual

Reimplemented from os::posix::file_system.

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

1192 {
1193 std::lock_guard<L> lock{ impl_instance_.locker () };
1194
1195 return file_system::utime (path, times);
1196 }
virtual int utime(const char *path, const utimbuf *times)
clock_t times(struct tms *buf)

References times(), and os::posix::file_system::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()

template<typename T , typename L >
int os::posix::file_system_lockable< T, L >::vmount ( const char *  path,
unsigned int  flags,
std::va_list  args 
)
overridevirtual
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 from os::posix::file_system.

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

1070 {
1071 std::lock_guard<L> lock{ impl_instance_.locker () };
1072
1073 return file_system::vmount (path, flags, args);
1074 }

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

◆ vopen()

template<typename T , typename L >
file * os::posix::file_system_lockable< T, L >::vopen ( const char *  path,
int  oflag,
std::va_list  args 
)
overridevirtual

Reimplemented from os::posix::file_system.

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

1096 {
1097 std::lock_guard<L> lock{ impl_instance_.locker () };
1098
1099 return file_system::vopen (path, oflag, args);
1100 }

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


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