1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Internal implementation details for msf_writer.h. Not meant to be included
16 : // directly.
17 :
18 : #ifndef SYZYGY_MSF_MSF_WRITER_H_
19 : #define SYZYGY_MSF_MSF_WRITER_H_
20 :
21 : #include "base/files/file_path.h"
22 : #include "base/files/file_util.h"
23 : #include "syzygy/msf/msf_decl.h"
24 : #include "syzygy/msf/msf_file.h"
25 : #include "syzygy/msf/msf_stream.h"
26 :
27 m : namespace msf {
28 m : namespace detail {
29 :
30 : // This class is used to write an MSF file to disk given a list of MsfStreams.
31 : // It will create a header and directory inside the MSF file that describe
32 : // the page layout of the streams in the file.
33 m : template <MsfFileType T>
34 m : class MsfWriterImpl {
35 m : public:
36 m : MsfWriterImpl();
37 m : virtual ~MsfWriterImpl();
38 :
39 : // Writes the given MsfFileImpl to disk with the given file name.
40 : // @param msf_path the path of the MSF file to write.
41 : // @param msf_file the MSF file to be written.
42 : // @returns true on success, false otherwise.
43 m : bool Write(const base::FilePath& msf_path, const MsfFileImpl<T>& msf_file);
44 :
45 m : protected:
46 : // Append the contents of the stream onto the file handle at the offset. The
47 : // contents of the file are padded to reach the next page boundary in the
48 : // output stream. The indices of the written pages are appended to
49 : // @p pages_written, while @p page_count is updated to reflect the total
50 : // number of pages written to disk.
51 m : bool AppendStream(MsfStreamImpl<T>* stream,
52 m : std::vector<uint32_t>* pages_written,
53 m : uint32_t* page_count);
54 :
55 : // Writes the MSF header after the directory has been written.
56 m : bool WriteHeader(const std::vector<uint32_t>& root_directory_pages,
57 m : uint32_t directory_size,
58 m : uint32_t page_count);
59 :
60 : // The current file handle open for writing.
61 m : base::ScopedFILE file_;
62 :
63 m : private:
64 m : DISALLOW_COPY_AND_ASSIGN(MsfWriterImpl);
65 m : };
66 :
67 m : } // namespace detail
68 :
69 m : using MsfWriter = detail::MsfWriterImpl<kGenericMsfFileType>;
70 :
71 m : } // namespace msf
72 :
73 : #include "syzygy/msf/msf_writer_impl.h"
74 :
75 : #endif // SYZYGY_MSF_MSF_WRITER_H_
|