[gparted] Handle missing FS size information before f2fs-tools 1.5.0 (!29)



commit 66a20ae9fa6f2bd5ecd9e246a44559f8bb0b9919
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Tue Mar 19 19:27:39 2019 +0000

    Handle missing FS size information before f2fs-tools 1.5.0 (!29)
    
    Before this commit [1] first included in f2fs-tools 1.5.0, dump.f2fs
    didn't report the total space used by the file system.  This causes F2FS
    file system usage not be reported on older distributions, including
    RHEL/CentOS 7 and Debian 8.
    
    On CentOS 7:
        # rpm -q f2fs-tools
        f2fs-tools-1.4.1-2.el7.nux.x86_64
        # dump.f2fs -d 1 /dev/sdb3 | egrep 'sector size =|total.*sectors ='
        Info: sector size = 512
        Info: total sectors = 2097152 (in 512 bytes)
    
    On Fedora 28:
        # rpm -q f2fs-tools
        f2f2-tools-1.10.0-1.fc28.x86_64
        # dump.f2fs -d 1 /dev/sdb2 | egrep -a 'sector size =|total.*sectors ='
        Info: sector size = 512
        Info: total sectors = 3145728 (1536 MB)
        Info: total FS sectors = 2621440 (1280 MB)
    
    "total sectors" reports the size of the partition.
    "total FS sectors" reports the size of the file system.
    
    Cope with the file system size being missing.  Pass -1 as the file
    system size to partition.set_sector_usage() in this case.  Note that
    this means GParted won't be able to detect and report unallocated space
    within the partition when using f2fs-tools < 1.5.0.
    
    [1] 
https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?id=fea6162a6db9af527648262d9fbb0335a0cc5460
        fsck.f2fs: show total sectors consumed by filesystem
    
    Closes !29 - Enhance F2FS support

 src/f2fs.cc | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
---
diff --git a/src/f2fs.cc b/src/f2fs.cc
index b619cc04..7ef62bd4 100644
--- a/src/f2fs.cc
+++ b/src/f2fs.cc
@@ -97,15 +97,20 @@ void f2fs::set_used_sectors(Partition & partition)
        if (index < output.length())
                sscanf(output.substr(index).c_str(), "Info: total FS sectors = %lld", &total_fs_sectors);
 
-       if (user_block_count > -1 && valid_block_count > -1 &&
-           log_blocksize > -1 && fs_sector_size > -1 && total_fs_sectors > -1)
+       if (user_block_count > -1 && valid_block_count > -1 && log_blocksize > -1)
        {
                long long blocksize  = 1 << log_blocksize;
                long long fs_free_bytes = (user_block_count - valid_block_count) * blocksize;
-               long long fs_size_bytes = total_fs_sectors * fs_sector_size;
-
                Sector fs_free_sectors = fs_free_bytes / partition.sector_size;
-               Sector fs_size_sectors = fs_size_bytes / partition.sector_size;
+
+               // dump.f2fs < 1.5.0 doesn't report "total FS sectors" so leave
+               // fs_size_sectors = -1 for unknown.
+               Sector fs_size_sectors = -1;
+               if (fs_sector_size > -1 && total_fs_sectors > -1)
+               {
+                       long long fs_size_bytes = total_fs_sectors * fs_sector_size;
+                       fs_size_sectors = fs_size_bytes / partition.sector_size;
+               }
 
                partition.set_sector_usage(fs_size_sectors, fs_free_sectors);
                partition.fs_block_size = blocksize;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]