support btrfs and ext4 for creator, chroot, convert
authorGui Chen <gui.chen@intel.com>
Thu, 17 Nov 2011 09:13:04 +0000 (17:13 +0800)
committerGui Chen <gui.chen@intel.com>
Thu, 17 Nov 2011 09:14:36 +0000 (17:14 +0800)
it's not backported from mic2

Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/utils/misc.py
plugins/imager/livecd_plugin.py
plugins/imager/liveusb_plugin.py
plugins/imager/loop_plugin.py
tools/mic

index e6cd294..3188b3c 100644 (file)
@@ -111,6 +111,8 @@ def get_image_type(path):
     rawptn = re.compile(r".*x86 boot sector.*")
     vmdkptn = re.compile(r".*VMware. disk image.*")
     ext3fsimgptn = re.compile(r".*Linux.*ext3 filesystem data.*")
+    ext4fsimgptn = re.compile(r".*Linux.*ext4 filesystem data.*")
+    btrfsimgptn = re.compile(r".*BTRFS.*")
     if isoptn.match(output):
         return maptab["iso"]
     elif usbimgptn.match(output):
@@ -121,6 +123,10 @@ def get_image_type(path):
         return maptab["vmdk"]
     elif ext3fsimgptn.match(output):
         return "ext3fsimg"
+    elif ext4fsimgptn.match(output):
+        return "ext4fsimg"
+    elif btrfsimgptn.match(output):
+        return "btrfsimg"
     else:
         raise CreatorError("Cannot detect the type of image: %s" % path)
 
index fa1d058..ef5590f 100644 (file)
@@ -113,16 +113,22 @@ class LiveCDPlugin(ImagerPlugin):
 
         # unpack image to target dir
         imgsize = misc.get_file_size(os_image) * 1024L * 1024L
-        extmnt = misc.mkdtemp()
-        tfstype = "ext3"
-        tlabel = "ext3 label"
+        imgtype = misc.get_image_type(os_image)
+        if imgtype == "btrfsimg":
+            fstype = "btrfs"
+            myDiskMount = fs_related.BtrfsDiskMount
+        elif imgtype in ("ext3fsimg", "ext4fsimg"):
+            fstype = imgtype[:4]
+            myDiskMount = fs_related.ExtDiskMount
+        else:
+            raise errors.CreatorError("Unsupported filesystem type: %s" % fstype)
 
-        MyDiskMount = fs_related.ExtDiskMount
-        extloop = MyDiskMount(fs_related.SparseLoopbackDisk(os_image, imgsize),
+        extmnt = misc.mkdtemp()
+        extloop = myDiskMount(fs_related.SparseLoopbackDisk(os_image, imgsize),
                               extmnt,
-                              tfstype,
+                              fstype,
                               4096,
-                              tlabel)
+                              "%s label" % fstype)
         try:
             extloop.mount()
 
@@ -162,7 +168,14 @@ class LiveCDPlugin(ImagerPlugin):
 
         convertor = livecd.LiveCDImageCreator()
         convertor.name = os.path.splitext(os.path.basename(base_on))[0]
-        convertor._set_fstype("ext3")
+        imgtype = misc.get_image_type(base_on)
+        if imgtype == "btrfsimg":
+            fstype = "btrfs"
+        elif imgtype in ("ext3fsimg", "ext4fsimg"):
+            fstype = imgtype[:4]
+        else:
+            raise errors.CreatorError("Unsupported filesystem type: %s" % fstype)
+        convertor._set_fstype(fstype)
         try:
             convertor.mount(base_on)
             __mkinitrd(convertor)
@@ -208,6 +221,7 @@ class LiveCDPlugin(ImagerPlugin):
                                           "LiveOS/ext3fs.img nor os.img exist" %img)
 
             imgname = os.path.basename(srcimg)
+            imgname = os.path.splitext(imgname)[0] + ".img"
             rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), imgname)
             shutil.copyfile(os_image, rtimage)
 
index 67d204b..7af6feb 100644 (file)
@@ -113,18 +113,25 @@ class LiveUSBPlugin(ImagerPlugin):
         os_image = cls.do_unpack(target)
         os_image_dir = os.path.dirname(os_image)
 
