[BusyBox 0001333]: "fdisk -l" (lower case ell) does not read partition table correctly
bugs at busybox.net
bugs at busybox.net
Sat Jun 2 04:32:43 PDT 2007
A NOTE has been added to this issue.
======================================================================
http://busybox.net/bugs/view.php?id=1333
======================================================================
Reported By: kiltedknight
Assigned To: BusyBox
======================================================================
Project: BusyBox
Issue ID: 1333
Category: Other
Reproducibility: always
Severity: major
Priority: normal
Status: assigned
======================================================================
Date Submitted: 05-04-2007 09:50 PDT
Last Modified: 06-02-2007 04:32 PDT
======================================================================
Summary: "fdisk -l" (lower case ell) does not read partition
table correctly
Description:
When running "busybox fdisk -l" against a known disk, I get the following:
Warning: ignoring extra data in partition table 5
Warning: ignoring extra data in partition table 5
Warning: ignoring extra data in partition table 6
Warning: ignoring extra data in partition table 6
Warning: ignoring extra data in partition table 6
Warning: invalid flag 0xe4,0x0f of partition table 5 will be corrected by
w(rite)
Warning: invalid flag 0x36,0xb0 of partition table 6 will be corrected by
w(rite)
Disk /dev/hde: 20.0 GB, 20020396032 bytes
255 heads, 63 sectors/track, 2434 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hde1 * 1 33 265041 83 Linux
/dev/hde2 34 925 7164990 83 Linux
/dev/hde3 926 1186 2096482+ 82 Linux swap
/dev/hde4 1187 2434 10024560 5 Extended
/dev/hde5 ? 17782 15955 2132811720 3f Unknown
/dev/hde6 ? 101267 247811 1177113252+ 11 Hidden FAT12
If I run the linux "fdisk -l", I get this:
Disk /dev/hde: 20.0 GB, 20020396032 bytes
255 heads, 63 sectors/track, 2434 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hde1 * 1 33 265041 83 Linux
/dev/hde2 34 925 7164990 83 Linux
/dev/hde3 926 1186 2096482+ 82 Linux swap /
Solaris
/dev/hde4 1187 2434 10024560 5 Extended
/dev/hde5 1187 1377 1534176 83 Linux
/dev/hde6 1378 2434 8490321 83 Linux
It looks like it's having problems reading the partitions out of an
extended partition.
======================================================================
----------------------------------------------------------------------
kiltedknight - 05-30-07 09:46
----------------------------------------------------------------------
The problem is the off_t value. For it to work, it must be a 64-bit number
and lseek64() must be used.
The attached patch will correct the problem.
----------------------------------------------------------------------
kiltedknight - 05-30-07 10:01
----------------------------------------------------------------------
Of note, the fdisk.c found in the Fedora Core 6 util-linux RPM does not use
off_t to define the various offsets. It defines them all as "unsigned long
long" instead, as it is highly unlikely that you will ever find a hard
drive that will no longer have its offsets fit within 32 bits.
----------------------------------------------------------------------
kiltedknight - 05-30-07 10:07
----------------------------------------------------------------------
Use the updated fix, as it more closely mimics the base fdisk.c file, only
casting to off_t in seek_sector().
----------------------------------------------------------------------
vda - 05-31-07 16:13
----------------------------------------------------------------------
- off_t offset = secno * sector_size;
+ off_t offset = (off_t) secno * sector_size;
Doesn't look right to me.
----------------------------------------------------------------------
vda - 05-31-07 16:15
----------------------------------------------------------------------
static void
-seek_sector(off_t secno)
+seek_sector(unsigned long long secno)
{
- off_t offset = secno * sector_size;
+ off_t offset = (off_t) secno * sector_size;
if (lseek(fd, offset, SEEK_SET) == (off_t) -1)
fdisk_fatal(unable_to_seek);
}
I mean, you need to use lseek64 instead, and also need to make sure fd is
opened with O_LARGEFILE.
----------------------------------------------------------------------
vda - 05-31-07 16:16
----------------------------------------------------------------------
%"OFF_FMT"ld and %"OFF_FMT"lu are wrong. Use %lld, %llu.
----------------------------------------------------------------------
bernhardf - 06-01-07 01:50
----------------------------------------------------------------------
no, %lld and %llu are wrong. For very obvious reasons, there is an
inttypes.h that defines the proper printf format specifiers.
Use PRId64 and PRIu64
For odd platforms, we have fixup defines for these printf specifiers in
platform.h, fwiw.
thanks,
----------------------------------------------------------------------
kiltedknight - 06-01-07 09:33
----------------------------------------------------------------------
- off_t offset = secno * sector_size;
+ off_t offset = (off_t) secno * sector_size;
That's exactly what's in the fdisk.c file that I just uploaded.
On linux (Fedora Core 6), lseek()'s second parameter is defined as an
off_t... which in this case is an unsigned long long. All other places
where busybox has an off_t, the util-linux-2.13-pre7 package's fdisk.c has
unsigned long long.
Granted, if you turn on the busybox option to use 64-bit sizes for files,
this issue goes away... but in the case of a hard disk, how often do you
come across one that is less than 2GB nowadays?
----------------------------------------------------------------------
vda - 06-02-07 04:32
----------------------------------------------------------------------
But, bernhard, the patch prints long longs with %"OFF_FMT"ld! This cannot
be right...
Issue History
Date Modified Username Field Change
======================================================================
05-04-07 09:50 kiltedknight New Issue
05-04-07 09:50 kiltedknight Status new => assigned
05-04-07 09:50 kiltedknight Assigned To => BusyBox
05-04-07 09:51 kiltedknight Issue Monitored: kiltedknight
05-30-07 09:46 kiltedknight Note Added: 0002419
05-30-07 09:46 kiltedknight File Added: bb-fdisk-fix.diff
05-30-07 10:01 kiltedknight Note Added: 0002420
05-30-07 10:06 kiltedknight File Added: bb-fdisk-fix-updated.diff
05-30-07 10:07 kiltedknight Note Added: 0002421
05-31-07 16:13 vda Note Added: 0002422
05-31-07 16:15 vda Note Added: 0002423
05-31-07 16:16 vda Note Added: 0002424
06-01-07 01:50 bernhardf Note Added: 0002425
06-01-07 09:30 kiltedknight File Added: fdisk.c
06-01-07 09:33 kiltedknight Note Added: 0002426
06-02-07 04:32 vda Note Added: 0002436
======================================================================
More information about the busybox-cvs
mailing list