-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from djs55/add-skeleton
Add `fold_s`
- Loading branch information
Showing
13 changed files
with
154 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(* | ||
* Copyright (C) 2015 David Scott <dave.scott@unikernel.com> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
*) | ||
|
||
let fold_s = Mirage_block_iter.fold_s | ||
|
||
let compare = Mirage_block_compare.compare | ||
|
||
let copy = Mirage_block_copy.copy | ||
|
||
let random = Mirage_block_patterns.random | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(* | ||
* Copyright (C) 2015 David Scott <dave.scott@unikernel.com> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
*) | ||
|
||
(** Utility functions over Mirage [BLOCK] devices *) | ||
|
||
val compare: | ||
(module V1_LWT.BLOCK with type t = 'a) -> 'a -> | ||
(module V1_LWT.BLOCK with type t = 'b) -> 'b -> | ||
[ `Ok of int | `Error of [> `Msg of string ]] Lwt.t | ||
(** Compare the contents of two block devices. *) | ||
|
||
val fold_s: | ||
f:('a -> int64 -> Cstruct.t -> 'a Lwt.t) -> 'a -> | ||
(module V1_LWT.BLOCK with type t = 'b) -> 'b -> | ||
[ `Ok of 'a | `Error of [> `Msg of string ]] Lwt.t | ||
(** Folds [f] across blocks read sequentially from a block device *) | ||
|
||
val copy: | ||
(module V1_LWT.BLOCK with type t = 'a) -> 'a -> | ||
(module V1_LWT.BLOCK with type t = 'b) -> 'b -> | ||
[ `Ok of unit | `Error of [> `Msg of string | `Is_read_only | `Different_sizes ]] Lwt.t | ||
(** Copy all data from a source BLOCK device to a destination BLOCK device. | ||
Fails with `Different_sizes if the source and destination are not exactly | ||
the same size. | ||
Fails with `Is_read_only if the destination device is read-only. | ||
*) | ||
|
||
val random: | ||
(module V1_LWT.BLOCK with type t = 'a) -> 'a -> | ||
[ `Ok of unit | `Error of [> `Msg of string ]] Lwt.t | ||
(** Fill a block device with pseudorandom data *) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(* | ||
* Copyright (C) 2015 David Scott <dave.scott@unikernel.com> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
*) | ||
open Lwt | ||
|
||
let error_to_string = function | ||
| `Unknown x -> x | ||
| `Unimplemented -> "Unimplemented" | ||
| `Is_read_only -> "Is_read_only" | ||
| `Disconnected -> "Disconnected" | ||
|
||
let fold_s ~f init | ||
(type block) (module Block: V1_LWT.BLOCK with type t = block) (b: block) = | ||
Block.get_info b | ||
>>= fun info -> | ||
let buffer = Io_page.(to_cstruct (get 8)) in | ||
let sectors = Cstruct.len buffer / info.Block.sector_size in | ||
|
||
let rec loop acc next = | ||
if next >= info.Block.size_sectors | ||
then return (`Ok acc) | ||
else begin | ||
let remaining = Int64.sub info.Block.size_sectors next in | ||
let this_time = min sectors (Int64.to_int remaining) in | ||
let buf = Cstruct.sub buffer 0 (info.Block.sector_size * this_time) in | ||
Block.read b next [ buf ] | ||
>>= function | ||
| `Error e -> | ||
return (`Error (`Msg (error_to_string e))) | ||
| `Ok () -> | ||
f acc Int64.(mul next (of_int info.Block.sector_size)) buf | ||
>>= fun acc -> | ||
loop acc Int64.(add next (of_int this_time)) | ||
end in | ||
loop init 0L |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(* | ||
* Copyright (C) 2015 David Scott <dave.scott@unikernel.com> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
*) | ||
|
||
val fold_s: | ||
f:('a -> int64 -> Cstruct.t -> 'a Lwt.t) -> 'a -> | ||
(module V1_LWT.BLOCK with type t = 'b) -> 'b -> | ||
[ `Ok of 'a | `Error of [> `Msg of string ]] Lwt.t | ||
(** Folds [f] across blocks read sequentially from a block device *) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters