1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
/*
File: sysv.c
Copyright (C) 2004-2006 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
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "types.h"
#include "common.h"
#include "sysv.h"
#include "fnctdsk.h"
#include "intrf.h"
#define SYSV4_SECTOR_SIZE 512
#define SYSV4_SBLOCK 8192
#define SYSV4_MAGIC 0x00011954
#define SYSV4_CIGAM 0x54190100 /* byteswapped MAGIC */
/* HP specific MAGIC values */
#define SYSV4_MAGIC_LFN 0x00095014 /* fs supports filenames > 14 chars */
#define SYSV4_CIGAM_LFN 0x14500900 /* srahc 41 < semanelif stroppus sf */
#define SYSV4_MAGIC_SEC 0x00612195 /* B1 security fs */
#define SYSV4_CIGAM_SEC 0x95216100
#define SYSV4_MAGIC_FEA 0x00195612 /* fs_featurebits supported */
#define SYSV4_CIGAM_FEA 0x12561900
#define SYSV4_MAGIC_4GB 0x05231994 /* fs > 4 GB && fs_featurebits */
#define SYSV4_CIGAM_4GB 0x94192305
static int set_sysv4_info(const t_param_disk *disk_car, const struct sysv4_super_block *sbd,t_partition *partition, const int debug, const int dump_ind);
static int test_sysv4(const t_param_disk *disk_car, const struct sysv4_super_block *sbd,t_partition *partition,const int debug, const int dump_ind);
int check_sysv(t_param_disk *disk_car,t_partition *partition,const int debug)
{
unsigned char *buffer=(unsigned char*)MALLOC(SYSV4_SECTOR_SIZE);
if(disk_car->read(disk_car,SYSV4_SECTOR_SIZE, buffer, partition->part_offset+0x200)!=0)
{
free(buffer);
return 1;
}
if(test_sysv4(disk_car,(const struct sysv4_super_block *)buffer,partition,debug,0)==0)
{
set_sysv4_info(disk_car,(const struct sysv4_super_block *)buffer,partition,debug,0);
free(buffer);
return 0;
}
free(buffer);
return 1;
}
static int test_sysv4(const t_param_disk *disk_car, const struct sysv4_super_block *sbd,t_partition *partition,const int debug, const int dump_ind)
{
if ((sbd->s_magic== le32(0xfd187e20))||(sbd->s_magic== be32(0xfd187e20)))
{
partition->upart_type = UP_SYSV4;
}
else
return 1;
if(debug>0)
ecrit_rapport("\nSYSV4 Marker at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
return 0;
}
int recover_sysv(t_param_disk *disk_car, const struct sysv4_super_block *sbd, t_partition *partition,const int debug, const int dump_ind)
{
if(test_sysv4(disk_car,sbd,partition,debug,dump_ind)==0)
{
if(debug>0 || dump_ind!=0)
{
ecrit_rapport("\nrecover_sysv4\n");
if(dump_ind!=0)
{
dump(stdscr,sbd,sizeof(*sbd));
}
}
switch(sbd->s_magic)
{
case le32(0xfd187e20):
partition->part_size = (uint64_t)le32(sbd->s_fsize)*(512<<(le32(sbd->s_type)-1));
break;
case be32(0xfd187e20):
partition->part_size = (uint64_t)be32(sbd->s_fsize)*(512<<(be32(sbd->s_type)-1));
break;
}
set_sysv4_info(disk_car,sbd,partition,debug,dump_ind);
partition->part_type_i386 = P_SYSV;
return 0;
}
return 1;
}
static int set_sysv4_info(const t_param_disk *disk_car,const struct sysv4_super_block *sbd,t_partition *partition, const int debug, const int dump_ind)
{
strncpy(partition->info,"SysV4",sizeof(partition->info));
set_part_name(partition,sbd->s_fname,sizeof(sbd->s_fname));
return 0;
}
|