
   gpart README


   Gpart is a small tool which tries to guess what partitions
   are on a PC type harddisk in case the primary partition table
   was damaged.

   Gpart works by scanning through the device (or file) given on
   the command line on a sector basis. Each guessing module is
   asked if it thinks a file system it knows about could start at
   a given sector. Several file system guessing modules are built
   in, others can be added dynamically.

   Consult the manual page for command line options and usage.



 - Installation ----------------------------------------------------------

   See file INSTALL.



 - Currently recognized partitions/filesystems types ---------------------

   Modname Typ   Description
   fat     0x01  "Primary DOS with 12 bit FAT"
           0x04  "Primary DOS with 16 bit FAT (<= 32MB)"
           0x06  "Primary 'big' DOS (> 32MB)"
           0x0B  "DOS or Windows 95 with 32 bit FAT"
           0x0C  "DOS or Windows 95 with 32 bit FAT, LBA"
   ntfs    0x07  "OS/2 HPFS, NTFS, QNX or Advanced UNIX"
   hpfs    0x07  "OS/2 HPFS, NTFS, QNX or Advanced UNIX"
   ext2    0x83  "Linux ext2 filesystem"
   lswap   0x82  "Linux swap"
   bsddl   0xA5  "FreeBSD/NetBSD/386BSD"
   s86dl   0x82  "Solaris/x86 disklabel"
   minix   0x80  "Minix V1"
           0x81  "Minix V2"



 - External guessing modules ---------------------------------------------

   gpart allows external partition type guessing modules to be
   added dynamically. An external module of type "xxx" must be
   compiled into a shared object file called "gm_xxx.so".

   External modules must provide three functions callable from
   gpart:

      int xxx_init(disk_desc *d,g_module *m)
         Initialisation function. Will be called before a scan.
         It should return the minimum number of bytes it wants
         to receive for a test. The module should set the
         description of the filesystem/partition type it handles
         in g_module.m_desc. If the filesystem/partition type
         included a partition table like first sector (like the
         *BSD disklabels do), the flag m_hasptbl should be set.
         Another flag is m_notinext which means the tested type
         cannot reside in a logical partition.

      int xxx_term(disk_desc *d)
         Termination/cleanup function, called after the scanning
         of the device has been done.

      int xxx_gfun(disk_desc *d,g_module *m)
         The actual guessing function, called from within the
         scan-loop. It should test the plausibility of the
         given sectors, and return its guess in m->m_guess (a
         probability between 0 and 1). See existing modules
         for examples.

         The given file descriptor d->d_fd can be used for seeking
         and reading (see e.g. gm_ext2.c which tries to read
         the first spare superblock). If a module is convinced
         that it has found a filesystem/partition start it should
         fill in the assumed begin and size of the partition.

         The test performed should not be too pedantic, for
         instance it should not be relied upon that the file-
         system is clean/was properly unmounted. On the other
         hand too much tolerance leads to misguided guesses,
         so a golden middle way must be found.

   To create a shared object file from C source, compile the
   module via

      gcc -Wall -fPIC -shared gm_xxx.c -o gm_xxx.so

   Then install the shared object in a directory searched by
   the dynamic linker, or set LD_LIBRARY_PATH accordingly.
   The new external module can then be included by calling
   gpart like

      gpart -t xxx <other options>



 - Output explanation ----------------------------------------------------

   Here is a sample gpart run on my first IDE hard disk
   (comments in brackets):

dev(/dev/hda) mss(512) chs(790/255/63)(LBA) #s(000012691350) size(6196mb)
[
   mss is the medium sector size, chs the geometry retrieved
   from the OS, #s is the total sector count.
]

Primary partition(1)
   type: 006(0x06)(Primary 'big' DOS (> 32MB))
   size: 502mb #s(000001028097) s(000000000063-000001028159)
   chs:  (0000/001/01)-(0063/254/63)d (0/1/1)-(63/254/63)r
   hex:  00 01 01 00 06 FE 3F 3F 3F 00 00 00 01 B0 0F 00
