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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! A library for working with qcow (version 1, 2, and 3) files.
//!
//! ## Example
//!
//! ```rust
//! # const PATH: &str = "/home/jamcleod/.panda/bionic-server-cloudimg-amd64-noaslr-nokaslr.qcow2";
//! # use std::fs::File;
//! # use std::io::{Read, BufReader};
//! // open qcow
//! let qcow = qcow::open(PATH).unwrap();
//!
//! // print out list of snapshots in the qcow
//! for snapshot in qcow.snapshots() {
//! println!(
//! "Snapshot {:?}: {:?} (size = {})",
//! snapshot.unique_id,
//! snapshot.name,
//! snapshot.vm_state_size
//! );
//! }
//!
//! // create a reader for accessing the virtual hard disk
//! let mut file = BufReader::new(File::open(PATH)?);
//! let qcow2 = qcow.unwrap_qcow2();
//! let mut reader = qcow2.reader(&mut file);
//!
//! // read the first 10 bytes of the virtual hard disk
//! let mut buf = [0; 10];
//! reader.read_exact(&mut buf)?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Important types/functions
//!
//! * Retrieving a qcow - [`open`] (from path), [`load`] (from reader), [`load_from_memory`] (from
//! slice)
//! * Converting to qcow2 - [`DynamicQcow::unwrap_qcow2`]
//! * Reading from a virtual hard disk - [`Qcow2::reader`] (returns [`Reader`], which implements
//! [`Read`](std::io::Read) + [`Seek`](std::io::Seek))
//!
//! ## Features
//!
//! * Parse qcow files
//! * Full qcow version 1 support
//! * Support for parsing the header and some associated data
//! * Full qcow version 2-3 support
//! * Header parsing, including extra version 3 header data
//! * Header extension parsing, allowing you to use addition data they provide
//! * Lookup table (L1 and L2) parsing, only loading L2 tables on demand
//! * Snapshot parsing, including snapshot L1 lookup tables
//! * Support for reading the contents of the virtual disk
//! * Includes compression support (for both zlib and zstd)
//! * Cluster lookup caching, backtracking on cache miss
//! * Allows arbitrary seeking within the guest
use ;
use *;
use File;
use ;
use Path;
pub use *;
pub use Error;
pub use *;
/// Module for types pertaining to QCOW header extensions
use *;
/// Module containing structs specific to the legacy QCOW v1 format
use Qcow1Header;
pub use *;
pub use *;
pub use DynamicQcow;
/// Parsed representation of a qcow2 file.
///
/// Can be aquired by using one of:
///
/// * [`open`]
/// * [`load`]
/// * [`load_from_memory`]
///
/// and then using [`DynamicQcow::unwrap_qcow2`].
///
/// ## Example
///
/// ```rust
/// # const PATH: &str = "/home/jamcleod/.panda/bionic-server-cloudimg-amd64-noaslr-nokaslr.qcow2";
/// let qcow = qcow::open(PATH).unwrap();
/// ```
/// Parsed representation of a v1 qcow file (legacy)
;
/// Open a qcow or qcow2 file from a path
///
/// ## Example
///
/// ```rust
/// # const PATH: &str = "/home/jamcleod/.panda/bionic-server-cloudimg-amd64-noaslr-nokaslr.qcow2";
/// let qcow = qcow::open(PATH)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Read a qcow or qcow2 file from a reader
///
/// **Note**: unlike [`open`] this does not buffer your I/O. Any buffering should be handled via a
/// wrapper such as [`BufReader`] in order to ensure good performance where applicable.
///
/// ## Example
///
/// ```rust
/// # const PATH: &str = "/home/jamcleod/.panda/bionic-server-cloudimg-amd64-noaslr-nokaslr.qcow2";
/// # use std::fs::File;
/// # use std::io::BufReader;
/// let mut file = BufReader::new(File::open(PATH)?);
/// let qcow = qcow::load(&mut file)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Read a qcow or qcow2 file from a slice