Coverage Report

Created: 2026-04-12 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/sleuthkit/tsk/pool/tsk_pool.hpp
Line
Count
Source
1
/*
2
 * The Sleuth Kit
3
 *
4
 * Brian Carrier [carrier <at> sleuthkit [dot] org]
5
 * Copyright (c) 2019-2020 Brian Carrier.  All Rights reserved
6
 * Copyright (c) 2018-2019 BlackBag Technologies.  All Rights reserved
7
 *
8
 * This software is distributed under the Common Public License 1.0
9
 */
10
/** \@file Public C++ API */
11
#pragma once
12
13
#include <cstdint>
14
#include <utility>
15
#include <vector>
16
17
#include "tsk/auto/guid.h"
18
#include "tsk_pool.h"
19
20
class TSKPool {
21
 public:
22
  using img_t = std::pair<TSK_IMG_INFO *const, const TSK_OFF_T>;
23
  using range = struct {
24
    uint64_t start_block;
25
    uint64_t num_blocks;
26
  };
27
28
  // Not default constructible
29
  TSKPool() = delete;
30
31
  // Not copyable, due the TSK_IMG_INFO pointers
32
  TSKPool(const TSKPool &) = delete;
33
  TSKPool &operator=(const TSKPool &) = delete;
34
35
  // Moveable
36
  TSKPool(TSKPool &&) = default;
37
  TSKPool &operator=(TSKPool &&) = default;
38
39
40
  virtual ~TSKPool() = default;
40
41
0
  inline const TSKGuid &uuid() const { return _uuid; }
42
43
21
  inline uint32_t block_size() const noexcept { return _block_size; }
44
1
  inline uint32_t dev_block_size() const noexcept { return _dev_block_size; }
45
4
  inline uint64_t num_blocks() const noexcept { return _num_blocks; }
46
3
  inline uint64_t first_img_offset() const noexcept {
47
3
      if (!_members.empty()) {
48
3
          return _members[0].second;
49
3
      }
50
0
      return 0;
51
3
  }
52
2
  inline int num_vols() const noexcept { return _num_vols; }
53
54
  virtual ssize_t read(uint64_t address, char *buf, size_t buf_size) const
55
      noexcept = 0;
56
57
0
  virtual const std::vector<range> unallocated_ranges() const { return {}; };
58
59
0
  TSK_IMG_INFO *getTSKImgInfo(unsigned int index) const {
60
0
      if (index < _members.size()) {
61
0
          return _members[index].first;
62
0
      }
63
0
      return NULL;
64
0
  };
65
66
 protected:
67
40
  TSKPool(std::vector<img_t> &&imgs) noexcept : _members{std::move(imgs)} {}
68
69
  std::vector<img_t> _members{};
70
  TSKGuid _uuid{};
71
  uint64_t _num_blocks;
72
  int _num_vols;
73
  uint32_t _block_size{};
74
  uint32_t _dev_block_size{};
75
};
76
77
// Helper function to make it easier to set flag bits on enumerations
78
template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>>
79
0
inline T &operator|=(T &a, T b) {
80
0
  a = static_cast<T>(a | b);
81
82
0
  return a;
83
0
}
Unexecuted instantiation: TSK_FS_INFO_FLAG_ENUM& operator|=<TSK_FS_INFO_FLAG_ENUM, void>(TSK_FS_INFO_FLAG_ENUM&, TSK_FS_INFO_FLAG_ENUM)
Unexecuted instantiation: TSK_FS_ATTR_RUN_FLAG_ENUM& operator|=<TSK_FS_ATTR_RUN_FLAG_ENUM, void>(TSK_FS_ATTR_RUN_FLAG_ENUM&, TSK_FS_ATTR_RUN_FLAG_ENUM)
Unexecuted instantiation: TSK_FS_META_FLAG_ENUM& operator|=<TSK_FS_META_FLAG_ENUM, void>(TSK_FS_META_FLAG_ENUM&, TSK_FS_META_FLAG_ENUM)
Unexecuted instantiation: TSK_POOL_VOLUME_FLAGS& operator|=<TSK_POOL_VOLUME_FLAGS, void>(TSK_POOL_VOLUME_FLAGS&, TSK_POOL_VOLUME_FLAGS)