X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=lib%2Fdiskimage_ext2.ml;h=ade794023c9cd427fc7f85e8d100b3cf05004df8;hb=7a5fc851494dacaae801ef578c2b68d6184543f4;hp=0457597147bccd551dfbc473f03430b3287fe6eb;hpb=9611aba66734efe3e2f1e0792a90003b657a89f5;p=virt-df.git diff --git a/lib/diskimage_ext2.ml b/lib/diskimage_ext2.ml index 0457597..ade7940 100644 --- a/lib/diskimage_ext2.ml +++ b/lib/diskimage_ext2.ml @@ -22,13 +22,22 @@ open Unix open Printf -open Diskimage_utils +open Diskimage_impl -let superblock_offset = 1024L +open Int63.Operators -let probe_ext2 dev = +let ( +* ) = Int32.add +let ( -* ) = Int32.sub +let ( ** ) = Int32.mul +let ( /* ) = Int32.div + +let id = "ext2" +let superblock_offset = ~^1024 +let superblock_len = ~^1024 + +let rec probe dev = (* Load the superblock. *) - let bits = dev#read_bitstring superblock_offset 1024 in + let bits = dev#read_bitstring superblock_offset superblock_len in (* The structure is straight from /usr/include/linux/ext3_fs.h *) bitmatch bits with @@ -87,8 +96,7 @@ let probe_ext2 dev = (* Work out the block size in bytes. *) let s_log_block_size = Int32.to_int s_log_block_size in - let block_size = 1024L in - let block_size = Int64.shift_left block_size s_log_block_size in + let block_size = ~^1024 <^< s_log_block_size in (* Number of groups. *) let s_groups_count = @@ -109,26 +117,47 @@ let probe_ext2 dev = (* Calculate the block overhead (used by superblocks, inodes, etc.) * See fs/ext2/super.c. *) - let overhead = Int64.of_int32 s_first_data_block in + let overhead = Int63.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 block_size dev in + { - fs_name = "Linux ext2/3"; - fs_block_size = block_size; - fs_blocks_total = Int64.of_int32 s_blocks_count -^ overhead; + fs_cb = callbacks; + fs_dev = fs_dev; + + fs_blocksize = block_size; + fs_blocks_total = Int63.of_int32 s_blocks_count -^ overhead; + fs_is_swap = false; - fs_blocks_reserved = Int64.of_int32 s_r_blocks_count; - fs_blocks_avail = Int64.of_int32 s_free_blocks_count; + + fs_blocks_reserved = Int63.of_int32 s_r_blocks_count; + fs_blocks_avail = Int63.of_int32 s_free_blocks_count; fs_blocks_used = - Int64.of_int32 s_blocks_count -^ overhead - -^ Int64.of_int32 s_free_blocks_count; - fs_inodes_total = Int64.of_int32 s_inodes_count; - fs_inodes_reserved = 0L; (* XXX? *) - fs_inodes_avail = Int64.of_int32 s_free_inodes_count; - fs_inodes_used = Int64.of_int32 s_inodes_count - (*-^ 0L*) - -^ Int64.of_int32 s_free_inodes_count; + Int63.of_int32 s_blocks_count -^ overhead + -^ Int63.of_int32 s_free_blocks_count; + fs_inodes_total = Int63.of_int32 s_inodes_count; + fs_inodes_reserved = ~^0; (* XXX? *) + fs_inodes_avail = Int63.of_int32 s_free_inodes_count; + fs_inodes_used = Int63.of_int32 s_inodes_count + (*-^ 0*) + -^ Int63.of_int32 s_free_inodes_count; } | { _ } -> raise Not_found (* Not an EXT2/3 superblock. *) + +and offset_is_free _ _ = false + +and callbacks = { + fs_cb_name = id; + fs_cb_printable_name = "Linux ext2/3"; + fs_cb_offset_is_free = offset_is_free; +} + +(* Register the plugin. *) +let () = register_plugin ~filesystem:probe id