diff options
author | Pierre-Alexandre Meyer <pierre@mouraf.org> | 2009-08-19 21:12:57 -0700 |
---|---|---|
committer | erwan <erwan@r1.paris> | 2009-08-20 06:17:52 +0200 |
commit | 3b4e0f5e471de0fc6a9c335343a4ad52f8b29aeb (patch) | |
tree | e31b0f75fdcdf9778a1f68eef70833ce2f8067a5 | |
parent | f856e30a7162319b9743d6742cec9d41b33269b5 (diff) | |
download | lwip-3b4e0f5e471de0fc6a9c335343a4ad52f8b29aeb.tar.gz lwip-3b4e0f5e471de0fc6a9c335343a4ad52f8b29aeb.tar.xz lwip-3b4e0f5e471de0fc6a9c335343a4ad52f8b29aeb.zip |
disklib: fix extended partition code
gert1 reported some issues using disklib with HDT. As it turned out, the
code that iterated through ebrs in an extended partition was broken: ebr offsets
need to be relative to the start of that partition.
Misc.: fix memory leak.
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Signed-off-by: Erwan Velu <erwan.velu@free.fr>
-rw-r--r-- | com32/gpllib/disk/msdos.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/com32/gpllib/disk/msdos.c b/com32/gpllib/disk/msdos.c index e69aa71b..1d1ef4df 100644 --- a/com32/gpllib/disk/msdos.c +++ b/com32/gpllib/disk/msdos.c @@ -34,39 +34,42 @@ static inline int msdos_magic_present(const char *ptab) /** * process_extended_partition - execute a callback for each partition contained listed in an ebr * @drive_info: driveinfo struct describing the drive - * @partition_offset: Absolute start (lba) of the partition + * @partition_offset: Absolute start (lba) of the extended partition + * @ebr_offset: Relative start (lba) of the current ebr processed within + * the extended partition * @callback: Callback to execute * @error: Buffer for I/O errors * @nb_part_seen: Number of partitions found on the disk so far **/ static int process_extended_partition(struct driveinfo *drive_info, - int partition_offset, - p_callback callback, - int nb_part_seen) + const int partition_offset, + const int ebr_offset, + p_callback callback, + int nb_part_seen) { int status = 0; /* The ebr is located at the first sector of the extended partition */ char* ebr = malloc(SECTOR * sizeof(char)); - if (read_sectors(drive_info, ebr, partition_offset, 1) == -1) - return -1; + if (read_sectors(drive_info, ebr, partition_offset + ebr_offset, 1) == -1) + goto abort; /* Check msdos magic signature */ if (!msdos_magic_present(ebr)) - return -1; + goto abort; struct part_entry *ptab = (struct part_entry *)(ebr + PARTITION_TABLES_OFFSET); for (int i = 0; i < 4; i++) { if (status == -1) - return -1; + goto abort; if (!is_extended_partition(&ptab[i])) { /* * This EBR partition table entry points to the * logical partition associated to that EBR */ - int logical_partition_start = partition_offset + ptab[i].start_lba; + int logical_partition_start = ebr_offset + ptab[i].start_lba; /* Last EBR in the extended partition? */ if (!logical_partition_start) @@ -84,16 +87,22 @@ static int process_extended_partition(struct driveinfo *drive_info, nb_part_seen++; callback(drive_info, &ptab[i], - logical_partition_start, + partition_offset + logical_partition_start, nb_part_seen); } else status = process_extended_partition(drive_info, - partition_offset + ptab[i].start_lba, + partition_offset, + ptab[i].start_lba, callback, nb_part_seen); } + free(ebr); return 0; + +abort: + free(ebr); + return -1; } /** @@ -117,7 +126,7 @@ static int process_mbr(struct driveinfo *drive_info, struct part_entry *ptab, &ptab[i], ptab[i].start_lba, i+1); - status = process_extended_partition(drive_info, ptab[i].start_lba, callback, 4); + status = process_extended_partition(drive_info, ptab[i].start_lba, 0, callback, 4); } else callback(drive_info, &ptab[i], |