From 091ddc2dd90ad9985aca308657d8120781defc11 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Detect Linux software suspend partitions (thanks Stephen Tweedie). --- lib/.depend | 13 ++++++--- lib/Makefile.in | 1 + lib/diskimage.ml | 2 ++ lib/diskimage_linux_swap.ml | 2 +- lib/diskimage_linux_swsuspend.ml | 61 +++++++++++++++++++++++++++++++++++++++ lib/diskimage_linux_swsuspend.mli | 23 +++++++++++++++ 6 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 lib/diskimage_linux_swsuspend.ml create mode 100644 lib/diskimage_linux_swsuspend.mli diff --git a/lib/.depend b/lib/.depend index 406b891..fa24106 100644 --- a/lib/.depend +++ b/lib/.depend @@ -1,5 +1,6 @@ diskimage_ext2.cmi: diskimage_utils.cmi diskimage_linux_swap.cmi: diskimage_utils.cmi +diskimage_linux_swsuspend.cmi: diskimage_utils.cmi diskimage_lvm2_metadata.cmi: int63.cmi diskimage_lvm2.cmi: diskimage_utils.cmi diskimage_lvm2_parser.cmi: int63.cmi diskimage_lvm2_metadata.cmi @@ -14,6 +15,10 @@ diskimage_linux_swap.cmo: int63.cmi diskimage_utils.cmi \ /usr/lib64/ocaml/bitmatch/bitmatch.cmi diskimage_linux_swap.cmi diskimage_linux_swap.cmx: int63.cmx diskimage_utils.cmx \ /usr/lib64/ocaml/bitmatch/bitmatch.cmi diskimage_linux_swap.cmi +diskimage_linux_swsuspend.cmo: int63.cmi diskimage_utils.cmi \ + /usr/lib64/ocaml/bitmatch/bitmatch.cmi diskimage_linux_swsuspend.cmi +diskimage_linux_swsuspend.cmx: int63.cmx diskimage_utils.cmx \ + /usr/lib64/ocaml/bitmatch/bitmatch.cmi diskimage_linux_swsuspend.cmi diskimage_lvm2_metadata.cmo: int63.cmi diskimage_lvm2_metadata.cmi diskimage_lvm2_metadata.cmx: int63.cmx diskimage_lvm2_metadata.cmi diskimage_lvm2.cmo: int63.cmi diskimage_utils.cmi diskimage_lvm2_metadata.cmi \ @@ -29,11 +34,11 @@ diskimage_mbr.cmo: int63.cmi diskimage_utils.cmi \ diskimage_mbr.cmx: int63.cmx diskimage_utils.cmx \ /usr/lib64/ocaml/bitmatch/bitmatch.cmi diskimage_mbr.cmi diskimage.cmo: int63.cmi diskimage_utils.cmi diskimage_mbr.cmi \ - diskimage_lvm2.cmi diskimage_linux_swap.cmi diskimage_ext2.cmi \ - diskimage.cmi + diskimage_lvm2.cmi diskimage_linux_swsuspend.cmi diskimage_linux_swap.cmi \ + diskimage_ext2.cmi diskimage.cmi diskimage.cmx: int63.cmx diskimage_utils.cmx diskimage_mbr.cmx \ - diskimage_lvm2.cmx diskimage_linux_swap.cmx diskimage_ext2.cmx \ - diskimage.cmi + diskimage_lvm2.cmx diskimage_linux_swsuspend.cmx diskimage_linux_swap.cmx \ + diskimage_ext2.cmx diskimage.cmi diskimage_utils.cmo: int63.cmi diskimage_utils.cmi diskimage_utils.cmx: int63.cmx diskimage_utils.cmi int63.cmo: int63.cmi diff --git a/lib/Makefile.in b/lib/Makefile.in index 185969e..0b7926a 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -39,6 +39,7 @@ OBJS := int63.cmo \ # Plugin objects. OBJS += diskimage_ext2.cmo \ diskimage_linux_swap.cmo \ + diskimage_linux_swsuspend.cmo \ diskimage_lvm2_metadata.cmo \ diskimage_lvm2_parser.cmo \ diskimage_lvm2_lexer.cmo \ diff --git a/lib/diskimage.ml b/lib/diskimage.ml index b08c50d..6f9ef1f 100644 --- a/lib/diskimage.ml +++ b/lib/diskimage.ml @@ -40,6 +40,8 @@ let filesystem_types = [ ("Linux ext2/3", Diskimage_ext2.probe); Diskimage_linux_swap.plugin_id, ("Linux swap", Diskimage_linux_swap.probe); + Diskimage_linux_swsuspend.plugin_id, + ("Linux s/w suspend", Diskimage_linux_swsuspend.probe); ] let lvm_types = [ diff --git a/lib/diskimage_linux_swap.ml b/lib/diskimage_linux_swap.ml index b9f01b1..b8c49e6 100644 --- a/lib/diskimage_linux_swap.ml +++ b/lib/diskimage_linux_swap.ml @@ -35,7 +35,7 @@ let probe dev = | { (* Actually this isn't just padding. *) padding : 8*0x1000 - 10*8 : bitstring; - "SWAPSPACE2" : 80 : string + ("SWAP-SPACE"|"SWAPSPACE2") : 80 : string } -> let fs_dev = new blocksize_overlay blocksize dev in diff --git a/lib/diskimage_linux_swsuspend.ml b/lib/diskimage_linux_swsuspend.ml new file mode 100644 index 0000000..5f29286 --- /dev/null +++ b/lib/diskimage_linux_swsuspend.ml @@ -0,0 +1,61 @@ +(* 'df' command for virtual domains. + + (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc. + http://libvirt.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Support for Linux software suspend partitions. +*) + +open Diskimage_utils + +open Int63.Operators + +let plugin_id = "linux_swsuspend" +let blocksize = ~^4096 (* XXX *) + +let probe dev = + (* Load the "superblock" (ie. first 0x1000 bytes). *) + let bits = dev#read_bitstring ~^0 ~^0x1000 in + + bitmatch bits with + | { + (* Actually this isn't just padding. *) + padding : 8*0x1000 - 10*8 : bitstring; + ("S1SUSPEND"|"S2SUSPEND") : 80 : string + } -> + + let fs_dev = new blocksize_overlay blocksize dev in + { + fs_plugin_id = plugin_id; + fs_dev = fs_dev; + + fs_blocksize = blocksize; + fs_blocks_total = fs_dev#size /^ blocksize; + + (* The remaining fields are ignored when fs_is_swap is true. *) + fs_is_swap = true; + fs_blocks_reserved = ~^0; + fs_blocks_avail = ~^0; + fs_blocks_used = ~^0; + fs_inodes_total = ~^0; + fs_inodes_reserved = ~^0; + fs_inodes_avail = ~^0; + fs_inodes_used = ~^0; + } + + | { _ } -> + raise Not_found (* Not Linux software suspend. *) diff --git a/lib/diskimage_linux_swsuspend.mli b/lib/diskimage_linux_swsuspend.mli new file mode 100644 index 0000000..df0c1fd --- /dev/null +++ b/lib/diskimage_linux_swsuspend.mli @@ -0,0 +1,23 @@ +(* 'df' command for virtual domains. + (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc. + http://libvirt.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *) + +(**/**) + +val plugin_id : string +val probe : Diskimage_utils.device -> Diskimage_utils.filesystem -- 1.8.3.1