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
This commit is contained in:
Mike Fleetwood 2019-07-11 19:33:45 +01:00 committed by Curtis Gedak
parent 228374fe50
commit 5bb3415bcb
2 changed files with 10 additions and 10 deletions

View File

@ -89,7 +89,7 @@ private:
std::vector<Glib::ustring> & messages ); std::vector<Glib::ustring> & messages );
void set_luks_partition( PartitionLUKS & partition ); void set_luks_partition( PartitionLUKS & partition );
void set_partition_label_and_uuid( Partition & 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, static FSType detect_filesystem( PedDevice * lp_device, PedPartition * lp_partition,
std::vector<Glib::ustring> & messages ); std::vector<Glib::ustring> & messages );
void read_label( Partition & partition ) ; void read_label( Partition & partition ) ;

View File

@ -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 // GParted simple internal file system signature detection. Use sparingly. Only when
// (old versions of) blkid and libparted don't recognise a signature. // (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 magic1[16]; // Big enough for largest signatures[].sig1 or sig2
char magic2[16]; char magic2[16];
FSType fstype = FS_UNKNOWN; FSType fstype = FS_UNKNOWN;
char * buf = static_cast<char *>( malloc( lp_device->sector_size ) ); char* buf = static_cast<char *>(malloc(sector_size));
if ( ! buf ) if ( ! buf )
return FS_UNKNOWN; 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 ) ) if ( len1 == 0UL || ( signatures[i].sig2 != NULL && len2 == 0UL ) )
continue; // Don't allow 0 length signatures to match 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 ); memset(buf, 0, sector_size);
if (lseek(fd, read_offset, SEEK_SET) == read_offset && if (lseek(fd, read_offset, SEEK_SET) == read_offset &&
read(fd, buf, lp_device->sector_size) == lp_device->sector_size ) 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 // WARNING: This assumes offset2 is in the same sector as offset1
if ( signatures[i].sig2 != NULL ) 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 && 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 // (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 ) if ( fstype != FS_UNKNOWN )
return fstype; return fstype;