Locate lost GFS2 partition but not yet the size

This commit is contained in:
Christophe Grenier 2011-08-28 09:55:27 +02:00
parent 789bb8645b
commit 03ecc7e037
6 changed files with 187 additions and 4 deletions

View file

@ -16,8 +16,8 @@ EXTRA_PROGRAMS = photorecf
base_C = autoset.c common.c crc.c ewf.c fnctdsk.c hdaccess.c hdcache.c hdwin32.c hidden.c hpa_dco.c intrf.c iso.c log.c log_part.c misc.c msdos.c parti386.c partgpt.c parthumax.c partmac.c partsun.c partnone.c partxbox.c io_redir.c ntfs_io.c ntfs_utl.c partauto.c sudo.c unicode.c win32.c
base_H = alignio.h autoset.h common.h crc.h ewf.h fnctdsk.h hdaccess.h hdwin32.h hidden.h guid_cmp.h guid_cpy.h hdcache.h hpa_dco.h intrf.h iso.h iso9660.h lang.h log.h log_part.h misc.h types.h io_redir.h msdos.h ntfs_utl.h parti386.h partgpt.h parthumax.h partmac.h partsun.h partxbox.h partauto.h sudo.h unicode.h win32.h
fs_C = analyse.c bfs.c bsd.c btrfs.c cramfs.c exfat.c fat.c fatx.c ext2.c jfs.c hfs.c hfsp.c hpfs.c luks.c lvm.c md.c netware.c ntfs.c rfs.c savehdr.c sun.c swap.c sysv.c ufs.c vmfs.c xfs.c zfs.c
fs_H = analyse.h bfs.h bsd.h btrfs.h cramfs.h exfat.h fat.h fatx.h ext2.h jfs_superblock.h jfs.h hfs.h hfsp.h hpfs.h luks.h lvm.h md.h netware.h ntfs.h rfs.h savehdr.h sun.h swap.h sysv.h ufs.h vmfs.h xfs.h zfs.h
fs_C = analyse.c bfs.c bsd.c btrfs.c cramfs.c exfat.c fat.c fatx.c ext2.c jfs.c gfs2.c hfs.c hfsp.c hpfs.c luks.c lvm.c md.c netware.c ntfs.c rfs.c savehdr.c sun.c swap.c sysv.c ufs.c vmfs.c xfs.c zfs.c
fs_H = analyse.h bfs.h bsd.h btrfs.h cramfs.h exfat.h fat.h fatx.h ext2.h jfs_superblock.h jfs.h gfs2.h hfs.h hfsp.h hpfs.h luks.h lvm.h md.h netware.h ntfs.h rfs.h savehdr.h sun.h swap.h sysv.h ufs.h vmfs.h xfs.h zfs.h
testdisk_ncurses_C = addpart.c adv.c askloc.c chgtype.c chgtypen.c dimage.c dirn.c dirpart.c diskacc.c diskcapa.c edit.c ext2_sb.c ext2_sbn.c fat1x.c fat32.c fat_adv.c fat_cluster.c fatn.c geometry.c godmode.c hiddenn.c intrface.c intrfn.c nodisk.c ntfs_adv.c ntfs_fix.c ntfs_udl.c parti386n.c partgptn.c partmacn.c partsunn.c partxboxn.c tanalyse.c tbanner.c tdelete.c tdiskop.c tdisksel.c testdisk.c texfat.c thfs.c tload.c tlog.c tmbrcode.c tntfs.c toptions.c tpartwr.c
testdisk_ncurses_H = addpart.h adv.h askloc.h chgtype.h chgtypen.h dimage.h dirn.h dirpart.h diskacc.h diskcapa.h edit.h ext2_sb.h ext2_sbn.h fat1x.h fat32.h fat_adv.h fat_cluster.h fatn.h geometry.h godmode.h hiddenn.h intrface.h intrfn.h nodisk.h ntfs_udl.h partgptn.h parti386n.h partmacn.h partsunn.h partxboxn.h tanalyse.h tdelete.h tdiskop.h tdisksel.h texfat.h thfs.h tload.h tlog.h tmbrcode.h tntfs.h toptions.h tpartwr.h

View file

@ -38,6 +38,7 @@
#include "ext2.h"
#include "fat.h"
#include "fatx.h"
#include "gfs2.h"
#include "hfs.h"
#include "hfsp.h"
#include "jfs_superblock.h"
@ -362,6 +363,7 @@ int search_type_128(unsigned char *buffer, disk_t *disk, partition_t *partition,
const struct reiser4_master_sb *rfs4=(const struct reiser4_master_sb *)data;
const struct ufs_super_block *ufs=(const struct ufs_super_block *)data;
const struct btrfs_super_block *btrfs=(const struct btrfs_super_block*)data;
const struct gfs2_sb *gfs2=(const struct gfs2_sb *)data;
/* 64k offset */
/* Test ReiserFS */
if((memcmp(rfs->s_magic,"ReIs",4) == 0 ||
@ -376,7 +378,9 @@ int search_type_128(unsigned char *buffer, disk_t *disk, partition_t *partition,
if(memcmp(&btrfs->magic, BTRFS_MAGIC, 8)==0 &&
recover_btrfs(disk, btrfs, partition, verbose, dump_ind)==0)
return 1;
// if(recover_gfs2(disk,(buffer+0x400),partition,verbose,dump_ind)==0) return 1;
if(gfs2->sb_header.mh_magic==be32(GFS2_MAGIC) &&
recover_gfs2(disk, gfs2, partition, dump_ind)==0)
return 1;
}
return 0;
}
@ -409,7 +413,8 @@ int check_linux(disk_t *disk, partition_t *partition, const int verbose)
check_cramfs(disk, partition, verbose)==0 ||
check_xfs(disk, partition, verbose)==0 ||
check_LUKS(disk, partition)==0 ||
check_btrfs(disk, partition, verbose)==0)
check_btrfs(disk, partition, verbose)==0 ||
check_gfs2(disk, partition)==0)
return 0;
return 1;
}

