[Forensics-changes] [gpart] 01/02: Imported Upstream version 0.2.2
Joao Eriberto Mota Filho
eriberto at moszumanska.debian.org
Thu Mar 12 17:28:27 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 ade8c2afaaf19355827f040c5241f80d38057a9b
Author: Joao Eriberto Mota Filho <eriberto at debian.org>
Date: Thu Mar 12 14:26:58 2015 -0300
Imported Upstream version 0.2.2
---
.gitignore | 18 +++++++++++
Changes | 12 ++++++++
Makefile | 23 --------------
Makefile.am | 6 ++++
README | 67 +++++++++++++++-------------------------
autogen.sh | 7 +++++
configure.ac | 35 +++++++++++++++++++++
inst.defs | 9 ------
make.defs | 12 --------
man/Makefile | 26 ----------------
man/Makefile.am | 1 +
man/{gpart.man => gpart.8.in} | 40 +++++++++++-------------
src/Makefile | 61 ------------------------------------
src/Makefile.am | 6 ++++
src/disku.c | 63 +++++++++++++++++++++++++++++++++-----
src/gm_ext2.c | 3 +-
src/gm_fat.h | 8 +++--
src/gm_ntfs.c | 8 -----
src/gm_ntfs.h | 36 +++++++++++-----------
src/{gm_rfs.c => gm_reiserfs.c} | 25 ++++++++-------
src/{gm_rfs.h => gm_reiserfs.h} | 30 +++++++++++++-----
src/gmodules.c | 67 ++++++++--------------------------------
src/gmodules.h | 33 ++++++++++++--------
src/gpart.c | 68 ++++++++++++++++++++---------------------
src/gpart.h | 64 +++++++++-----------------------------
src/l64seek.c | 17 -----------
src/l64seek.h | 17 ++---------
27 files changed, 330 insertions(+), 432 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d02824a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,18 @@
+*.o
+src/gpart
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache/
+compile
+config.h
+config.h.in
+config.log
+config.status
+configure
+depcomp
+install-sh
+man/gpart.8
+missing
+.deps/
+stamp-h1
diff --git a/Changes b/Changes
index 5bbd0c1..9c0d4c5 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,15 @@
+v0.2.1
+ - Fix distribution issues that prevented builds of dist tarball
+
+v0.2
+ - Import some FreeBSD patches
+ - Default scan by sector size to handle new 4k alignment method
+ - Properly consider the real size of the disk to not invalidate partitions
+
+v0.1i
+ - Switch to autoconf/automake for cross-platform support
+ - Integrate patches from distributions to fix build and overflow issues
+
v0.1h
- New support for the following filesystems: BeOS, QNX 4.x & SGI XFS.
- Updated Reiser filesystem support (Francis Devereux <francis at devereux.tc>).
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 99d6764..0000000
--- a/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-# gpart Makefile
-#
-include inst.defs
-include make.defs
-
-all: gpart
-
-gpart:
- $(MAKE) -C src
- $(MAKE) -C man
-
-install:
- $(MAKE) -C src install
- $(MAKE) -C man install
-
-uninstall:
- $(MAKE) -C src uninstall
- $(MAKE) -C man uninstall
-
-clean:
- $(MAKE) -C src clean
- $(MAKE) -C man clean
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..566c6e1
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,6 @@
+AUTOMAKE_OPTIONS = foreign
+SUBDIRS = src man
+
+docdir = $(datadir)/doc/@PACKAGE@
+doc_DATA = Changes README
+EXTRA_DIST = Changes README
diff --git a/README b/README
index dc5ed68..d7e0d16 100644
--- a/README
+++ b/README
@@ -24,35 +24,31 @@
- 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"
- rfs 0x83 "Reiser filesystem"
- hmlvm 0xFE "Linux LVM physical volumes"
- qnx4 0x4F "QNX 4.x"
- beos 0xEB "BeOS fs"
- xfs 0x83 "SGI XFS filesystem"
-
-
-
- - 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
+ 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)
@@ -89,19 +85,6 @@
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 ----------------------------------------------------
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..7882de4
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+set -e
+aclocal
+autoconf
+autoheader
+automake --add-missing
+./configure
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..6357bd5
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,35 @@
+# -*- 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_CONFIG_SRCDIR([src/gpart.c])
+AC_CONFIG_HEADERS([config.h])
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_INSTALL
+
+# Checks for header files.
+AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h sys/ioctl.h sys/mount.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_TYPE_INT16_T
+AC_TYPE_INT8_T
+AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
+AC_TYPE_UINT16_T
+AC_TYPE_UINT32_T
+AC_TYPE_UINT64_T
+AC_TYPE_UINT8_T
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_CHECK_FUNCS([getpagesize memset strchr strdup strerror strtoul])
+
+AC_CONFIG_FILES([Makefile
+ man/Makefile
+ src/Makefile
+ man/gpart.8])
+AC_OUTPUT
diff --git a/inst.defs b/inst.defs
deleted file mode 100644
index 575a27f..0000000
--- a/inst.defs
+++ /dev/null
@@ -1,9 +0,0 @@
-#
-# installation directories for gpart
-#
-prefix=/usr/local
-bindir=$(prefix)/bin
-libdir=$(prefix)/lib
-mandir=$(prefix)/man
-manext=8
-sharedir=$(prefix)/share
diff --git a/make.defs b/make.defs
deleted file mode 100644
index 42412c8..0000000
--- a/make.defs
+++ /dev/null
@@ -1,12 +0,0 @@
-#
-#
-#
-CC = gcc
-CFLAGS = -Wall -O2 -pedantic
-LDFLAGS =
-MAKEDEP = gcc -M
-INSTALL = install
-RM = rm -f
-#
-prg = gpart
-version = 0.1h
diff --git a/man/Makefile b/man/Makefile
deleted file mode 100644
index 3e05e47..0000000
--- a/man/Makefile
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# gpart man Makefile
-#
-include ../inst.defs
-include ../make.defs
-
-
-all: $(prg).$(manext)
-
-$(prg).$(manext): $(prg).man
- @sed -e 's/%MANEXT%/$(manext)/g' \
- -e 's/%VERSION%/$(version)/g' < $< > $@
-
-$(prg).$(manext).ps: $(prg).$(manext)
- @groff -man $< > $@
-
-clean:
- @$(RM) $(prg).$(manext) $(prg).$(manext).ps
-
-install: $(prg).$(manext)
- $(INSTALL) -d $(mandir)
- $(INSTALL) -d $(mandir)/man$(manext)
- $(INSTALL) -m 0444 $(prg).$(manext) $(mandir)/man$(manext)
-
-uninstall:
- $(RM) $(mandir)/man$(manext)/$(prg).$(manext)
diff --git a/man/Makefile.am b/man/Makefile.am
new file mode 100644
index 0000000..87f032d
--- /dev/null
+++ b/man/Makefile.am
@@ -0,0 +1 @@
+man_MANS = gpart.8
diff --git a/man/gpart.man b/man/gpart.8.in
similarity index 94%
rename from man/gpart.man
rename to man/gpart.8.in
index 7ebbaf4..40aa5ff 100644
--- a/man/gpart.man
+++ b/man/gpart.8.in
@@ -1,7 +1,7 @@
.\"
-.\" gpart v%VERSION% man page (c) Jan 1999 Michail Brzitwa
+.\" gpart v at VERSION@ man page (c) Jan 1999 Michail Brzitwa
.\"
-.TH GPART %MANEXT% "January 2001" "Administration Tools"
+.TH GPART 8 "January 2001" "Administration Tools"
.SH NAME
gpart \- guess PC-type hard disk partitions
.SH SYNOPSIS
@@ -9,10 +9,10 @@ gpart \- guess PC-type hard disk partitions
[options]
.I device
-Options: [-b <backup MBR>][-C c,h,s][-c][-d][-E][-e][-f]
-[-g][-h][-i][-K <last-sector>][-k <# of sectors>] [-L]
-[-l <log file>][-n <increment>] [-q][-s <sector-size>]
-[-t <module-name>][-V][-v] [-W <device>][-w <module-name,
+Options: [\-b <backup MBR>][\-C c,h,s][\-c][\-d][\-E][\-e][\-f]
+[\-g][\-h][\-i][\-K <last-sector>][\-k <# of sectors>] [\-L]
+[\-l <log file>][\-n <increment>] [\-q][\-s <sector-size>]
+[\-t <module-name>][\-V][\-v] [\-W <device>][\-w <module-name,
weight>]
.SH DESCRIPTION
.B gpart
@@ -63,8 +63,8 @@ MS Windows NT/2000 filesystem.
.I qnx4
QNX 4.x filesystem.
.TP
-.I rfs
-The Reiser filesystem (version 3.5.X, X > 11).
+.I reiserfs
+The Reiser filesystem (version 3.5.X, X > 11, 3.6.X).
.TP
.I s86dl
Sun Solaris on Intel platforms uses a sub-partitioning
@@ -187,7 +187,7 @@ geometry. For instance if a disk with the geometry
should be called like
.RS
-gpart -C 1028,255,63 <other options> <device>
+gpart \-C 1028,255,63 <other options> <device>
.RE
.SH PRECAUTIONS
@@ -223,7 +223,7 @@ should be stored in a safe place like a floppy disk.
If the guessed primary partition table seems consistent
and should be written (see the
.I
--W
+\-W
option) backup the current MBR into the specified file.
.IP "-C c,h,s"
Set the disk geometry (cylinders, heads, sectors) for
@@ -328,10 +328,6 @@ tries to find out the sector size but may fail in
doing so. Probed sector sizes are 2^i, i=9..14
(512 to 16384 bytes). The default medium sector
size is 512 bytes.
-.IP "-t module name"
-Plug in another guessing module. The module to
-be dynamically linked in must be a shared object
-file named "gm_<modname>.so".
.IP -V
Show version number.
.IP -v
@@ -364,7 +360,7 @@ are allowed.
.PP
-Default settings are "-n h".
+Default settings are "\-n h".
.SH EXAMPLES
\-\ To scan the first IDE hard disk under Linux using default
@@ -378,7 +374,7 @@ gpart /dev/hda
drive without starting the scan loop in FreeBSD type
.RS
-gpart -vvd /dev/wd2
+gpart \-vvd /dev/wd2
.RE
.RE
@@ -390,7 +386,7 @@ in a file called /boot/boot.<major/minor>. To list
the partitions contained in such a file type e.g.
.RS
-gpart -vdg /boot/boot.0300
+gpart \-vdg /boot/boot.0300
.RE
If the partition table contains an extended partition,
@@ -409,7 +405,7 @@ can be told to start the scan directly from sector one
of the disk, using the sector-wise scan mode:
.RS
-gpart -k 1 -n s /dev/hdb
+gpart \-k 1 \-n s /dev/hdb
.RE
\-\ Suppose
@@ -420,7 +416,7 @@ made the first module to be probed and given a
weight higher than the usual weight of 1.0:
.RS
-gpart -w ntfs,1.5 /dev/hdb
+gpart \-w ntfs,1.5 /dev/hdb
.RE
To list the available modules and their weights use
@@ -434,7 +430,7 @@ at least thrice, the primary partition table can
be written back to the device this way:
.RS
-gpart -W /dev/sdc /dev/sdc
+gpart \-W /dev/sdc /dev/sdc
.RE
This of course may be extremely dangerous to your health
@@ -445,7 +441,7 @@ steps of 63 sectors. To perform the scan on every second
head while skipping the first 1008 sectors type
.RS
-gpart -k 1008 -n 126 /dev/sda
+gpart \-k 1008 \-n 126 /dev/sda
.RE
\-\ If you want to see how easily
@@ -455,7 +451,7 @@ are on a disk, search the whole disk really sector by
sector, writing all output to a logfile:
.RS
-gpart -vvfn s -ql /tmp/gpart.log /dev/sd2 &
+gpart \-vvfn s \-ql /tmp/gpart.log /dev/sd2 &
.RE
Usually
diff --git a/src/Makefile b/src/Makefile
deleted file mode 100644
index fb3dd4b..0000000
--- a/src/Makefile
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# gpart src Makefile
-#
-include ../inst.defs
-include ../make.defs
-
-CFLAGS+=-DVERSION=\"$(version)\"
-ifeq ($(shell uname),Linux)
-LIBS=-ldl
-endif
-
-ifdef DEBUG
-CFLAGS+=-g
-LDFLAGS+=-g
-endif
-
-ifdef GPART_LANG
-CFLAGS+=-DGPART_LANG=\'$(GPART_LANG)\'
-endif
-
-
-mod=ext2 lswap fat bsddl ntfs hpfs s86dl minix rfs hmlvm qnx4 beos xfs
-modobj=$(foreach m,$(mod),gm_$(m).o)
-obj=gpart.o gmodules.o disku.o l64seek.o $(modobj)
-src=$(obj:.o=.c)
-hdr=$(wildcard *.h)
-allsrc=Makefile $(src) $(hdr)
-
-all: $(prg)
-
-$(prg): $(obj)
- $(CC) -o $@ $(LDFLAGS) $(obj) $(LIBS)
-
-install: $(prg)
- $(INSTALL) -d $(bindir)
- $(INSTALL) -s $(prg) $(bindir)
-
-uninstall:
- $(RM) $(bindir)/$(prg)
-
-clean:
- @$(RM) $(obj) $(prg) .depend
-
-static:
- @$(MAKE) LDFLAGS=-static
-
-rcscheck:
- @for f in $(allsrc); do \
- rcsdiff $$f >/dev/null 2>&1 || echo "Please checkin $$f"; \
- done
-
-checkin:
- @for f in $(allsrc); do \
- rcsdiff $$f >/dev/null 2>&1 || ci -m"v$(version)" -l $$f; \
- done
-
-
-.depend: $(src)
- @$(MAKEDEP) $(src) > $@
-
--include .depend
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..ad9bc9a
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,6 @@
+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
diff --git a/src/disku.c b/src/disku.c
index d340e66..b918147 100644
--- a/src/disku.c
+++ b/src/disku.c
@@ -16,9 +16,11 @@
*/
+#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <errno.h>
#include "gpart.h"
#if defined(__linux__)
@@ -27,10 +29,12 @@
#endif
#if defined(__FreeBSD__)
-#include <errno.h>
+#include <sys/param.h>
#include <sys/disklabel.h>
+#include <sys/disk.h>
#endif
+#include <unistd.h>
/*
@@ -41,16 +45,44 @@
struct disk_geom *disk_geometry(disk_desc *d)
{
static struct disk_geom g;
+ uint64_t nsects;
+
+ memset(&g, 0, sizeof(g));
#if defined(__linux__)
struct hd_geometry hg;
- long nsects;
+#endif
+#if defined(__FreeBSD__)
+ struct disklabel dl;
+#endif
+
+ struct stat st;
+ int ret;
+ uint64_t lba;
+ ret = stat(d->d_dev, &st);
+ if (ret == 0)
+ {
+ if (S_ISREG(st.st_mode))
+ {
+ nsects = st.st_size / 512;
+ if (nsects == 0)
+ pr(FATAL, EM_FATALERROR, "Not a block device image file");
+ lba = nsects - 1;
+ g.d_h = (lba / 63) % 255;
+ g.d_s = lba % 63 + 1;
+ g.d_c = lba / (255 * 63);
+ g.d_nsecs = nsects;
+ return (&g);
+ }
+ }
+#if defined(__linux__)
if (ioctl(d->d_fd,HDIO_GETGEO,&hg) == -1)
pr(FATAL,EM_IOCTLFAILED,"HDIO_GETGEO",strerror(errno));
#ifdef BLKGETSIZE
if (ioctl(d->d_fd,BLKGETSIZE,&nsects) == -1)
pr(FATAL,EM_IOCTLFAILED,"BLKGETSIZE",strerror(errno));
+ g.d_nsecs = nsects;
g.d_c = nsects / (hg.heads * hg.sectors);
#else
g.d_c = hg.cylinders;
@@ -61,12 +93,27 @@ struct disk_geom *disk_geometry(disk_desc *d)
#endif
#if defined(__FreeBSD__)
- struct disklabel dl;
- if (ioctl(d->d_fd,DIOCGDINFO,&dl) == -1)
- pr(FATAL,EM_IOCTLFAILED,"DIOCGDINFO",strerror(errno));
- g.d_c = dl.d_ncylinders;
- g.d_h = dl.d_ntracks;
- g.d_s = dl.d_nsectors;
+ struct disklabel loclab;
+ u_int u;
+ off_t o; /* total disk size */
+
+ if (ioctl(d->d_fd, DIOCGFWSECTORS, &u) == 0)
+ g.d_s = u;
+ else
+ pr(FATAL, EM_IOCTLFAILED, "DIOCGFWSECTORS", strerror(errno));
+ // loclab.d_nsectors = 63;
+ if (ioctl(d->d_fd, DIOCGFWHEADS, &u) == 0)
+ g.d_h = u;
+ else
+ pr(FATAL, EM_IOCTLFAILED, "DIOCGFWHEADS", strerror(errno));
+ if (ioctl(d->d_fd, DIOCGSECTORSIZE, &u) == 0)
+ if (u != 512)
+ pr(FATAL, "sector size not a multiple of 512");
+ if (ioctl(d->d_fd, DIOCGMEDIASIZE, &o))
+ pr(FATAL, EM_IOCTLFAILED, "DIOCGMEDIASIZE", strerror(errno));
+
+ g.d_nsecs = o / u;
+ g.d_c = g.d_nsecs / g.d_h / g.d_s;
#endif
return (&g);
diff --git a/src/gm_ext2.c b/src/gm_ext2.c
index bff7f10..81c2762 100644
--- a/src/gm_ext2.c
+++ b/src/gm_ext2.c
@@ -121,9 +121,10 @@ int ext2_gfun(disk_desc *d,g_module *m)
/*
* current mount count shouldn't be greater than max+20
+ * but ext3 usually has s_max_mnt_count==-1
*/
- if (sb->s_mnt_count > sb->s_max_mnt_count + 20)
+ if ((sb->s_max_mnt_count!=-1)&&(sb->s_mnt_count > sb->s_max_mnt_count + 20))
return (1);
/*
diff --git a/src/gm_fat.h b/src/gm_fat.h
index 506023a..5e0adf7 100644
--- a/src/gm_fat.h
+++ b/src/gm_fat.h
@@ -60,6 +60,10 @@ struct fat_boot_sector {
__u16 info_sector; /* filesystem info sector */
__u16 backup_boot; /* backup boot sector */
__u16 reserved2[6]; /* Unused */
-};
-
+} __attribute__ ((packed));
+/* "__attribute__ ((packed))"
+ added by davidc at debian.org,
+ as suggested by falk at zxmjz18.extern.uni-tuebingen.de
+ Fri Jul 07 18:04:15 2000
+ in debian bug report #66893 "FAT detection broken on Alpha" */
#endif /* _GM_FAT_H */
diff --git a/src/gm_ntfs.c b/src/gm_ntfs.c
index 2522029..f3e2a16 100644
--- a/src/gm_ntfs.c
+++ b/src/gm_ntfs.c
@@ -46,7 +46,6 @@ int ntfs_term(disk_desc *d)
int ntfs_gfun(disk_desc *d,g_module *m)
{
- int blocksize, clusterfactor, clustersize;
int mft_clusters_per_record;
s64_t size, ls;
byte_t *ubuf, *sbuf;
@@ -65,18 +64,11 @@ int ntfs_gfun(disk_desc *d,g_module *m)
if (NTFS_GETU32(d->d_sbuf + 0x44) > 256UL)
return (1);
- blocksize = NTFS_GETU16(d->d_sbuf + 0x0B);
- clusterfactor = NTFS_GETU8(d->d_sbuf + 0x0D);
- clustersize = blocksize * clusterfactor;
mft_clusters_per_record = NTFS_GETS8(d->d_sbuf + 0x40);
if ((mft_clusters_per_record < 0) && (mft_clusters_per_record != -10))
return (1);
size = NTFS_GETU64(d->d_sbuf + 0x28);
- size /= clusterfactor;
- size *= clustersize;
- size /= d->d_ssize;
-
/*
* look for an additional backup boot sector at the end of
* this FS (NT4 puts this backup sector after the FS, this
diff --git a/src/gm_ntfs.h b/src/gm_ntfs.h
index 89c953d..9aef640 100644
--- a/src/gm_ntfs.h
+++ b/src/gm_ntfs.h
@@ -14,6 +14,9 @@
*
*/
+#include <stdint.h>
+#include <endian.h>
+
#ifndef _GM_NTFS_H
#define _GM_NTFS_H
@@ -29,32 +32,31 @@
/* 'NTFS' in little endian */
#define NTFS_SUPER_MAGIC 0x5346544E
-#if defined(i386) || defined(__i386__) || defined(__alpha__)
-
/* unsigned integral types */
#ifndef NTFS_INTEGRAL_TYPES
#define NTFS_INTEGRAL_TYPES
-typedef unsigned char ntfs_u8;
-typedef unsigned short ntfs_u16;
-typedef unsigned int ntfs_u32;
-typedef s64_t ntfs_u64;
+typedef uint8_t ntfs_u8;
+typedef uint16_t ntfs_u16;
+typedef uint32_t ntfs_u32;
+typedef uint64_t ntfs_u64;
+typedef int8_t ntfs_s8;
+typedef int16_t ntfs_s16;
#endif /* NTFS_INTEGRAL_TYPES */
-#endif /* defined(i386) || defined(__i386__) || defined(__alpha__) */
/* Macros reading unsigned integers from a byte pointer */
-/* these should work for all little endian machines */
#define NTFS_GETU8(p) (*(ntfs_u8*)(p))
-#define NTFS_GETU16(p) (*(ntfs_u16*)(p))
-#define NTFS_GETU24(p) (NTFS_GETU32(p) & 0xFFFFFF)
-#define NTFS_GETU32(p) (*(ntfs_u32*)(p))
-#define NTFS_GETU64(p) (*(ntfs_u64*)(p))
+#define NTFS_GETU16(p) ((ntfs_u16)htole16(*(ntfs_u16*)(p)))
+#define NTFS_GETU24(p) ((ntfs_u32)NTFS_GETU16(p) | \
+ ((ntfs_u32)NTFS_GETU8(((char*)p)+2))<<16)
+#define NTFS_GETU32(p) ((ntfs_u32)htole32(*(ntfs_u32*)(p)))
+#define NTFS_GETU64(p) ((ntfs_u64)htole64(*(ntfs_u64*)(p)))
/* Macros reading signed integers, returning int */
-#define NTFS_GETS8(p) ((int)(*(char*)(p)))
-#define NTFS_GETS16(p) ((int)(*(short*)(p)))
-#define NTFS_GETS24(p) (NTFS_GETU24(p) < 0x800000 ? (int)NTFS_GETU24(p) :
-
-
+#define NTFS_GETS8(p) (*(ntfs_s8*)(p))
+#define NTFS_GETS16(p) ((ntfs_s16)htole16(*(ntfs_s16*)(p)))
+#define NTFS_GETS24(p) (NTFS_GETU24(p) < 0x800000 ? \
+ (int)NTFS_GETU24(p) : \
+ (int)(NTFS_GETU24(p) - 0x1000000))
#endif /* _GM_NTFS_H */
diff --git a/src/gm_rfs.c b/src/gm_reiserfs.c
similarity index 66%
rename from src/gm_rfs.c
rename to src/gm_reiserfs.c
index 8c78b5a..8cd4e59 100644
--- a/src/gm_rfs.c
+++ b/src/gm_reiserfs.c
@@ -1,5 +1,5 @@
/*
- * gm_rfs.c -- gpart ReiserFS guessing module
+ * gm_reiserfs.c -- gpart ReiserFS guessing module
*
* gpart (c) 1999-2001 Michail Brzitwa <mb at ichabod.han.de>
* Guess PC-type hard disk partitions.
@@ -12,44 +12,47 @@
* Created: 21.01.1999 <mb at ichabod.han.de>
* Modified: 26.12.2000 Francis Devereux <francis at devereux.tc>
* Added reiserfs 3.5.28 support.
+ * Modified: 10.01.2003 Yury Umanets <umka at namesys.com>
+ * Added reiserfs 3.6.x support.
*
*/
#include <string.h>
#include <errno.h>
#include "gpart.h"
-#include "gm_rfs.h"
+#include "gm_reiserfs.h"
-static const char rcsid[] = "$Id: gm_rfs.c,v 1.5 2001/02/07 18:08:08 mb Exp mb $";
+static const char rcsid[] = "$Id: gm_reiserfs.c,v 1.5 2003/01/10 16:38:08 mb Exp mb $";
-int rfs_init(disk_desc *d,g_module *m)
+int reiserfs_init(disk_desc *d,g_module *m)
{
if ((d == 0) || (m == 0))
return (0);
- m->m_desc = "Reiser filesystem";
- return (REISERFS_FIRST_BLOCK * 1024 + SB_SIZE);
+ m->m_desc = "ReiserFS filesystem";
+ return (REISERFS_FIRST_BLOCK * 1024 + SB_V35_SIZE);
}
-int rfs_term(disk_desc *d)
+int reiserfs_term(disk_desc *d)
{
return (1);
}
-int rfs_gfun(disk_desc *d,g_module *m)
+int reiserfs_gfun(disk_desc *d,g_module *m)
{
- struct reiserfs_super_block *sb;
+ struct reiserfs_super_block_v35 *sb;
dos_part_entry *pt = &m->m_part;
s64_t size;
m->m_guess = GM_NO;
- sb = (struct reiserfs_super_block *)(d->d_sbuf + REISERFS_FIRST_BLOCK * 1024);
- if (strncmp(sb->s_magic,REISERFS_SUPER_MAGIC,12) == 0)
+ sb = (struct reiserfs_super_block_v35 *)(d->d_sbuf + REISERFS_FIRST_BLOCK * 1024);
+ if (strncmp(sb->s_magic,REISERFS_SUPER_V35_MAGIC,12) == 0 ||
+ strncmp(sb->s_magic,REISERFS_SUPER_V36_MAGIC,12) == 0)
{
/*
* sanity checks.
diff --git a/src/gm_rfs.h b/src/gm_reiserfs.h
similarity index 75%
rename from src/gm_rfs.h
rename to src/gm_reiserfs.h
index da86cc5..c653d16 100644
--- a/src/gm_rfs.h
+++ b/src/gm_reiserfs.h
@@ -1,5 +1,5 @@
/*
- * gm_rfs.h -- gpart ReiserFS guessing module header
+ * gm_reiserfs.h -- gpart ReiserFS guessing module header
*
* gpart (c) 1999-2001 Michail Brzitwa <mb at ichabod.han.de>
* Guess PC-type hard disk partitions.
@@ -12,11 +12,13 @@
* Created: 21.01.1999 <mb at ichabod.han.de>
* Modified: 26.12.2000 Francis Devereux <francis at devereux.tc>
* Update support reiserfs version 3.5.28
+ * Modified: 10.01.2003 Yury Umanets <umka at namesys.com>
+ * Added reiserfs 3.6.x support.
*
*/
-#ifndef _GM_RFS_H
-#define _GM_RFS_H
+#ifndef _GM_reiserfs_H
+#define _GM_reiserfs_H
/* imported from asm/types.h */
typedef __signed__ char __s8;
@@ -29,16 +31,18 @@ typedef __signed__ int __s32;
typedef unsigned int __u32;
/*
- * taken from ReiserFS v3.5.28. Reiserfs Copyright 1996-2000 Hans Reiser
+ * taken from ReiserFS v3.5.28, v3.6.x. Reiserfs Copyright 1996-2000 Hans Reiser
*/
-#define REISERFS_SUPER_MAGIC "ReIsErFs"
+#define REISERFS_SUPER_V35_MAGIC "ReIsErFs"
+#define REISERFS_SUPER_V36_MAGIC "ReIsEr2Fs"
+
#define REISERFS_FIRST_BLOCK 64
#define REISERFS_VALID_FS 1
#define REISERFS_ERROR_FS 2
#define REISERFS_MIN_BLOCK_AMOUNT 100
-struct reiserfs_super_block
+struct reiserfs_super_block_v35
{
__u32 s_block_count; /* blocks count */
__u32 s_free_blocks; /* free blocks count */
@@ -62,7 +66,17 @@ struct reiserfs_super_block
__u16 s_reserved;
};
-#define SB_SIZE (sizeof(struct reiserfs_super_block))
+#define SB_V35_SIZE (sizeof(struct reiserfs_super_block_v35))
+
+struct reiserfs_super_block_v36 {
+ struct reiserfs_super_block_v35 s_v35;
+ __u32 s_inode_generation;
+ __u32 s_flags;
+ char s_uuid[16];
+ char s_label[16];
+ char s_unused[88];
+};
+#define SB_V36_SIZE (sizeof(struct reiserfs_super_block_v36))
-#endif /* _GM_RFS_H */
+#endif /* _GM_REISERFS_H */
diff --git a/src/gmodules.c b/src/gmodules.c
index f56aae0..d2f849e 100644
--- a/src/gmodules.c
+++ b/src/gmodules.c
@@ -18,7 +18,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <dlfcn.h>
#include "gpart.h"
@@ -57,7 +56,6 @@ void g_mod_delete(g_module *m)
{
if (m)
{
- if (m->m_hd) dlclose(m->m_hd);
if (m->m_name) free((void *)m->m_name);
free(m);
g_count--;
@@ -132,8 +130,6 @@ g_module *g_mod_lookup(int how,char *name)
return (m);
}
-
-
/*
* preloaded modules
*/
@@ -142,61 +138,22 @@ void g_mod_addinternals()
{
g_module *m;
-#define GMODINS(mod) if(!(m = g_mod_lookup(GM_INSERT,#mod))->m_hd){ \
- m->m_init=mod##_init; m->m_term=mod##_term; \
- m->m_gfun=mod##_gfun; }
+#define GMODINS(mod) \
+ do { \
+ m = g_mod_lookup(GM_INSERT,#mod); \
+ if (m) { \
+ m->m_init=mod##_init; \
+ m->m_term=mod##_term; \
+ m->m_gfun=mod##_gfun; \
+ } \
+ } while (0);
/*
* If no weights are given on the command line, the order
* is somehow important.
*/
- GMODINS(bsddl);
- GMODINS(lswap);
- GMODINS(qnx4);
- GMODINS(rfs);
- GMODINS(ntfs);
- GMODINS(hpfs);
- GMODINS(minix);
- GMODINS(beos);
- GMODINS(ext2);
- GMODINS(fat);
- GMODINS(s86dl);
- GMODINS(hmlvm);
- GMODINS(xfs);
-}
-
-
-
-int g_mod_addexternal(char *name)
-{
- g_module *m;
- char buf[FILENAME_MAX];
-
- /*
- * external modules are named 'gm_' name '.so', and will
- * be searched in the standard ld.so library directories
- * or those explicitly given by LD_LIBRARY_PATH.
- */
-
- snprintf(buf,FILENAME_MAX-1,"gm_%s.so",name);
- buf[FILENAME_MAX-1] = 0;
-
- m = g_mod_lookup(GM_INSERT,name);
- if (m->m_hd)
- dlclose(m->m_hd);
-
- if ((m->m_hd = dlopen(buf,RTLD_NOW)) == 0)
- pr(FATAL,(char *)dlerror());
-
- snprintf(buf,FILENAME_MAX-1,"%s_init",name);
- m->m_init = (int (*)())dlsym(m->m_hd,buf);
- snprintf(buf,FILENAME_MAX-1,"%s_term",name);
- m->m_term = (int (*)())dlsym(m->m_hd,buf);
- snprintf(buf,FILENAME_MAX-1,"%s_gfun",name);
- m->m_gfun = (int (*)())dlsym(m->m_hd,buf);
- if ((m->m_gfun == 0))
- pr(FATAL,"module %s: missing vital functions",name);
-
- return (1);
+#define G_MODULE(mod) GMODINS(mod)
+G_MODULES
+#undef G_MODULE
}
diff --git a/src/gmodules.h b/src/gmodules.h
index c28e3ad..0b43b43 100644
--- a/src/gmodules.h
+++ b/src/gmodules.h
@@ -33,7 +33,6 @@ typedef struct g_mod
int (*m_gfun)(disk_desc *,struct g_mod *);
float m_guess;
float m_weight; /* probability weight */
- void *m_hd; /* dlopen() descriptor */
dos_part_entry m_part; /* a guessed partition entry */
long m_align; /* alignment of partition */
struct g_mod *m_next;
@@ -48,24 +47,34 @@ typedef struct g_mod
void g_mod_list(), g_mod_delete(g_module *), g_mod_deleteall();
g_module *g_mod_head(), *g_mod_lookup(int,char *);
void g_mod_addinternals();
-int g_mod_count(), g_mod_addexternal(char *);
+int g_mod_count();
g_module *g_mod_setweight(char *,float);
/*
- * preloaded guessing modules
+ * preloaded guessing modules, order is important as it is also the order of registering and guessing
*/
-#define GMODDECL(mod) int mod##_init(disk_desc *,g_module *), \
- mod##_term(disk_desc *), \
- mod##_gfun(disk_desc *,g_module *)
-
-GMODDECL(bsddl); GMODDECL(ext2); GMODDECL(fat);
-GMODDECL(hpfs); GMODDECL(lswap); GMODDECL(ntfs);
-GMODDECL(s86dl); GMODDECL(minix); GMODDECL(rfs);
-GMODDECL(hmlvm); GMODDECL(qnx4); GMODDECL(beos);
-GMODDECL(xfs);
+#define G_MODULES \
+ G_MODULE(bsddl) \
+ G_MODULE(lswap) \
+ G_MODULE(qnx4) \
+ G_MODULE(reiserfs) \
+ G_MODULE(ntfs) \
+ G_MODULE(hpfs) \
+ G_MODULE(minix) \
+ G_MODULE(beos) \
+ G_MODULE(ext2) \
+ G_MODULE(fat) \
+ G_MODULE(s86dl) \
+ G_MODULE(hmlvm) \
+ G_MODULE(xfs)
+#define G_MODULE(mod) int mod##_init(disk_desc *,g_module *), \
+ mod##_term(disk_desc *), \
+ mod##_gfun(disk_desc *,g_module *);
+G_MODULES
+#undef G_MODULE
#endif /* _GMODULES_H */
diff --git a/src/gpart.c b/src/gpart.c
index 27e32ef..50899ea 100644
--- a/src/gpart.c
+++ b/src/gpart.c
@@ -60,16 +60,16 @@
static const char rcsid[] = "$Id: gpart.c,v 1.11 2001/02/07 18:08:08 mb Exp mb $";
-static const char *gpart_version = PROGRAM " v" VERSION;
+static const char *gpart_version = PACKAGE_NAME " v" VERSION;
int f_check = 0, f_verbose = 0, f_dontguess = 0, f_fast = 1;
int f_getgeom = 1, f_interactive = 0, f_quiet = 0, f_testext = 1;
int f_skiperrors = 1, berrno = 0;
int (*boundary_fun)(disk_desc *,s64_t);
-unsigned long increment = 'h', gc = 0, gh = 0, gs = 0;
+unsigned long increment = 's', gc = 0, gh = 0, gs = 0;
s64_t skipsec = 0, maxsec = 0;
-FILE *log = 0;
+FILE *logfile = 0;
@@ -77,15 +77,13 @@ void usage()
{
FILE *fp = stderr;
- fprintf(fp,"Usage: %s [options] device\n",PROGRAM);
+ fprintf(fp,"Usage: %s [options] device\n",PACKAGE_NAME);
fprintf(fp,"Options: [-b <backup MBR>][-C c,h,s][-c][-d][-E][-e][-f][-g][-h][-i]\n");
fprintf(fp," [-K <last sector>][-k <# of sectors>][-L][-l <log file>]\n");
- fprintf(fp," [-n <increment>][-q][-s <sector-size>][-t <module-name>]\n");
+ fprintf(fp," [-n <increment>][-q][-s <sector-size>]\n");
fprintf(fp," [-V][-v][-W <device>][-w <module-name,weight>]\n");
fprintf(fp,"%s (c) 1999-2001 Michail Brzitwa <michail at brzitwa.de>.\n",gpart_version);
fprintf(fp,"Guess PC-type hard disk partitions.\n\n");
- if (! f_verbose)
- return;
fprintf(fp,"Options:\n");
fprintf(fp," -b Save a backup of the original MBR to specified file.\n");
fprintf(fp," -C Set c/h/s to be used in the scan.\n");
@@ -104,7 +102,6 @@ void usage()
fprintf(fp," -n Scan increment: number or 's' sector, 'h' head, 'c' cylinder.\n");
fprintf(fp," -q Run quiet (however log file is written if specified).\n");
fprintf(fp," -s Sector size to use (disable sector size probing).\n");
- fprintf(fp," -t Name of a guessing module to be added.\n");
fprintf(fp," -V Show version.\n");
fprintf(fp," -v Verbose mode. Can be given more than once.\n");
fprintf(fp," -W Write guessed primary partition table to given device or file.\n");
@@ -125,26 +122,26 @@ void pr(int type,char *fmt,...)
case FATAL :
g_mod_deleteall();
if (! f_quiet) fprintf(stderr,EM_FATALERROR,msg);
- if (log)
+ if (logfile)
{
- fprintf(log,EM_FATALERROR,msg);
- fclose(log);
+ fprintf(logfile,EM_FATALERROR,msg);
+ fclose(logfile);
}
exit(1);
case ERROR :
if (! f_quiet) fprintf(stderr,EM_SIMPLEERROR,msg);
- if (log) fprintf(log,EM_SIMPLEERROR,msg);
+ if (logfile) fprintf(logfile,EM_SIMPLEERROR,msg);
break;
case WARN :
if (! f_quiet) fprintf(stderr,EM_WARNING,msg);
- if (log) fprintf(log,EM_WARNING,msg);
+ if (logfile) fprintf(logfile,EM_WARNING,msg);
break;
case MSG :
if (! f_quiet) fputs(msg,stdout); fflush(stdout);
- if (log) fputs(msg,log);
+ if (logfile) fputs(msg,logfile);
break;
}
- if (log) fflush(log);
+ if (logfile) fflush(logfile);
}
@@ -374,7 +371,7 @@ static int no_of_ext_partitions(dos_part_entry *p)
dos_part_entry *t;
int ne = 0;
- for (t = &p[0]; t < &p[NDOSPARTS]; t++)
+ for (t = &p[0]; t <= &p[NDOSPARTS - 1]; t++)
if (is_ext_parttype(t))
ne++;
return (ne);
@@ -387,7 +384,7 @@ static int no_of_real_partitions(dos_part_entry *p)
dos_part_entry *t;
int nr = 0;
- for (t = &p[0]; t < &p[NDOSPARTS]; t++)
+ for (t = &p[0]; t <= &p[NDOSPARTS - 1]; t++)
if (is_real_parttype(t))
nr++;
return (nr);
@@ -457,7 +454,7 @@ static int is_ext_parttable(disk_desc *d,byte_t *buf)
* ptbl sanity checks.
*/
- for (t = p; t < &p[NDOSPARTS]; t++)
+ for (t = p; t <= &p[NDOSPARTS - 1]; t++)
if (! is_sane_partentry(d,t,0))
return (0);
@@ -602,11 +599,11 @@ static void print_ext_partitions(disk_desc *d,s64_t offset)
for ( ; pt; pt = pt->t_ext)
{
pr(MSG,PM_EXTPART);
- for (p = pt->t_parts; p < &pt->t_parts[NDOSPARTS + 1]; p++)
+ for (p = pt->t_parts; p <= &pt->t_parts[NDOSPARTS - 1]; p++)
if (is_real_parttype(p))
print_partition(d,p,1,offset + extst);
- for (p = pt->t_parts; p < &pt->t_parts[NDOSPARTS + 1]; p++)
+ for (p = pt->t_parts; p <= &pt->t_parts[NDOSPARTS - 1]; p++)
if (is_ext_parttype(p))
extst = p->p_start;
}
@@ -706,7 +703,7 @@ static void read_ext_part_table(disk_desc *d,dos_part_table *pt)
while (1)
{
ep = 0;
- for (p = pt->t_parts; p < &pt->t_parts[NDOSPARTS + 1]; p++)
+ for (p = pt->t_parts; p <= &pt->t_parts[NDOSPARTS - 1]; p++)
if (is_ext_parttype(p))
{
if (ep == 0)
@@ -833,6 +830,8 @@ static disk_desc *get_disk_desc(char *dev,int sectsize)
pr(FATAL,EM_CANTGETGEOM);
memcpy(&d->d_dg,dg,sizeof(struct disk_geom));
+ d->d_nsecs = dg->d_nsecs;
+
/*
* command line geometry overrides
*/
@@ -849,9 +848,14 @@ static disk_desc *get_disk_desc(char *dev,int sectsize)
}
if (d->d_dg.d_c < 1024) d->d_dosc = 1;
if ((d->d_dg.d_h > 16) || (d->d_dg.d_s > 63)) d->d_lba = 1;
- d->d_nsecs = d->d_dg.d_c;
- d->d_nsecs *= d->d_dg.d_h;
- d->d_nsecs *= d->d_dg.d_s;
+
+ if (gh && gc && gs) {
+ /* Override number of sectors with command line parameters */
+ d->d_nsecs = d->d_dg.d_c;
+ d->d_nsecs *= d->d_dg.d_h;
+ d->d_nsecs *= d->d_dg.d_s;
+ }
+
read_ext_part_table(d,&d->d_pt);
close(d->d_fd);
free((void *)ubuf);
@@ -1221,7 +1225,7 @@ static int make_mbr_backup(disk_desc *d,char *bfile)
{
int fd, ret = 0;
- if ((fd = open(bfile,O_WRONLY|O_CREAT)) < 0)
+ if ((fd = open(bfile, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
return (ret);
if (write(fd,d->d_pt.t_boot,512) == 512)
@@ -1430,7 +1434,7 @@ static int check_partition_list(disk_desc *d)
if (no_of_ext_partitions(gp->g_p) == 0)
in_ext = 0;
rp = 0;
- for (p = &gp->g_p[0]; p < &gp->g_p[NDOSPARTS]; p++)
+ for (p = &gp->g_p[0]; p <= &gp->g_p[NDOSPARTS - 1]; p++)
{
if (is_real_parttype(p))
rp = p;
@@ -1531,7 +1535,7 @@ static int check_partition_list(disk_desc *d)
in_ext = 1; ofs = gp->g_sec;
}
rp = ep = 0;
- for (p = &gp->g_p[0]; p < &gp->g_p[NDOSPARTS]; p++)
+ for (p = &gp->g_p[0]; p <= &gp->g_p[NDOSPARTS - 1]; p++)
{
if (is_real_parttype(p))
rp = p;
@@ -1750,8 +1754,8 @@ int main(int ac,char **av)
}
break;
case 'l' :
- if (log) fclose(log);
- if ((log = fopen(optarg,"w")) == 0)
+ if (logfile) fclose(logfile);
+ if ((logfile = fopen(optarg,"w")) == 0)
pr(FATAL,EM_OPENLOG,optarg);
break;
case 'L' :
@@ -1763,10 +1767,6 @@ int main(int ac,char **av)
if ((sectsize = atoi(optarg)) <= 0)
pr(FATAL,"sector size must be >= 0");
break;
- case 't' :
- if (! g_mod_addexternal(optarg))
- return (EXIT_FAILURE);
- break;
case 'v' :
f_verbose++; break;
case 'V' :
@@ -1831,7 +1831,7 @@ int main(int ac,char **av)
}
}
free_disk_desc(d);
- if (log) fclose(log);
+ if (logfile) fclose(logfile);
return (f_check ? no_of_incons : 0);
}
diff --git a/src/gpart.h b/src/gpart.h
index 37a6180..d973d65 100644
--- a/src/gpart.h
+++ b/src/gpart.h
@@ -17,57 +17,23 @@
#ifndef _GPART_H
#define _GPART_H
+#include "config.h"
+
#include "errmsgs.h"
#include "l64seek.h"
-#define PROGRAM "gpart"
-
-
-typedef unsigned char byte_t;
+#include <stdint.h>
+typedef uint8_t byte_t;
-/*
- * endianness (incomplete, later)
- */
-#if defined(__i386__) || defined(__alpha__)
-# define le16(x) (x) /* x as little endian */
-# define be16(x) ((((x)&0xff00)>>8) | \
- (((x)&0x00ff)<<8))
-# define le32(x) (x)
-# define be32(x) ((((x)&0xff000000L)>>24) | \
- (((x)&0x00ff0000L)>>8) | \
- (((x)&0x0000ff00L)<<8) | \
- (((x)&0x000000ffL)<<24))
-# define le64(x) (x)
-# define be64(x) ((((x)&0xff00000000000000LL)>>56) | \
- (((x)&0x00ff000000000000LL)>>40) | \
- (((x)&0x0000ff0000000000LL)>>24) | \
- (((x)&0x000000ff00000000LL)>>8) | \
- (((x)&0x00000000ff000000LL)<<8) | \
- (((x)&0x0000000000ff0000LL)<<24) | \
- (((x)&0x000000000000ff00LL)<<40) | \
- (((x)&0x00000000000000ffLL)<<56))
-#else /* bigendian */
-# define le16(x) ((((x)&0xff00)>>8) | \
- (((x)&0x00ff)<<8))
-# define be16(x) (x)
-# define le32(x) ((((x)&0xff000000L)>>24) | \
- (((x)&0x00ff0000L)>>8) | \
- (((x)&0x0000ff00L)<<8) | \
- (((x)&0x000000ffL)<<24))
-# define be32(x) (x)
-# define le64(x) ((((x)&0xff00000000000000LL)>>56) | \
- (((x)&0x00ff000000000000LL)>>40) | \
- (((x)&0x0000ff0000000000LL)>>24) | \
- (((x)&0x000000ff00000000LL)>>8) | \
- (((x)&0x00000000ff000000LL)<<8) | \
- (((x)&0x0000000000ff0000LL)<<24) | \
- (((x)&0x000000000000ff00LL)<<40) | \
- (((x)&0x00000000000000ffLL)<<56))
-# define be64(x) (x)
-#endif
+#define le16(x) htole16(x)
+#define be16(x) htobe16(x)
+#define le32(x) htole32(x)
+#define be32(x) htobe32(x)
+#define le64(x) htole64(x)
+#define be64(x) htobe64(x)
#ifndef max
@@ -112,8 +78,8 @@ typedef struct
byte_t p_ehd; /* end head */
byte_t p_esect; /* end sector */
byte_t p_ecyl; /* end cylinder */
- unsigned long p_start; /* start sector (absolute) */
- unsigned long p_size; /* # of sectors */
+ uint32_t p_start; /* start sector (absolute) */
+ uint32_t p_size; /* # of sectors */
} dos_part_entry;
@@ -123,7 +89,7 @@ typedef struct dos_pt
byte_t _align[2];
byte_t t_boot[DOSPARTOFF];
dos_part_entry t_parts[NDOSPARTS];
- unsigned short t_magic; /* DOSPTMAGIC */
+ uint16_t t_magic; /* DOSPTMAGIC */
} dos_part_table;
@@ -156,9 +122,7 @@ typedef struct
long d_c; /* cylinder count */
long d_h; /* heads/cyl */
long d_s; /* sectors/head */
- long d_rc; /* real values if the above are */
- long d_rh; /* translated */
- long d_rs;
+ uint64_t d_nsecs; /* Number of sectors total */
} d_dg;
unsigned int d_lba : 1;
unsigned int d_dosc : 1; /* dos compatible? (g_c < 1024) */
diff --git a/src/l64seek.c b/src/l64seek.c
index 55b3a87..9b2084c 100644
--- a/src/l64seek.c
+++ b/src/l64seek.c
@@ -25,30 +25,13 @@ static struct
} ostck[OSTACKLEN];
static int osptr = -1;
-#if defined(__linux__) && defined(__i386__)
-_syscall5(int,_llseek,uint,fd,ulong,hi,ulong,lo,loff_t *,res,uint,wh)
-#endif
-
off64_t l64seek(int fd,off64_t offset,int whence)
{
off64_t ret = (off64_t)-1;
-#if defined(__linux__) && defined(__i386__)
- int iret;
- unsigned long ohi, olo;
-
- ohi = (unsigned long)((offset >> 32) & 0xFFFFFFFF);
- olo = (unsigned long)(offset & 0xFFFFFFFF);
- iret = _llseek(fd,ohi,olo,&ret,whence);
- if (iret == -1)
- ret = (off64_t)-1;
-#endif
-
-#if defined(__FreeBSD__) || (defined(__linux__) && defined(__alpha__))
ret = lseek(fd,offset,whence);
-#endif
return (ret);
}
diff --git a/src/l64seek.h b/src/l64seek.h
index 946a7cf..669b655 100644
--- a/src/l64seek.h
+++ b/src/l64seek.h
@@ -17,6 +17,8 @@
#ifndef _L64SEEK_H
#define _L64SEEK_H
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
/*
@@ -25,19 +27,7 @@
* offsets.
*/
-
-#if defined(__linux__)
-# include <linux/unistd.h>
-# include <sys/types.h>
- typedef int64_t off64_t;
-#endif
-
-
-#if defined(__FreeBSD__)
- typedef off_t off64_t;
-#endif
-
-
+typedef loff_t off64_t;
typedef off64_t s64_t;
off64_t l64seek(int fd, off64_t offset, int whence);
@@ -45,5 +35,4 @@ off64_t l64seek(int fd, off64_t offset, int whence);
int l64opush(int);
s64_t l64opop(int);
-
#endif
--
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