diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index 3d3d8c4ece..c5fd40effa 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -146,7 +146,7 @@ .memorySizeInBytes(16) .accessMode(iox::posix::AccessMode::READ_WRITE) .openMode(iox::posix::OpenMode::PURGE_AND_CREATE) - .permissions(perms::owner_all) + .permissions(iox::perms::owner_all) .create(); ``` @@ -1023,3 +1023,13 @@ // after #include "iox/duration.hpp" ``` + +46. The `perms` enum is replaced by the `access_rights` class + + ```cpp + // before + iox::perms foo { iox::perms::owner_all | iox::perms::group_read }; + + // after + iox::access_rights foo { iox::perms::owner_all | iox::perms::group_read }; + ``` diff --git a/iceoryx_hoofs/README.md b/iceoryx_hoofs/README.md index af7a8a1d06..a225680e8f 100644 --- a/iceoryx_hoofs/README.md +++ b/iceoryx_hoofs/README.md @@ -57,7 +57,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an | class | internal | description | |:---------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -|`filesystem` | | Implementation of C++17 filesystem features for instance `cxx::perms` to abstract file permissions | +|`filesystem` | | Implementation of C++17 filesystem features for instance `iox::access_rights` and `iox::perms` to abstract file permissions | |`AccessController` | i | Interface for Access Control Lists (ACL). | |`FileLock` | | File lock C++ wrapping class. | |`posix_access_rights` | | Rights and user management interface. | diff --git a/iceoryx_hoofs/filesystem/include/iox/detail/filesystem.inl b/iceoryx_hoofs/filesystem/include/iox/detail/filesystem.inl index 2cc8647a27..95e21ff32c 100644 --- a/iceoryx_hoofs/filesystem/include/iox/detail/filesystem.inl +++ b/iceoryx_hoofs/filesystem/include/iox/detail/filesystem.inl @@ -39,11 +39,15 @@ inline bool isValidPathEntry(const iox::string& name, // AXIVION Next Construct AutosarC++19_03-A3.9.1: Not used as an integer but as actual character const char c{name[i]}; + // AXIVION DISABLE STYLE AutosarC++19_03-A0.1.1, FaultDetection-UnusedAssignments : False positive, variable IS used + // AXIVION DISABLE STYLE AutosarC++19_03-M4.5.3 : We are explicitly checking for ASCII characters which have defined consecutive values const bool isSmallLetter{(internal::ASCII_A <= c) && (c <= internal::ASCII_Z)}; const bool isCapitalLetter{(internal::ASCII_CAPITAL_A <= c) && (c <= internal::ASCII_CAPITAL_Z)}; const bool isNumber{(internal::ASCII_0 <= c) && (c <= internal::ASCII_9)}; - const bool isSpecialCharacter{((c == internal::ASCII_MINUS) || (c == internal::ASCII_DOT)) + const bool isSpecialCharacter{((c == internal::ASCII_DASH) || (c == internal::ASCII_DOT)) || ((c == internal::ASCII_COLON) || (c == internal::ASCII_UNDERSCORE))}; + // AXIVION ENABLE STYLE AutosarC++19_03-M4.5.3 + // AXIVION ENABLE STYLE AutosarC++19_03-A0.1.1, FaultDetection-UnusedAssignments if ((!isSmallLetter && !isCapitalLetter) && (!isNumber && !isSpecialCharacter)) { @@ -80,18 +84,30 @@ inline bool isValidPathToFile(const iox::string& name) noexcept return false; } - iox::string filePart{name}; - iox::string pathPart; + auto maybeSeparator = name.find_last_of(iox::string( + TruncateToCapacity, &platform::IOX_PATH_SEPARATORS[0], platform::IOX_NUMBER_OF_PATH_SEPARATORS)); - name.find_last_of(iox::string(TruncateToCapacity, - &platform::IOX_PATH_SEPARATORS[0], - platform::IOX_NUMBER_OF_PATH_SEPARATORS)) - .and_then([&](auto position) { - name.substr(position + 1).and_then([&filePart](auto& s) { filePart = s; }); - name.substr(0, position).and_then([&pathPart](auto& s) { pathPart = s; }); - }); + if (!maybeSeparator.has_value()) + { + return isValidFileName(name); + } + + const auto& position = maybeSeparator.value(); + + bool isFileNameValid{false}; + name.substr(position + 1).and_then([&isFileNameValid](const auto& s) noexcept { + isFileNameValid = isValidFileName(s); + }); + + bool isPathValid{false}; + name.substr(0, position).and_then([&isPathValid](const auto& s) noexcept { + const bool isEmptyPath{s.empty()}; + const bool isPathToDirectoryValid{isValidPathToDirectory(s)}; + isPathValid = isEmptyPath || isPathToDirectoryValid; + }); - return (pathPart.empty() || isValidPathToDirectory(pathPart)) && isValidFileName(filePart); + // AXIVION Next Construct AutosarC++19_03-M0.1.2, AutosarC++19_03-M0.1.9, FaultDetection-DeadBranches : False positive! Branching depends on input parameter + return isPathValid && isFileNameValid; } template @@ -102,52 +118,54 @@ inline bool isValidPathToDirectory(const iox::string& name) noex return false; } - auto temp = name; - const iox::string currentDirectory{"."}; const iox::string parentDirectory{".."}; - while (!temp.empty()) + const iox::string pathSeparators{ + TruncateToCapacity, &platform::IOX_PATH_SEPARATORS[0], platform::IOX_NUMBER_OF_PATH_SEPARATORS}; + + auto remaining = name; + while (!remaining.empty()) { - auto separatorPosition = temp.find_first_of(iox::string( - TruncateToCapacity, &platform::IOX_PATH_SEPARATORS[0], platform::IOX_NUMBER_OF_PATH_SEPARATORS)); - - // multiple slashes are explicitly allowed. the following paths - // are equivalent: - // /some/fuu/bar - // //some///fuu////bar - if (separatorPosition && (*separatorPosition == 0)) - { - temp.substr(*separatorPosition + 1).and_then([&temp](auto& s) { temp = s; }); - continue; - } + const auto separatorPosition = remaining.find_first_of(pathSeparators); - // verify if the entry between two path separators is a valid directory - // name, e.g. either it has the relative component . or .. or conforms - // with a valid file name - if (separatorPosition) + if (separatorPosition.has_value()) { - auto filenameToVerify = temp.substr(0, *separatorPosition); - bool isValidDirectory{ - (isValidFileName(*filenameToVerify)) - || ((*filenameToVerify == currentDirectory) || (*filenameToVerify == parentDirectory))}; - if (!isValidDirectory) + const uint64_t position{separatorPosition.value()}; + + // multiple slashes are explicitly allowed. the following paths + // are equivalent: + // /some/fuu/bar + // //some///fuu////bar + + // verify if the entry between two path separators is a valid directory + // name, e.g. either it has the relative component . or .. or conforms + // with a valid file name + if (position != 0) { - return false; + const auto guaranteedSubstr = remaining.substr(0, position); + const auto& filenameToVerify = guaranteedSubstr.value(); + const bool isValidDirectory{ + (isValidFileName(filenameToVerify)) + || ((filenameToVerify == currentDirectory) || (filenameToVerify == parentDirectory))}; + if (!isValidDirectory) + { + return false; + } } - temp.substr(*separatorPosition + 1).and_then([&temp](auto& s) { temp = s; }); + remaining.substr(position + 1).and_then([&remaining](const auto& s) noexcept { remaining = s; }); } - // we reached the last entry, if its a valid file name the path is valid - else + else // we reached the last entry, if its a valid file name the path is valid { - return isValidPathEntry(temp, RelativePathComponents::ACCEPT); + return isValidPathEntry(remaining, RelativePathComponents::ACCEPT); } } return true; } +// AXIVION Next Construct AutosarC++19_03-A5.2.5, AutosarC++19_03-M5.0.16, FaultDetection-OutOfBounds : IOX_PATH_SEPARATORS is not a string but an array of chars without a null termination and all elements are valid characters template inline bool doesEndWithPathSeparator(const iox::string& name) noexcept { @@ -156,7 +174,7 @@ inline bool doesEndWithPathSeparator(const iox::string& name) no return false; } // AXIVION Next Construct AutosarC++19_03-A3.9.1: Not used as an integer but as actual character - char lastCharacter{name[name.size() - 1U]}; + const char lastCharacter{name[name.size() - 1U]}; for (const auto separator : iox::platform::IOX_PATH_SEPARATORS) { @@ -168,53 +186,53 @@ inline bool doesEndWithPathSeparator(const iox::string& name) no return false; } -constexpr perms operator|(const perms lhs, const perms rhs) noexcept +constexpr access_rights::value_type access_rights::value() const noexcept +{ + return m_value; +} + +constexpr bool operator==(const access_rights lhs, const access_rights rhs) noexcept +{ + return lhs.value() == rhs.value(); +} + +constexpr bool operator!=(const access_rights lhs, const access_rights rhs) noexcept +{ + return !(lhs == rhs); +} + +constexpr access_rights operator|(const access_rights lhs, const access_rights rhs) noexcept { - using T = std::underlying_type::type; - // AXIVION Next Construct AutosarC++19_03-A7.2.1 : Designed according to the C++17 std::perms pendant - // which also can be used like a bitset like the corresponding C defines. - // Diverting from this behavior would be unexpected for users and may introduce bugs. - return static_cast(static_cast(lhs) | static_cast(rhs)); + return access_rights(lhs.value() | rhs.value()); } -constexpr perms operator&(const perms lhs, const perms rhs) noexcept +constexpr access_rights operator&(const access_rights lhs, const access_rights rhs) noexcept { - using T = std::underlying_type::type; - // AXIVION Next Construct AutosarC++19_03-A7.2.1 : Designed according to the C++17 std::perms pendant - // which also can be used like a bitset like the corresponding C defines. - // Diverting from this behavior would be unexpected for users and may introduce bugs. - return static_cast(static_cast(lhs) & static_cast(rhs)); + return access_rights(lhs.value() & rhs.value()); } -constexpr perms operator^(const perms lhs, const perms rhs) noexcept +constexpr access_rights operator^(const access_rights lhs, const access_rights rhs) noexcept { - using T = std::underlying_type::type; - // AXIVION Next Construct AutosarC++19_03-A7.2.1 : Designed according to the C++17 std::perms pendant - // which also can be used like a bitset like the corresponding C defines. - // Diverting from this behavior would be unexpected for users and may introduce bugs. - return static_cast(static_cast(lhs) ^ static_cast(rhs)); + return access_rights(lhs.value() ^ rhs.value()); } -constexpr perms operator~(const perms value) noexcept +constexpr access_rights operator~(const access_rights value) noexcept { - using T = std::underlying_type::type; - // AXIVION Next Construct AutosarC++19_03-A7.2.1 : Designed according to the C++17 std::perms pendant - // which also can be used like a bitset like the corresponding C defines. - // Diverting from this behavior would be unexpected for users and may introduce bugs. - return static_cast(~static_cast(value)); + // AXIVION Next Construct AutosarC++19_03-A4.7.1, AutosarC++19_03-M0.3.1, FaultDetection-IntegerOverflow : Cast is safe and required due to integer promotion + return access_rights(static_cast(~value.value())); } -constexpr perms operator|=(const perms lhs, const perms rhs) noexcept +constexpr access_rights operator|=(const access_rights lhs, const access_rights rhs) noexcept { return operator|(lhs, rhs); } -constexpr perms operator&=(const perms lhs, const perms rhs) noexcept +constexpr access_rights operator&=(const access_rights lhs, const access_rights rhs) noexcept { return operator&(lhs, rhs); } -constexpr perms operator^=(const perms lhs, const perms rhs) noexcept +constexpr access_rights operator^=(const access_rights lhs, const access_rights rhs) noexcept { return operator^(lhs, rhs); } diff --git a/iceoryx_hoofs/filesystem/include/iox/filesystem.hpp b/iceoryx_hoofs/filesystem/include/iox/filesystem.hpp index 68b9197b7b..87241101ee 100644 --- a/iceoryx_hoofs/filesystem/include/iox/filesystem.hpp +++ b/iceoryx_hoofs/filesystem/include/iox/filesystem.hpp @@ -32,7 +32,7 @@ constexpr char ASCII_CAPITAL_A{'A'}; constexpr char ASCII_CAPITAL_Z{'Z'}; constexpr char ASCII_0{'0'}; constexpr char ASCII_9{'9'}; -constexpr char ASCII_MINUS{'-'}; +constexpr char ASCII_DASH{'-'}; constexpr char ASCII_DOT{'.'}; constexpr char ASCII_COLON{':'}; constexpr char ASCII_UNDERSCORE{'_'}; @@ -89,112 +89,313 @@ bool isValidPathToDirectory(const string& name) noexcept; template bool doesEndWithPathSeparator(const string& name) noexcept; -/// @brief this enum class implements the filesystem perms feature of C++17. The -/// API is identical to the C++17 one so that the class can be removed -/// as soon as iceoryx switches to C++17. -/// The enum satisfies also all requirements of the BitmaskType, this means +/// @brief this class implements the filesystem perms feature of C++17 but as a new type +/// instead of an enum. +/// The class satisfies also all requirements of the BitmaskType, this means /// the operators '|', '&', '^', '~', '|=', '&=' and '^=' are implemented as /// free functions as C++17 requires it. -enum class perms : uint32_t +/// @code +/// #include +/// void foo() +/// { +/// iox::access_rights bar { iox::perms::owner_all | iox::perms::group_read }; +/// } +/// +/// @endcode +class access_rights final { - /// @brief Deny everything - none = 0, - - /// @brief owner has read permission - owner_read = 0400, - /// @brief owner has write permission - owner_write = 0200, - /// @brief owner has execution permission - owner_exec = 0100, - /// @brief owner has all permissions - owner_all = 0700, - - /// @brief group has read permission - group_read = 040, - /// @brief group has write permission - group_write = 020, - /// @brief group has execution permission - group_exec = 010, - /// @brief group has all permissions - group_all = 070, - - /// @brief others have read permission - others_read = 04, - /// @brief others have write permission - others_write = 02, - /// @brief others have execution permission - others_exec = 01, - /// @brief others have all permissions - others_all = 07, - - /// @brief all permissions for everyone - all = 0777, - - /// @brief set uid bit - /// @note introduction into setgit/setuid: https://en.wikipedia.org/wiki/Setuid - set_uid = 04000, - /// @brief set gid bit - /// @note introduction into setgit/setuid: https://en.wikipedia.org/wiki/Setuid - set_gid = 02000, - /// @brief set sticky bit - /// @note sticky bit introduction: https://en.wikipedia.org/wiki/Sticky_bit - sticky_bit = 01000, - - /// @brief all permissions for everyone as well as uid, gid and sticky bit - mask = 07777, - - /// @brief unknown permissions - unknown = 0xFFFF + public: + using value_type = uint16_t; + + access_rights() noexcept = default; + access_rights(const access_rights&) noexcept = default; + access_rights(access_rights&&) noexcept = default; + + access_rights& operator=(const access_rights&) noexcept = default; + access_rights& operator=(access_rights&&) noexcept = default; + + ~access_rights() noexcept = default; + + constexpr value_type value() const noexcept; + + struct detail + { + // AXIVION DISABLE STYLE AutosarC++19_03-M2.13.2 : Filesystem permissions are defined in octal representation + + // the code cannot be moved to the '*.inl' file since the functions are used in the 'perms' namespace to define + // the respective constants + + /// @note Implementation detail! Please use 'iox::perms::none'. + static constexpr access_rights none() noexcept + { + constexpr value_type VALUE{0}; + return access_rights{VALUE}; + } + + /// @note Implementation detail! Please use 'iox::perms::owner_read'. + static constexpr access_rights owner_read() noexcept + { + constexpr value_type VALUE{0400}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::owner_write'. + static constexpr access_rights owner_write() noexcept + { + constexpr value_type VALUE{0200}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::owner_exec'. + static constexpr access_rights owner_exec() noexcept + { + constexpr value_type VALUE{0100}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::owner_all'. + static constexpr access_rights owner_all() noexcept + { + constexpr value_type VALUE{0700}; + return access_rights{VALUE}; + } + + /// @note Implementation detail! Please use 'iox::perms::group_read'. + static constexpr access_rights group_read() noexcept + { + constexpr value_type VALUE{040}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::group_write'. + static constexpr access_rights group_write() noexcept + { + constexpr value_type VALUE{020}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::group_exec'. + static constexpr access_rights group_exec() noexcept + { + constexpr value_type VALUE{010}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::group_all'. + static constexpr access_rights group_all() noexcept + { + constexpr value_type VALUE{070}; + return access_rights{VALUE}; + } + + /// @note Implementation detail! Please use 'iox::perms::others_read'. + static constexpr access_rights others_read() noexcept + { + constexpr value_type VALUE{04}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::others_write'. + static constexpr access_rights others_write() noexcept + { + constexpr value_type VALUE{02}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::others_exec'. + static constexpr access_rights others_exec() noexcept + { + constexpr value_type VALUE{01}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::others_all'. + static constexpr access_rights others_all() noexcept + { + constexpr value_type VALUE{07}; + return access_rights{VALUE}; + } + + /// @note Implementation detail! Please use 'iox::perms::all'. + static constexpr access_rights all() noexcept + { + constexpr value_type VALUE{0777}; + return access_rights{VALUE}; + } + + /// @note Implementation detail! Please use 'iox::perms::set_uid'. + static constexpr access_rights set_uid() noexcept + { + constexpr value_type VALUE{04000}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::set_gid'. + static constexpr access_rights set_gid() noexcept + { + constexpr value_type VALUE{02000}; + return access_rights{VALUE}; + } + /// @note Implementation detail! Please use 'iox::perms::sticky_bit'. + static constexpr access_rights sticky_bit() noexcept + { + constexpr value_type VALUE{01000}; + return access_rights{VALUE}; + } + + /// @note Implementation detail! Please use 'iox::perms::mask'. + static constexpr access_rights mask() noexcept + { + constexpr value_type VALUE{07777}; + return access_rights{VALUE}; + } + + /// @note Implementation detail! Please use 'iox::perms::unknown'. + static constexpr access_rights unknown() noexcept + { + constexpr value_type VALUE{0xFFFFU}; + return access_rights{VALUE}; + } + + // AXIVION ENABLE STYLE AutosarC++19_03-M2.13.2 + }; + + friend constexpr bool operator==(const access_rights lhs, const access_rights rhs) noexcept; + friend constexpr bool operator!=(const access_rights lhs, const access_rights rhs) noexcept; + + friend constexpr access_rights operator|(const access_rights lhs, const access_rights rhs) noexcept; + friend constexpr access_rights operator&(const access_rights lhs, const access_rights rhs) noexcept; + friend constexpr access_rights operator^(const access_rights lhs, const access_rights rhs) noexcept; + friend constexpr access_rights operator~(const access_rights value) noexcept; + friend constexpr access_rights operator|=(const access_rights lhs, const access_rights rhs) noexcept; + friend constexpr access_rights operator&=(const access_rights lhs, const access_rights rhs) noexcept; + friend constexpr access_rights operator^=(const access_rights lhs, const access_rights rhs) noexcept; + + private: + explicit constexpr access_rights(value_type value) noexcept + : m_value(value) + { + } + + private: + value_type m_value{0}; }; +namespace perms +{ +// AXIVION DISABLE STYLE AutosarC++19_03-A2.10.5 : Name reuse is intentional since they refer to the same value. Additionally, different namespaces are used. + +/// @brief Deny everything +static constexpr access_rights none{access_rights::detail::none()}; + +/// @brief owner has read permission +static constexpr access_rights owner_read{access_rights::detail::owner_read()}; +/// @brief owner has write permission +static constexpr access_rights owner_write{access_rights::detail::owner_write()}; +/// @brief owner has execution permission +static constexpr access_rights owner_exec{access_rights::detail::owner_exec()}; +/// @brief owner has all permissions +static constexpr access_rights owner_all{access_rights::detail::owner_all()}; + +/// @brief group has read permission +static constexpr access_rights group_read{access_rights::detail::group_read()}; +/// @brief group has write permission +static constexpr access_rights group_write{access_rights::detail::group_write()}; +/// @brief group has execution permission +static constexpr access_rights group_exec{access_rights::detail::group_exec()}; +/// @brief group has all permissions +static constexpr access_rights group_all{access_rights::detail::group_all()}; + +/// @brief others have read permission +static constexpr access_rights others_read{access_rights::detail::others_read()}; +/// @brief others have write permission +static constexpr access_rights others_write{access_rights::detail::others_write()}; +/// @brief others have execution permission +static constexpr access_rights others_exec{access_rights::detail::others_exec()}; +/// @brief others have all permissions +static constexpr access_rights others_all{access_rights::detail::others_all()}; + +/// @brief all permissions for everyone +static constexpr access_rights all{access_rights::detail::all()}; + +/// @brief set uid bit +/// @note introduction into setgit/setuid: https://en.wikipedia.org/wiki/Setuid +// AXIVION Next Construct AutosarC++19_03-M2.10.1: The constant is in a namespace and mimics the C++17 STL equivalent +static constexpr access_rights set_uid{access_rights::detail::set_uid()}; +/// @brief set gid bit +/// @note introduction into setgit/setuid: https://en.wikipedia.org/wiki/Setuid +// AXIVION Next Construct AutosarC++19_03-M2.10.1: The constant is in a namespace and mimics the C++17 STL equivalent +static constexpr access_rights set_gid{access_rights::detail::set_gid()}; +/// @brief set sticky bit +/// @note sticky bit introduction: https://en.wikipedia.org/wiki/Sticky_bit +static constexpr access_rights sticky_bit{access_rights::detail::sticky_bit()}; + +/// @brief all permissions for everyone as well as uid, gid and sticky bit +static constexpr access_rights mask{access_rights::detail::mask()}; + +/// @brief unknown permissions +static constexpr access_rights unknown{access_rights::detail::unknown()}; + +// AXIVION ENABLE STYLE AutosarC++19_03-A2.10.5 +} // namespace perms + + +/// @brief Implements the equal operator +/// @param[in] lhs left hand side of the operation +/// @param[in] rhs right hand side of the operation +/// @return lhs == rhs +constexpr bool operator==(const access_rights lhs, const access_rights rhs) noexcept; + +/// @brief Implements the not equal operator +/// @param[in] lhs left hand side of the operation +/// @param[in] rhs right hand side of the operation +/// @return lhs != rhs +constexpr bool operator!=(const access_rights lhs, const access_rights rhs) noexcept; + /// @brief Implements the binary or operation /// @param[in] lhs left hand side of the operation /// @param[in] rhs right hand side of the operation /// @return lhs | rhs -constexpr perms operator|(const perms lhs, const perms rhs) noexcept; +constexpr access_rights operator|(const access_rights lhs, const access_rights rhs) noexcept; /// @brief Implements the binary and operation /// @param[in] lhs left hand side of the operation /// @param[in] rhs right hand side of the operation /// @return lhs & rhs -constexpr perms operator&(const perms lhs, const perms rhs) noexcept; +constexpr access_rights operator&(const access_rights lhs, const access_rights rhs) noexcept; /// @brief Implements the binary exclusive or operation /// @param[in] lhs left hand side of the operation /// @param[in] rhs right hand side of the operation /// @return lhs ^ rhs -constexpr perms operator^(const perms lhs, const perms rhs) noexcept; +constexpr access_rights operator^(const access_rights lhs, const access_rights rhs) noexcept; /// @brief Implements the binary complement operation /// @param[in] value the value used for the operation /// @return ~value -constexpr perms operator~(const perms value) noexcept; +constexpr access_rights operator~(const access_rights value) noexcept; /// @brief Implements the binary or assignment operation /// @param[in] lhs left hand side of the operation /// @param[in] rhs right hand side of the operation /// @return lhs = lhs | rhs -constexpr perms operator|=(const perms lhs, const perms rhs) noexcept; +constexpr access_rights operator|=(const access_rights lhs, const access_rights rhs) noexcept; /// @brief Implements the binary and assignment operation /// @param[in] lhs left hand side of the operation /// @param[in] rhs right hand side of the operation /// @return lhs = lhs & rhs -constexpr perms operator&=(const perms lhs, const perms rhs) noexcept; +constexpr access_rights operator&=(const access_rights lhs, const access_rights rhs) noexcept; /// @brief Implements the binary exclusive or assignment operation /// @param[in] lhs left hand side of the operation /// @param[in] rhs right hand side of the operation /// @return lhs = lhs ^ rhs -constexpr perms operator^=(const perms lhs, const perms rhs) noexcept; +constexpr access_rights operator^=(const access_rights lhs, const access_rights rhs) noexcept; + +/// @brief The 'ostream' operator for the 'access_rights' class. It handles the class as if +/// it was a bitset and always lists the values for owner, group, others, special bits +/// @param[in] stream reference to the 'ostream' +/// @param[in] value the file permission +/// @return the reference to the stream +std::ostream& operator<<(std::ostream& stream, const access_rights value) noexcept; -/// @brief The streaming operator for the perms enum. It handles the enum as if +/// @brief The 'LogStream' operator for the 'access_rights' class. It handles the class as if /// it was a bitset and always lists the values for owner, group, others, special bits -/// @param[in] stream reference to the stream +/// @param[in] stream reference to the 'LogStream' /// @param[in] value the file permission /// @return the reference to the stream -template -StreamType& operator<<(StreamType& stream, const perms value) noexcept; +iox::log::LogStream& operator<<(iox::log::LogStream& stream, const access_rights value) noexcept; } // namespace iox #include "iox/detail/filesystem.inl" diff --git a/iceoryx_hoofs/filesystem/source/filesystem.cpp b/iceoryx_hoofs/filesystem/source/filesystem.cpp index 982b48461e..024fb03133 100644 --- a/iceoryx_hoofs/filesystem/source/filesystem.cpp +++ b/iceoryx_hoofs/filesystem/source/filesystem.cpp @@ -51,7 +51,7 @@ static void finishEntry(StreamType& stream, const bool hasPrecedingEntry, const } template -static void printOwnerPermissions(StreamType& stream, const perms value) +static void printOwnerPermissions(StreamType& stream, const access_rights value) { bool hasPrecedingEntry = false; stream << "owner: {"; @@ -75,7 +75,7 @@ static void printOwnerPermissions(StreamType& stream, const perms value) } template -static void printGroupPermissions(StreamType& stream, const perms value) +static void printGroupPermissions(StreamType& stream, const access_rights value) { bool hasPrecedingEntry = false; stream << "group: {"; @@ -99,7 +99,7 @@ static void printGroupPermissions(StreamType& stream, const perms value) } template -static void printOtherPermissions(StreamType& stream, const perms value) +static void printOtherPermissions(StreamType& stream, const access_rights value) { bool hasPrecedingEntry = false; stream << "others: {"; @@ -123,7 +123,7 @@ static void printOtherPermissions(StreamType& stream, const perms value) } template -static void printSpecialBits(StreamType& stream, const perms value) +static void printSpecialBits(StreamType& stream, const access_rights value) { bool hasPrecedingEntry = false; stream << "special bits: {"; @@ -147,22 +147,29 @@ static void printSpecialBits(StreamType& stream, const perms value) } template -StreamType& operator<<(StreamType& stream, const perms value) noexcept +void printAccessControl(StreamType& stream, const access_rights value) noexcept { if (value == perms::unknown) { stream << "unknown permissions"; - return stream; + return; } printOwnerPermissions(stream, value); printGroupPermissions(stream, value); printOtherPermissions(stream, value); printSpecialBits(stream, value); +} +std::ostream& operator<<(std::ostream& stream, const access_rights value) noexcept +{ + printAccessControl(stream, value); return stream; } -template std::ostream& operator<<(std::ostream&, const perms) noexcept; -template log::LogStream& operator<<(log::LogStream&, const perms) noexcept; +iox::log::LogStream& operator<<(iox::log::LogStream& stream, const access_rights value) noexcept +{ + printAccessControl(stream, value); + return stream; +} } // namespace iox diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp index 49d7918b20..9ff0587536 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp @@ -138,7 +138,7 @@ class SharedMemoryObjectBuilder IOX_BUILDER_PARAMETER(optional, baseAddressHint, nullopt) /// @brief Defines the access permissions of the shared memory - IOX_BUILDER_PARAMETER(perms, permissions, perms::none) + IOX_BUILDER_PARAMETER(access_rights, permissions, perms::none) public: expected create() noexcept; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp index d4b1797ebc..1e23bda57d 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/shared_memory.hpp @@ -116,7 +116,7 @@ class SharedMemoryBuilder IOX_BUILDER_PARAMETER(OpenMode, openMode, OpenMode::OPEN_EXISTING) /// @brief Defines the access permissions of the shared memory - IOX_BUILDER_PARAMETER(perms, filePermissions, perms::none) + IOX_BUILDER_PARAMETER(access_rights, filePermissions, perms::none) /// @brief Defines the size of the shared memory IOX_BUILDER_PARAMETER(uint64_t, size, 0U) diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/file_lock.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/file_lock.hpp index 8a4ed25ddf..803e417a0f 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/file_lock.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/file_lock.hpp @@ -52,7 +52,7 @@ enum class FileLockError /// @code /// auto fileLock = iox::posix::FileLockBuilder().name("myLockName") /// .path("/tmp") -/// .permission(iox::cxx::perms::owner_all) +/// .permission(iox::perms::owner_all) /// .create() /// .expect("Oh no I couldn't create the lock"); /// @endcode @@ -121,7 +121,7 @@ class FileLockBuilder /// @brief Defines the access permissions of the file lock. If they are not /// explicitly set they will be none - IOX_BUILDER_PARAMETER(perms, permission, perms::none) + IOX_BUILDER_PARAMETER(access_rights, permission, perms::none) public: /// @brief Creates a file lock diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_semaphore.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_semaphore.hpp index afd3deb9db..11acb86996 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_semaphore.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/named_semaphore.hpp @@ -64,7 +64,7 @@ class NamedSemaphoreBuilder IOX_BUILDER_PARAMETER(OpenMode, openMode, OpenMode::OPEN_EXISTING) /// @brief Defines the access permissions of the semaphore - IOX_BUILDER_PARAMETER(perms, permissions, perms::owner_all) + IOX_BUILDER_PARAMETER(access_rights, permissions, perms::owner_all) /// @brief Set the initial value of the unnamed posix semaphore. This value is only used when a new semaphore is /// created. diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/filesystem.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/filesystem.hpp index 83497adc1a..989cf24f44 100644 --- a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/filesystem.hpp +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/filesystem.hpp @@ -24,8 +24,8 @@ namespace iox /// [[deprecated("Deprecated in 3.0, removed in 4.0, please include 'iox/filesystem.hpp' instead")]] namespace cxx { -/// @deprecated use `iox::perms` instead of `iox::cxx::perms` -using iox::perms; +/// @deprecated use 'iox::access_rights' instead of 'iox::cxx::perms' +using perms = iox::access_rights; } // namespace cxx } // namespace iox diff --git a/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp b/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp index bf3b4d63eb..7eab17a20a 100644 --- a/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/file_lock.cpp @@ -59,7 +59,7 @@ expected FileLockBuilder::create() noexcept auto openCall = posixCall(iox_open)(fileLockPath.c_str(), convertToOflags(AccessMode::READ_ONLY, OpenMode::OPEN_OR_CREATE), - static_cast(m_permission)) + m_permission.value()) .failureReturnValue(-1) .evaluate(); diff --git a/iceoryx_hoofs/source/posix_wrapper/named_semaphore.cpp b/iceoryx_hoofs/source/posix_wrapper/named_semaphore.cpp index e1c0273e4c..6157e4dfef 100644 --- a/iceoryx_hoofs/source/posix_wrapper/named_semaphore.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/named_semaphore.cpp @@ -104,12 +104,12 @@ tryOpenExistingSemaphore(optional& uninitializedSemaphore, const static expected createSemaphore(optional& uninitializedSemaphore, const NamedSemaphore::Name_t& name, const OpenMode openMode, - const perms permissions, + const access_rights permissions, const uint32_t initialValue) noexcept { auto result = posixCall(iox_sem_open_ext)(createNameWithSlash(name).c_str(), convertToOflags(openMode), - static_cast(permissions), + permissions.value(), static_cast(initialValue)) .failureReturnValue(IOX_SEM_FAILED) .evaluate(); diff --git a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp index 61017ccbf6..4dc1f15e9f 100644 --- a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp @@ -75,7 +75,7 @@ expected SharedMemoryObjectBuilder: << ", access mode = " << asStringLiteral(m_accessMode) << ", open mode = " << asStringLiteral(m_openMode) << ", baseAddressHint = " << logBaseAddressHint - << ", permissions = " << iox::log::oct(static_cast(m_permissions)) << " ]"; + << ", permissions = " << iox::log::oct(m_permissions.value()) << " ]"; }; auto sharedMemory = SharedMemoryBuilder() @@ -136,14 +136,14 @@ expected SharedMemoryObjectBuilder: SIGBUS_ERROR_MESSAGE_LENGTH, "While setting the acquired shared memory to zero a fatal SIGBUS signal appeared caused by memset. The " "shared memory object with the following properties [ name = %s, sizeInBytes = %llu, access mode = %s, " - "open mode = %s, baseAddressHint = %p, permissions = %lu ] maybe requires more memory than it is " + "open mode = %s, baseAddressHint = %p, permissions = %u ] maybe requires more memory than it is " "currently available in the system.\n", m_name.c_str(), static_cast(m_memorySizeInBytes), asStringLiteral(m_accessMode), asStringLiteral(m_openMode), (m_baseAddressHint) ? *m_baseAddressHint : nullptr, - std::bitset(static_cast(m_permissions)).to_ulong())); + m_permissions.value())); memset(memoryMap->getBaseAddress(), 0, m_memorySizeInBytes); } diff --git a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp index 3714f89452..eaa8306653 100644 --- a/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp +++ b/iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp @@ -26,7 +26,6 @@ #include "iceoryx_platform/unistd.hpp" #include "iox/scope_guard.hpp" -#include #include namespace iox @@ -46,8 +45,8 @@ expected SharedMemoryBuilder::create() noexcept IOX_LOG(ERROR) << "Unable to create shared memory with the following properties [ name = " << m_name << ", access mode = " << asStringLiteral(m_accessMode) << ", open mode = " << asStringLiteral(m_openMode) - << ", mode = " << std::bitset(static_cast(m_filePermissions)).to_string() - << ", sizeInBytes = " << m_size << " ]"; + << ", mode = " << iox::log::oct(m_filePermissions.value()) << ", sizeInBytes = " << m_size + << " ]"; }; @@ -96,7 +95,7 @@ expected SharedMemoryBuilder::create() noexcept nameWithLeadingSlash.c_str(), convertToOflags(m_accessMode, (m_openMode == OpenMode::OPEN_OR_CREATE) ? OpenMode::EXCLUSIVE_CREATE : m_openMode), - static_cast(m_filePermissions)) + m_filePermissions.value()) .failureReturnValue(SharedMemory::INVALID_HANDLE) .suppressErrorMessagesForErrnos((m_openMode == OpenMode::OPEN_OR_CREATE) ? EEXIST : 0) .evaluate(); @@ -109,7 +108,7 @@ expected SharedMemoryBuilder::create() noexcept hasOwnership = false; result = posixCall(iox_shm_open)(nameWithLeadingSlash.c_str(), convertToOflags(m_accessMode, OpenMode::OPEN_EXISTING), - static_cast(m_filePermissions)) + m_filePermissions.value()) .failureReturnValue(SharedMemory::INVALID_HANDLE) .evaluate(); } diff --git a/iceoryx_hoofs/test/moduletests/test_filesystem_filesystem.cpp b/iceoryx_hoofs/test/moduletests/test_filesystem_filesystem.cpp index 20e9daa5f4..91f6c191ba 100644 --- a/iceoryx_hoofs/test/moduletests/test_filesystem_filesystem.cpp +++ b/iceoryx_hoofs/test/moduletests/test_filesystem_filesystem.cpp @@ -29,14 +29,12 @@ using namespace iox::internal; using iox::testing::Logger_Mock; -using base_t = std::underlying_type::type; - constexpr uint64_t FILE_PATH_LENGTH = 128U; bool isValidFileCharacter(const int32_t i) noexcept { return ((ASCII_A <= i && i <= ASCII_Z) || (ASCII_CAPITAL_A <= i && i <= ASCII_CAPITAL_Z) - || (ASCII_0 <= i && i <= ASCII_9) || i == ASCII_MINUS || i == ASCII_DOT || i == ASCII_COLON + || (ASCII_0 <= i && i <= ASCII_9) || i == ASCII_DASH || i == ASCII_DOT || i == ASCII_COLON || i == ASCII_UNDERSCORE); } @@ -49,7 +47,7 @@ TEST(filesystem_test_isValidFileName, CorrectInternalAsciiAliases) EXPECT_EQ(ASCII_CAPITAL_Z, 'Z'); EXPECT_EQ(ASCII_0, '0'); EXPECT_EQ(ASCII_9, '9'); - EXPECT_EQ(ASCII_MINUS, '-'); + EXPECT_EQ(ASCII_DASH, '-'); EXPECT_EQ(ASCII_DOT, '.'); EXPECT_EQ(ASCII_COLON, ':'); EXPECT_EQ(ASCII_UNDERSCORE, '_'); @@ -593,97 +591,95 @@ TEST(filesystem_test_isValidPathEntry, StringWithRelativeComponentsIsInvalidWhen iox::RelativePathComponents::REJECT)); } -constexpr base_t toBase(const perms permission) noexcept -{ - return static_cast(permission); -} - TEST(filesystem_test, permsBinaryOrEqualToBinaryOrOfUnderlyingType) { ::testing::Test::RecordProperty("TEST_ID", "0b72fcec-c2b3-4a45-801f-542ff3195a2f"); - constexpr perms TEST_VALUE_LHS = perms::others_write; - constexpr perms TEST_VALUE_RHS = perms::group_all; + constexpr access_rights TEST_VALUE_LHS = perms::others_write; + constexpr access_rights TEST_VALUE_RHS = perms::group_all; - constexpr auto BASE_VALUE_LHS = toBase(TEST_VALUE_LHS); - constexpr auto BASE_VALUE_RHS = toBase(TEST_VALUE_RHS); + constexpr auto BASE_VALUE_LHS = TEST_VALUE_LHS.value(); + constexpr auto BASE_VALUE_RHS = TEST_VALUE_RHS.value(); - EXPECT_THAT(toBase(TEST_VALUE_LHS | TEST_VALUE_RHS), Eq(BASE_VALUE_LHS | BASE_VALUE_RHS)); + EXPECT_THAT((TEST_VALUE_LHS | TEST_VALUE_RHS).value(), Eq(BASE_VALUE_LHS | BASE_VALUE_RHS)); } TEST(filesystem_test, permsBinaryAndEqualToBinaryAndOfUnderlyingType) { ::testing::Test::RecordProperty("TEST_ID", "15a02845-21b0-41fb-80bf-ee2ff9a81427"); - constexpr perms TEST_VALUE_LHS = perms::others_read; - constexpr perms TEST_VALUE_RHS = perms::mask; + constexpr access_rights TEST_VALUE_LHS = perms::others_read; + constexpr access_rights TEST_VALUE_RHS = perms::mask; - constexpr auto BASE_VALUE_LHS = toBase(TEST_VALUE_LHS); - constexpr auto BASE_VALUE_RHS = toBase(TEST_VALUE_RHS); + constexpr auto BASE_VALUE_LHS = TEST_VALUE_LHS.value(); + constexpr auto BASE_VALUE_RHS = TEST_VALUE_RHS.value(); - EXPECT_THAT(toBase(TEST_VALUE_LHS & TEST_VALUE_RHS), Eq(BASE_VALUE_LHS & BASE_VALUE_RHS)); + EXPECT_THAT((TEST_VALUE_LHS & TEST_VALUE_RHS).value(), Eq(BASE_VALUE_LHS & BASE_VALUE_RHS)); } TEST(filesystem_test, permsBinaryExclusiveOrEqualToBinaryExclusiveOrOfUnderlyingType) { ::testing::Test::RecordProperty("TEST_ID", "8094a263-2861-45ad-aecd-9312d477bc2d"); - constexpr perms TEST_VALUE_LHS = perms::set_gid; - constexpr perms TEST_VALUE_RHS = perms::set_uid; + constexpr access_rights TEST_VALUE_LHS = perms::set_gid; + constexpr access_rights TEST_VALUE_RHS = perms::set_uid; - constexpr auto BASE_VALUE_LHS = toBase(TEST_VALUE_LHS); - constexpr auto BASE_VALUE_RHS = toBase(TEST_VALUE_RHS); + constexpr auto BASE_VALUE_LHS = TEST_VALUE_LHS.value(); + constexpr auto BASE_VALUE_RHS = TEST_VALUE_RHS.value(); - EXPECT_THAT(toBase(TEST_VALUE_LHS ^ TEST_VALUE_RHS), Eq(BASE_VALUE_LHS ^ BASE_VALUE_RHS)); + EXPECT_THAT((TEST_VALUE_LHS ^ TEST_VALUE_RHS).value(), Eq(BASE_VALUE_LHS ^ BASE_VALUE_RHS)); } TEST(filesystem_test, permsBinaryComplementEqualToBinaryComplementOfUnderlyingType) { ::testing::Test::RecordProperty("TEST_ID", "c313cf42-4cf0-4836-95ff-129111a707b0"); - constexpr perms TEST_VALUE = perms::owner_read; + constexpr access_rights TEST_VALUE = perms::owner_read; + + constexpr access_rights::value_type BASE_VALUE = 0x0100; + constexpr access_rights::value_type EXPECTED_VALUE = 0xFEFF; - constexpr auto BASE_VALUE = toBase(TEST_VALUE); + ASSERT_THAT(TEST_VALUE.value(), Eq(BASE_VALUE)); - EXPECT_THAT(toBase(~TEST_VALUE), Eq(~BASE_VALUE)); + EXPECT_THAT((~TEST_VALUE).value(), Eq(EXPECTED_VALUE)); } TEST(filesystem_test, permsBinaryOrAssignmentEqualToBinaryOrAssignmentOfUnderlyingType) { ::testing::Test::RecordProperty("TEST_ID", "d3611de8-f932-4485-9e64-6cd8af4526dc"); - constexpr perms TEST_VALUE = perms::sticky_bit; - constexpr perms TEST_VALUE_RHS = perms::group_read; + constexpr access_rights TEST_VALUE = perms::sticky_bit; + constexpr access_rights TEST_VALUE_RHS = perms::group_read; - auto sutBaseValue = toBase(TEST_VALUE); - constexpr auto BASE_VALUE_RHS = toBase(TEST_VALUE_RHS); + auto sutBaseValue = TEST_VALUE.value(); + constexpr auto BASE_VALUE_RHS = TEST_VALUE_RHS.value(); - perms sut = TEST_VALUE; + access_rights sut = TEST_VALUE; - EXPECT_THAT(toBase(sut |= TEST_VALUE_RHS), Eq(sutBaseValue |= BASE_VALUE_RHS)); + EXPECT_THAT((sut |= TEST_VALUE_RHS).value(), Eq(sutBaseValue |= BASE_VALUE_RHS)); } TEST(filesystem_test, permsBinaryAndAssignmentEqualToBinaryAndAssignmentOfUnderlyingType) { ::testing::Test::RecordProperty("TEST_ID", "03c139be-e3ec-477e-8598-5da93699ab75"); - constexpr perms TEST_VALUE = perms::others_exec; - constexpr perms TEST_VALUE_RHS = perms::others_all; + constexpr access_rights TEST_VALUE = perms::others_exec; + constexpr access_rights TEST_VALUE_RHS = perms::others_all; - auto sutBaseValue = toBase(TEST_VALUE); - constexpr auto BASE_VALUE_RHS = toBase(TEST_VALUE_RHS); + auto sutBaseValue = TEST_VALUE.value(); + constexpr auto BASE_VALUE_RHS = TEST_VALUE_RHS.value(); - perms sut = TEST_VALUE; + access_rights sut = TEST_VALUE; - EXPECT_THAT(toBase(sut &= TEST_VALUE_RHS), Eq(sutBaseValue &= BASE_VALUE_RHS)); + EXPECT_THAT((sut &= TEST_VALUE_RHS).value(), Eq(sutBaseValue &= BASE_VALUE_RHS)); } TEST(filesystem_test, permsBinaryExclusiveOrAssignmentEqualToBinaryExclusiveOrAssignmentOfUnderylingType) { ::testing::Test::RecordProperty("TEST_ID", "dae75205-a635-4535-8e8d-05541bb05b60"); - constexpr perms TEST_VALUE = perms::none; - constexpr perms TEST_VALUE_RHS = perms::owner_all; + constexpr access_rights TEST_VALUE = perms::none; + constexpr access_rights TEST_VALUE_RHS = perms::owner_all; - auto sutBaseValue = toBase(TEST_VALUE); - constexpr auto BASE_VALUE_RHS = toBase(TEST_VALUE_RHS); + auto sutBaseValue = TEST_VALUE.value(); + constexpr auto BASE_VALUE_RHS = TEST_VALUE_RHS.value(); - perms sut = TEST_VALUE; + access_rights sut = TEST_VALUE; - EXPECT_THAT(toBase(sut ^= TEST_VALUE_RHS), Eq(sutBaseValue ^= BASE_VALUE_RHS)); + EXPECT_THAT((sut ^= TEST_VALUE_RHS).value(), Eq(sutBaseValue ^= BASE_VALUE_RHS)); } TEST(filesystem_test, streamOperatorPrintsCorrectlyWhenEverythingIsSet) diff --git a/iceoryx_hoofs/test/moduletests/test_posix_named_semaphore.cpp b/iceoryx_hoofs/test/moduletests/test_posix_named_semaphore.cpp index d092b82579..a47c7c0bb5 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_named_semaphore.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_named_semaphore.cpp @@ -38,7 +38,7 @@ class NamedSemaphoreTest : public Test optional sut; NamedSemaphore::Name_t sutName{TruncateToCapacity, "dr.peacock_rocks"}; - const iox::perms sutPermission = iox::perms::owner_all; + const iox::access_rights sutPermission = iox::perms::owner_all; }; TEST_F(NamedSemaphoreTest, DefaultInitialValueIsZero) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.hpp index ecc8285807..916d4a1f02 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.hpp @@ -59,7 +59,7 @@ class MePooSegment uint64_t m_segmentId; iox::mepoo::MemoryInfo m_memoryInfo; - static constexpr perms SEGMENT_PERMISSIONS = + static constexpr access_rights SEGMENT_PERMISSIONS = perms::owner_read | perms::owner_write | perms::group_read | perms::group_write; private: diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl index f733ee24a8..40b33e0acc 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mepoo_segment.inl @@ -29,7 +29,7 @@ namespace iox namespace mepoo { template -constexpr perms MePooSegment::SEGMENT_PERMISSIONS; +constexpr access_rights MePooSegment::SEGMENT_PERMISSIONS; template inline MePooSegment::MePooSegment( diff --git a/iceoryx_posh/include/iceoryx_posh/internal/runtime/shared_memory_user.hpp b/iceoryx_posh/include/iceoryx_posh/internal/runtime/shared_memory_user.hpp index c1b9c99a2f..93946c60d9 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/runtime/shared_memory_user.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/runtime/shared_memory_user.hpp @@ -49,7 +49,7 @@ class SharedMemoryUser private: optional m_shmObject; vector m_dataShmObjects; - static constexpr perms SHM_SEGMENT_PERMISSIONS = + static constexpr access_rights SHM_SEGMENT_PERMISSIONS = perms::owner_read | perms::owner_write | perms::group_read | perms::group_write; }; diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/memory/posix_shm_memory_provider.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/memory/posix_shm_memory_provider.hpp index 43c7eab959..dd6b6fcc03 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/memory/posix_shm_memory_provider.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/memory/posix_shm_memory_provider.hpp @@ -66,7 +66,7 @@ class PosixShmMemoryProvider : public MemoryProvider posix::OpenMode m_openMode{posix::OpenMode::OPEN_EXISTING}; optional m_shmObject; - static constexpr perms SHM_MEMORY_PERMISSIONS = + static constexpr access_rights SHM_MEMORY_PERMISSIONS = perms::owner_read | perms::owner_write | perms::group_read | perms::group_write; }; diff --git a/iceoryx_posh/source/roudi/memory/posix_shm_memory_provider.cpp b/iceoryx_posh/source/roudi/memory/posix_shm_memory_provider.cpp index e77398a679..3d19e364a8 100644 --- a/iceoryx_posh/source/roudi/memory/posix_shm_memory_provider.cpp +++ b/iceoryx_posh/source/roudi/memory/posix_shm_memory_provider.cpp @@ -27,7 +27,7 @@ namespace iox { namespace roudi { -constexpr perms PosixShmMemoryProvider::SHM_MEMORY_PERMISSIONS; +constexpr access_rights PosixShmMemoryProvider::SHM_MEMORY_PERMISSIONS; PosixShmMemoryProvider::PosixShmMemoryProvider(const ShmName_t& shmName, const posix::AccessMode accessMode, diff --git a/iceoryx_posh/source/runtime/shared_memory_user.cpp b/iceoryx_posh/source/runtime/shared_memory_user.cpp index 979fe1b289..bb4a309c74 100644 --- a/iceoryx_posh/source/runtime/shared_memory_user.cpp +++ b/iceoryx_posh/source/runtime/shared_memory_user.cpp @@ -25,7 +25,7 @@ namespace iox { namespace runtime { -constexpr perms SharedMemoryUser::SHM_SEGMENT_PERMISSIONS; +constexpr access_rights SharedMemoryUser::SHM_SEGMENT_PERMISSIONS; SharedMemoryUser::SharedMemoryUser(const size_t topicSize, const uint64_t segmentId, diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp index eee4f322f0..f7f614d961 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp @@ -49,13 +49,13 @@ class MePooSegment_test : public Test const iox::posix::AccessMode, const iox::posix::OpenMode, const void*, - const iox::perms)>; + const iox::access_rights)>; SharedMemoryObject_MOCK(const SharedMemory::Name_t& name, const uint64_t memorySizeInBytes, const AccessMode accessMode, const OpenMode openMode, const void* baseAddressHint, - const iox::perms permissions) + const iox::access_rights permissions) : m_memorySizeInBytes(memorySizeInBytes) , m_baseAddressHint(const_cast(baseAddressHint)) { @@ -121,7 +121,7 @@ class MePooSegment_test : public Test IOX_BUILDER_PARAMETER(iox::optional, baseAddressHint, iox::nullopt) - IOX_BUILDER_PARAMETER(iox::perms, permissions, iox::perms::none) + IOX_BUILDER_PARAMETER(iox::access_rights, permissions, iox::perms::none) public: iox::expected create() noexcept @@ -174,7 +174,7 @@ TEST_F(MePooSegment_test, SharedMemoryCreationParameter) const iox::posix::AccessMode f_accessMode, const iox::posix::OpenMode openMode, const void*, - const iox::perms) { + const iox::access_rights) { EXPECT_THAT(f_name, Eq(SharedMemory::Name_t("iox_roudi_test2"))); EXPECT_THAT(f_accessMode, Eq(iox::posix::AccessMode::READ_WRITE)); EXPECT_THAT(openMode, Eq(iox::posix::OpenMode::PURGE_AND_CREATE)); @@ -195,7 +195,7 @@ TEST_F(MePooSegment_test, GetSharedMemoryObject) const iox::posix::AccessMode, const iox::posix::OpenMode, const void*, - const iox::perms) { + const iox::access_rights) { memorySizeInBytes = f_memorySizeInBytes; }; SUT sut{mepooConfig, m_managementAllocator, PosixGroup{"iox_roudi_test1"}, PosixGroup{"iox_roudi_test2"}};