'fsopts': part.fsopts or None,
'aft_fstype': aft_fstype or None,
'extopts': part.extopts or None,
+ 'f2fsopts': part.f2fsopts or None,
'vdfsopts': part.vdfsopts or None,
'squashfsopts': part.squashfsopts or None,
'cpioopts': part.cpioopts or None,
"name": imgname,
"size": self.__image_size or 4096,
"fstype": self.__fstype or "ext3",
+ "f2fsopts": None,
"extopts": None,
"loop": None,
"uuid": None,
if fstype in ("ext2", "ext3", "ext4"):
loop['loop'].extopts = loop['extopts']
+ elif fstype == "f2fs":
+ loop['loop'].f2fsopts = loop['f2fsopts']
try:
msger.verbose('Mounting image "%s" on "%s"' % (imgname, mp))
self.deleteRemovedAttrs()
self.align = kwargs.get("align", None)
self.extopts = kwargs.get("extopts", None)
+ self.f2fsopts = kwargs.get("f2fsopts", None)
self.part_type = kwargs.get("part_type", None)
self.uuid = kwargs.get("uuid", None)
self.exclude_image = kwargs.get("exclude_from_image", False)
retval += " --align"
if self.extopts:
retval += " --extoptions=%s" % self.extopts
+ if self.f2fsopts:
+ retval += " --f2fsoptions=%s" % self.f2fsopts
if self.part_type:
retval += " --part-type=%s" % self.part_type
if self.uuid:
default=None)
op.add_option("--extoptions", type="string", action="store", dest="extopts",
default=None)
+ op.add_option("--f2fsoptions", type="string", action="store", dest="f2fsopts",
+ default=None)
op.add_option("--part-type", type="string", action="store", dest="part_type",
default=None)
op.add_option("--uuid", dest="uuid", action="store", type="string")
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):
+ self.__check_f2fs()
DiskMount.__init__(self, disk, mountdir, fstype, rmmountdir)
self.blocksize = blocksize
self.fslabel = fslabel.replace("/", "")
- self.uuid = fsuuid or str(uuid.uuid4())
+ self.uuid = fsuuid or None
self.skipformat = skipformat
self.fsopts = fsopts
- self.__extopts = None
+ self.__f2fsopts = None
+ self.blkidcmd = find_binary_path("blkid")
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 __get_f2fsopts(self):
+ return self.__f2f2opts
+
+ def __set_f2fsopts(self, val):
+ if val is None:
+ self.__f2fsopts = None
+ else:
+ self.__f2fsopts = val
+ f2fsopts = property(__get_f2fsopts, __set_f2fsopts)
+
+ def __check_f2fs(self):
+ found = False
+ """ Need to load f2fs module to mount it """
+ load_module("f2fs")
+ for line in open("/proc/filesystems").xreadlines():
+ if line.find("f2fs") > -1:
+ found = True
+ break
+ if not found:
+ raise MountError("Your system can't mount f2fs filesystem, please make sure your kernel has f2fs support and the module f2fs.ko has been loaded.")
+
def __parse_field(self, output, field):
- return
+ for line in output.split(" "):
+ if line.startswith(field + "="):
+ return line[len(field) + 1:].strip().replace("\"", "")
+
+ raise KeyError("Failed to find field '%s' in output" % field)
def __format_filesystem(self):
if self.skipformat:
return
msger.verbose("Formating %s filesystem on %s" % (self.fstype, self.disk.device))
- rc = runner.show([self.mkfscmd, "-l", self.fslabel, self.disk.device])
+
+ cmdlist = [self.mkfscmd, "-l", self.fslabel]
+ if self.__f2fsopts:
+ cmdlist.extend(self.__f2fsopts.split())
+ cmdlist.extend([self.disk.device])
+
+ rc, errout = runner.runtool(cmdlist, catch=2)
if rc != 0:
- raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device))
+ raise MountError("Error creating %s filesystem on disk %s:\n%s" %
+ (self.fstype, self.disk.device, errout))
+
+ self.uuid = self.__parse_field(runner.outs([self.blkidcmd, self.disk.device]), "UUID")
def __resize_filesystem(self, size = None):
msger.info("Resizing filesystem ...")