Subject: [PATCH] libparted: fix fat resize

From: Phillip Susi <[email-masked]>
Date: Fri, 18 Apr 2014 18:54:01 -0400

The changes to fix filesystem detection on non 512 byte sector sizes broke
fat filesystem resizing.
---
 libparted/fs/r/fat/fat.c    |  6 +++++-
 libparted/fs/r/fat/resize.c | 10 ++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/libparted/fs/r/fat/fat.c b/libparted/fs/r/fat/fat.c
index fdc1ecc..8d7420b 100644
--- a/libparted/fs/r/fat/fat.c
+++ b/libparted/fs/r/fat/fat.c
@@ -35,7 +35,9 @@ fat_alloc (const PedGeometry* geom)
 	fs->type_specific = (FatSpecific*) ped_malloc (sizeof (FatSpecific));
 	if (!fs->type_specific)
 		goto error_free_fs;
-
+	FatSpecific* fs_info = (FatSpecific*) fs->type_specific;
+	fs_info->boot_sector = NULL;
+	fs_info->info_sector = NULL;
 	fs->geom = ped_geometry_duplicate (geom);
 	if (!fs->geom)
 		goto error_free_type_specific;
@@ -86,6 +88,8 @@ fat_free_buffers (PedFileSystem* fs)
 void
 fat_free (PedFileSystem* fs)
 {
+	FatSpecific* fs_info = (FatSpecific*) fs->type_specific;
+	free (fs_info->boot_sector);
 	ped_geometry_destroy (fs->geom);
 	free (fs->type_specific);
 	free (fs);
diff --git a/libparted/fs/r/fat/resize.c b/libparted/fs/r/fat/resize.c
index f3439ac..046382b 100644
--- a/libparted/fs/r/fat/resize.c
+++ b/libparted/fs/r/fat/resize.c
@@ -667,10 +667,12 @@ create_resize_context (PedFileSystem* fs, const PedGeometry* new_geom)
 		goto error_free_new_fs;
 
 /* preserve boot code, etc. */
-	memcpy (&new_fs_info->boot_sector, &fs_info->boot_sector,
-		sizeof (FatBootSector));
-	memcpy (&new_fs_info->info_sector, &fs_info->info_sector,
-		sizeof (FatInfoSector));
+	new_fs_info->boot_sector = ped_malloc (new_geom->dev->sector_size);
+	new_fs_info->info_sector = ped_malloc (new_geom->dev->sector_size);
+	memcpy (new_fs_info->boot_sector, fs_info->boot_sector,
+		new_geom->dev->sector_size);
+	memcpy (new_fs_info->info_sector, fs_info->info_sector,
+		new_geom->dev->sector_size);
 
 	new_fs_info->logical_sector_size = fs_info->logical_sector_size;
 	new_fs_info->sector_count = new_geom->length;
-- 
1.9.1