Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / utility / safe_browsing / mac / hfs.h
blob8a4a6d7752a7dbe5d2652225389e171353ec7f30
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_UTILITY_SAFE_BROWSING_MAC_HFS_H_
6 #define CHROME_UTILITY_SAFE_BROWSING_MAC_HFS_H_
8 #include <hfs/hfs_format.h>
9 #include <stdint.h>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
15 namespace safe_browsing {
16 namespace dmg {
18 class ReadStream;
19 class HFSBTreeIterator;
20 class HFSForkReadStream;
22 // HFSIterator is a read-only iterator over an HFS+ file system. It provides
23 // access to the data fork of all files on the system, as well as the path. This
24 // implementation has several deliberate limitations:
25 // - Only HFS+ and HFSX are supported.
26 // - The journal file is ignored. As this is intended to be used for HFS+ in
27 // a DMG, replaying the journal should not typically be required.
28 // - The extents overflow file is not consulted. In a DMG, the file system
29 // should not be fragmented, and so consulting this should not typically be
30 // required.
31 // - No access is provided to resource forks.
32 // - Getting the ReadStream for hard linked files is not supported.
33 // - Files in hard linked directories are ignored.
34 // - No content will be returned for files that are decmpfs compressed.
35 // For information on the HFS format, see
36 // <https://developer.apple.com/legacy/library/technotes/tn/tn1150.html>.
37 class HFSIterator {
38 public:
39 // Constructs an iterator from a stream.
40 explicit HFSIterator(ReadStream* stream);
41 ~HFSIterator();
43 // Opens the filesystem and initializes the iterator. The iterator is
44 // initialized to an invalid item before the first entry. Use Next() to
45 // advance the iterator. This method must be called before any other
46 // method. If this returns false, it is not legal to call any other methods.
47 bool Open();
49 // Advances the iterator to the next item. If this returns false, then it
50 // is not legal to call any other methods.
51 bool Next();
53 // Returns true if the current iterator item is a directory and false if it
54 // is a file.
55 bool IsDirectory();
57 // Returns true if the current iterator item is a symbolic link.
58 bool IsSymbolicLink();
60 // Returns true if the current iterator item is a hard link.
61 bool IsHardLink();
63 // Returns true if the current iterator item is decmpfs-compressed.
64 bool IsDecmpfsCompressed();
66 // Returns the full filesystem path of the current iterator item.
67 base::string16 GetPath();
69 // Returns a stream for the data fork of the current iterator item. This may
70 // only be called if IsDirectory() and IsHardLink() returns false.
71 scoped_ptr<ReadStream> GetReadStream();
73 private:
74 friend class HFSForkReadStream;
76 // Moves the |stream_| position to a specific HFS+ |block|.
77 bool SeekToBlock(uint64_t block);
79 // Reads the catalog file to initialize the iterator.
80 bool ReadCatalogFile();
82 uint32_t block_size() const { return volume_header_.blockSize; }
83 ReadStream* stream() const { return stream_; }
85 ReadStream* const stream_; // The stream backing the filesystem.
86 HFSPlusVolumeHeader volume_header_;
87 scoped_ptr<HFSForkReadStream> catalog_file_; // Data of the catalog file.
88 scoped_ptr<HFSBTreeIterator> catalog_; // Iterator over the catalog file.
90 DISALLOW_COPY_AND_ASSIGN(HFSIterator);
93 } // namespace dmg
94 } // namespace safe_browsing
96 #endif // CHROME_UTILITY_SAFE_BROWSING_MAC_HFS_H_