diff --git a/src/lib/storage/fs_management/cpp/format.cc b/src/lib/storage/fs_management/cpp/format.cc index 37cbc8b..d7b2c6b 100644 --- a/src/lib/storage/fs_management/cpp/format.cc +++ b/src/lib/storage/fs_management/cpp/format.cc @@ -222,6 +222,24 @@ __EXPORT std::string_view DiskFormatString(DiskFormat fs_type) { return format->name().c_str(); } +__EXPORT DiskFormat DiskFormatFromString(std::string_view str) { + static auto* formats = [] { + auto* formats = new std::unordered_map(); + for (auto format : {kDiskFormatGpt, kDiskFormatMbr, kDiskFormatMinfs, kDiskFormatFat, + kDiskFormatBlobfs, kDiskFormatFvm, kDiskFormatZxcrypt, kDiskFormatFactoryfs, + kDiskFormatBlockVerity, kDiskFormatVbmeta, kDiskFormatBootpart, + kDiskFormatFxfs, kDiskFormatF2fs, kDiskFormatNandBroker}) { + formats->emplace(DiskFormatString(format), format); + } + return formats; + }(); + if (auto iter = formats->find(str); iter == formats->end()) { + return kDiskFormatUnknown; + } else { + return iter->second; + } +} + __EXPORT std::string_view DiskFormatComponentUrl(DiskFormat fs_type) { switch (fs_type) { case kDiskFormatBlobfs: diff --git a/src/lib/storage/fs_management/cpp/format.h b/src/lib/storage/fs_management/cpp/format.h index eb921dc..92a12e7 100644 --- a/src/lib/storage/fs_management/cpp/format.h +++ b/src/lib/storage/fs_management/cpp/format.h @@ -36,6 +36,7 @@ enum DiskFormat { }; std::string_view DiskFormatString(DiskFormat fs_type); +DiskFormat DiskFormatFromString(std::string_view str); // Get the component url for the disk format, if it's known. If it's not known, this returns an // empty string.