[gparted] Just pass sector size to detect_filesystem_internal() (!46)(#16)



commit 5bb3415bcb9106560b581e4180fcb93ae5f8fa45
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Thu Jul 11 19:33:45 2019 +0100

    Just pass sector size to detect_filesystem_internal() (!46)(#16)
    
    After the previous commit the lp_device structure pointer parameter is
    only used to provide sector_size.  Just pass that instead.
    
    Closes !46 - Whole device FAT32 file system reports device busy warning
                 from mlabel
    Closes #16 - "invalid argument for seek()" error on very small (<=40KiB)
                 drives

 include/GParted_Core.h |  2 +-
 src/GParted_Core.cc    | 18 +++++++++---------
 2 files changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index b9b12ad8..5c72260c 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -89,7 +89,7 @@ private:
                                       std::vector<Glib::ustring> & messages );
        void set_luks_partition( PartitionLUKS & partition );
        void set_partition_label_and_uuid( Partition & partition );
-       static FSType detect_filesystem_internal(const Glib::ustring& path, const PedDevice* lp_device);
+       static FSType detect_filesystem_internal(const Glib::ustring& path, Byte_Value sector_size);
        static FSType detect_filesystem( PedDevice * lp_device, PedPartition * lp_partition,
                                         std::vector<Glib::ustring> & messages );
        void read_label( Partition & partition ) ;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index d5ada63f..93b17bce 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -1119,13 +1119,13 @@ void GParted_Core::set_partition_label_and_uuid( Partition & partition )
 
 // GParted simple internal file system signature detection.  Use sparingly.  Only when
 // (old versions of) blkid and libparted don't recognise a signature.
-FSType GParted_Core::detect_filesystem_internal(const Glib::ustring& path, const PedDevice* lp_device)
+FSType GParted_Core::detect_filesystem_internal(const Glib::ustring& path, Byte_Value sector_size)
 {
        char magic1[16];  // Big enough for largest signatures[].sig1 or sig2
        char magic2[16];
        FSType fstype = FS_UNKNOWN;
 
-       char * buf = static_cast<char *>( malloc( lp_device->sector_size ) );
+       char* buf = static_cast<char *>(malloc(sector_size));
        if ( ! buf )
                return FS_UNKNOWN;
 
@@ -1191,18 +1191,18 @@ FSType GParted_Core::detect_filesystem_internal(const Glib::ustring& path, const
                if ( len1 == 0UL || ( signatures[i].sig2 != NULL && len2 == 0UL ) )
                        continue;  // Don't allow 0 length signatures to match
 
-               Byte_Value read_offset = signatures[i].offset1 / lp_device->sector_size * 
lp_device->sector_size;
+               Byte_Value read_offset = signatures[i].offset1 / sector_size * sector_size;
 
-               memset( buf, 0, lp_device->sector_size );
-               if (lseek(fd, read_offset, SEEK_SET)      == read_offset            &&
-                   read(fd, buf, lp_device->sector_size) == lp_device->sector_size   )
+               memset(buf, 0, sector_size);
+               if (lseek(fd, read_offset, SEEK_SET) == read_offset &&
+                   read(fd, buf, sector_size)       == sector_size   )
                {
-                       memcpy( magic1, buf + signatures[i].offset1 % lp_device->sector_size, len1 );
+                       memcpy(magic1, buf + signatures[i].offset1 % sector_size, len1);
 
                        // WARNING: This assumes offset2 is in the same sector as offset1
                        if ( signatures[i].sig2 != NULL )
                        {
-                               memcpy( magic2, buf + signatures[i].offset2 % lp_device->sector_size, len2 );
+                               memcpy(magic2, buf + signatures[i].offset2 % sector_size, len2);
                        }
 
                        if ( memcmp( magic1, signatures[i].sig1, len1 ) == 0     &&
@@ -1321,7 +1321,7 @@ FSType GParted_Core::detect_filesystem( PedDevice * lp_device, PedPartition * lp
        }
 
        // (Q4) Fallback to GParted simple internal file system detection
-       FSType fstype = detect_filesystem_internal(path, lp_device);
+       FSType fstype = detect_filesystem_internal(path, lp_device->sector_size);
        if ( fstype != FS_UNKNOWN )
                return fstype;
 


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