Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / utility / safe_browsing / mac / udif.h
blob7f4b30ce3c496b9e4ceda8b723a7456b75798267
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_UDIF_H_
6 #define CHROME_UTILITY_SAFE_BROWSING_MAC_UDIF_H_
8 #include <CoreFoundation/CoreFoundation.h>
10 #include <string>
11 #include <vector>
13 #include <sys/types.h>
15 #include "base/mac/scoped_cftyperef.h"
16 #include "base/macros.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/scoped_vector.h"
20 namespace safe_browsing {
21 namespace dmg {
23 class ReadStream;
24 class UDIFBlock;
25 struct UDIFBlockChunk;
27 // UDIFParser parses a Universal Disk Image Format file, allowing access to the
28 // name, types, and data of the partitions held within the file. There is no
29 // canonical documentation for UDIF, and not all disk images use UDIF (though
30 // the majority do). Note that this implementation only handles UDIF and SPARSE
31 // image types, not SPARSEBUNDLE.
33 // No guarantees are made about the position of ReadStream when using an
34 // instance of this class.
36 // Note that this implementation relies on the UDIF blkx table to provide
37 // accurate partition information. Otherwise, Apple Partition Map and
38 // GUID would need to be parsed. See:
39 // - http://opensource.apple.com/source/IOStorageFamily/IOStorageFamily-182.1.1/IOApplePartitionScheme.h
40 // - http://opensource.apple.com/source/IOStorageFamily/IOStorageFamily-182.1.1/IOGUIDPartitionScheme.h
42 // The following references are useful for understanding the UDIF format:
43 // - http://newosxbook.com/DMG.html
44 // - http://www.macdisk.com/dmgen.php
45 class UDIFParser {
46 public:
47 // Constructs an instance from a stream.
48 explicit UDIFParser(ReadStream* stream);
49 ~UDIFParser();
51 // Parses the UDIF file. This method must be called before any other method.
52 // If this returns false, it is not legal to call any other methods.
53 bool Parse();
55 // Returns the number of partitions in this UDIF image.
56 size_t GetNumberOfPartitions();
58 // Returns the partition name for a given partition number, in the range of
59 // [0,GetNumberOfPartitions()). This will include the number, name, and type
60 // of partition. E.g., "disk image (Apple_HFS : 2)".
61 std::string GetPartitionName(size_t part_number);
63 // Returns the partition type as a string for the given partition number.
64 // E.g., "Apple_HFS" and "Apple_Free".
65 std::string GetPartitionType(size_t part_number);
67 // Returns the size of the partition in bytes.
68 size_t GetPartitionSize(size_t part_number);
70 // Returns a stream of the raw partition data for the given partition
71 // number.
72 scoped_ptr<ReadStream> GetPartitionReadStream(size_t part_number);
74 private:
75 // Parses the blkx plist trailer structure.
76 bool ParseBlkx();
78 // Reads the data pointed to by the block |chunk|, decompressing it as
79 // necessary, into the out-buffer |decompressed_data|.
80 bool ReadBlockChunk(const UDIFBlockChunk* chunk,
81 std::vector<uint8_t>* decompressed_data);
83 ReadStream* const stream_; // The stream backing the UDIF image. Weak.
84 std::vector<std::string> partition_names_; // The names of all partitions.
85 ScopedVector<const UDIFBlock> blocks_; // All blocks in the UDIF image.
86 uint16_t block_size_; // The image's block size, in bytes.
88 DISALLOW_COPY_AND_ASSIGN(UDIFParser);
91 } // namespace dmg
92 } // namespace safe_browsing
94 #endif // CHROME_UTILITY_SAFE_BROWSING_MAC_UDIF_H_