View file

@ -237,6 +237,7 @@ enum upart_type {
UP_FAT32=0x0b,
UP_FATX,
UP_FREEBSD,
UP_GFS2,
UP_HFS,
UP_HFSP,
UP_HFSX,

90
src/gfs2.c Normal file
View file

@ -0,0 +1,90 @@
/*
File: gfs2.c
Copyright (C) 2011 Christophe GRENIER <grenier@cgsecurity.org>
This software 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 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write the Free Software Foundation, Inc., 51
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "types.h"
#include "common.h"
#include "gfs2.h"
#include "fnctdsk.h"
#include "log.h"
static int set_gfs2_info(const struct gfs2_sb *sb, partition_t *partition)
{
partition->info[0]='\0';
return 0;
}
static int test_gfs2(disk_t *disk, const struct gfs2_sb *sb, partition_t *partition, const int dump_ind)
{
if(sb->sb_header.mh_magic != be32(GFS2_MAGIC))
return 1;
if(sb->sb_header.mh_format != be32(GFS2_FORMAT_SB))
return 1;
partition->upart_type=UP_GFS2;
if(dump_ind!=0)
{
log_info("\ngfs2 magic value at %u/%u/%u\n",
offset2cylinder(disk, partition->part_offset),
offset2head(disk, partition->part_offset),
offset2sector(disk, partition->part_offset));
dump_log(sb,DEFAULT_SECTOR_SIZE);
}
return 0;
}
int check_gfs2(disk_t *disk, partition_t *partition)
{
unsigned char *buffer;
buffer=(unsigned char*)MALLOC(512);
if(disk->pread(disk, buffer, 512, partition->part_offset + (GFS2_SB_ADDR << GFS2_BASIC_BLOCK_SHIFT)) != 512)
{
free(buffer);
return 1;
}
if(test_gfs2(disk, (const struct gfs2_sb *)buffer, partition,0)!=0)
{
free(buffer);
return 1;
}
set_gfs2_info((const struct gfs2_sb *)buffer, partition);
free(buffer);
return 0;
}
int recover_gfs2(disk_t *disk, const struct gfs2_sb *sb, partition_t *partition, const int dump_ind)
{
if(test_gfs2(disk,sb,partition,dump_ind)!=0)
return 1;
set_gfs2_info(sb, partition);
partition->part_size=disk->sector_size;
partition->part_type_i386=(unsigned char)P_LINUX;
return 0;
}

86
src/gfs2.h Normal file
View file

@ -0,0 +1,86 @@
/*
File: gfs2.h
Copyright (C) 2011 Christophe GRENIER <grenier@cgsecurity.org>
This software 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 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write the Free Software Foundation, Inc., 51
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef __cplusplus
extern "C" {
#endif
// Structure from gfs2_ondisk.h
#define GFS2_MAGIC 0x01161970
#define GFS2_BASIC_BLOCK 512
#define GFS2_BASIC_BLOCK_SHIFT 9
#define GFS2_FORMAT_SB 100
/*
* An on-disk inode number
*/
struct gfs2_inum {
uint64_t no_formal_ino;
uint64_t no_addr;
};
struct gfs2_meta_header {
uint32_t mh_magic;
uint32_t mh_type;
uint64_t __pad0; /* Was generation number in gfs1 */
uint32_t mh_format;
/* This union is to keep userspace happy */
union {
uint32_t mh_jid; /* Was incarnation number in gfs1 */
uint32_t __pad1;
};
};
/* Address of superblock in GFS2 basic blocks */
#define GFS2_SB_ADDR 128
#define GFS2_LOCKNAME_LEN 64
struct gfs2_sb {
struct gfs2_meta_header sb_header;
uint32_t sb_fs_format;
uint32_t sb_multihost_format;
uint32_t __pad0; /* Was superblock flags in gfs1 */
uint32_t sb_bsize;
uint32_t sb_bsize_shift;
uint32_t __pad1; /* Was journal segment size in gfs1 */
struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */
struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */
struct gfs2_inum sb_root_dir;
char sb_lockproto[GFS2_LOCKNAME_LEN];
char sb_locktable[GFS2_LOCKNAME_LEN];
struct gfs2_inum __pad3; /* Was quota inode in gfs1 */
struct gfs2_inum __pad4; /* Was licence inode in gfs1 */
#define GFS2_HAS_UUID 1
uint8_t sb_uuid[16]; /* The UUID, maybe 0 for backwards compat */
};
//
int check_gfs2(disk_t *disk_car, partition_t *partition);
int recover_gfs2(disk_t *disk_car, const struct gfs2_sb *sb, partition_t *partition, const int dump_ind);
#ifdef __cplusplus
} /* closing brace for extern "C" */
#endif

View file

@ -94,6 +94,7 @@ static const struct systypes none_sys_types[] = {
{UP_FAT16, "FAT16"},
{UP_FAT32, "FAT32"},
{UP_FREEBSD, "FreeBSD"},
{UP_GFS2, "GFS2"},
{UP_HFS, "HFS"},
{UP_HFSP, "HFS+"},
{UP_HFSX, "HFSX"},