[Forensics-changes] [gpart] 01/01: New upstream release.
Joao Eriberto Mota Filho
eriberto at moszumanska.debian.org
Thu Mar 12 14:20:35 UTC 2015
This is an automated email from the git hooks/post-receive script.
eriberto pushed a commit to branch upstream
in repository gpart.
commit fe367239bf9fcb843897bfa57e11b031163e2aef
Author: Joao Eriberto Mota Filho <eriberto at debian.org>
Date: Thu Mar 12 11:19:42 2015 -0300
New upstream release.
---
.gitignore | 18 -----------
Changes | 12 --------
Makefile | 23 ++++++++++++++
Makefile.am | 6 ----
README | 67 +++++++++++++++++++++++++---------------
autogen.sh | 7 -----
configure.ac | 39 -----------------------
inst.defs | 9 ++++++
make.defs | 12 ++++++++
man/Makefile | 26 ++++++++++++++++
man/Makefile.am | 1 -
man/{gpart.8.in => gpart.man} | 12 +++++---
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_reiserfs.c => gm_rfs.c} | 25 +++++++--------
src/{gm_reiserfs.h => gm_rfs.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, 418 insertions(+), 320 deletions(-)
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index d02824a..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,18 +0,0 @@
-*.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 9c0d4c5..5bbd0c1 100644
--- a/Changes
+++ b/Changes
@@ -1,15 +1,3 @@
-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
new file mode 100644
index 0000000..99d6764
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,23 @@
+#
+# 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
deleted file mode 100644
index 566c6e1..0000000
--- a/Makefile.am
+++ /dev/null
@@ -1,6 +0,0 @@
-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 d7e0d16..dc5ed68 100644
--- a/README
+++ b/README
@@ -24,31 +24,35 @@
- 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
+ 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
gpart:
int xxx_init(disk_desc *d,g_module *m)
@@ -85,6 +89,19 @@
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
deleted file mode 100755
index 7882de4..0000000
--- a/autogen.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-set -e
-aclocal
-autoconf
-autoheader
-automake --add-missing
-./configure
diff --git a/configure.ac b/configure.ac
deleted file mode 100644
index 76a3ef3..0000000
--- a/configure.ac
+++ /dev/null
@@ -1,39 +0,0 @@
-# -*- 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 libraries.
-# FIXME: Replace `main' with a function in `-ldl':
-AC_CHECK_LIB([dl], [main])
-
-# 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
new file mode 100644
index 0000000..575a27f
--- /dev/null
+++ b/inst.defs
@@ -0,0 +1,9 @@
+#
+# 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
new file mode 100644
index 0000000..42412c8
--- /dev/null
+++ b/make.defs
@@ -0,0 +1,12 @@
+#
+#
+#
+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
new file mode 100644
index 0000000..3e05e47
--- /dev/null
+++ b/man/Makefile
@@ -0,0 +1,26 @@
+#
+# 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
deleted file mode 100644
index 87f032d..0000000
--- a/man/Makefile.am
+++ /dev/null
@@ -1 +0,0 @@
-man_MANS = gpart.8
diff --git a/man/gpart.8.in b/man/gpart.man
similarity index 97%
rename from man/gpart.8.in
rename to man/gpart.man
index 614bb2e..7ebbaf4 100644
--- a/man/gpart.8.in
+++ b/man/gpart.man
@@ -1,7 +1,7 @@
.\"
-.\" gpart v at VERSION@ man page (c) Jan 1999 Michail Brzitwa
+.\" gpart v%VERSION% man page (c) Jan 1999 Michail Brzitwa
.\"
-.TH GPART 8 "January 2001" "Administration Tools"
+.TH GPART %MANEXT% "January 2001" "Administration Tools"
.SH NAME
gpart \- guess PC-type hard disk partitions
.SH SYNOPSIS
@@ -63,8 +63,8 @@ MS Windows NT/2000 filesystem.
.I qnx4
QNX 4.x filesystem.
.TP
-.I reiserfs
-The Reiser filesystem (version 3.5.X, X > 11, 3.6.X).
+.I rfs
+The Reiser filesystem (version 3.5.X, X > 11).
.TP
.I s86dl
Sun Solaris on Intel platforms uses a sub-partitioning
@@ -328,6 +328,10 @@ 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
diff --git a/src/Makefile b/src/Makefile
new file mode 100644
index 0000000..fb3dd4b
--- /dev/null
+++ b/src/Makefile
@@ -0,0 +1,61 @@
+#
+# 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
deleted file mode 100644
index 6d022f7..0000000
--- a/src/Makefile.am
+++ /dev/null
@@ -1,6 +0,0 @@
-AM_CFLAGS = -Wall -O2
-AM_LDFLAGS =
-
-bin_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 b918147..d340e66 100644
--- a/src/disku.c
+++ b/src/disku.c
@@ -16,11 +16,9 @@
*/
-#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
-#include <errno.h>
#include "gpart.h"
#if defined(__linux__)
@@ -29,12 +27,10 @@
#endif
#if defined(__FreeBSD__)
-#include <sys/param.h>
+#include <errno.h>
#include <sys/disklabel.h>
-#include <sys/disk.h>
#endif
-#include <unistd.h>
/*
@@ -45,44 +41,16 @@
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;
-#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);
- }
- }
+ long nsects;
-#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;
@@ -93,27 +61,12 @@ struct disk_geom *disk_geometry(disk_desc *d)
#endif
#if defined(__FreeBSD__)
- 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;
+ 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;
#endif
return (&g);
diff --git a/src/gm_ext2.c b/src/gm_ext2.c
index 81c2762..bff7f10 100644
--- a/src/gm_ext2.c
+++ b/src/gm_ext2.c
@@ -121,10 +121,9 @@ 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_max_mnt_count!=-1)&&(sb->s_mnt_count > sb->s_max_mnt_count + 20))
+ if (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 5e0adf7..506023a 100644
--- a/src/gm_fat.h
+++ b/src/gm_fat.h
@@ -60,10 +60,6 @@ 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 f3e2a16..2522029 100644
--- a/src/gm_ntfs.c
+++ b/src/gm_ntfs.c
@@ -46,6 +46,7 @@ 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;
@@ -64,11 +65,18 @@ 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 c701c05..89c953d 100644
--- a/src/gm_ntfs.h
+++ b/src/gm_ntfs.h
@@ -14,9 +14,6 @@
*
*/
-#include <stdint.h>
-#include <asm/byteorder.h>
-
#ifndef _GM_NTFS_H
#define _GM_NTFS_H
@@ -32,31 +29,32 @@
/* '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 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;
+typedef unsigned char ntfs_u8;
+typedef unsigned short ntfs_u16;
+typedef unsigned int ntfs_u32;
+typedef s64_t ntfs_u64;
#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)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)))
+#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))
/* Macros reading signed integers, returning int */
-#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))
+#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) :
+
+
#endif /* _GM_NTFS_H */
diff --git a/src/gm_reiserfs.c b/src/gm_rfs.c
similarity index 66%
rename from src/gm_reiserfs.c
rename to src/gm_rfs.c
index 8cd4e59..8c78b5a 100644
--- a/src/gm_reiserfs.c
+++ b/src/gm_rfs.c
@@ -1,5 +1,5 @@
/*
- * gm_reiserfs.c -- gpart ReiserFS guessing module
+ * gm_rfs.c -- gpart ReiserFS guessing module
*
* gpart (c) 1999-2001 Michail Brzitwa <mb at ichabod.han.de>
* Guess PC-type hard disk partitions.
@@ -12,47 +12,44 @@
* 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_reiserfs.h"
+#include "gm_rfs.h"
-static const char rcsid[] = "$Id: gm_reiserfs.c,v 1.5 2003/01/10 16:38:08 mb Exp mb $";
+static const char rcsid[] = "$Id: gm_rfs.c,v 1.5 2001/02/07 18:08:08 mb Exp mb $";
-int reiserfs_init(disk_desc *d,g_module *m)
+int rfs_init(disk_desc *d,g_module *m)
{
if ((d == 0) || (m == 0))
return (0);
- m->m_desc = "ReiserFS filesystem";
- return (REISERFS_FIRST_BLOCK * 1024 + SB_V35_SIZE);
+ m->m_desc = "Reiser filesystem";
+ return (REISERFS_FIRST_BLOCK * 1024 + SB_SIZE);
}
-int reiserfs_term(disk_desc *d)
+int rfs_term(disk_desc *d)
{
return (1);
}
-int reiserfs_gfun(disk_desc *d,g_module *m)
+int rfs_gfun(disk_desc *d,g_module *m)
{
- struct reiserfs_super_block_v35 *sb;
+ struct reiserfs_super_block *sb;
dos_part_entry *pt = &m->m_part;
s64_t size;
m->m_guess = GM_NO;
- 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)
+ sb = (struct reiserfs_super_block *)(d->d_sbuf + REISERFS_FIRST_BLOCK * 1024);
+ if (strncmp(sb->s_magic,REISERFS_SUPER_MAGIC,12) == 0)
{
/*
* sanity checks.
diff --git a/src/gm_reiserfs.h b/src/gm_rfs.h
similarity index 75%
rename from src/gm_reiserfs.h
rename to src/gm_rfs.h
index c653d16..da86cc5 100644
--- a/src/gm_reiserfs.h
+++ b/src/gm_rfs.h
@@ -1,5 +1,5 @@
/*
- * gm_reiserfs.h -- gpart ReiserFS guessing module header
+ * gm_rfs.h -- gpart ReiserFS guessing module header
*
* gpart (c) 1999-2001 Michail Brzitwa <mb at ichabod.han.de>
* Guess PC-type hard disk partitions.
@@ -12,13 +12,11 @@
* 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_reiserfs_H
-#define _GM_reiserfs_H
+#ifndef _GM_RFS_H
+#define _GM_RFS_H
/* imported from asm/types.h */
typedef __signed__ char __s8;
@@ -31,18 +29,16 @@ typedef __signed__ int __s32;
typedef unsigned int __u32;
/*
- * taken from ReiserFS v3.5.28, v3.6.x. Reiserfs Copyright 1996-2000 Hans Reiser
+ * taken from ReiserFS v3.5.28. Reiserfs Copyright 1996-2000 Hans Reiser
*/
-#define REISERFS_SUPER_V35_MAGIC "ReIsErFs"
-#define REISERFS_SUPER_V36_MAGIC "ReIsEr2Fs"
-
+#define REISERFS_SUPER_MAGIC "ReIsErFs"
#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_v35
+struct reiserfs_super_block
{
__u32 s_block_count; /* blocks count */
__u32 s_free_blocks; /* free blocks count */
@@ -66,17 +62,7 @@ struct reiserfs_super_block_v35
__u16 s_reserved;
};
-#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_SIZE (sizeof(struct reiserfs_super_block))
-#define SB_V36_SIZE (sizeof(struct reiserfs_super_block_v36))
-#endif /* _GM_REISERFS_H */
+#endif /* _GM_RFS_H */
diff --git a/src/gmodules.c b/src/gmodules.c
index d2f849e..f56aae0 100644
--- a/src/gmodules.c
+++ b/src/gmodules.c
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <dlfcn.h>
#include "gpart.h"
@@ -56,6 +57,7 @@ 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--;
@@ -130,6 +132,8 @@ g_module *g_mod_lookup(int how,char *name)
return (m);
}
+
+
/*
* preloaded modules
*/
@@ -138,22 +142,61 @@ void g_mod_addinternals()
{
g_module *m;
-#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);
+#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; }
/*
* If no weights are given on the command line, the order
* is somehow important.
*/
-#define G_MODULE(mod) GMODINS(mod)
-G_MODULES
-#undef G_MODULE
+ 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);
}
diff --git a/src/gmodules.h b/src/gmodules.h
index 0b43b43..c28e3ad 100644
--- a/src/gmodules.h
+++ b/src/gmodules.h
@@ -33,6 +33,7 @@ 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;
@@ -47,34 +48,24 @@ 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();
+int g_mod_count(), g_mod_addexternal(char *);
g_module *g_mod_setweight(char *,float);
/*
- * preloaded guessing modules, order is important as it is also the order of registering and guessing
+ * preloaded guessing modules
*/
-#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 *), \
+#define GMODDECL(mod) int mod##_init(disk_desc *,g_module *), \
mod##_term(disk_desc *), \
- mod##_gfun(disk_desc *,g_module *);
-G_MODULES
-#undef G_MODULE
+ 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);
+
#endif /* _GMODULES_H */
diff --git a/src/gpart.c b/src/gpart.c
index 50899ea..27e32ef 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 = PACKAGE_NAME " v" VERSION;
+static const char *gpart_version = PROGRAM " 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 = 's', gc = 0, gh = 0, gs = 0;
+unsigned long increment = 'h', gc = 0, gh = 0, gs = 0;
s64_t skipsec = 0, maxsec = 0;
-FILE *logfile = 0;
+FILE *log = 0;
@@ -77,13 +77,15 @@ void usage()
{
FILE *fp = stderr;
- fprintf(fp,"Usage: %s [options] device\n",PACKAGE_NAME);
+ fprintf(fp,"Usage: %s [options] device\n",PROGRAM);
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>]\n");
+ fprintf(fp," [-n <increment>][-q][-s <sector-size>][-t <module-name>]\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");
@@ -102,6 +104,7 @@ 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");
@@ -122,26 +125,26 @@ void pr(int type,char *fmt,...)
case FATAL :
g_mod_deleteall();
if (! f_quiet) fprintf(stderr,EM_FATALERROR,msg);
- if (logfile)
+ if (log)
{
- fprintf(logfile,EM_FATALERROR,msg);
- fclose(logfile);
+ fprintf(log,EM_FATALERROR,msg);
+ fclose(log);
}
exit(1);
case ERROR :
if (! f_quiet) fprintf(stderr,EM_SIMPLEERROR,msg);
- if (logfile) fprintf(logfile,EM_SIMPLEERROR,msg);
+ if (log) fprintf(log,EM_SIMPLEERROR,msg);
break;
case WARN :
if (! f_quiet) fprintf(stderr,EM_WARNING,msg);
- if (logfile) fprintf(logfile,EM_WARNING,msg);
+ if (log) fprintf(log,EM_WARNING,msg);
break;
case MSG :
if (! f_quiet) fputs(msg,stdout); fflush(stdout);
- if (logfile) fputs(msg,logfile);
+ if (log) fputs(msg,log);
break;
}
- if (logfile) fflush(logfile);
+ if (log) fflush(log);
}
@@ -371,7 +374,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 - 1]; t++)
+ for (t = &p[0]; t < &p[NDOSPARTS]; t++)
if (is_ext_parttype(t))
ne++;
return (ne);
@@ -384,7 +387,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 - 1]; t++)
+ for (t = &p[0]; t < &p[NDOSPARTS]; t++)
if (is_real_parttype(t))
nr++;
return (nr);
@@ -454,7 +457,7 @@ static int is_ext_parttable(disk_desc *d,byte_t *buf)
* ptbl sanity checks.
*/
- for (t = p; t <= &p[NDOSPARTS - 1]; t++)
+ for (t = p; t < &p[NDOSPARTS]; t++)
if (! is_sane_partentry(d,t,0))
return (0);
@@ -599,11 +602,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;
}
@@ -703,7 +706,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)
@@ -830,8 +833,6 @@ 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
*/
@@ -848,14 +849,9 @@ 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;
-
- 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;
- }
-
+ 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);
@@ -1225,7 +1221,7 @@ static int make_mbr_backup(disk_desc *d,char *bfile)
{
int fd, ret = 0;
- if ((fd = open(bfile, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
+ if ((fd = open(bfile,O_WRONLY|O_CREAT)) < 0)
return (ret);
if (write(fd,d->d_pt.t_boot,512) == 512)
@@ -1434,7 +1430,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 - 1]; p++)
+ for (p = &gp->g_p[0]; p < &gp->g_p[NDOSPARTS]; p++)
{
if (is_real_parttype(p))
rp = p;
@@ -1535,7 +1531,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 - 1]; p++)
+ for (p = &gp->g_p[0]; p < &gp->g_p[NDOSPARTS]; p++)
{
if (is_real_parttype(p))
rp = p;
@@ -1754,8 +1750,8 @@ int main(int ac,char **av)
}
break;
case 'l' :
- if (logfile) fclose(logfile);
- if ((logfile = fopen(optarg,"w")) == 0)
+ if (log) fclose(log);
+ if ((log = fopen(optarg,"w")) == 0)
pr(FATAL,EM_OPENLOG,optarg);
break;
case 'L' :
@@ -1767,6 +1763,10 @@ 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 (logfile) fclose(logfile);
+ if (log) fclose(log);
return (f_check ? no_of_incons : 0);
}
diff --git a/src/gpart.h b/src/gpart.h
index d973d65..37a6180 100644
--- a/src/gpart.h
+++ b/src/gpart.h
@@ -17,23 +17,57 @@
#ifndef _GPART_H
#define _GPART_H
-#include "config.h"
-
#include "errmsgs.h"
#include "l64seek.h"
-#include <stdint.h>
+#define PROGRAM "gpart"
+
+
+typedef unsigned char byte_t;
-typedef uint8_t byte_t;
+/*
+ * endianness (incomplete, later)
+ */
-#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)
+#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
#ifndef max
@@ -78,8 +112,8 @@ typedef struct
byte_t p_ehd; /* end head */
byte_t p_esect; /* end sector */
byte_t p_ecyl; /* end cylinder */
- uint32_t p_start; /* start sector (absolute) */
- uint32_t p_size; /* # of sectors */
+ unsigned long p_start; /* start sector (absolute) */
+ unsigned long p_size; /* # of sectors */
} dos_part_entry;
@@ -89,7 +123,7 @@ typedef struct dos_pt
byte_t _align[2];
byte_t t_boot[DOSPARTOFF];
dos_part_entry t_parts[NDOSPARTS];
- uint16_t t_magic; /* DOSPTMAGIC */
+ unsigned short t_magic; /* DOSPTMAGIC */
} dos_part_table;
@@ -122,7 +156,9 @@ typedef struct
long d_c; /* cylinder count */
long d_h; /* heads/cyl */
long d_s; /* sectors/head */
- uint64_t d_nsecs; /* Number of sectors total */
+ long d_rc; /* real values if the above are */
+ long d_rh; /* translated */
+ long d_rs;
} 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 9b2084c..55b3a87 100644
--- a/src/l64seek.c
+++ b/src/l64seek.c
@@ -25,13 +25,30 @@ 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 669b655..946a7cf 100644
--- a/src/l64seek.h
+++ b/src/l64seek.h
@@ -17,8 +17,6 @@
#ifndef _L64SEEK_H
#define _L64SEEK_H
-#include <sys/stat.h>
-#include <sys/types.h>
#include <unistd.h>
/*
@@ -27,7 +25,19 @@
* offsets.
*/
-typedef loff_t off64_t;
+
+#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 off64_t s64_t;
off64_t l64seek(int fd, off64_t offset, int whence);
@@ -35,4 +45,5 @@ 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