-
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
Add 'disk signature' argument to 'make' #19
Conversation
Great! As you note in #1 the tests would need to be updated. Another option would be to make |
Thanks @reynir, |
Hello @reynir, I have not changed 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.
This is getting close!
lib/mbr.mli
Outdated
@@ -79,11 +79,11 @@ type t = private { | |||
seconds : int; | |||
minutes : int; | |||
hours : int; | |||
disk_signature : int32; | |||
disk_signature : int32 option; |
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.
This does not need changing. We want the disk signature to always be present, and in the "smart" constructor (function make
) we fill in a default value if not provided.
disk_signature : int32 option; | |
disk_signature : int32; |
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.
Will the default value be something like 0l
?
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.
something like let make (?disk_signature = 0l) in partitions
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.
And change back the line disk_signature = (match disk_signature with Some s -> s | None -> 0l);
to just 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.
I updated the code to reflect the changes, but i wish to say the implementation of the optional argument is what I don't understand since the way I saw it used in the documentation you sent is using the ?disk_signature
format. thanks
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.
Yes, optional arguments in OCaml is a bit convoluted. There are many ways you can define a function with optional arguments: let f ?x () = Option.get x
, let f ?(x=42) () = x
, let f ?x:(y=42) () = y
. Then there's a different syntax for calling the function, and for the type of the function. It may not have been the best very first issue, but I am glad that you have solved it!
lib/mbr.mli
Outdated
partitions : Partition.t list; | ||
} | ||
|
||
val make : Partition.t list -> (t, string) result | ||
val make : Partition.t list -> int32 -> (t, string) result |
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.
The signature for functions with optional arguments look a bit different. This signature is for a function with a mandatory unlabelled argument.
See https://v2.ocaml.org/releases/5.0/htmlman/lablexamples.html#s:optional-arguments
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.
Hello @reynir, I'm sorry, but I am confused about what you mean, does it mean that ?disk_signature
is a mandatory unlabelled argument?
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Okay I think I get it, you mean, I have to create a signature
, I never knew what that was, after doing some research, I wish this will do val make : ?disk_signature:int32 -> 'a list -> 'a
`
lib/mbr.ml
Outdated
let signature_msg = match disk_signature with | ||
| Some signature -> Printf.sprintf "Disk signature is: %ld\n" signature | ||
| None -> "No disk signature provided\n" in | ||
print_endline signature_msg; | ||
|
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.
Debug printing is fine, but before merging we should remove this :-)
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Co-authored-by: Reynir Björnsson <reynir@reynir.dk> Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
lib/mbr.mli
Outdated
val make : Partition.t list -> (t, string) result | ||
|
||
val make : ?disk_signature:int32 -> 'a list -> 'a |
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.
You got it right with the ?disk_signature:int32
part. If you can add it to the type signature of make
above that would be great. The rest of the type function of the latter make
is not quite right.
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.
Hello @reynir, thanks for the review, I just added it now.
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Co-authored-by: Reynir Björnsson <reynir@reynir.dk>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
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)
fixes #1