diff options
author | Niall Douglas <s_github@nedprod.com> | 2022-10-12 18:57:06 +0300 |
---|---|---|
committer | Niall Douglas <s_github@nedprod.com> | 2022-10-12 18:57:06 +0300 |
commit | 82ea3ddb718d5a8f9633a7ee786d2a4961ade4f3 (patch) | |
tree | 9d509e8bda6c0965e7a67e780556dfa4ce7e6916 | |
parent | 2eec8aaae24305c6fbf4a05df61339b22b5c80e7 (diff) |
-rw-r--r-- | include/llfio/revision.hpp | 6 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/path_discovery.ipp | 17 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/posix/statfs.ipp | 9 | ||||
-rw-r--r-- | include/llfio/v2.0/detail/impl/windows/statfs.ipp | 6 | ||||
-rw-r--r-- | include/llfio/v2.0/path_discovery.hpp | 6 | ||||
-rw-r--r-- | include/llfio/v2.0/statfs.hpp | 35 |
6 files changed, 58 insertions, 21 deletions
diff --git a/include/llfio/revision.hpp b/include/llfio/revision.hpp index f7490426..2d7bdbba 100644 --- a/include/llfio/revision.hpp +++ b/include/llfio/revision.hpp @@ -1,4 +1,4 @@ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define LLFIO_PREVIOUS_COMMIT_REF 85eb69464878d4b36bacb337ec665176aea8fe69 -#define LLFIO_PREVIOUS_COMMIT_DATE "2022-09-15 14:04:57 +00:00" -#define LLFIO_PREVIOUS_COMMIT_UNIQUE 85eb6946 +#define LLFIO_PREVIOUS_COMMIT_REF 2eec8aaae24305c6fbf4a05df61339b22b5c80e7 +#define LLFIO_PREVIOUS_COMMIT_DATE "2022-10-12 15:38:46 +00:00" +#define LLFIO_PREVIOUS_COMMIT_UNIQUE 2eec8aaa diff --git a/include/llfio/v2.0/detail/impl/path_discovery.ipp b/include/llfio/v2.0/detail/impl/path_discovery.ipp index 27f59d17..c4cc8020 100644 --- a/include/llfio/v2.0/detail/impl/path_discovery.ipp +++ b/include/llfio/v2.0/detail/impl/path_discovery.ipp @@ -49,6 +49,7 @@ namespace path_discovery filesystem::path path; size_t priority{0}; std::string fstypename; + bool is_networked{false}; directory_handle h; // not retained after verification explicit _discovered_path(filesystem::path _path) : path(std::move(_path)) @@ -57,6 +58,7 @@ namespace path_discovery }; std::vector<_discovered_path> _all; directory_handle storage_backed, memory_backed; + bool storage_backed_is_networked{false}, memory_backed_is_networked{false}; }; _store &path_store() { @@ -202,6 +204,7 @@ namespace path_discovery if(statfsres) { ps._all[n].fstypename = std::move(statfs.f_fstypename); + ps._all[n].is_networked = statfs.f_flags.networked; } else { @@ -242,10 +245,12 @@ namespace path_discovery if(!ps.storage_backed.is_valid() && std::regex_match(ps._all[n].fstypename, storage_backed_regex_)) { ps.storage_backed = std::move(ps._all[n].h); + ps.storage_backed_is_networked = ps._all[n].is_networked; } if(!ps.memory_backed.is_valid() && std::regex_match(ps._all[n].fstypename, memory_backed_regex_)) { ps.memory_backed = std::move(ps._all[n].h); + ps.memory_backed_is_networked = ps._all[n].is_networked; } ps.all[n].path = ps._all[n].path; (void) ps._all[n].h.close(); @@ -286,12 +291,24 @@ namespace path_discovery auto &ps = detail::path_store(); return ps.storage_backed; } + bool storage_backed_temporary_files_directory_is_networked() noexcept + { + (void) verified_temporary_directories(); + auto &ps = detail::path_store(); + return ps.storage_backed_is_networked; + } const path_handle &memory_backed_temporary_files_directory() noexcept { (void) verified_temporary_directories(); auto &ps = detail::path_store(); return ps.memory_backed; } + bool memory_backed_temporary_files_directory_is_networked() noexcept + { + (void) verified_temporary_directories(); + auto &ps = detail::path_store(); + return ps.memory_backed_is_networked; + } } // namespace path_discovery LLFIO_V2_NAMESPACE_END diff --git a/include/llfio/v2.0/detail/impl/posix/statfs.ipp b/include/llfio/v2.0/detail/impl/posix/statfs.ipp index d8a00c8e..cbac110a 100644 --- a/include/llfio/v2.0/detail/impl/posix/statfs.ipp +++ b/include/llfio/v2.0/detail/impl/posix/statfs.ipp @@ -23,10 +23,12 @@ Distributed under the Boost Software License, Version 1.0. */ #include "../../../handle.hpp" +#include "../../../path_discovery.hpp" #include "../../../statfs.hpp" #include <chrono> #include <mutex> +#include <regex> #include <vector> #include <sys/mount.h> @@ -207,6 +209,8 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<size_t> statfs_t::fill(const handle &h, s if(!!(wanted & want::fstypename)) { f_fstypename = mountentries.front().first.mnt_type; + static const std::regex regex(path_discovery::network_backed_regex, std::regex::icase); + f_flags.networked = !!std::regex_match(f_fstypename, regex); ++ret; } if(!!(wanted & want::mntfromname)) @@ -306,6 +310,8 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<size_t> statfs_t::fill(const handle &h, s if(!!(wanted & want::fstypename)) { f_fstypename = s.f_fstypename; + static const std::regex regex(path_discovery::network_backed_regex, std::regex::icase); + f_flags.networked = !!std::regex_match(f_fstypename, regex); ++ret; } if(!!(wanted & want::mntfromname)) @@ -424,7 +430,8 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<std::pair<uint32_t, float>> statfs_t::_fi Field 9 is i/o's currently in progress. Field 10 is milliseconds spent doing i/o (cumulative). */ - auto match_line = [&](string_view sv) { + auto match_line = [&](string_view sv) + { int major = 0, minor = 0; sscanf(sv.data(), "%d %d", &major, &minor); // printf("Does %d,%d match %d,%d?\n", major, minor, major(s.st_dev), minor(s.st_dev)); diff --git a/include/llfio/v2.0/detail/impl/windows/statfs.ipp b/include/llfio/v2.0/detail/impl/windows/statfs.ipp index a712433b..f4a5e5b5 100644 --- a/include/llfio/v2.0/detail/impl/windows/statfs.ipp +++ b/include/llfio/v2.0/detail/impl/windows/statfs.ipp @@ -24,6 +24,10 @@ Distributed under the Boost Software License, Version 1.0. #include "../../../handle.hpp" #include "../../../statfs.hpp" +#include "../../../path_discovery.hpp" + +#include <regex> + #include "import.hpp" LLFIO_V2_NAMESPACE_BEGIN @@ -72,6 +76,8 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<size_t> statfs_t::fill(const handle &h, s { f_fstypename[n] = static_cast<char>(ffai->FileSystemName[n]); } + static const std::regex regex(path_discovery::network_backed_regex, std::regex::icase); + f_flags.networked = !!std::regex_match(f_fstypename, regex); ++ret; } } diff --git a/include/llfio/v2.0/path_discovery.hpp b/include/llfio/v2.0/path_discovery.hpp index 5e0666dd..da3fae27 100644 --- a/include/llfio/v2.0/path_discovery.hpp +++ b/include/llfio/v2.0/path_discovery.hpp @@ -129,6 +129,8 @@ namespace path_discovery "btrfs|cifs|exfat|ext[2-4]|f2fs|hfs|apfs|jfs|lxfs|nfs[1-9]?|lustre|nilf2|ufs|vfat|xfs|zfs|msdosfs|newnfs|ntfs|smbfs|unionfs|fat|fat32|overlay2?"; //! \brief The default regex used to determine what temporary directories are backed by memory not storage. static constexpr const char memory_backed_regex[] = "tmpfs|ramfs"; + //! \brief The default regex used to determine whether a temporary directory resides on a networked filing system. + static constexpr const char network_backed_regex[] = "cifs|nfs[1-9]?|lustre|smbfs"; /*! \brief Returns a subset of `all_temporary_directories()` each of which has been tested to be writable by the current process. No testing is done of available writable space. @@ -158,6 +160,8 @@ namespace path_discovery The handle is created during `verified_temporary_directories()` and is statically cached thereafter. */ LLFIO_HEADERS_ONLY_FUNC_SPEC const path_handle &storage_backed_temporary_files_directory() noexcept; + //! \brief True if the storage backed temporary files directory is on a networked file system + LLFIO_HEADERS_ONLY_FUNC_SPEC bool storage_backed_temporary_files_directory_is_networked() noexcept; /*! \brief Returns a reference to an open handle to a verified temporary directory where files created are stored in memory/paging file, and thus access may be a lot quicker, but stronger limits on @@ -173,6 +177,8 @@ namespace path_discovery strongly consider using a non-file-backed `section_handle` as this is more portable. */ LLFIO_HEADERS_ONLY_FUNC_SPEC const path_handle &memory_backed_temporary_files_directory() noexcept; + //! \brief True if the memory backed temporary files directory is on a networked file system + LLFIO_HEADERS_ONLY_FUNC_SPEC bool memory_backed_temporary_files_directory_is_networked() noexcept; /*! \brief Returns a reference to an open handle to a verified temporary directory where named pipes may be created and found. diff --git a/include/llfio/v2.0/statfs.hpp b/include/llfio/v2.0/statfs.hpp index c8af2fde..e7452ae7 100644 --- a/include/llfio/v2.0/statfs.hpp +++ b/include/llfio/v2.0/statfs.hpp @@ -77,23 +77,24 @@ struct LLFIO_DECL statfs_t static constexpr float _allbits1_float = detail::constexpr_float_allbits_set_nan(); struct f_flags_t { - uint32_t rdonly : 1; //!< Filing system is read only (Windows, POSIX) - uint32_t noexec : 1; //!< Filing system cannot execute programs (POSIX) - uint32_t nosuid : 1; //!< Filing system cannot superuser (POSIX) - uint32_t acls : 1; //!< Filing system provides ACLs (Windows, POSIX) - uint32_t xattr : 1; //!< Filing system provides extended attributes (Windows, POSIX) - uint32_t compression : 1; //!< Filing system provides whole volume compression (Windows, POSIX) - uint32_t extents : 1; //!< Filing system provides extent based file storage (sparse files) (Windows, POSIX) - uint32_t filecompression : 1; //!< Filing system provides per-file selectable compression (Windows) - } f_flags{0, 0, 0, 0, 0, 0, 0, 0}; /*!< copy of mount exported flags (Windows, POSIX) */ - uint64_t f_bsize{_allbits1_64}; /*!< fundamental filesystem block size (Windows, POSIX) */ - uint64_t f_iosize{_allbits1_64}; /*!< optimal transfer block size (Windows, POSIX) */ - uint64_t f_blocks{_allbits1_64}; /*!< total data blocks in filesystem (Windows, POSIX) */ - uint64_t f_bfree{_allbits1_64}; /*!< free blocks in filesystem (Windows, POSIX) */ - uint64_t f_bavail{_allbits1_64}; /*!< free blocks avail to non-superuser (Windows, POSIX) */ - uint64_t f_files{_allbits1_64}; /*!< total file nodes in filesystem (POSIX) */ - uint64_t f_ffree{_allbits1_64}; /*!< free nodes avail to non-superuser (POSIX) */ - uint32_t f_namemax{_allbits1_32}; /*!< maximum filename length (Windows, POSIX) */ + uint32_t rdonly : 1; //!< Filing system is read only (Windows, POSIX) + uint32_t noexec : 1; //!< Filing system cannot execute programs (POSIX) + uint32_t nosuid : 1; //!< Filing system cannot superuser (POSIX) + uint32_t acls : 1; //!< Filing system provides ACLs (Windows, POSIX) + uint32_t xattr : 1; //!< Filing system provides extended attributes (Windows, POSIX) + uint32_t compression : 1; //!< Filing system provides whole volume compression (Windows, POSIX) + uint32_t extents : 1; //!< Filing system provides extent based file storage (sparse files) (Windows, POSIX) + uint32_t filecompression : 1; //!< Filing system provides per-file selectable compression (Windows) + uint32_t networked : 1; //!< Filing system operates over a network. Requires `want::fstypename`. (Windows, POSIX) + } f_flags{0, 0, 0, 0, 0, 0, 0, 0, 0}; /*!< copy of mount exported flags (Windows, POSIX) */ + uint64_t f_bsize{_allbits1_64}; /*!< fundamental filesystem block size (Windows, POSIX) */ + uint64_t f_iosize{_allbits1_64}; /*!< optimal transfer block size (Windows, POSIX) */ + uint64_t f_blocks{_allbits1_64}; /*!< total data blocks in filesystem (Windows, POSIX) */ + uint64_t f_bfree{_allbits1_64}; /*!< free blocks in filesystem (Windows, POSIX) */ + uint64_t f_bavail{_allbits1_64}; /*!< free blocks avail to non-superuser (Windows, POSIX) */ + uint64_t f_files{_allbits1_64}; /*!< total file nodes in filesystem (POSIX) */ + uint64_t f_ffree{_allbits1_64}; /*!< free nodes avail to non-superuser (POSIX) */ + uint32_t f_namemax{_allbits1_32}; /*!< maximum filename length (Windows, POSIX) */ #ifndef _WIN32 int16_t f_owner{-1}; /*!< user that mounted the filesystem (BSD, OS X) */ #endif |