On 07/22/2007 03:11 AM, Theodore Tso wrote: >> This is a problem. Today the CHS fields in the partition entries don't >> mean much of anything anymore and Linux happily ignores them but DOS >> and (hence) Windows 9x do not. From time to time I still have the >> Windows 98 install that's sitting in a corner of my disk throw a fit >> just by having set the BIOS from LBA to Large (meaning the geometry the >> BIOS pretends the disk has changes) for example. Old DOS installs that >> I keep around for the purpose of hardware testing with the originally >> supplied drivers make for even more of a "don't touch, don't touch!" >> thing -- various version of DOS throw fits for various reasons. > > This is true, but that's due to the fundamentally broken nature of CHS. > You need them to boot, and that's about it. I will say up front that I > don't particularly care about legacy operating system such as DOS, > Windows 98, or Minix 3. So the idea of simply having the number of heads > and sectors in the partition header is that we can reconstruct CHS fields > such that it is likely with modern hardware you will get it right. Well, I still don't believe this all to be a great idea but it was sort of fun so the attached does largely what you want -- build a list of all data partitions. The heads/sectors fields it for now just gets from the HDIO_GETGEO call. A better source would be guessing the values from the partition table itself but that _also_ doesn't make too much sense. If you're reconstructing a sanitized version of the table anyway, it makes better sense to reconstruct it with the values HDIO_GETGEO returns at restoration time. I kept your suggested format, but in fact, the 64-bit "start" value seems not very useful if we're getting the value from a 32-bit field in the old partition tables anyway. With that shrunk down to 32-bit again, there would be enough room for the complete partition table entry... > For ancient systems that do all sorts of weird things such as ECHS, > etc., yeah, you're pretty much doomed, and the bigger danger comes > from futzing with BIOS settings, et. al. But it's 2007, gosh darn it! > "Here's a quarter, kid, buy yourself a real computer". :-) Thanks, but real computers won't host my ISA cards... > Yes, I'm very aware of the extended partitioning scheme mess. What I > was proposing to back up here is only the real partitions, not the > fake extended partitions. The idea is to store *just* enough > information so that a partition table manager can recover the > partition tables in such a way that the original filesystem > information can be recovered. This should do I guess. It enters all data partitions into the list, in the order in which they are encountered and sets a flag to signify that a partition was a logical rather than primary. Another option would be to just reserve the first 4 entries for the primaries and the rest for the logicals but this saves entries if there are fewer than 4 primaries and was in fact easier... The program enters partitions in what should be the same order as Linux itself does. Primaries from slot 0 to 3 as normal (but not backed up to entry 0 to 3 as said -- the LOGICAL flag indentifies them), extended partitions in the MBR in the order as encountered, with the logicals in the second-level table as encountered, and following only the first extented in the second-level table. Made it into a generic C program -- didn't look at e2fsprogs sources yet. Need to be off now and haven't yet stared at this as long as I'd like so don't slap me if I've left a few bugs in (although it seems to work nicely). The program dumps the backup sector to stdout -- it's ofcourse easy to change it to print the entries out so they're easy to compare against, say, "fdisk -l -us". Oh, and once you've looked at it, please throw it away. As said, I still don't think it's a great idea ;-) Rene.