[
   size: the size of the partition in megabytes, number of
   sectors and the sector range.
   chs: the partition table chs range (d) and the real one.
   If the number of cylinders is less than 1024 both are
   identical.
   hex: the hexadecimal representation of the partition entry
   as found in the partition table.
]

Begin scan...
Possible partition(DOS FAT), size(502mb), offset(0mb)
Possible extended partition at offset(502mb)
   Possible partition(Linux ext2), size(31mb), offset(502mb)
   Possible partition(Linux swap), size(125mb), offset(533mb)
   Possible partition(Linux ext2), size(2047mb), offset(658mb)
   Possible partition(Linux ext2), size(1396mb), offset(2706mb)
Possible partition(*BSD disklabel), size(1027mb), offset(4102mb)
Possible partition(Solaris/x86 disklabel), size(1027mb), offset(5130mb)
End scan.
[
   During the scan phase all found partitions are listed by
   their real type names. In the above example, both the Linux
   swap partition and the Solaris disklabel are shown as different
   partition types but will eventually share the same type
   identifier 0x82 in the guessed partition table.
]

Checking partitions...
Partition(Primary 'big' DOS (> 32MB)): primary 
   Partition(Linux ext2 filesystem): logical 
   Partition(Linux swap or Solaris/x86): orphaned logical 
   Partition(Linux ext2 filesystem): logical 
   Partition(Linux ext2 filesystem): logical 
Partition(FreeBSD/NetBSD/386BSD): primary 
Partition(Linux swap or Solaris/x86): primary 
Ok.
[
   As mentioned above both Linux swap and Solaris partitions
   got the same type identifier. The "orphaned" attribute
   means that the logical partition seems ok but was not
   included in the logical partition chain. This happens
   if a logical partition is deleted within fdisk but the
   actual partition space on the disk is left untouched.  
]

Guessed primary partition table:
Primary partition(1)
   type: 006(0x06)(Primary 'big' DOS (> 32MB))
   size: 502mb #s(000001028097) s(000000000063-000001028159)
   chs:  (0000/001/01)-(0063/254/63)d (0/1/1)-(63/254/63)r
   hex:  00 01 01 00 06 FE 3F 3F 3F 00 00 00 01 B0 0F 00

Primary partition(2)
   type: 005(0x05)(Extended DOS)
   size: 3600mb #s(000007373835) s(000001028160-000008401994)
   chs:  (0064/000/01)-(0522/254/63)d (64/0/1)-(522/254/63)r
   hex:  00 00 01 40 05 FE BF 0A 40 B0 0F 00 0B 84 70 00

Primary partition(3)
   type: 165(0xA5)(FreeBSD/NetBSD/386BSD)
   size: 1027mb #s(000002104515) s(000008401995-000010506509)
   chs:  (0523/000/01)-(0653/254/63)d (523/0/1)-(653/254/63)r
   hex:  00 00 81 0B A5 FE BF 8D 4B 34 80 00 C3 1C 20 00

Primary partition(4)
   type: 130(0x82)(Linux swap or Solaris/x86)
   size: 1027mb #s(000002104515) s(000010506510-000012611024)
   chs:  (0654/000/01)-(0784/254/63)d (654/0/1)-(784/254/63)r
   hex:  00 00 81 8E 82 FE FF 10 0E 51 A0 00 C3 1C 20 00
[
   This is a resulting primary partition table. Note that
   the logical partition guesses were only used to create
   the extended partition entry. Up to now gpart cannot
   reconstruct a damaged logical partition chain itself.

   If a guessed primary partition table should be written to
   some file or device the user must specify which partition
   gets the active (bootable) one.
]



   gpart README, Jan 1999, Michail Brzitwa <mb@ichabod.han.de>
