diff options
author | Jim Meyering <jim@meyering.net> | 2007-06-01 19:10:56 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2009-07-24 15:04:39 +0200 |
commit | 4e6e6c44ff85f1234d583c116ab812ff08cb0341 (patch) | |
tree | dcaaa2ccd878500d24cab955ca7d93a6b35f0c7f /libparted/labels/bsd.c | |
parent | 401ff449ceeb086369673c3a8654bf01f9d58296 (diff) | |
download | parted-4e6e6c44ff85f1234d583c116ab812ff08cb0341.tar.gz |
start to make things work with 2048-byte sector size.
Done so far: amiga, bsd, loop, gpt.
Fix leaks along the way.
remove unused label
Add a cast to avoid a warning.
Diffstat (limited to 'libparted/labels/bsd.c')
-rw-r--r-- | libparted/labels/bsd.c | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/libparted/labels/bsd.c b/libparted/labels/bsd.c index 3d6b5ab..d030d44 100644 --- a/libparted/labels/bsd.c +++ b/libparted/labels/bsd.c @@ -21,6 +21,7 @@ #include <config.h> +#include <stdbool.h> #include <parted/parted.h> #include <parted/debug.h> #include <parted/endian.h> @@ -146,30 +147,45 @@ alpha_bootblock_checksum (char *boot) { dp[63] = sum; } +/* FIXME: factor out this function: copied from dos.c + Read sector, SECTOR_NUM (which has length DEV->sector_size) into malloc'd + storage. If the read fails, free the memory and return zero without + modifying *BUF. Otherwise, set *BUF to the new buffer and return 1. */ +static int +read_sector (const PedDevice *dev, PedSector sector_num, char **buf) +{ + char *b = ped_malloc (dev->sector_size); + PED_ASSERT (b != NULL, return 0); + if (!ped_device_read (dev, b, sector_num, 1)) { + free (b); + return 0; + } + *buf = b; + return 1; +} static int bsd_probe (const PedDevice *dev) { - char boot[512]; - BSDRawLabel *label; + BSDRawLabel *partition; PED_ASSERT (dev != NULL, return 0); - if (dev->sector_size != 512) + if (dev->sector_size < 512) return 0; - if (!ped_device_read (dev, boot, 0, 1)) + char *label; + if (!read_sector (dev, 0, &label)) return 0; - label = (BSDRawLabel *) (boot + BSD_LABEL_OFFSET); + partition = (BSDRawLabel *) (label + BSD_LABEL_OFFSET); - alpha_bootblock_checksum(boot); + alpha_bootblock_checksum(label); /* check magic */ - if (PED_LE32_TO_CPU (label->d_magic) != BSD_DISKMAGIC) - return 0; - - return 1; + bool found = PED_LE32_TO_CPU (partition->d_magic) == BSD_DISKMAGIC; + free (label); + return found; } static PedDisk* @@ -258,13 +274,12 @@ bsd_free (PedDisk* disk) static int bsd_clobber (PedDevice* dev) { - char boot [512]; - BSDRawLabel* label = (BSDRawLabel *) (boot + BSD_LABEL_OFFSET); - - if (!ped_device_read (dev, boot, 0, 1)) + char *label; + if (!read_sector (dev, 0, &label)) return 0; - label->d_magic = 0; - return ped_device_write (dev, (void*) boot, 0, 1); + BSDRawLabel *rawlabel = (BSDRawLabel *) (label + BSD_LABEL_OFFSET); + rawlabel->d_magic = 0; + return ped_device_write (dev, label, 0, 1); } #endif /* !DISCOVER_ONLY */ @@ -277,8 +292,13 @@ bsd_read (PedDisk* disk) ped_disk_delete_all (disk); - if (!ped_device_read (disk->dev, bsd_specific->boot_code, 0, 1)) - goto error; + char *s0; + if (!read_sector (disk->dev, 0, &s0)) + return 0; + + memcpy (bsd_specific->boot_code, s0, sizeof (bsd_specific->boot_code)); + free (s0); + label = (BSDRawLabel *) (bsd_specific->boot_code + BSD_LABEL_OFFSET); for (i = 1; i <= BSD_MAXPARTITIONS; i++) { |