From: biao716.wang Date: Wed, 23 Dec 2020 13:33:53 +0000 (+0900) Subject: Support f2fs file system X-Git-Tag: submit/trunk/20210201.152700^2~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53d7bcb64a7130257a485dac8094af8857bb46bb;p=tools%2Fmic.git Support f2fs file system Change-Id: I54013ce3ca4d0322ee6a488ef7c00bbefd7fd288 Signed-off-by: biao716.wang --- diff --git a/mic/cmd_chroot.py b/mic/cmd_chroot.py index d7d76ef..35b089b 100755 --- a/mic/cmd_chroot.py +++ b/mic/cmd_chroot.py @@ -53,7 +53,7 @@ def main(parser, args, argv): configmgr.chroot['saveto'] = args.saveto imagetype = misc.get_image_type(targetimage) - if imagetype in ("ext3fsimg", "ext4fsimg", "btrfsimg"): + if imagetype in ("ext3fsimg", "ext4fsimg", "btrfsimg", "f2fsimg"): imagetype = "loop" chrootclass = None diff --git a/mic/imager/loop.py b/mic/imager/loop.py old mode 100755 new mode 100644 index 11db831..a46d0ab --- a/mic/imager/loop.py +++ b/mic/imager/loop.py @@ -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) diff --git a/mic/imager/qcow.py b/mic/imager/qcow.py old mode 100755 new mode 100644 diff --git a/mic/imager/raw.py b/mic/imager/raw.py old mode 100755 new mode 100644 diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py index 160b885..5ddae6b 100755 --- a/mic/utils/fs_related.py +++ b/mic/utils/fs_related.py @@ -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): diff --git a/mic/utils/misc.py b/mic/utils/misc.py index 399fd4e..a49e20f 100755 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -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.*") diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index ceaa351..f35ffd8 100755 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -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) diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index fa24583..697a35e 100755 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -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