@@ -212,9 +212,11 @@ class filesystem_ final {
212
212
std::shared_ptr<performance_monitor const > const & perfmon);
213
213
214
214
int check (filesystem_check_level level, size_t num_threads) const ;
215
- void dump (std::ostream& os, fsinfo_options const & opts) const ;
216
- std::string dump (fsinfo_options const & opts) const ;
217
- nlohmann::json info_as_json (fsinfo_options const & opts) const ;
215
+ void
216
+ dump (std::ostream& os, fsinfo_options const & opts, history const & hist) const ;
217
+ std::string dump (fsinfo_options const & opts, history const & hist) const ;
218
+ nlohmann::json
219
+ info_as_json (fsinfo_options const & opts, history const & hist) const ;
218
220
nlohmann::json metadata_as_json () const ;
219
221
std::string serialize_metadata_as_json (bool simple) const ;
220
222
void walk (std::function<void (dir_entry_view)> const & func) const ;
@@ -280,7 +282,7 @@ class filesystem_ final {
280
282
}
281
283
size_t num_blocks () const { return ir_.num_blocks (); }
282
284
bool has_symlinks () const { return meta_.has_symlinks (); }
283
- history const & get_history () const { return history_; }
285
+ history get_history () const ;
284
286
nlohmann::json get_inode_info (inode_view entry) const {
285
287
return meta_.get_inode_info (std::move (entry),
286
288
std::numeric_limits<size_t >::max ());
@@ -362,7 +364,7 @@ class filesystem_ final {
362
364
mutable block_access_level fsinfo_block_access_level_{
363
365
block_access_level::no_access};
364
366
mutable std::unique_ptr<filesystem_info const > fsinfo_;
365
- history history_ ;
367
+ std::vector<fs_section> history_sections_ ;
366
368
file_off_t const image_offset_;
367
369
filesystem_options const options_;
368
370
PERFMON_CLS_PROXY_DECL
@@ -458,7 +460,6 @@ filesystem_<LoggerPolicy>::filesystem_(
458
460
: LOG_PROXY_INIT(lgr)
459
461
, os_{os}
460
462
, mm_{std::move (mm)}
461
- , history_({.with_timestamps = true })
462
463
, image_offset_{filesystem_parser::find_image_offset (*mm_,
463
464
options.image_offset )}
464
465
, options_{options} // clang-format off
@@ -542,13 +543,22 @@ filesystem_<LoggerPolicy>::filesystem_(
542
543
ir_ = inode_reader_v2 (lgr, std::move (cache), options.inode_reader , perfmon);
543
544
544
545
if (auto it = sections.find (section_type::HISTORY); it != sections.end ()) {
545
- for (auto & section : it->second ) {
546
- if (section.check_fast (*mm_)) {
547
- auto buffer = get_section_data (mm_, section);
548
- history_.parse_append (buffer.span ());
549
- }
546
+ history_sections_ = std::move (it->second );
547
+ }
548
+ }
549
+
550
+ template <typename LoggerPolicy>
551
+ history filesystem_<LoggerPolicy>::get_history() const {
552
+ history hist ({.with_timestamps = true });
553
+
554
+ for (auto & section : history_sections_) {
555
+ if (section.check_fast (*mm_)) {
556
+ auto buffer = get_section_data (mm_, section);
557
+ hist.parse_append (buffer.span ());
550
558
}
551
559
}
560
+
561
+ return hist;
552
562
}
553
563
554
564
template <typename LoggerPolicy>
@@ -618,7 +628,8 @@ int filesystem_<LoggerPolicy>::check(filesystem_check_level level,
618
628
619
629
template <typename LoggerPolicy>
620
630
void filesystem_<LoggerPolicy>::dump(std::ostream& os,
621
- fsinfo_options const & opts) const {
631
+ fsinfo_options const & opts,
632
+ history const & hist) const {
622
633
auto parser = make_fs_parser ();
623
634
624
635
if (opts.features .has (fsinfo_feature::version)) {
@@ -670,7 +681,7 @@ void filesystem_<LoggerPolicy>::dump(std::ostream& os,
670
681
}
671
682
672
683
if (opts.features .has (fsinfo_feature::history)) {
673
- history_ .dump (os);
684
+ hist .dump (os);
674
685
}
675
686
676
687
metadata_v2_utils (meta_).dump (
@@ -688,15 +699,17 @@ void filesystem_<LoggerPolicy>::dump(std::ostream& os,
688
699
}
689
700
690
701
template <typename LoggerPolicy>
691
- std::string filesystem_<LoggerPolicy>::dump(fsinfo_options const & opts) const {
702
+ std::string filesystem_<LoggerPolicy>::dump(fsinfo_options const & opts,
703
+ history const & hist) const {
692
704
std::ostringstream oss;
693
- dump (oss, opts);
705
+ dump (oss, opts, hist );
694
706
return oss.str ();
695
707
}
696
708
697
709
template <typename LoggerPolicy>
698
710
nlohmann::json
699
- filesystem_<LoggerPolicy>::info_as_json(fsinfo_options const & opts) const {
711
+ filesystem_<LoggerPolicy>::info_as_json(fsinfo_options const & opts,
712
+ history const & hist) const {
700
713
auto parser = make_fs_parser ();
701
714
702
715
auto info = nlohmann::json::object ();
@@ -711,7 +724,7 @@ filesystem_<LoggerPolicy>::info_as_json(fsinfo_options const& opts) const {
711
724
}
712
725
713
726
if (opts.features .has (fsinfo_feature::history)) {
714
- info[" history" ] = history_ .as_json ();
727
+ info[" history" ] = hist .as_json ();
715
728
}
716
729
717
730
if (opts.features .has (fsinfo_feature::section_details)) {
@@ -1310,21 +1323,26 @@ template <typename LoggerPolicy>
1310
1323
class filesystem_full_
1311
1324
: public filesystem_common_<LoggerPolicy, filesystem_v2::impl> {
1312
1325
public:
1313
- using filesystem_common_<LoggerPolicy,
1314
- filesystem_v2::impl>::filesystem_common_;
1315
1326
using filesystem_common_<LoggerPolicy, filesystem_v2::impl>::fs;
1316
1327
1328
+ filesystem_full_ (logger& lgr, os_access const & os, std::shared_ptr<mmif> mm,
1329
+ filesystem_options const & options,
1330
+ std::shared_ptr<performance_monitor const > const & perfmon)
1331
+ : filesystem_common_<LoggerPolicy, filesystem_v2::impl>(
1332
+ lgr, os, std::move(mm), options, perfmon)
1333
+ , history_{fs ().get_history ()} {}
1334
+
1317
1335
int check (filesystem_check_level level, size_t num_threads) const override {
1318
1336
return fs ().check (level, num_threads);
1319
1337
}
1320
1338
void dump (std::ostream& os, fsinfo_options const & opts) const override {
1321
- fs ().dump (os, opts);
1339
+ fs ().dump (os, opts, history_ );
1322
1340
}
1323
1341
std::string dump (fsinfo_options const & opts) const override {
1324
- return fs ().dump (opts);
1342
+ return fs ().dump (opts, history_ );
1325
1343
}
1326
1344
nlohmann::json info_as_json (fsinfo_options const & opts) const override {
1327
- return fs ().info_as_json (opts);
1345
+ return fs ().info_as_json (opts, history_ );
1328
1346
}
1329
1347
nlohmann::json metadata_as_json () const override {
1330
1348
return fs ().metadata_as_json ();
@@ -1335,7 +1353,10 @@ class filesystem_full_
1335
1353
std::optional<std::span<uint8_t const >> header () const override {
1336
1354
return fs ().header ();
1337
1355
}
1338
- history const & get_history () const override { return fs ().get_history (); }
1356
+ history const & get_history () const override { return history_; }
1357
+
1358
+ private:
1359
+ history history_;
1339
1360
};
1340
1361
1341
1362
} // namespace internal
0 commit comments