[Forensics-changes] [gpart] 01/02: Imported Upstream version 0.3

Joao Eriberto Mota Filho eriberto at moszumanska.debian.org
Sun Nov 29 13:01:16 UTC 2015


This is an automated email from the git hooks/post-receive script.

eriberto pushed a commit to branch debian
in repository gpart.

commit 98d68d0c1fdb38e5c6f8abcce054442f9e9db61b
Author: Joao Eriberto Mota Filho <eriberto at debian.org>
Date:   Sun Nov 29 11:01:02 2015 -0200

    Imported Upstream version 0.3
---
 .travis.yml       |   7 ++
 Makefile.am       |   4 +-
 README            | 213 ------------------------------------------------------
 README.md         | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac      |   9 ++-
 src/Makefile.am   |   4 +-
 src/gm_beos.c     |   3 -
 src/gm_bsddl.c    |   2 -
 src/gm_btrfs.c    |  74 +++++++++++++++++++
 src/gm_btrfs.h    | 175 ++++++++++++++++++++++++++++++++++++++++++++
 src/gm_ext2.c     |   2 -
 src/gm_fat.c      |   6 +-
 src/gm_fat.h      |   4 +-
 src/gm_hmlvm.c    |   2 -
 src/gm_hpfs.c     |   4 +-
 src/gm_hpfs.h     |   2 +-
 src/gm_lswap.c    |   1 -
 src/gm_lvm2.c     |  66 +++++++++++++++++
 src/gm_lvm2.h     |  65 +++++++++++++++++
 src/gm_minix.c    |   2 -
 src/gm_ntfs.c     |   2 -
 src/gm_qnx4.c     |   2 -
 src/gm_reiserfs.c |   2 -
 src/gm_s86dl.c    |   2 -
 src/gm_xfs.c      |   2 -
 src/gmodules.h    |   2 +
 src/gpart.c       |   1 -
 src/l64seek.c     |   1 +
 28 files changed, 617 insertions(+), 253 deletions(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..ddffe97
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+language: c
+
+script: ./autogen.sh && make
+
+compiler:
+  - gcc
+  - clang
diff --git a/Makefile.am b/Makefile.am
index 566c6e1..51932b2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,5 +2,5 @@ AUTOMAKE_OPTIONS = foreign
 SUBDIRS = src man
 
 docdir = $(datadir)/doc/@PACKAGE@
-doc_DATA = Changes README
-EXTRA_DIST = Changes README
+doc_DATA = Changes README.md
+EXTRA_DIST = Changes README.md
diff --git a/README b/README
deleted file mode 100644
index d7e0d16..0000000
--- a/README
+++ /dev/null
@@ -1,213 +0,0 @@
-
-   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"
-   reiserfs 0x83  "ReiserFS filesystem"
-   hmlvm    0xFE  "Linux LVM physical volumes"
-   qnx4     0x4F  "QNX 4.x"
-   beos     0xEB  "BeOS fs"
-   xfs      0x83  "SGI XFS filesystem"
-
-
-
- - Guessing modules ------------------------------------------------------
-
-   Each guessing module must provide three functions callabble 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.
-
-
- - Output explanation ----------------------------------------------------
-
-   Here is a sample 'gpart -v' run on my first IDE hard disk
-   (comments in brackets):
-
-dev(/dev/hda) mss(512) chs(1232/255/63)(LBA) #s(19792080) size(9664mb)
-[
-   mss is the medium sector size, chs the geometry retrieved
-   from the OS (or from the command line), #s is the total
-   sector count.
-]
-
-Primary partition(1)
-   type: 006(0x06)(Primary 'big' DOS (> 32MB)) (BOOT)
-   size: 502mb #s(1028097) s(63-1028159)
-   chs:  (0/1/1)-(63/254/63)d (0/1/1)-(63/254/63)r
-   hex:  80 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)
-   type: 006(0x06)(Primary 'big' DOS (> 32MB))
-   size: 502mb #s(1028097) s(63-1028159)
-   chs:  (0/1/1)-(63/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
-
-Possible extended partition at offset(502mb)
-   Possible partition(Linux ext2), size(31mb), offset(502mb)
-      type: 131(0x83)(Linux ext2 filesystem)
-      size: 31mb #s(64196) s(1028223-1092418)
-      chs:  (64/1/1)-(67/254/62)d (64/1/1)-(67/254/62)r
-      hex:  00 01 01 40 83 FE 3E 43 7F B0 0F 00 C4 FA 00 00
-
-   Possible partition(Linux swap), size(125mb), offset(533mb)
-      type: 130(0x82)(Linux swap or Solaris/x86)
-      size: 125mb #s(256976) s(1092483-1349458)
-      chs:  (68/1/1)-(83/254/62)d (68/1/1)-(83/254/62)r
-      hex:  00 01 01 44 82 FE 3E 53 83 AB 10 00 D0 EB 03 00
-[
-   During the scan phase all found partitions are listed by
-   their real type names. The Linux swap partition above is
-   recognized as Linux swap but will get the 0x82 partition
-   identifier which can be both a Solaris disklabel or a
-   Linux swap partition.
-
-   When examing the hex values of the first primary partition
-   it can be seen that they are identical to the values of the
-   actual partition table (good guess) except for the first
-   value (0x80 vs. 0x00). This entry denotes the partition
-   'boot' flag which cannot be guessed.
-]
-...
-End scan.
-
-Checking partitions...
-Partition(Primary 'big' DOS (> 32MB)): primary
-   Partition(Linux ext2 filesystem): logical
-   Partition(Linux swap or Solaris/x86): logical
-   Partition(Linux LVM physical volume): logical
-   Partition(Linux ext2 filesystem): logical
-   Partition(DOS or Windows 95 with 32 bit FAT, LBA): logical
-Partition(FreeBSD/NetBSD/386BSD): primary
-Partition(Linux LVM physical volume): primary
-Ok.
-[
-   During the scan phase gpart gathers a simple list of possible
-   partitions, the check phase now tries to decide if found
-   extended partitions seem consistent, if partitions do not
-   overlap etc. Overlapping partitions are silently discarded,
-   all remaining ones are given an attribute 'primary', 'logical',
-   'orphaned' or 'invalid'. If gpart is called like 'gpart -vv ...',
-   it also tells why it thinks a partition guess is invalid.
-
-   If any inconsistencies are found, gpart prints the number
-   of remaining inconsistencies, otherwise it says 'Ok.'
-]
-
-Guessed primary partition table:
-Primary partition(1)
-   type: 006(0x06)(Primary 'big' DOS (> 32MB))
-   size: 502mb #s(1028097) s(63-1028159)
-   chs:  (0/1/1)-(63/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: 6157mb #s(12611025) s(1028160-13639184)
-   chs:  (64/0/1)-(848/254/63)d (64/0/1)-(848/254/63)r
-   hex:  00 00 01 40 05 FE FF 50 40 B0 0F 00 D1 6D C0 00
-
-Primary partition(3)
-   type: 165(0xA5)(FreeBSD/NetBSD/386BSD)
-   size: 1396mb #s(2859570) s(13639185-16498754)
-   chs:  (849/0/1)-(1023/254/63)d (849/0/1)-(1026/254/63)r
-   hex:  00 00 C1 51 A5 FE FF FF 11 1E D0 00 32 A2 2B 00
-
-Primary partition(4)
-   type: 254(0xFE)(Linux LVM physical volume)
-   size: 1608mb #s(3293325) s(16498755-19792079)
-   chs:  (1023/254/63)-(1023/254/63)d (1027/0/1)-(1231/254/63)r
-   hex:  00 FE FF FF FE FE FF FF 43 C0 FB 00 8D 40 32 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 (via the '-W'
-   option) which partition gets the active (bootable) one.
-]
-
-
-
-   gpart README, Aug 1999, Michail Brzitwa <mb at ichabod.han.de>
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7cd3e2d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,211 @@
+# gpart
+
+[![Build Status](https://travis-ci.org/baruch/gpart.svg)](https://travis-ci.org/baruch/gpart)
+
+Gpart is a small tool which tries to guess what partitions
+are on a PC type, MBR-partitioned hard disk 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 filesystem it knows about could start at
+a given sector. Several filesystem guessing modules are built
+in.
+
+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
+   reiserfs | 0x83 | ReiserFS filesystem
+   hmlvm    | 0xFE | Linux LVM physical volumes
+   qnx4     | 0x4F | QNX 4.x
+   beos     | 0xEB | BeOS fs
+   xfs      | 0x83 | SGI XFS filesystem
+
+
+
+## Guessing modules
+
+Each guessing module 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.
+
+
+## Output explanation
+
+Here is a sample `gpart -v` run on my first IDE hard disk
+(comments in block-quotes):
+
+    dev(/dev/hda) mss(512) chs(1232/255/63)(LBA) #s(19792080) size(9664mb)
+
+>   `mss` is the medium sector size, `chs` the geometry retrieved
+>   from the OS (or from the command line), `#s` is the total
+>   sector count.
+
+    Primary partition(1)
+       type: 006(0x06)(Primary 'big' DOS (> 32MB)) (BOOT)
+       size: 502mb #s(1028097) s(63-1028159)
+       chs:  (0/1/1)-(63/254/63)d (0/1/1)-(63/254/63)r
+       hex:  80 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
+>   (`r`). 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)
+       type: 006(0x06)(Primary 'big' DOS (> 32MB))
+       size: 502mb #s(1028097) s(63-1028159)
+       chs:  (0/1/1)-(63/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
+
+    Possible extended partition at offset(502mb)
+        Possible partition(Linux ext2), size(31mb), offset(502mb)
+          type: 131(0x83)(Linux ext2 filesystem)
+          size: 31mb #s(64196) s(1028223-1092418)
+          chs:  (64/1/1)-(67/254/62)d (64/1/1)-(67/254/62)r
+          hex:  00 01 01 40 83 FE 3E 43 7F B0 0F 00 C4 FA 00 00
+
+       Possible partition(Linux swap), size(125mb), offset(533mb)
+          type: 130(0x82)(Linux swap or Solaris/x86)
+          size: 125mb #s(256976) s(1092483-1349458)
+          chs:  (68/1/1)-(83/254/62)d (68/1/1)-(83/254/62)r
+          hex:  00 01 01 44 82 FE 3E 53 83 AB 10 00 D0 EB 03 00
+
+>   During the scan phase all found partitions are listed by
+>   their real type names. The Linux swap partition above is
+>   recognized as Linux swap but will get the 0x82 partition
+>   identifier which can be both a Solaris disklabel or a
+>   Linux swap partition.
+>
+>   When examining the hex values of the first primary partition
+>   it can be seen that they are identical to the values of the
+>   actual partition table (good guess) except for the first
+>   value (0x80 vs. 0x00). This entry denotes the partition
+>   'boot' flag which cannot be guessed.
+
+...
+
+    End scan.
+
+    Checking partitions...
+    Partition(Primary 'big' DOS (> 32MB)): primary
+       Partition(Linux ext2 filesystem): logical
+       Partition(Linux swap or Solaris/x86): logical
+       Partition(Linux LVM physical volume): logical
+       Partition(Linux ext2 filesystem): logical
+       Partition(DOS or Windows 95 with 32 bit FAT, LBA): logical
+    Partition(FreeBSD/NetBSD/386BSD): primary
+    Partition(Linux LVM physical volume): primary
+    Ok.
+
+>   During the scan phase gpart gathers a simple list of possible
+>   partitions, the check phase now tries to decide if found
+>   extended partitions seem consistent, if partitions do not
+>   overlap etc. Overlapping partitions are silently discarded,
+>   all remaining ones are given an attribute 'primary', 'logical',
+>   'orphaned' or 'invalid'. If gpart is called like `gpart -vv ...`,
+>   it also tells why it thinks a partition guess is invalid.
+>
+>   If any inconsistencies are found, gpart prints the number
+>   of remaining inconsistencies, otherwise it says 'Ok.'
+
+    Guessed primary partition table:
+    Primary partition(1)
+       type: 006(0x06)(Primary 'big' DOS (> 32MB))
+       size: 502mb #s(1028097) s(63-1028159)
+       chs:  (0/1/1)-(63/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: 6157mb #s(12611025) s(1028160-13639184)
+       chs:  (64/0/1)-(848/254/63)d (64/0/1)-(848/254/63)r
+       hex:  00 00 01 40 05 FE FF 50 40 B0 0F 00 D1 6D C0 00
+
+    Primary partition(3)
+       type: 165(0xA5)(FreeBSD/NetBSD/386BSD)
+       size: 1396mb #s(2859570) s(13639185-16498754)
+       chs:  (849/0/1)-(1023/254/63)d (849/0/1)-(1026/254/63)r
+       hex:  00 00 C1 51 A5 FE FF FF 11 1E D0 00 32 A2 2B 00
+
+    Primary partition(4)
+       type: 254(0xFE)(Linux LVM physical volume)
+       size: 1608mb #s(3293325) s(16498755-19792079)
+       chs:  (1023/254/63)-(1023/254/63)d (1027/0/1)-(1231/254/63)r
+       hex:  00 FE FF FF FE FE FF FF 43 C0 FB 00 8D 40 32 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 (via the `-W`
+>   option) which partition gets the active (bootable) one.
+
+## Author
+
+gpart README, Aug 1999, Michail Brzitwa <mb at ichabod.han.de>
diff --git a/configure.ac b/configure.ac
index 6357bd5..6eca1de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,9 +1,9 @@
 #                                               -*- Autoconf -*-
 # Process this file with autoconf to produce a configure script.
 
-AC_PREREQ([2.69])
-AC_INIT(gpart, 0.2.1, https://github.com/baruch/gpart/issues)
-AM_INIT_AUTOMAKE([1.14])
+AC_PREREQ([2.64])
+AC_INIT(gpart, 0.2.3-dev, https://github.com/baruch/gpart/issues)
+AM_INIT_AUTOMAKE([1.11])
 AC_CONFIG_SRCDIR([src/gpart.c])
 AC_CONFIG_HEADERS([config.h])
 
@@ -28,6 +28,9 @@ AC_TYPE_UINT8_T
 AC_FUNC_MALLOC
 AC_CHECK_FUNCS([getpagesize memset strchr strdup strerror strtoul])
 
+# Configure system services.
+AC_SYS_LARGEFILE
+
 AC_CONFIG_FILES([Makefile
                  man/Makefile
                  src/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index ad9bc9a..9e6086c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,5 +2,5 @@ AM_CFLAGS = -Wall -O2
 AM_LDFLAGS =
 
 sbin_PROGRAMS = gpart
-gpart_SOURCES = disku.c gm_beos.c gm_bsddl.c gm_ext2.c gm_fat.c gm_hmlvm.c gm_hpfs.c gm_lswap.c gm_minix.c gm_ntfs.c gmodules.c gm_qnx4.c gm_reiserfs.c gm_s86dl.c gm_xfs.c gpart.c l64seek.c
-EXTRA_DIST = errmsgs.h gm_bsddl.h gm_fat.h gm_hpfs.h gm_ntfs.h gm_qnx4.h gm_s86dl.h gpart.h gm_beos.h gm_ext2.h gm_hmlvm.h gm_minix.h gmodules.h gm_reiserfs.h gm_xfs.h l64seek.h
+gpart_SOURCES = disku.c gm_beos.c gm_bsddl.c gm_ext2.c gm_btrfs.c gm_fat.c gm_hmlvm.c gm_lvm2.c gm_hpfs.c gm_lswap.c gm_minix.c gm_ntfs.c gmodules.c gm_qnx4.c gm_reiserfs.c gm_s86dl.c gm_xfs.c gpart.c l64seek.c
+EXTRA_DIST = errmsgs.h gm_bsddl.h gm_fat.h gm_hpfs.h gm_ntfs.h gm_qnx4.h gm_s86dl.h gpart.h gm_beos.h gm_ext2.h gm_btrfs.h gm_hmlvm.h gm_lvm2.h gm_minix.h gmodules.h gm_reiserfs.h gm_xfs.h l64seek.h
diff --git a/src/gm_beos.c b/src/gm_beos.c
index 4b88d6a..2f65586 100644
--- a/src/gm_beos.c
+++ b/src/gm_beos.c
@@ -22,9 +22,6 @@
 
 #include <stdio.h>
 
-static const char	rcsid[] = "$Id: gm_beos.c,v 1.2 2001/02/07 18:08:08 mb Exp mb $";
-
-
 int beos_init(disk_desc *d,g_module *m)
 {
 	if ((d == 0) || (m == 0))
diff --git a/src/gm_bsddl.c b/src/gm_bsddl.c
index daf6d92..334c08b 100644
--- a/src/gm_bsddl.c
+++ b/src/gm_bsddl.c
@@ -17,8 +17,6 @@
 #include "gpart.h"
 #include "gm_bsddl.h"
 
-static const char	rcsid[] = "$Id: gm_bsddl.c,v 1.6 2001/02/07 18:08:08 mb Exp mb $";
-
 
 int bsddl_init(disk_desc *d,g_module *m)
 {
diff --git a/src/gm_btrfs.c b/src/gm_btrfs.c
new file mode 100644
index 0000000..309bb48
--- /dev/null
+++ b/src/gm_btrfs.c
@@ -0,0 +1,74 @@
+/*
+ * gm_btrfs.c -- gpart Linux Btrfs volume guessing module
+ *
+ * gpart (c) 1999-2001 Michail Brzitwa <mb at ichabod.han.de>
+ * Guess PC-type hard disk partitions.
+ *
+ * gpart is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Created:   20.11.2015 <mwilck at arcor.de>
+ *
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <endian.h>
+#include "gpart.h"
+#include "gm_btrfs.h"
+
+
+int btrfs_init(disk_desc *d,g_module *m)
+{
+	if ((d == 0) || (m == 0))
+		return (0);
+
+	m->m_desc = "Btrfs volume";
+	return BTRFS_SUPER_INFO_OFFSET + BTRFS_SUPER_INFO_SIZE;
+}
+
+int btrfs_term(disk_desc *d)
+{
+	return (1);
+}
+
+int btrfs_gfun(disk_desc *d,g_module *m)
+{
+	struct btrfs_super_block *sb;
+	dos_part_entry *pt = &m->m_part;
+	s64_t psize;
+
+	m->m_guess = GM_NO;
+	sb = (struct btrfs_super_block*)
+		(d->d_sbuf + BTRFS_SUPER_INFO_OFFSET);
+
+	if (le64toh(sb->magic) != BTRFS_MAGIC)
+		return 1;
+
+	if (memcmp(sb->fsid, sb->dev_item.fsid, BTRFS_FSID_SIZE))
+		return 1;
+
+	psize = le64toh(sb->dev_item.total_bytes);
+	if (psize > btrfs_sb_offset(1)) {
+		struct btrfs_super_block sb_copy;
+		if (l64seek(d->d_fd,
+			    d->d_nsb * d->d_ssize + btrfs_sb_offset(1),
+			    SEEK_SET) == -1)
+			pr(FATAL,"btrfs: cannot seek: %s", strerror(errno));
+		read(d->d_fd, &sb_copy, sizeof(sb_copy));
+		if (le64toh(sb_copy.magic) != BTRFS_MAGIC ||
+		    memcmp(sb->fsid, sb_copy.fsid, BTRFS_FSID_SIZE)) {
+			pr(MSG,"btrfs: superblock copy mismatch\n");
+			return 1;
+		}
+	}
+
+	m->m_guess = GM_YES;
+	pt->p_start = d->d_nsb;
+	pt->p_size = psize / d->d_ssize;
+	pt->p_typ = 0x83;
+
+	return 1;
+}
diff --git a/src/gm_btrfs.h b/src/gm_btrfs.h
new file mode 100644
index 0000000..7b3d13f
--- /dev/null
+++ b/src/gm_btrfs.h
@@ -0,0 +1,175 @@
+/*
+ * gm_btrfs.h -- gpart Btrfs volume guessing module header
+ *
+ * gpart (c) 1999-2001 Michail Brzitwa <mb at ichabod.han.de>
+ * Guess PC-type hard disk partitions.
+ *
+ * gpart is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Created:   20.11.2015 <mwilck at arcor.de>
+ * Modified:
+ *
+ */
+
+#ifndef _GM_BTRFS_H
+#define _GM_BTRFS_H
+
+/*
+ * structs & defines gathered from btrfs-progs
+ */
+
+#if !defined(__FreeBSD__)
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+#endif
+
+typedef uint64_t __le64;
+typedef uint32_t __le32;
+typedef uint16_t __le16;
+typedef uint8_t u8;
+
+#define BTRFS_SUPER_INFO_OFFSET (64 * 1024)
+#define BTRFS_SUPER_INFO_SIZE 4096
+#define btrfs_sb_offset(i) ((i) ? ((16*1024) << (BTRFS_SUPER_MIRROR_SHIFT * (i))) : BTRFS_SUPER_INFO_SIZE)
+#define BTRFS_SUPER_MIRROR_SHIFT 12
+#define BTRFS_CSUM_SIZE 32
+#define BTRFS_FSID_SIZE 16
+#define BTRFS_UUID_SIZE 16
+#define BTRFS_MAGIC 0x4D5F53665248425FULL
+#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
+#define BTRFS_LABEL_SIZE 256
+
+#define BTRFS_NUM_BACKUP_ROOTS 4
+struct btrfs_root_backup {
+	__le64 tree_root;
+	__le64 tree_root_gen;
+
+	__le64 chunk_root;
+	__le64 chunk_root_gen;
+
+	__le64 extent_root;
+	__le64 extent_root_gen;
+
+	__le64 fs_root;
+	__le64 fs_root_gen;
+
+	__le64 dev_root;
+	__le64 dev_root_gen;
+
+	__le64 csum_root;
+	__le64 csum_root_gen;
+
+	__le64 total_bytes;
+	__le64 bytes_used;
+	__le64 num_devices;
+	/* future */
+	__le64 unsed_64[4];
+
+	u8 tree_root_level;
+	u8 chunk_root_level;
+	u8 extent_root_level;
+	u8 fs_root_level;
+	u8 dev_root_level;
+	u8 csum_root_level;
+	/* future and to align */
+	u8 unused_8[10];
+} __attribute__ ((__packed__));
+
+#define BTRFS_UUID_SIZE 16
+struct btrfs_dev_item {
+	/* the internal btrfs device id */
+	__le64 devid;
+
+	/* size of the device */
+	__le64 total_bytes;
+
+	/* bytes used */
+	__le64 bytes_used;
+
+	/* optimal io alignment for this device */
+	__le32 io_align;
+
+	/* optimal io width for this device */
+	__le32 io_width;
+
+	/* minimal io size for this device */
+	__le32 sector_size;
+
+	/* type and info about this device */
+	__le64 type;
+
+	/* expected generation for this device */
+	__le64 generation;
+
+	/*
+	 * starting byte of this partition on the device,
+	 * to allowr for stripe alignment in the future
+	 */
+	__le64 start_offset;
+
+	/* grouping information for allocation decisions */
+	__le32 dev_group;
+
+	/* seek speed 0-100 where 100 is fastest */
+	u8 seek_speed;
+
+	/* bandwidth 0-100 where 100 is fastest */
+	u8 bandwidth;
+
+	/* btrfs generated uuid for this device */
+	u8 uuid[BTRFS_UUID_SIZE];
+
+	/* uuid of FS who owns this device */
+	u8 fsid[BTRFS_UUID_SIZE];
+} __attribute__ ((__packed__));
+
+struct btrfs_super_block {
+	u8 csum[BTRFS_CSUM_SIZE];
+	/* the first 3 fields must match struct btrfs_header */
+	u8 fsid[BTRFS_FSID_SIZE];    /* FS specific uuid */
+	__le64 bytenr; /* this block number */
+	__le64 flags;
+	/* allowed to be different from the btrfs_header from here own down */
+	__le64 magic;
+	__le64 generation;
+	__le64 root;
+	__le64 chunk_root;
+	__le64 log_root;
+
+	/* this will help find the new super based on the log root */
+	__le64 log_root_transid;
+	__le64 total_bytes;
+	__le64 bytes_used;
+	__le64 root_dir_objectid;
+	__le64 num_devices;
+	__le32 sectorsize;
+	__le32 nodesize;
+	__le32 leafsize;
+	__le32 stripesize;
+	__le32 sys_chunk_array_size;
+	__le64 chunk_root_generation;
+	__le64 compat_flags;
+	__le64 compat_ro_flags;
+	__le64 incompat_flags;
+	__le16 csum_type;
+	u8 root_level;
+	u8 chunk_root_level;
+	u8 log_root_level;
+	struct btrfs_dev_item dev_item;
+
+	char label[BTRFS_LABEL_SIZE];
+
+	__le64 cache_generation;
+	__le64 uuid_tree_generation;
+
+	/* future expansion */
+	__le64 reserved[30];
+	u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
+	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
+} __attribute__ ((__packed__));
+
+#endif /* _GM_BTRFS_H */
diff --git a/src/gm_ext2.c b/src/gm_ext2.c
index 81c2762..827013c 100644
--- a/src/gm_ext2.c
+++ b/src/gm_ext2.c
@@ -27,8 +27,6 @@
 #include "gpart.h"
 #include "gm_ext2.h"
 
-static const char	rcsid[] = "$Id: gm_ext2.c,v 1.8 2001/02/07 18:08:08 mb Exp mb $";
-
 
 int ext2_init(disk_desc *d,g_module *m)
 {
diff --git a/src/gm_fat.c b/src/gm_fat.c
index 3784a0c..9fde0bf 100644
--- a/src/gm_fat.c
+++ b/src/gm_fat.c
@@ -17,8 +17,6 @@
 #include "gpart.h"
 #include "gm_fat.h"
 
-static const char	rcsid[] = "$Id: gm_fat.c,v 1.6 2001/02/07 18:08:08 mb Exp mb $";
-
 
 int fat_init(disk_desc *d,g_module *m)
 {
@@ -60,12 +58,12 @@ int fat_gfun(disk_desc *d,g_module *m)
 		 */
 
 		pt->p_start = d->d_nsb;
-		nsecs = le16(*(unsigned short *)sb->sectors);
+		nsecs = le16(sb->sectors);
 		if (nsecs == 0)
 			nsecs = le32(sb->total_sect);
 		if (nsecs == 0)
 			return (1);
-		sectsize = le16(*(unsigned short *)sb->sector_size);
+		sectsize = le16(sb->sector_size);
 		if ((d->d_sbuf[0x39] == '1') && (d->d_sbuf[0x3a] == '2'))
 			fat12 = 1;
 		if (sb->fat_length == 0)
diff --git a/src/gm_fat.h b/src/gm_fat.h
index 5e0adf7..d205d9c 100644
--- a/src/gm_fat.h
+++ b/src/gm_fat.h
@@ -39,12 +39,12 @@ struct fat_boot_sector {
 	__s8	ignored[3];	/* Boot strap short or near jump */
 	__s8	system_id[8];	/* Name - can be used to special case
 				   partition manager volumes */
-	__u8	sector_size[2];	/* bytes per logical sector */
+	__u16	sector_size;	/* bytes per logical sector */
 	__u8	cluster_size;	/* sectors/cluster */
 	__u16	reserved;	/* reserved sectors */
 	__u8	fats;		/* number of FATs */
 	__u8	dir_entries[2];	/* root directory entries */
-	__u8	sectors[2];	/* number of sectors */
+	__u16	sectors;	/* number of sectors */
 	__u8	media;		/* media code (unused) */
 	__u16	fat_length;	/* sectors/FAT */
 	__u16	secs_track;	/* sectors per track */
diff --git a/src/gm_hmlvm.c b/src/gm_hmlvm.c
index e7aa467..2a3d411 100644
--- a/src/gm_hmlvm.c
+++ b/src/gm_hmlvm.c
@@ -20,8 +20,6 @@
 #include "gpart.h"
 #include "gm_hmlvm.h"
 
-static const char	rcsid[] = "$Id: gm_hmlvm.c,v 1.3 2001/02/07 18:08:08 mb Exp mb $";
-
 
 int hmlvm_init(disk_desc *d,g_module *m)
 {
diff --git a/src/gm_hpfs.c b/src/gm_hpfs.c
index 2cb50ea..e50659e 100644
--- a/src/gm_hpfs.c
+++ b/src/gm_hpfs.c
@@ -22,8 +22,6 @@
 #include "gpart.h"
 #include "gm_hpfs.h"
 
-static const char	rcsid[] = "$Id: gm_hpfs.c,v 1.8 2001/02/07 18:08:08 mb Exp mb $";
-
 #define OS2SECTSIZE		512
 
 
@@ -58,7 +56,7 @@ int hpfs_gfun(disk_desc *d,g_module *m)
 	if (	(bb->sig_28h == 0x28) &&
 		(strncmp((char *)bb->sig_hpfs,"HPFS    ",8) == 0) &&
 		(bb->magic == le16(0xaa55)) &&
-		(*(unsigned short *)bb->bytes_per_sector == le16(OS2SECTSIZE)))
+		(bb->bytes_per_sector == le16(OS2SECTSIZE)))
 	{
 		/*
 		 * looks like a hpfs boot sector. Test hpfs superblock
diff --git a/src/gm_hpfs.h b/src/gm_hpfs.h
index 9754eb7..b06e82e 100644
--- a/src/gm_hpfs.h
+++ b/src/gm_hpfs.h
@@ -42,7 +42,7 @@ struct hpfs_boot_block
 {
   unsigned char jmp[3];
   unsigned char oem_id[8];
-  unsigned char bytes_per_sector[2];	/* 512 */
+  unsigned short bytes_per_sector;	/* 512 */
   unsigned char sectors_per_cluster;
   unsigned char n_reserved_sectors[2];
   unsigned char n_fats;
diff --git a/src/gm_lswap.c b/src/gm_lswap.c
index e408f62..e7f4f55 100644
--- a/src/gm_lswap.c
+++ b/src/gm_lswap.c
@@ -19,7 +19,6 @@
 #include "gpart.h"
 
 
-static const char	rcsid[] = "$Id: gm_lswap.c,v 1.8 2001/02/07 18:08:08 mb Exp mb $";
 static char		*sigs[] = { "SWAP-SPACE", "SWAPSPACE2" };
 static int		pszs[] = { 4096, 8192 };
 static int		siglen = 10;
diff --git a/src/gm_lvm2.c b/src/gm_lvm2.c
new file mode 100644
index 0000000..23a66b8
--- /dev/null
+++ b/src/gm_lvm2.c
@@ -0,0 +1,66 @@
+/*
+ * gm_lvm2.c -- gpart Linux LVM2 physical volume guessing module
+ *
+ * gpart (c) 1999-2001 Michail Brzitwa <mb at ichabod.han.de>
+ * Guess PC-type hard disk partitions.
+ *
+ * gpart is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Created:   20.11.2015 <mwilck at arcor.de>
+ *
+ */
+
+#include <string.h>
+#include <errno.h>
+#include "gpart.h"
+#include "gm_lvm2.h"
+
+
+int lvm2_init(disk_desc *d,g_module *m)
+{
+	if ((d == 0) || (m == 0))
+		return (0);
+
+	m->m_desc = "Linux LVM2 physical volume";
+	return SECTOR_SIZE + LABEL_SIZE;
+}
+
+
+
+int lvm2_term(disk_desc *d)
+{
+	return (1);
+}
+
+
+
+int lvm2_gfun(disk_desc *d,g_module *m)
+{
+	struct label_header *lh;
+	struct pv_header *pvh;
+	dos_part_entry *pt = &m->m_part;
+	s64_t pv_size;
+	byte_t *p = d->d_sbuf + SECTOR_SIZE;
+
+	m->m_guess = GM_NO;
+	lh = (struct label_header*)p;
+	if (strncmp((char*)lh->id, LABEL_ID, sizeof(lh->id)) ||
+	    strncmp((char*)lh->type, LVM2_LABEL, sizeof(lh->type)))
+		return 1;
+
+	pvh = (struct pv_header*) ((char*)lh + le32toh(lh->offset_xl));
+	pv_size = le64toh(pvh->device_size_xl);
+	pv_size /=  d->d_ssize;
+	if (d->d_nsecs != 0 && pv_size > d->d_nsecs - d->d_nsb)
+		return 1;
+
+	m->m_guess = GM_YES;
+	pt->p_start = d->d_nsb;
+	pt->p_size = pv_size;
+	pt->p_typ = 0x8E;
+
+	return 1;
+}
diff --git a/src/gm_lvm2.h b/src/gm_lvm2.h
new file mode 100644
index 0000000..0bf4966
--- /dev/null
+++ b/src/gm_lvm2.h
@@ -0,0 +1,65 @@
+/*
+ * gm_lvm2.h -- gpart Linux LVM physical volume guessing module header
+ *
+ * gpart (c) 1999-2001 Michail Brzitwa <mb at ichabod.han.de>
+ * Guess PC-type hard disk partitions.
+ *
+ * gpart is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Created:   19.11.2015 <mwilck at arcor.de>
+ * Modified:
+ *
+ */
+
+#ifndef _GM_LVM2_H
+#define _GM_LVM2_H
+#include <endian.h>
+
+/*
+ * structs & defines gathered from LVM2
+ */
+
+#if !defined(__FreeBSD__)
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+#endif
+
+#define ID_LEN 32
+#define SECTOR_SHIFT 9
+#define SECTOR_SIZE (1 << SECTOR_SHIFT)
+#define LABEL_ID "LABELONE"
+#define LABEL_SIZE SECTOR_SIZE
+#define LABEL_SCAN_SECTORS 4L
+#define LABEL_SCAN_SIZE (LABEL_SCAN_SECTORS << SECTOR_SHIFT)
+#define LVM2_LABEL "LVM2 001"
+
+/* On disk - 32 bytes */
+struct label_header {
+	int8_t id[8];		/* LABELONE */
+	uint64_t sector_xl;	/* Sector number of this label */
+	uint32_t crc_xl;	/* From next field to end of sector */
+	uint32_t offset_xl;	/* Offset from start of struct to contents */
+	int8_t type[8];		/* LVM2 001 */
+} __attribute__ ((packed));
+
+struct disk_locn {
+        uint64_t offset;        /* Offset in bytes to start sector */
+        uint64_t size;          /* Bytes */
+} __attribute__ ((packed));
+
+struct pv_header {
+	int8_t pv_uuid[ID_LEN];
+
+	/* This size can be overridden if PV belongs to a VG */
+	uint64_t device_size_xl;	/* Bytes */
+
+	/* NULL-terminated list of data areas followed by */
+	/* NULL-terminated list of metadata area headers */
+	struct disk_locn disk_areas_xl[0];	/* Two lists */
+} __attribute__ ((packed));
+
+#endif /* _GM_LVM2_H */
diff --git a/src/gm_minix.c b/src/gm_minix.c
index a1a26d2..98b1ac4 100644
--- a/src/gm_minix.c
+++ b/src/gm_minix.c
@@ -17,8 +17,6 @@
 #include "gpart.h"
 #include "gm_minix.h"
 
-static const char	rcsid[] = "$Id: gm_minix.c,v 1.5 2001/02/07 18:08:08 mb Exp mb $";
-
 
 int minix_init(disk_desc *d,g_module *m)
 {
diff --git a/src/gm_ntfs.c b/src/gm_ntfs.c
index f3e2a16..25bdaad 100644
--- a/src/gm_ntfs.c
+++ b/src/gm_ntfs.c
@@ -21,8 +21,6 @@
 #include "gpart.h"
 #include "gm_ntfs.h"
 
-static const char	rcsid[] = "$Id: gm_ntfs.c,v 1.6 2001/02/07 18:08:08 mb Exp mb $";
-
 #define NTFS_SECTSIZE	512
 
 int ntfs_init(disk_desc *d,g_module *m)
diff --git a/src/gm_qnx4.c b/src/gm_qnx4.c
index 17d6317..f13cbe6 100644
--- a/src/gm_qnx4.c
+++ b/src/gm_qnx4.c
@@ -22,8 +22,6 @@
 
 #include <stdio.h>
 
-static const char	rcsid[] = "$Id: gm_qnx4.c,v 1.1 2001/01/29 17:11:34 mb Exp mb $";
-
 
 int qnx4_init(disk_desc *d,g_module *m)
 {
diff --git a/src/gm_reiserfs.c b/src/gm_reiserfs.c
index 8cd4e59..4017da3 100644
--- a/src/gm_reiserfs.c
+++ b/src/gm_reiserfs.c
@@ -22,8 +22,6 @@
 #include "gpart.h"
 #include "gm_reiserfs.h"
 
-static const char	rcsid[] = "$Id: gm_reiserfs.c,v 1.5 2003/01/10 16:38:08 mb Exp mb $";
-
 
 int reiserfs_init(disk_desc *d,g_module *m)
 {
diff --git a/src/gm_s86dl.c b/src/gm_s86dl.c
index 8c240e2..4831798 100644
--- a/src/gm_s86dl.c
+++ b/src/gm_s86dl.c
@@ -17,8 +17,6 @@
 #include "gpart.h"
 #include "gm_s86dl.h"
 
-static const char	rcsid[] = "$Id: gm_s86dl.c,v 1.6 2001/02/07 18:08:08 mb Exp mb $";
-
 
 int s86dl_init(disk_desc *d,g_module *m)
 {
diff --git a/src/gm_xfs.c b/src/gm_xfs.c
index f5bc9b9..8e8d268 100644
--- a/src/gm_xfs.c
+++ b/src/gm_xfs.c
@@ -18,8 +18,6 @@
 #include "gpart.h"
 #include "gm_xfs.h"
 
-static const char	rcsid[] = "$Id: gm_xfs.c,v 1.1 2001/02/07 18:08:08 mb Exp mb $";
-
 
 int xfs_init(disk_desc *d,g_module *m)
 {
diff --git a/src/gmodules.h b/src/gmodules.h
index 0b43b43..05c6d9c 100644
--- a/src/gmodules.h
+++ b/src/gmodules.h
@@ -66,9 +66,11 @@ g_module *g_mod_setweight(char *,float);
 	G_MODULE(minix) \
 	G_MODULE(beos) \
 	G_MODULE(ext2) \
+	G_MODULE(btrfs) \
 	G_MODULE(fat) \
 	G_MODULE(s86dl) \
 	G_MODULE(hmlvm) \
+	G_MODULE(lvm2) \
 	G_MODULE(xfs)
 
 #define G_MODULE(mod)	int mod##_init(disk_desc *,g_module *),	\
diff --git a/src/gpart.c b/src/gpart.c
index 50899ea..8555f66 100644
--- a/src/gpart.c
+++ b/src/gpart.c
@@ -59,7 +59,6 @@
 #include "gpart.h"
 
 
-static const char	rcsid[] = "$Id: gpart.c,v 1.11 2001/02/07 18:08:08 mb Exp mb $";
 static const char	*gpart_version = PACKAGE_NAME " v" VERSION;
 
 
diff --git a/src/l64seek.c b/src/l64seek.c
index 9b2084c..a9df80a 100644
--- a/src/l64seek.c
+++ b/src/l64seek.c
@@ -14,6 +14,7 @@
  *
  */
 
+#include "config.h" /* for large file support */
 #include "l64seek.h"
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/gpart.git



More information about the forensics-changes mailing list