Support f2fs file system 32/250332/8
authorbiao716.wang <biao716.wang@samsung.com>
Wed, 23 Dec 2020 13:33:53 +0000 (22:33 +0900)
committerbiao716.wang <biao716.wang@samsung.com>
Mon, 4 Jan 2021 08:26:50 +0000 (17:26 +0900)
Change-Id: I54013ce3ca4d0322ee6a488ef7c00bbefd7fd288
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
mic/cmd_chroot.py
mic/imager/loop.py [changed mode: 0755->0644]
mic/imager/qcow.py [changed mode: 0755->0644]
mic/imager/raw.py [changed mode: 0755->0644]
mic/utils/fs_related.py
mic/utils/misc.py
plugins/imager/loop_plugin.py
plugins/imager/raw_plugin.py

index d7d76ef..35b089b 100755 (executable)
@@ -53,7 +53,7 @@ def main(parser, args, argv):
     configmgr.chroot['saveto'] = args.saveto\r
 \r
     imagetype = misc.get_image_type(targetimage)\r
-    if imagetype in ("ext3fsimg", "ext4fsimg", "btrfsimg"):\r
+    if imagetype in ("ext3fsimg", "ext4fsimg", "btrfsimg", "f2fsimg"):\r
         imagetype = "loop"\r
 \r
     chrootclass = None\r
old mode 100755 (executable)
new mode 100644 (file)
index 11db831..a46d0ab
@@ -376,6 +376,8 @@ class LoopImageCreator(BaseImageCreator):
                 MyDiskMount = fs.BtrfsDiskMount
             elif fstype in ("vfat", "msdos"):
                 MyDiskMount = fs.VfatDiskMount
+            elif fstype == "f2fs":
+                MyDiskMount = fs.F2fsDiskMount
             else:
                 raise MountError('Cannot support fstype: %s' % fstype)
 
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 160b885..5ddae6b 100755 (executable)
@@ -446,6 +446,94 @@ class DiskMount(Mount):
 
         self.mounted = True
 
+class F2fsDiskMount(DiskMount):
+    """A DiskMount object that is able to format/resize f2fs filesystems."""
+    def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None, fsuuid=None):
+        DiskMount.__init__(self, disk, mountdir, fstype, rmmountdir)
+        self.blocksize = blocksize
+        self.fslabel = fslabel.replace("/", "")
+        self.uuid = fsuuid or str(uuid.uuid4())
+        self.skipformat = skipformat
+        self.fsopts = fsopts
+        self.__extopts = None
+        self.dumpe2fs = find_binary_path("dump." + self.fstype)
+        self.fsckcmd = find_binary_path("fsck." + self.fstype)
+        self.resizecmd = find_binary_path("resize." + self.fstype)
+
+    def __parse_field(self, output, field):
+        return
+
+    def __format_filesystem(self):
+        if self.skipformat:
+            msger.debug("Skip filesystem format.")
+            return
+
+        msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
+        rc = runner.show([self.mkfscmd, "-l", self.fslabel, self.disk.device])
+        if rc != 0:
+            raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device))
+
+    def __resize_filesystem(self, size = None):
+        msger.info("Resizing filesystem ...")
+        current_size = os.stat(self.disk.lofile)[stat.ST_SIZE]
+
+        if size is None:
+            size = self.disk.size
+
+        if size == current_size:
+            return
+
+        if size > current_size:
+            self.disk.expand(size=size)
+
+        self.__fsck()
+
+        return size
+
+    def __create(self):
+        resize = False
+        if not self.disk.fixed() and self.disk.exists():
+            resize = True
+
+        self.disk.create()
+
+        if resize:
+            self.__resize_filesystem()
+        else:
+            self.__format_filesystem()
+
+    def mount(self, options = None, init_expand = False):
+        self.__create()
+        if init_expand:
+            expand_size = long(self.disk.size * 1.5)
+            msger.info("Initial partition size expanded : %ld -> %ld" % (self.disk.size, expand_size))
+            self.__resize_filesystem(expand_size)
+            self.disk.reread_size()
+        DiskMount.mount(self, options)
+
+    def __fsck(self):
+        msger.info("Checking filesystem %s" % self.disk.lofile)
+        runner.quiet([self.fsckcmd, self.disk.lofile])
+
+    def __get_size_from_filesystem(self):
+        return self.disk.size
+
+    def __resize_to_minimal(self):
+        msger.info("Resizing filesystem to minimal ...")
+        self.__fsck()
+
+        return self.__get_size_from_filesystem()
+
+    def resparse(self, size = None):
+        self.cleanup()
+        if size == 0:
+            minsize = 0
+        else:
+            minsize = self.__resize_to_minimal()
+            self.disk.truncate(minsize)
+            self.__resize_filesystem(size)
+        return minsize
+
 class ExtDiskMount(DiskMount):
     """A DiskMount object that is able to format/resize ext[23] filesystems."""
     def __init__(self, disk, mountdir, fstype, blocksize, fslabel, rmmountdir=True, skipformat = False, fsopts = None, fsuuid=None):
index 399fd4e..a49e20f 100755 (executable)
@@ -375,6 +375,11 @@ def get_image_type(path):
     if file_header[0:len(vdi_flag)] == vdi_flag:
         return maptab["vdi"]
 
+    #Checking f2fs fs type.
+    blkidcmd = find_binary_path("blkid")
+    out = runner.outs([blkidcmd, '-o', 'value', '-s', 'TYPE', path])
+    if out == "f2fs":
+        return "f2fsimg"
     output = runner.outs(['file', path])
     isoptn = re.compile(r".*ISO 9660 CD-ROM filesystem.*(bootable).*")
     usbimgptn = re.compile(r".*x86 boot sector.*active.*")
index ceaa351..f35ffd8 100755 (executable)
@@ -166,6 +166,9 @@ class LoopPlugin(ImagerPlugin):
         elif imgtype in ("ext3fsimg", "ext4fsimg"):
             fstype = imgtype[:4]
             myDiskMount = fs_related.ExtDiskMount
+        elif imgtype == "f2fsimg":
+            fstype = "f2fs"
+            myDiskMount = fs_related.F2fsDiskMount
         else:
             raise errors.CreatorError("Unsupported filesystem type: %s" \
                                       % imgtype)
index fa24583..697a35e 100755 (executable)
@@ -143,7 +143,7 @@ class RawPlugin(ImagerPlugin):
                 # not recognize properly.
                 # TODO: Can we make better assumption?
                 fstype = "btrfs"
-            elif partition_info[5] in [ "ext2", "ext3", "ext4", "btrfs" ]:
+            elif partition_info[5] in [ "ext2", "ext3", "ext4", "btrfs", "f2fs" ]:
                 fstype = partition_info[5]
             elif partition_info[5] in [ "fat16", "fat32" ]:
                 fstype = "vfat"
@@ -155,7 +155,7 @@ class RawPlugin(ImagerPlugin):
 
             if rootpart and rootpart == line[0]:
                 mountpoint = '/'
-            elif not root_mounted and fstype in [ "ext2", "ext3", "ext4", "btrfs" ]:
+            elif not root_mounted and fstype in [ "ext2", "ext3", "ext4", "btrfs", "f2fs" ]:
                 # TODO: Check that this is actually the valid root partition from /etc/fstab
                 mountpoint = "/"
                 root_mounted = True