Script to create an MBR formatted disk.#28
Conversation
|
One hiccup with this PR that I am yet to figure out is that when ever the partitions are created and we write data to them, the last partition has some issues and we can't read anything from it. It just displays "END OF FILE" |
reynir
left a comment
There was a problem hiding this comment.
Cool! I made a few comments. I mentioned yesterday that letting exceptions bubble all the way up is not always so nice: We don't fully control how the error is displayed, and depending on the setup a stack trace may be printed.
Instead of failwith "oh no! an error" we can write (Printf.eprintf "oh no! an error. Exiting...\n%!"; exit 2). This prints the error message to stderr, and we control the exit code (in this case 2). The %! in the format string is to ensure the internal OCaml buffer is flushed.
Alternatively, we can catch all exceptions in the "beginning" of the program and handle them there (e.g. printing nice error messages and choosing a suitable exit code). Or use Printexc.set_uncaught_exception_handler to set a handler.
bin/create_mbr_disk.ml
Outdated
| (fun i size -> | ||
| Printf.printf "Creating partition: %d" (i + 1); | ||
| let start_sector = (i + 1) * sector_size in | ||
| let num_sectors = (size + sector_size - 1) / sector_size in |
There was a problem hiding this comment.
Here we round up the size to the nearest sector boundary. This is certainly a valid choice. I lean more towards erroring out as rounding up means we have to think about the (potential) slack at the end of the partition and whether to zero it out.
There was a problem hiding this comment.
@reynir Here I wish to ask, the files to be written to the disk, should they have a size that is an exact multiple of sector_size before it is validated and we error otherwise.
I agree too much slack at the end of the partition will be a waste.
There was a problem hiding this comment.
Yes, I would do it that way. The user can call truncate to add padding if they need it and it makes sense for the data in question.
|
@reynir I think we have an issue with our CI/CD pipleline |
closes #14
This PR tackles the final task of issue #14.
Helpful notes from @reynir :
Currently we are able to achieve the following:
This new script can be compiled and executed by running:
disk.img: The destination (the disk image that will be created in the current directory)notes.txt: A sample fileThe above command will create a disk file named
disk.imgwith one partition which has a size equivalent to the size of notes.txtA helpful menu can be opened by
dune exec -- bin/create_mbr_disk.exe --helpNotes:
Some modifications will have to be made to accommodate features like paddings between partitions and restricting how many files should be passed with the script. This PR serves as a starting point.