summaryrefslogtreecommitdiff
path: root/libparted/fs/r
diff options
context:
space:
mode:
Diffstat (limited to 'libparted/fs/r')
-rw-r--r--libparted/fs/r/fat/bootsector.c32
-rw-r--r--libparted/fs/r/fat/bootsector.h8
-rw-r--r--libparted/fs/r/fat/fat.c29
-rw-r--r--libparted/fs/r/fat/fat.h4
-rw-r--r--libparted/fs/r/fat/resize.c4
-rw-r--r--libparted/fs/r/fat/table.c4
6 files changed, 44 insertions, 37 deletions
diff --git a/libparted/fs/r/fat/bootsector.c b/libparted/fs/r/fat/bootsector.c
index 3aff1d7..fcb9782 100644
--- a/libparted/fs/r/fat/bootsector.c
+++ b/libparted/fs/r/fat/bootsector.c
@@ -36,14 +36,14 @@
* fat_boot_sector_probe_type() to work (or possibly crash on a divide-by-zero)
*/
int
-fat_boot_sector_read (FatBootSector* bs, const PedGeometry *geom)
+fat_boot_sector_read (FatBootSector** bsp, const PedGeometry *geom)
{
- PED_ASSERT (bs != NULL);
+ PED_ASSERT (bsp != NULL);
PED_ASSERT (geom != NULL);
- if (!ped_geometry_read (geom, bs, 0, 1))
+ if (!ped_geometry_read_alloc (geom, (void **)bsp, 0, 1))
return 0;
-
+ FatBootSector *bs = *bsp;
if (PED_LE16_TO_CPU (bs->boot_sign) != 0xAA55) {
ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("File system has an invalid signature for a FAT "
@@ -250,10 +250,10 @@ fat_boot_sector_analyse (FatBootSector* bs, PedFileSystem* fs)
fs_info->serial_number
= PED_LE32_TO_CPU (bs->u.fat32.serial_number);
fs_info->info_sector_offset
- = PED_LE16_TO_CPU (fs_info->boot_sector.u.fat32.info_sector)
+ = PED_LE16_TO_CPU (fs_info->boot_sector->u.fat32.info_sector)
* fs_info->logical_sector_size;
fs_info->boot_sector_backup_offset
- = PED_LE16_TO_CPU (fs_info->boot_sector.u.fat32.backup_sector)
+ = PED_LE16_TO_CPU (fs_info->boot_sector->u.fat32.backup_sector)
* fs_info->logical_sector_size;
fs_info->root_cluster
= PED_LE32_TO_CPU (bs->u.fat32.root_dir_cluster);
@@ -292,11 +292,13 @@ fat_boot_sector_set_boot_code (FatBootSector* bs)
}
int
-fat_boot_sector_generate (FatBootSector* bs, const PedFileSystem* fs)
+fat_boot_sector_generate (FatBootSector** bsp, const PedFileSystem* fs)
{
FatSpecific* fs_info = FAT_SPECIFIC (fs);
- PED_ASSERT (bs != NULL);
+ PED_ASSERT (bsp != NULL);
+ *bsp = ped_malloc (fs->geom->dev->sector_size);
+ FatBootSector *bs = *bsp;
memcpy (bs->system_id, "MSWIN4.1", 8);
bs->sector_size = PED_CPU_TO_LE16 (fs_info->logical_sector_size * 512);
@@ -388,16 +390,16 @@ fat_boot_sector_write (const FatBootSector* bs, PedFileSystem* fs)
}
int
-fat_info_sector_read (FatInfoSector* is, const PedFileSystem* fs)
+fat_info_sector_read (FatInfoSector** isp, const PedFileSystem* fs)
{
FatSpecific* fs_info = FAT_SPECIFIC (fs);
int status;
- PED_ASSERT (is != NULL);
+ PED_ASSERT (isp != NULL);
- if (!ped_geometry_read (fs->geom, is, fs_info->info_sector_offset, 1))
+ if (!ped_geometry_read_alloc (fs->geom, (void **)isp, fs_info->info_sector_offset, 1))
return 0;
-
+ FatInfoSector *is = *isp;
if (PED_LE32_TO_CPU (is->signature_2) != FAT32_INFO_MAGIC2) {
status = ped_exception_throw (PED_EXCEPTION_WARNING,
PED_EXCEPTION_IGNORE_CANCEL,
@@ -412,11 +414,13 @@ fat_info_sector_read (FatInfoSector* is, const PedFileSystem* fs)
}
int
-fat_info_sector_generate (FatInfoSector* is, const PedFileSystem* fs)
+fat_info_sector_generate (FatInfoSector** isp, const PedFileSystem* fs)
{
FatSpecific* fs_info = FAT_SPECIFIC (fs);
- PED_ASSERT (is != NULL);
+ PED_ASSERT (isp != NULL);
+ *isp = ped_malloc (fs->geom->dev->sector_size);
+ FatInfoSector *is = *isp;
fat_table_count_stats (fs_info->fat);
diff --git a/libparted/fs/r/fat/bootsector.h b/libparted/fs/r/fat/bootsector.h
index ec367c3..6e8b9ce 100644
--- a/libparted/fs/r/fat/bootsector.h
+++ b/libparted/fs/r/fat/bootsector.h
@@ -116,16 +116,16 @@ struct __attribute__ ((packed)) _FatInfoSector {
uint16_t signature_3; /* should be 0xaa55 */
};
-int fat_boot_sector_read (FatBootSector* bs, const PedGeometry* geom);
+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_generate (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);
-int fat_info_sector_read (FatInfoSector* is, const PedFileSystem* fs);
-int fat_info_sector_generate (FatInfoSector* is, const PedFileSystem* fs);
+int fat_info_sector_read (FatInfoSector** is, const PedFileSystem* fs);
+int fat_info_sector_generate (FatInfoSector** is, const PedFileSystem* fs);
int fat_info_sector_write (const FatInfoSector* is, PedFileSystem* fs);
#endif /* PED_FAT_BOOTSECTOR_H */
diff --git a/libparted/fs/r/fat/fat.c b/libparted/fs/r/fat/fat.c
index c8e4552..fdc1ecc 100644
--- a/libparted/fs/r/fat/fat.c
+++ b/libparted/fs/r/fat/fat.c
@@ -112,19 +112,22 @@ fat_set_frag_sectors (PedFileSystem* fs, PedSector frag_sectors)
int
fat_clobber (PedGeometry* geom)
{
- FatBootSector boot_sector;
+ FatBootSector *boot_sector;
+ int ok;
if (!fat_boot_sector_read (&boot_sector, geom))
return 1;
- boot_sector.system_id[0] = 0;
- boot_sector.boot_sign = 0;
- if (boot_sector.u.fat16.fat_name[0] == 'F')
- boot_sector.u.fat16.fat_name[0] = 0;
- if (boot_sector.u.fat32.fat_name[0] == 'F')
- boot_sector.u.fat32.fat_name[0] = 0;
+ boot_sector->system_id[0] = 0;
+ boot_sector->boot_sign = 0;
+ if (boot_sector->u.fat16.fat_name[0] == 'F')
+ boot_sector->u.fat16.fat_name[0] = 0;
+ if (boot_sector->u.fat32.fat_name[0] == 'F')
+ boot_sector->u.fat32.fat_name[0] = 0;
- return ped_geometry_write (geom, &boot_sector, 0, 1);
+ ok = ped_geometry_write (geom, boot_sector, 0, 1);
+ free (boot_sector);
+ return ok;
}
static int
@@ -163,7 +166,7 @@ fat_open (PedGeometry* geom)
if (!fat_boot_sector_read (&fs_info->boot_sector, geom))
goto error_free_fs;
- if (!fat_boot_sector_analyse (&fs_info->boot_sector, fs))
+ if (!fat_boot_sector_analyse (fs_info->boot_sector, fs))
goto error_free_fs;
fs->type = (fs_info->fat_type == FAT_TYPE_FAT16)
? &fat16_type
@@ -303,16 +306,16 @@ 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))
goto error_free_buffers;
if (!fat_boot_sector_generate (&fs_info->boot_sector, fs))
goto error_free_buffers;
- if (!fat_boot_sector_write (&fs_info->boot_sector, fs))
+ if (!fat_boot_sector_write (fs_info->boot_sector, fs))
goto error_free_buffers;
if (fs_info->fat_type == FAT_TYPE_FAT32) {
if (!fat_info_sector_generate (&fs_info->info_sector, fs))
goto error_free_buffers;
- if (!fat_info_sector_write (&fs_info->info_sector, fs))
+ if (!fat_info_sector_write (fs_info->info_sector, fs))
goto error_free_buffers;
}
@@ -469,7 +472,7 @@ fat_check (PedFileSystem* fs, PedTimer* timer)
if (fs_info->fat_type == FAT_TYPE_FAT32) {
info_free_clusters
- = PED_LE32_TO_CPU (fs_info->info_sector.free_clusters);
+ = PED_LE32_TO_CPU (fs_info->info_sector->free_clusters);
if (info_free_clusters != (FatCluster) -1
&& info_free_clusters != fs_info->fat->free_cluster_count) {
if (ped_exception_throw (PED_EXCEPTION_WARNING,
diff --git a/libparted/fs/r/fat/fat.h b/libparted/fs/r/fat/fat.h
index d2ac2aa..943c5e5 100644
--- a/libparted/fs/r/fat/fat.h
+++ b/libparted/fs/r/fat/fat.h
@@ -77,8 +77,8 @@ struct __attribute__ ((packed)) _FatDirEntry {
};
struct _FatSpecific {
- FatBootSector boot_sector; /* structure of boot sector */
- FatInfoSector info_sector; /* fat32-only information sector */
+ FatBootSector *boot_sector; /* structure of boot sector */
+ FatInfoSector *info_sector; /* fat32-only information sector */
int logical_sector_size; /* illogical sector size :-) */
PedSector sector_count;
diff --git a/libparted/fs/r/fat/resize.c b/libparted/fs/r/fat/resize.c
index 2b68a8b..f3439ac 100644
--- a/libparted/fs/r/fat/resize.c
+++ b/libparted/fs/r/fat/resize.c
@@ -857,10 +857,10 @@ fat_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
_copy_hidden_sectors (ctx);
fat_boot_sector_generate (&new_fs_info->boot_sector, new_fs);
- fat_boot_sector_write (&new_fs_info->boot_sector, new_fs);
+ fat_boot_sector_write (new_fs_info->boot_sector, new_fs);
if (new_fs_info->fat_type == FAT_TYPE_FAT32) {
fat_info_sector_generate (&new_fs_info->info_sector, new_fs);
- fat_info_sector_write (&new_fs_info->info_sector, new_fs);
+ fat_info_sector_write (new_fs_info->info_sector, new_fs);
}
if (!resize_context_assimilate (ctx))
diff --git a/libparted/fs/r/fat/table.c b/libparted/fs/r/fat/table.c
index 974dea8..62bc3b3 100644
--- a/libparted/fs/r/fat/table.c
+++ b/libparted/fs/r/fat/table.c
@@ -129,7 +129,7 @@ fat_table_read (FatTable* ft, const PedFileSystem* fs, int table_num)
fs_info->fat_sectors))
return 0;
- if ( *((unsigned char*) ft->table) != fs_info->boot_sector.media) {
+ if ( *((unsigned char*) ft->table) != fs_info->boot_sector->media) {
if (ped_exception_throw (
PED_EXCEPTION_ERROR,
PED_EXCEPTION_IGNORE_CANCEL,
@@ -137,7 +137,7 @@ fat_table_read (FatTable* ft, const PedFileSystem* fs, int table_num)
"media %x. You should probably run scandisk."),
(int) table_num + 1,
(int) *((unsigned char*) ft->table),
- (int) fs_info->boot_sector.media)
+ (int) fs_info->boot_sector->media)
!= PED_EXCEPTION_IGNORE)
return 0;
}