Skip to content
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

Merged
merged 14 commits into from
Mar 20, 2023
Merged

Conversation

Burnleydev1
Copy link
Contributor

fixes #1

@Burnleydev1 Burnleydev1 marked this pull request as draft March 13, 2023 20:52
@reynir
Copy link
Member

reynir commented Mar 14, 2023

Great! As you note in #1 the tests would need to be updated. Another option would be to make disk_signature an optional argument https://v2.ocaml.org/releases/5.0/htmlman/lablexamples.html. This way users of the library (most likely) don't have to change their code.

@Burnleydev1
Copy link
Contributor Author

Thanks @reynir,
I’m currently trying to understand optional arguments from the link you sent.

@Burnleydev1
Copy link
Contributor Author

Hello @reynir, I have not changed the test_mbr.ml file, but I get errors like This pattern should not be a constructor, the expected type is int32 -> (Mbr.t, string) result
is given by the line | Ok _ -> () on line 58.

Copy link
Member

@reynir reynir left a 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;
Copy link
Member

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.

Suggested change
disk_signature : int32 option;
disk_signature : int32;

Copy link
Contributor Author

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?

Copy link
Contributor Author

@Burnleydev1 Burnleydev1 Mar 17, 2023

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

Copy link
Contributor Author

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;

Copy link
Contributor Author

@Burnleydev1 Burnleydev1 Mar 17, 2023

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

Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@Burnleydev1 Burnleydev1 Mar 17, 2023

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
Comment on lines 165 to 169
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;

Copy link
Member

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 :-)

Burnleydev1 and others added 5 commits March 16, 2023 17:02
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>
@Burnleydev1 Burnleydev1 marked this pull request as ready for review March 17, 2023 14:07
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
@Burnleydev1 Burnleydev1 requested a review from reynir March 17, 2023 14:33
lib/mbr.mli Outdated
Comment on lines 86 to 88
val make : Partition.t list -> (t, string) result

val make : ?disk_signature:int32 -> 'a list -> 'a
Copy link
Member

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.

Copy link
Contributor Author

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>
@Burnleydev1 Burnleydev1 requested a review from reynir March 17, 2023 16:55
lib/mbr.mli Outdated Show resolved Hide resolved
Burnleydev1 and others added 4 commits March 17, 2023 17:59
Co-authored-by: Reynir Björnsson <reynir@reynir.dk>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
Signed-off-by: Burnleydev1 <abongwabonalais@gmail.com>
@reynir reynir merged commit 783ca87 into mirage:master Mar 20, 2023
@Burnleydev1 Burnleydev1 deleted the disksig branch March 20, 2023 12:58
reynir added a commit to reynir/opam-repository that referenced this pull request Apr 19, 2023
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 'disk signature' argument to 'make'?
2 participants