diff --git a/doc/dwarfsck.md b/doc/dwarfsck.md index 47145d8b..4dba7fd3 100644 --- a/doc/dwarfsck.md +++ b/doc/dwarfsck.md @@ -19,8 +19,9 @@ with a non-zero exit code. - `-d`, `--detail=`*value*: Level of filesystem information detail. This can be a numeric level - between 0 and 6, or a comma-separated list of feature names. The - default corresponds to a level of 2. + between 0 and 7, or a comma-separated list of feature names. The + default corresponds to a level of 2. The feature names are shown + in the command help. - `-q`, `--quiet`: Don't produce any output unless there is an error. diff --git a/include/dwarfs/reader/fsinfo_features.h b/include/dwarfs/reader/fsinfo_features.h index 0361eb96..38a74b14 100644 --- a/include/dwarfs/reader/fsinfo_features.h +++ b/include/dwarfs/reader/fsinfo_features.h @@ -47,6 +47,7 @@ enum class fsinfo_feature { metadata_full_dump, frozen_analysis, frozen_layout, + schema_raw_dump, directory_tree, section_details, chunk_details, diff --git a/src/reader/fsinfo_features.cpp b/src/reader/fsinfo_features.cpp index cb9c58f9..b1e210f8 100644 --- a/src/reader/fsinfo_features.cpp +++ b/src/reader/fsinfo_features.cpp @@ -55,6 +55,7 @@ constexpr std::array level_features{ {fsinfo_feature::directory_tree, fsinfo_feature::frozen_layout}), /* 5 */ fsinfo_features({fsinfo_feature::chunk_details}), /* 6 */ fsinfo_features({fsinfo_feature::metadata_full_dump}), + /* 7 */ fsinfo_features({fsinfo_feature::schema_raw_dump}), }; constexpr std::array, @@ -68,6 +69,7 @@ constexpr std::array, FSINFO_FEATURE_PAIR_(metadata_full_dump), FSINFO_FEATURE_PAIR_(frozen_analysis), FSINFO_FEATURE_PAIR_(frozen_layout), + FSINFO_FEATURE_PAIR_(schema_raw_dump), FSINFO_FEATURE_PAIR_(directory_tree), FSINFO_FEATURE_PAIR_(section_details), FSINFO_FEATURE_PAIR_(chunk_details), diff --git a/src/reader/internal/metadata_v2.cpp b/src/reader/internal/metadata_v2.cpp index fd8fa9dc..2f13a5a1 100644 --- a/src/reader/internal/metadata_v2.cpp +++ b/src/reader/internal/metadata_v2.cpp @@ -91,14 +91,19 @@ namespace { using ::apache::thrift::frozen::MappedFrozen; -void check_schema(std::span data) { - using namespace ::apache::thrift; - frozen::schema::Schema schema; - size_t schemaSize = CompactSerializer::deserialize(data, schema); - // std::cerr << debugString(schema) << '\n'; - if (schemaSize != data.size()) { +::apache::thrift::frozen::schema::Schema +deserialize_schema(std::span data) { + ::apache::thrift::frozen::schema::Schema schema; + size_t schema_size = + ::apache::thrift::CompactSerializer::deserialize(data, schema); + if (schema_size != data.size()) { DWARFS_THROW(runtime_error, "invalid schema size"); } + return schema; +} + +void check_schema(std::span data) { + auto schema = deserialize_schema(data); if (!schema.layouts()->contains(*schema.rootLayout())) { DWARFS_THROW(runtime_error, "invalid rootLayout in schema"); } @@ -818,6 +823,7 @@ class metadata_v2_data { : 0); } + std::vector schema_; std::span data_; MappedFrozen meta_; global_metadata const global_; @@ -850,7 +856,8 @@ metadata_v2_data::metadata_v2_data( std::span data, metadata_options const& options, int inode_offset, bool force_consistency_check, std::shared_ptr const& perfmon [[maybe_unused]]) - : data_{data} + : schema_{schema.begin(), schema.end()} + , data_{data} , meta_{check_frozen(map_frozen(schema, data_))} , global_{lgr, check_metadata_consistency(lgr, meta_, options.check_consistency || @@ -1664,6 +1671,10 @@ void metadata_v2_data::dump( os << '\n'; } + if (opts.features.has(fsinfo_feature::schema_raw_dump)) { + os << ::apache::thrift::debugString(deserialize_schema(schema_)) << '\n'; + } + if (opts.features.has(fsinfo_feature::metadata_details)) { os << "symlink_inode_offset: " << symlink_inode_offset_ << "\n"; os << "file_inode_offset: " << file_inode_offset_ << "\n";