summaryrefslogtreecommitdiffstats
path: root/src/godmode.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2015-09-25 20:38:57 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2015-09-25 20:38:57 +0200
commitb9184f1ed1d727e64d7b3de19131856a78cb38f8 (patch)
tree8fbb79802c8526ba79c392935e7420903247c92b /src/godmode.c
parent3f3da1a06c1c3bdc28efe6f66baaf822b5b0557e (diff)
PC/Intel partition table: Do not align the partition if it overlaps with the next one because of this alignement.
Diffstat (limited to 'src/godmode.c')
-rw-r--r--src/godmode.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/godmode.c b/src/godmode.c
index ec82862..6c108d1 100644
--- a/src/godmode.c
+++ b/src/godmode.c
@@ -115,22 +115,39 @@ static unsigned int align_structure_aux(const uint64_t offset, const disk_t *dis
return disk->sector_size;
}
-static void align_structure(list_part_t *list_part, const disk_t *disk, const unsigned int align)
+static void align_structure_i386(list_part_t *list_part, const disk_t *disk, const unsigned int align)
{
- if(disk->arch==&arch_i386)
+ list_part_t *element;
+ for(element=list_part; element!=NULL; element=element->next)
{
- list_part_t *element;
- for(element=list_part; element!=NULL; element=element->next)
+ uint64_t partition_end;
+ unsigned int location_boundary;
+ const partition_t *part=element->part;
+ if(align==0)
+ location_boundary=disk->sector_size;
+ else
+ location_boundary=align_structure_aux(part->part_offset, disk);
+ partition_end=(part->part_offset+part->part_size-1+location_boundary-1)/location_boundary*location_boundary-1;
+ if(align!=0 && element->next!=NULL)
{
- uint64_t partition_end;
- unsigned int location_boundary;
- if(align==0)
+ const partition_t *next_partition=element->next->part;
+ if( next_partition->part_offset > part->part_offset + part->part_size -1 &&
+ next_partition->part_offset <= partition_end)
+ {
+ /* Do not align the partition if it overlaps with the next one because of that */
location_boundary=disk->sector_size;
- else
- location_boundary=align_structure_aux(element->part->part_offset, disk);
- partition_end=(element->part->part_offset+element->part->part_size-1+location_boundary-1)/location_boundary*location_boundary-1;
- element->part->part_size=partition_end-element->part->part_offset+1;
+ partition_end=(part->part_offset + part->part_size-1+location_boundary-1)/location_boundary*location_boundary-1;
+ }
}
+ element->part->part_size=partition_end - part->part_offset+1;
+ }
+}
+
+static void align_structure(list_part_t *list_part, const disk_t *disk, const unsigned int align)
+{
+ if(disk->arch==&arch_i386)
+ {
+ align_structure_i386(list_part, disk, align);
return ;
}
{