diff --git a/plugins/gpt/helpers.h b/plugins/gpt/helpers.h index d749a67..dd910ad 100644 --- a/plugins/gpt/helpers.h +++ b/plugins/gpt/helpers.h @@ -72,7 +72,9 @@ char * guid_to_string( guid_t *id ); #define MAX_HEADS 254 #define MAX_SECTORS 63 +/* we don't actually do cylinders anymore, align for 1MB boundary */ + #define BOUNDARY_IN_SECTORS_512 2048 /* * Called to return the Logical Disk that a segment belongs to. @@ -243,6 +245,13 @@ static inline int LBA_to_Ptable_CHS( LOGICALDISK *ld, lba_t lba, chs_t *chs ) */ static inline boolean starts_on_cylinder_boundary( LOGICALDISK *ld, lba_t lba ) { + + // just check against 2048s boundary + if ( lba % BOUNDARY_IN_SECTORS_512 == 0 ) + return TRUE; + else + return FALSE; + chs_t chs; if ( LBAtoCHS( ld, lba, &chs ) ) { @@ -266,6 +275,13 @@ static inline boolean starts_on_cylinder_boundary( LOGICALDISK *ld, lba_t lba ) */ static inline boolean ends_on_cylinder_boundary( LOGICALDISK *ld, lba_t lba ) { + + // just check against 2048s boundary + if ( lba % BOUNDARY_IN_SECTORS_512 == BOUNDARY_IN_SECTORS_512 - 1 ) + return TRUE; + else + return FALSE; + chs_t chs; DISK_PRIVATE_DATA *disk_pdata = get_gpt_disk_private_data( ld ); @@ -300,6 +316,11 @@ static inline sector_count_t get_cylinder_size( storage_object_t *ld ) sector_count_t sectors_per_cylinder=0; DISK_PRIVATE_DATA *disk_pdata=NULL; + // align to 1MB boundary, cylinders are long dead + if (ld) + return BOUNDARY_IN_SECTORS_512; + else + return 0; if (ld) { @@ -330,6 +351,18 @@ static inline lba_t roundup_to_track_boundary( LOGICALDISK *ld, lba_t lba ) { lba_t new_lba = lba; sector_count_t extra_sectors=0; + + extra_sectors = lba % BOUNDARY_IN_SECTORS_512; + + if ( extra_sectors != 0) { + new_lba = lba + ( BOUNDARY_IN_SECTORS_512 - extra_sectors); + } + + LOG_DEBUG("ALT: Nearest upper boundary to %"PRIu64" is %"PRIu64"\n", lba, new_lba); + + return new_lba; + + sector_count_t sectors_per_track=0; DISK_PRIVATE_DATA *disk_pdata; @@ -363,6 +396,17 @@ static inline lba_t roundup_to_cylinder_boundary( LOGICALDISK *ld, lba_t lba ) { lba_t new_lba = lba; sector_count_t extra_sectors=0; + + extra_sectors = lba % BOUNDARY_IN_SECTORS_512; + + if ( extra_sectors != 0) { + new_lba = lba - extra_sectors; + } + + LOG_DEBUG("ALT: Nearest down boundary to %"PRIu64" is %"PRIu64"\n", lba, new_lba); + return new_lba; + + sector_count_t sectors_per_cylinder;