-
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
Script for printing MBR headers to stdout #17
Conversation
The reason for moving the |
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'm quite pleased overall with the code. There are some minor issues with how some values are printed and I would like the read_mbr
function moved back out of the mbr library. With those changes I would be happy to merge.
Another task on top of this could be to add flags to toggle printing the boot code for example. For this I like to use the library cmdliner.
lib/mbr.ml
Outdated
|
||
let print_mbr_fields mbr = | ||
Printf.printf "MBR fields:\n"; | ||
Printf.printf " bootstrap_code: %s\n" mbr.bootstrap_code; |
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.
mbr.bootstrap_code
contains binary (executable) data. In OCaml you can use the %S
printf modifier to print it as an escaped string, but even better would be to print it as hexadecimal.
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.
Thank you. I will see how to implement the cmdliner
library. It looks great with good documentation.
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.
@reynir concerning this, I'll open a new Issue for it to keep as a reminder so that when cstruct 6.2.0 is released we can implement the command line flags to toggle display for the bootstrap_code. so if that's okay by you then we could merge .
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.
Sounds good! Please go ahead and open an issue.
lib/mbr.ml
Outdated
Printf.printf " seconds: %d\n" mbr.seconds; | ||
Printf.printf " minutes: %d\n" mbr.minutes; | ||
Printf.printf " hours: %d\n" mbr.hours; | ||
Printf.printf " disk_signature: %ld\n" mbr.disk_signature; |
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.
It would be great to print the disk signature as hexadecimal. This is what fdisk -l test.img
does.
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.
for this, I was exploring the Cstruct
library and found a useful function to_hex_string
, however this function exist only in v6.2.0
while the latest release of Cstruct
on Opam is v6.1.1
The PR to publish the new release is still pending.
ocaml/opam-repository#23374
I am unsure if it's wise to wait or find some other way to convert the Cstruct.t
value to a hex string.
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.
For disk_signature
you can use %lx
in printf.
Good question about bootstrap_code
. There is a 'hex' library that can be used. That would introduce another dependency for the binary, but that is maybe alright. Another way forward could be to print "" since I think that's rarely what you're interested in. And then later when cstruct.6.2.0 is released we can add a flag to print the bootstrap code.
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 think the best way will be to print an empty string and update later when cstruct 6.2.0 is released.
I think adding another dependency (hex library) will be too much given that we are using it just for this purpose.
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.
:-) Thanks for the %lx
. It's just what I needed.
Thanks! I merged and pushed a commit that makes the usage message use the 'basename' of the command so as to not print the whole path to the command in the usage message. |
that's great. thank you. I'll go over it to learn how you did that. |
part of #14
Using this script:
replace [file_name] with the name to any disk image you want to read the MBR Header.
This will print the headers of an MBR to stdout including information about the partitions it contains.
Sample output looks like this:
to test, create a disk image:
the commands above will create an MBR with three partitions
to make any of the partitions bootable, you can use the
parted
command.parted test.img set 1 boot on
cc @reynir