]
and filesystem = {
+ fs_dev : device; (** Device containing the filesystem. *)
fs_plugin_id : fs_plugin_id; (** Filesystem type. *)
fs_block_size : int64; (** Block size (bytes). *)
fs_blocks_total : int64; (** Total blocks. *)
let overhead = Int64.of_int32 s_first_data_block in
let overhead = (* XXX *) overhead in
+ (* The blocksize of the filesystem is likely to be quite different
+ * from that of the underlying device, so create an overlay device
+ * with the natural filesystem blocksize.
+ *)
+ let fs_dev = new blocksize_overlay (Int64.to_int block_size) dev in
+
{
+ fs_dev = fs_dev;
fs_plugin_id = plugin_id;
fs_block_size = block_size;
fs_blocks_total = Int64.of_int32 s_blocks_count -^ overhead;
let plugin_id = "linux_swap"
+let blocksize = 4096 (* XXX *)
+let blocksize64 = 4096L (* XXX *)
+
let probe dev =
(* Load the "superblock" (ie. first 0x1000 bytes). *)
let bits = dev#read_bitstring 0L 0x1000 in
padding : 8*0x1000 - 10*8 : bitstring;
"SWAPSPACE2" : 80 : string
} ->
- {
- fs_plugin_id = plugin_id;
- fs_block_size = 4096L; (* XXX *)
- fs_blocks_total = dev#size /^ 4096L;
-
- (* The remaining fields are ignored when fs_is_swap is true. *)
- fs_is_swap = true;
- fs_blocks_reserved = 0L;
- fs_blocks_avail = 0L;
- fs_blocks_used = 0L;
- fs_inodes_total = 0L;
- fs_inodes_reserved = 0L;
- fs_inodes_avail = 0L;
- fs_inodes_used = 0L;
- }
+
+ let fs_dev = new blocksize_overlay blocksize dev in
+ {
+ fs_dev = fs_dev;
+ fs_plugin_id = plugin_id;
+ fs_block_size = blocksize64;
+ fs_blocks_total = fs_dev#size /^ blocksize64;
+
+ (* The remaining fields are ignored when fs_is_swap is true. *)
+ fs_is_swap = true;
+ fs_blocks_reserved = 0L;
+ fs_blocks_avail = 0L;
+ fs_blocks_used = 0L;
+ fs_inodes_total = 0L;
+ fs_inodes_reserved = 0L;
+ fs_inodes_avail = 0L;
+ fs_inodes_used = 0L;
+ }
+
| { _ } ->
raise Not_found (* Not Linux swapspace. *)
method mapblock i = [dev, i *^ Int64.of_int blocksize +^ start]
end
+(* A device with just a modified block size. *)
+class blocksize_overlay new_blocksize (dev : device) =
+object
+ inherit device
+ method name = dev#name
+ method size = dev#size
+ method read offset len = dev#read offset len
+ method blocksize = new_blocksize
+ method mapblock new_blk =
+ let orig_blk =
+ new_blk *^ Int64.of_int new_blocksize /^ Int64.of_int dev#blocksize in
+ dev#mapblock orig_blk
+end
+
(* The null device. Any attempt to read generates an error. *)
let null_device : device =
object
(* Filesystems (also swap devices). *)
and filesystem = {
+ fs_dev : device; (* Device containing the filesystem. *)
fs_plugin_id : fs_plugin_id; (* Filesystem. *)
fs_block_size : int64; (* Block size (bytes). *)
fs_blocks_total : int64; (* Total blocks. *)
method mapblock : int64 -> (device * int64) list
end
+class blocksize_overlay : int -> device ->
+ object
+ method name : string
+ method size : int64
+ method read : int64 -> int -> string
+ method read_bitstring : int64 -> int -> Bitmatch.bitstring
+ method blocksize : int
+ method mapblock : int64 -> (device * int64) list
+ end
+
val null_device : device
type machine = {
]
and filesystem = {
+ fs_dev : device;
fs_plugin_id : fs_plugin_id;
fs_block_size : int64;
fs_blocks_total : int64;