>From d9a424a6fd922f5275183ea96e911af9abb9b745 Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Sun, 10 Apr 2016 11:38:41 -0600 Subject: [PATCH] lib-fs-resize: Fix recognition of FAT file system after resizing When resizing a FAT partition, an extra boot_sector memory allocation was causing the original boot_sector information to be lost. The resulting FAT file system was still recognized by GNU/Linux, but not recognized by the proprietary Windows operating system. The problem with Windows FAT32 recognition was introduced with: Fix filesystem detection on non 512 byte sectors 80678bdd957cf49a9ccfc8b88ba3fb8b4c63fc12 Fix by removing the extra boot_sector memory allocation. Note that since parted-3.0 another code path to the extra memory allocation of fat_create(...) via ped_file_system_create(...) is inaccessible. In an effort to maintain the ability to re-instate the code, add a new boot_sector memory allocation where it is needed in the alternate code path. GNU bug report logs - #22266 [libparted] jump instruction and boot code is corrupted with random bytes after fat is resized http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22266 --- libparted/fs/r/fat/bootsector.c | 9 +++++++-- libparted/fs/r/fat/bootsector.h | 2 +- libparted/fs/r/fat/fat.c | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libparted/fs/r/fat/bootsector.c b/libparted/fs/r/fat/bootsector.c index 1d2b601..99d788d 100644 --- a/libparted/fs/r/fat/bootsector.c +++ b/libparted/fs/r/fat/bootsector.c @@ -281,8 +281,13 @@ fat_boot_sector_analyse (FatBootSector* bs, PedFileSystem* fs) #ifndef DISCOVER_ONLY int -fat_boot_sector_set_boot_code (FatBootSector* bs) +fat_boot_sector_set_boot_code (FatBootSector** bsp, const PedFileSystem* fs) { + FatSpecific* fs_info = FAT_SPECIFIC (fs); + + PED_ASSERT (bsp != NULL); + *bsp = ped_malloc (fs->geom->dev->sector_size); + FatBootSector *bs = *bsp; PED_ASSERT (bs != NULL); memset (bs, 0, 512); @@ -297,8 +302,8 @@ fat_boot_sector_generate (FatBootSector** bsp, const PedFileSystem* fs) FatSpecific* fs_info = FAT_SPECIFIC (fs); PED_ASSERT (bsp != NULL); - *bsp = ped_malloc (fs->geom->dev->sector_size); FatBootSector *bs = *bsp; + PED_ASSERT (bs != NULL); memcpy (bs->system_id, "MSWIN4.1", 8); bs->sector_size = PED_CPU_TO_LE16 (fs_info->logical_sector_size * 512); diff --git a/libparted/fs/r/fat/bootsector.h b/libparted/fs/r/fat/bootsector.h index e92842c..3f84d7f 100644 --- a/libparted/fs/r/fat/bootsector.h +++ b/libparted/fs/r/fat/bootsector.h @@ -120,7 +120,7 @@ int fat_boot_sector_read (FatBootSector** bs, const PedGeometry* geom); FatType fat_boot_sector_probe_type (const FatBootSector* bs, const PedGeometry* geom); int fat_boot_sector_analyse (FatBootSector* bs, PedFileSystem* fs); -int fat_boot_sector_set_boot_code (FatBootSector* bs); +int fat_boot_sector_set_boot_code (FatBootSector** bs, const PedFileSystem* fs); int fat_boot_sector_generate (FatBootSector** bs, const PedFileSystem* fs); int fat_boot_sector_write (const FatBootSector* bs, PedFileSystem* fs); diff --git a/libparted/fs/r/fat/fat.c b/libparted/fs/r/fat/fat.c index 4ecf5c5..444668d 100644 --- a/libparted/fs/r/fat/fat.c +++ b/libparted/fs/r/fat/fat.c @@ -310,7 +310,7 @@ fat_create (PedGeometry* geom, FatType fat_type, PedTimer* timer) fs_info->serial_number = generate_random_uint32 (); - if (!fat_boot_sector_set_boot_code (fs_info->boot_sector)) + if (!fat_boot_sector_set_boot_code (&fs_info->boot_sector, fs)) goto error_free_buffers; if (!fat_boot_sector_generate (&fs_info->boot_sector, fs)) goto error_free_buffers; -- 1.9.1