-        #unpack image to target dir
+        # unpack image to target dir
         imgsize = misc.get_file_size(os_image) * 1024L * 1024L
-        extmnt = misc.mkdtemp()
-        tfstype = "ext3"
-        tlabel = "ext3 label"
+        imgtype = misc.get_image_type(os_image)
+        if imgtype == "btrfsimg":
+            fstype = "btrfs"
+            myDiskMount = fs_related.BtrfsDiskMount
+        elif imgtype in ("ext3fsimg", "ext4fsimg"):
+            fstype = imgtype[:4]
+            myDiskMount = fs_related.ExtDiskMount
+        else:
+            raise errors.CreatorError("Unsupported filesystem type: %s" % fstype)
 
-        MyDiskMount = fs_related.ExtDiskMount
+        extmnt = misc.mkdtemp()
         extloop = MyDiskMount(fs_related.SparseLoopbackDisk(os_image, imgsize),
                               extmnt,
-                              tfstype,
+                              fstype,
                               4096,
-                              tlabel)
+                              "%s label" % fstype)
+
         try:
             extloop.mount()
 
@@ -164,7 +171,14 @@ class LiveUSBPlugin(ImagerPlugin):
 
         convertor = liveusb.LiveUSBImageCreator()
         convertor.name = os.path.splitext(os.path.basename(base_on))[0]
-        convertor._set_fstype("ext3")
+        imgtype = misc.get_image_type(base_on)
+        if imgtype == "btrfsimg":
+            fstype = "btrfs"
+        elif imgtype in ("ext3fsimg", "ext4fsimg"):
+            fstype = imgtype[:4]
+        else:
+            raise errors.CreatorError("Unsupported filesystem type: %s" % fstyp)
+        convertor._set_fstype(fstype)
         try:
             convertor.mount(base_on)
             __mkinitrd(convertor)
@@ -212,6 +226,7 @@ class LiveUSBPlugin(ImagerPlugin):
                 raise errors.CreatorError("'%s' is not a valid live CD ISO : neither "
                                           "LiveOS/ext3fs.img nor os.img exist" %img)
             imgname = os.path.basename(srcimg)
+            imgname = os.path.splitext(imgname)[0] + ".img"
             rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), imgname)
             shutil.copyfile(os_image, rtimage)
 
index f2ca0ee..4dc2236 100644 (file)
@@ -111,12 +111,22 @@ class LoopPlugin(ImagerPlugin):
     def do_chroot(cls, target):#chroot.py parse opts&args
         img = target
         imgsize = misc.get_file_size(img) * 1024L * 1024L
+        imgtype = misc.get_image_type(img)
+        if imgtype == "btrfsimg":
+            fstype = "btrfs"
+            myDiskMount = fs_related.BtrfsDiskMount
+        elif imgtype in ("ext3fsimg", "ext4fsimg"):
+            fstype = imgtype[:4]
+            myDiskMount = fs_related.ExtDiskMount
+        else:
+            raise errors.CreatorError("Unsupported filesystem type: %s" % imgtype)
+
         extmnt = misc.mkdtemp()
-        extloop = fs_related.ExtDiskMount(fs_related.SparseLoopbackDisk(img, imgsize),
+        extloop = myDiskMount(fs_related.SparseLoopbackDisk(img, imgsize),
                                                          extmnt,
-                                                         "ext3",
+                                                         fstype,
                                                          4096,
-                                                         "ext3 label")
+                                                         "%s label" % fstype)
         try:
             extloop.mount()
 
index ee46b0d..82d10f6 100755 (executable)
--- a/tools/mic
+++ b/tools/mic
@@ -145,7 +145,7 @@ class Mic(cmdln.Cmdln):
         self._root_confirm()
 
         imagetype = misc.get_image_type(targetimage)
-        if imagetype == "ext3fsimg":
+        if imagetype in ("ext3fsimg", "ext4fsimg", "btrfsimg"):
             imagetype = "loop"
 
         chrootclass = None