-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read data in partition, output to stdout or file #23
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
$ fallocate -l test.img 2M
$ parted --align none test.img mklabel msdos
$ parted --align none test.img mkpart primary 1s 20s
$ tar -cf tmp.tar LICENSE
$ dd if=test.tar of=test.img seek=1 conv=notrunc
20+0 records in
20+0 records out
10240 bytes (10 kB, 10 KiB) copied, 0.000348219 s, 29.4 MB/s
$ dune exec -- bin/read_partition.exe test.img 1 | tar -t
LICENSE
bin/read_partition.ml
Outdated
let start_sector, num_sectors, sector_size = | ||
calculate_partition_info partition | ||
in | ||
let buffer = read_partition_data mbr start_sector num_sectors sector_size in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should incrementally read and write the data as the partition could potentially be larger than what we can fit in memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated it to use a chunk size of 4096 bytes. let me know if to use a bigger chunk size.
Thanks! |
CHANGES: * Add optional argument `?disk_signature` to `Mbr.make` (@Burnleydev1, review by @reynir, mirage/ocaml-mbr#19) * Make the partition type a required argument to `Mbr.Partition.make` and rename it `~partition_type` (@AryanGodara, review by @reynir, mirage/ocaml-mbr#20) * Add tools for inspecting and modifying MBR, and reading/writing data to partitions. The command line tools are not installed as part of the opam package. The tools are `bin/mbr_inspect.exe`, `bin/read_partition.exe`, `bin/resize_partition.exe` and `bin/write_partition.exe`. (@PizieDust, review by @reynir, mirage/ocaml-mbr#22, mirage/ocaml-mbr#23, mirage/ocaml-mbr#24, mirage/ocaml-mbr#26) * Remove dependency on `ppx_cstruct` (@reynir, mirage/ocaml-mbr#27)
part of #14
Outline
read_partition.ml
which reads content stored in a partition.cmdliner
package to parse and read arguments passed when calling this executable and also generates a lovely manual which can be called by adding the--help
flag (I love this package)Usage
After building, the command can be called with:
test.img
: The disk image which contains the partition.2
: The partition number we want to read from.Running this command will print the contents of partition 2 to stdout.
To output the contents to a file:
This will output the contents to a file called
file.txt
. If this file doesn't exist, the command will create the file.Simple Test
read_partition.exe test.img 1`
cc @reynir