Skip to content

Commit

Permalink
Merge pull request #1307 from vojtechtrefny/main_fat-resize
Browse files Browse the repository at this point in the history
VFAT resize support
  • Loading branch information
vojtechtrefny authored Oct 23, 2024
2 parents 6b57567 + 58bdab9 commit 26783f2
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
6 changes: 6 additions & 0 deletions blivet/formats/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,15 @@ class FATFS(FS):
_uuidfs = fsuuid.FATFSUUID()
_supported = True
_formattable = True
_resizable = True
_resize_support = FSResize.OFFLINE_GROW | FSResize.OFFLINE_SHRINK
_max_size = Size("1 TiB")
_packages = ["dosfstools"]
_fsck_class = fsck.DosFSCK
_info_class = fsinfo.FATFSInfo
_minsize_class = fsminsize.FATFSMinSize
_resize_class = fsresize.FATFSResize
_size_info_class = fssize.FATFSSize
_mkfs_class = fsmkfs.FATFSMkfs
_mount_class = fsmount.FATFSMount
_readlabel_class = fsreadlabel.DosFSReadLabel
Expand Down
1 change: 1 addition & 0 deletions blivet/tasks/availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ class FSOperation():
BLOCKDEV_EXT_RESIZE = blockdev_fs_plugin_operation(BlockDevFSMethod(FSOperation.RESIZE, blockdev.fs.can_resize, "ext2"))
BLOCKDEV_XFS_RESIZE = blockdev_fs_plugin_operation(BlockDevFSMethod(FSOperation.RESIZE, blockdev.fs.can_resize, "xfs"))
BLOCKDEV_NTFS_RESIZE = blockdev_fs_plugin_operation(BlockDevFSMethod(FSOperation.RESIZE, blockdev.fs.can_resize, "ntfs"))
BLOCKDEV_VFAT_RESIZE = blockdev_fs_plugin_operation(BlockDevFSMethod(FSOperation.RESIZE, blockdev.fs.can_resize, "vfat"))

BLOCKDEV_EXT_INFO = blockdev_fs_plugin_operation(BlockDevFSMethod(FSOperation.INFO, blockdev.fs.can_get_size, "ext2"))
BLOCKDEV_XFS_INFO = blockdev_fs_plugin_operation(BlockDevFSMethod(FSOperation.INFO, blockdev.fs.can_get_size, "xfs"))
Expand Down
7 changes: 7 additions & 0 deletions blivet/tasks/fsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,12 @@ def _get_info(self):
return BlockDev.fs.xfs_get_info(self.fs.device)


class FATFSInfo(FSInfo):
ext = availability.BLOCKDEV_VFAT_INFO

def _get_info(self):
return BlockDev.fs.vfat_get_info(self.fs.device)


class UnimplementedFSInfo(fstask.UnimplementedFSTask):
pass
18 changes: 18 additions & 0 deletions blivet/tasks/fsminsize.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,23 @@ def do_task(self): # pylint: disable=arguments-differ
return min_size


class FATFSMinSize(FSMinSize):
ext = availability.BLOCKDEV_VFAT_INFO

def do_task(self): # pylint: disable=arguments-differ
error_msgs = self.availability_errors
if error_msgs:
raise FSError("\n".join(error_msgs))

try:
info = BlockDev.fs.vfat_get_info(self.fs.device)
except BlockDev.FSError as e:
raise FSError("failed to get fs min size: %s" % e)
min_size = Size((info.free_cluster_count - info.free_cluster_count) * info.cluster_size)
# resizing below 32 MiB would require changing from VFAT/FAT32 to FAT16 which is not
# currently supported by libparted which libblockdev uses for FAT resize
return max(min_size, Size("32 MiB"))


class UnimplementedFSMinSize(fstask.UnimplementedFSTask):
pass
16 changes: 15 additions & 1 deletion blivet/tasks/fsresize.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class FSResize(task.BasicApplication, FSResizeTask):

# IMPLEMENTATION methods

@property
def fs_type(self):
return self.fs.type

def do_task(self): # pylint: disable=arguments-differ
""" Resize the device.
Expand All @@ -57,7 +61,7 @@ def do_task(self): # pylint: disable=arguments-differ
raise FSError("\n".join(error_msgs))

try:
BlockDev.fs.resize(self.fs.device, self.fs.target_size.convert_to(B), self.fs.type)
BlockDev.fs.resize(self.fs.device, self.fs.target_size.convert_to(B), self.fs_type)
except BlockDev.FSError as e:
raise FSError(str(e))

Expand All @@ -77,6 +81,16 @@ class XFSResize(FSResize):
unit = B


class FATFSResize(FSResize):
ext = availability.BLOCKDEV_VFAT_RESIZE
unit = B

@property
def fs_type(self):
# we don't want 'efi' to be used for EFIFS
return "vfat"


class TmpFSResize(FSResize):
ext = availability.BLOCKDEV_FS_PLUGIN
unit = MiB
Expand Down
5 changes: 5 additions & 0 deletions blivet/tasks/fssize.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def _get_size(self):
return Size(self.fs._current_info.block_size * self.fs._current_info.block_count)


class FATFSSize(FSSize):
def _get_size(self):
return Size(self.fs._current_info.cluster_size * self.fs._current_info.cluster_count)


class TmpFSSize(fstask.FSTask):
description = "current filesystem size"

Expand Down
3 changes: 3 additions & 0 deletions misc/install-test-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- gfs2-utils
- stratisd
- stratis-cli
- libblockdev-tools
when: ansible_distribution == 'Fedora' and test_dependencies|bool

####### CentOS 9/10
Expand Down Expand Up @@ -103,6 +104,7 @@
- iscsi-initiator-utils
- stratisd
- stratis-cli
- libblockdev-tools
when: ansible_distribution == 'CentOS' and test_dependencies|bool

- name: Install additional test dependencies (CentOS 9)
Expand Down Expand Up @@ -175,6 +177,7 @@
- targetcli-fb
- open-iscsi
- gfs2-utils
- libblockdev-tools
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' and test_dependencies|bool

- name: Install libmount (Debian/Ubuntu)
Expand Down
2 changes: 1 addition & 1 deletion tests/storage_tests/formats_test/fstesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def test_shrink(self):
an_fs.target_size = TARGET_SIZE
self.assertIsNone(an_fs.do_resize())

TARGET_SIZE = TARGET_SIZE / 2
TARGET_SIZE = TARGET_SIZE - Size("10 MiB")
self.assertTrue(TARGET_SIZE > an_fs.min_size)
an_fs.target_size = TARGET_SIZE
self.assertEqual(an_fs.target_size, TARGET_SIZE)
Expand Down

0 comments on commit 26783f2

Please sign in to comment.