File: hfs.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (101 lines) | stat: -rw-r--r-- 3,523 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_UTILITY_SAFE_BROWSING_MAC_HFS_H_
#define CHROME_UTILITY_SAFE_BROWSING_MAC_HFS_H_

#include <hfs/hfs_format.h>
#include <stdint.h>

#include <memory>
#include <string>

#include "base/memory/raw_ptr.h"

namespace safe_browsing {
namespace dmg {

class ReadStream;
class HFSBTreeIterator;
class HFSForkReadStream;

// HFSIterator is a read-only iterator over an HFS+ file system. It provides
// access to the data fork of all files on the system, as well as the path. This
// implementation has several deliberate limitations:
//   - Only HFS+ and HFSX are supported.
//   - The journal file is ignored. As this is intended to be used for HFS+ in
//     a DMG, replaying the journal should not typically be required.
//   - The extents overflow file is not consulted. In a DMG, the file system
//     should not be fragmented, and so consulting this should not typically be
//     required.
//   - No access is provided to resource forks.
//   - Getting the ReadStream for hard linked files is not supported.
//   - Files in hard linked directories are ignored.
//   - No content will be returned for files that are decmpfs compressed.
// For information on the HFS format, see
// <https://developer.apple.com/legacy/library/technotes/tn/tn1150.html>.
class HFSIterator {
 public:
  // Constructs an iterator from a stream.
  explicit HFSIterator(ReadStream* stream);

  HFSIterator(const HFSIterator&) = delete;
  HFSIterator& operator=(const HFSIterator&) = delete;

  ~HFSIterator();

  // Opens the filesystem and initializes the iterator. The iterator is
  // initialized to an invalid item before the first entry. Use Next() to
  // advance the iterator. This method must be called before any other
  // method. If this returns false, it is not legal to call any other methods.
  bool Open();

  // Advances the iterator to the next item. If this returns false, then it
  // is not legal to call any other methods.
  bool Next();

  // Returns true if the current iterator item is a directory and false if it
  // is a file.
  bool IsDirectory();

  // Returns true if the current iterator item is a symbolic link.
  bool IsSymbolicLink();

  // Returns true if the current iterator item is a hard link.
  bool IsHardLink();

  // Returns true if the current iterator item is decmpfs-compressed.
  bool IsDecmpfsCompressed();

  // Returns the full filesystem path of the current iterator item.
  std::u16string GetPath();

  // Returns a stream for the data fork of the current iterator item. This may
  // only be called if IsDirectory() and IsHardLink() returns false.
  std::unique_ptr<ReadStream> GetReadStream();

 private:
  friend class HFSForkReadStream;

  // Moves the |stream_| position to a specific HFS+ |block|.
  bool SeekToBlock(uint64_t block);

  // Reads the catalog file to initialize the iterator.
  bool ReadCatalogFile();

  uint32_t block_size() const { return volume_header_.blockSize; }
  ReadStream* stream() const { return stream_; }

  const raw_ptr<ReadStream> stream_;  // The stream backing the filesystem.
  HFSPlusVolumeHeader volume_header_;
  std::unique_ptr<HFSForkReadStream>
      catalog_file_;  // Data of the catalog file.
  std::unique_ptr<HFSBTreeIterator>
      catalog_;  // Iterator over the catalog file.
};

}  // namespace dmg
}  // namespace safe_browsing

#endif  // CHROME_UTILITY_SAFE_BROWSING_MAC_HFS_H_