-
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
Write data to partition, read stdin or file #24
Conversation
Hello @reynir |
I tested it briefly with a fresh disk image with one partition. I was able I imagine you don't need neither |
Rereading your last sentence: we do want to overwrite the contents of the partition with new data! So that's fine. |
Oh thank you for catching this. I kept running the command but the output was so many lines and my terminal couldn't display the full output. I had to output to a file using |
Very correct. Just tried it without any of them and it still works great. |
and haha the reason for this is actually crazy. When I first wrote this I had a major problem which was that after writing to a partition, each time I tried to read from the partition it would indicate that the MBR header was not valid. I realized it was because the code was overwriting the MBR header as well. So I did changed somethings to prevent this, which is also why I was adding the 512 bytes (MBR header size) to the start of where the writing will begin. Good thing the other changes made it work so this was not even necessary and if you didn't notice it I never would have. |
Hello @reynir |
Sorry for not leaving a review before now.
|
Thank you. Let me see how to implement reading and writing in chunks. |
@reynir |
Reading is done until EOF is hit. While writing an error is raised if more is read than what the partition allows for. If the input is a file the size is checked early against the size reported by `Unix.stat`.
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
This creates a new file
write_partition.ml
that can copy a file into a partition, or receive input fromstdin
and copy it into the partition.We are using the
cmdliner
package to read arguments from the command line. It also provides a helpful--help
flag which can displays a user manual.Basically we read in a disk image, unmarshal it's MBR header to get the partition table, grab the specific partition we want to read from. After getting this partition, we calculate information about it's sectors and then read the data from these sectors.
Usage
After building, the command can be called with:
writing into partition 2
: the data to write into partition 2.To write a file into the partition:
This will copy all the contents of
file.txt
into partition 2.Simple Test
Create a new text file with some text:
Create a new disk image with 3 partitions:
Add the text file to the partition 1
Add some other text to partition 2
Verify the data was written to both partitions:
Observation
The data in partition1 and 2 should be printed to stdout. Partition 1 should contain what was in
file.txt
and partition 2 should contain what was typed in stdin.UPDATE
To write multiline comments, you just keep using the enter key to write the next line. To stop writing, you use this character
>