From dd4973936aac7090bbe17ed502fba6c7b5467907 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Add a fs_dev field to filesystem --- lib/diskimage.mli | 1 + lib/diskimage_ext2.ml | 7 +++++++ lib/diskimage_linux_swap.ml | 37 ++++++++++++++++++++++--------------- lib/diskimage_utils.ml | 15 +++++++++++++++ lib/diskimage_utils.mli | 11 +++++++++++ 5 files changed, 56 insertions(+), 15 deletions(-) diff --git a/lib/diskimage.mli b/lib/diskimage.mli index 5711630..09d791e 100644 --- a/lib/diskimage.mli +++ b/lib/diskimage.mli @@ -194,6 +194,7 @@ and partition_content = ] 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. *) diff --git a/lib/diskimage_ext2.ml b/lib/diskimage_ext2.ml index 1b70977..f9913ca 100644 --- a/lib/diskimage_ext2.ml +++ b/lib/diskimage_ext2.ml @@ -113,7 +113,14 @@ let probe dev = 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; diff --git a/lib/diskimage_linux_swap.ml b/lib/diskimage_linux_swap.ml index 8f15651..ae8c405 100644 --- a/lib/diskimage_linux_swap.ml +++ b/lib/diskimage_linux_swap.ml @@ -24,6 +24,9 @@ open Diskimage_utils 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 @@ -34,20 +37,24 @@ let probe dev = 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. *) diff --git a/lib/diskimage_utils.ml b/lib/diskimage_utils.ml index 00c085e..84eec94 100644 --- a/lib/diskimage_utils.ml +++ b/lib/diskimage_utils.ml @@ -137,6 +137,20 @@ object 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 @@ -189,6 +203,7 @@ and partition_content = (* 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. *) diff --git a/lib/diskimage_utils.mli b/lib/diskimage_utils.mli index 0a46197..bc67474 100644 --- a/lib/diskimage_utils.mli +++ b/lib/diskimage_utils.mli @@ -53,6 +53,16 @@ class offset_device : string -> int64 -> int64 -> int -> device -> 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 = { @@ -94,6 +104,7 @@ and partition_content = ] and filesystem = { + fs_dev : device; fs_plugin_id : fs_plugin_id; fs_block_size : int64; fs_blocks_total : int64; -- 1.8.3.1