Skip to content

Commit

Permalink
Merge pull request #101 from Obirvalger/master
Browse files Browse the repository at this point in the history
Add support for qcow2 qemu disks
  • Loading branch information
bojand authored Feb 2, 2025
2 parents 4256ea0 + e99a2b3 commit df3053d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ assert_eq!(kind.extension(), "foo");
- **dey** - `application/vnd.android.dey`
- **der** - `application/x-x509-ca-cert`
- **obj** - `application/x-executable`
- **qcow2** - `application/x-qemu-disk`

## Known Issues

Expand Down
6 changes: 6 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ matcher_map!(
"pem",
matchers::app::is_pem
),
(
MatcherType::App,
"application/x-qemu-disk",
"qcow2",
matchers::app::is_qcow2
),
// Book
(
MatcherType::Book,
Expand Down
6 changes: 6 additions & 0 deletions src/matchers/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,9 @@ pub fn is_pem(buf: &[u8]) -> bool {
&& buf[9] == b'N'
&& buf[10] == b' '
}

/// Returns whether a buffer is a QCOW2 disk.
pub fn is_qcow2(buf: &[u8]) -> bool {
// https://github.com/qemu/qemu/blob/master/docs/interop/qcow2.txt
buf.len() > 4 && buf[0] == b'Q' && buf[1] == b'F' && buf[2] == b'I' && buf[3] == 0xFB
}
Binary file added testdata/sample.qcow2
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ test_format!(App, "application/wasm", "wasm", wasm, "sample.wasm");
test_format!(App, "application/x-x509-ca-cert", "der", der, "sample.der");

test_format!(App, "application/x-x509-ca-cert", "pem", pem, "sample.pem");

test_format!(
App,
"application/x-qemu-disk",
"qcow2",
qcow2,
"sample.qcow2"
);

0 comments on commit df3053d

Please sign in to comment.