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: sun.c
Copyright (C) 2004-2007 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
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "types.h"
#include "common.h"
#include "sun.h"
#include "fnctdsk.h"
#include "log.h"
#include "log_part.h"
#define SUN_LABEL_MAGIC 0xDABE
#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_SUN)
extern const arch_fnct_t arch_sun;
#endif
static void set_sun_info_i386(partition_t *partition);
static int test_sun_i386(const disk_t *disk_car, const sun_partition_i386 *sunlabel, const partition_t *partition, const int verbose);
int check_sun_i386(disk_t *disk_car,partition_t *partition,const int verbose)
{
unsigned char *buffer=(unsigned char*)MALLOC(SUN_PARTITION_I386_SIZE);
const sun_partition_i386 *sunlabel=(const sun_partition_i386*)buffer;
if(disk_car->pread(disk_car, buffer, SUN_PARTITION_I386_SIZE, partition->part_offset + 0x200) != SUN_PARTITION_I386_SIZE)
{
free(buffer);
return 1;
}
if(test_sun_i386(disk_car, sunlabel, partition, verbose)!=0)
{
free(buffer);
return 1;
}
set_sun_info_i386(partition);
free(buffer);
return 0;
}
static int test_sun_i386(const disk_t *disk_car, const sun_partition_i386 *sunlabel, const partition_t *partition, const int verbose)
{
if ((le16(sunlabel->magic) != SUN_LABEL_MAGIC) ||
(le32(sunlabel->magic_start) != SUN_LABEL_MAGIC_START))
return 1;
if(verbose>0)
log_info("\nSUN Marker at %u/%u/%u\n",
offset2cylinder(disk_car,partition->part_offset),
offset2head(disk_car,partition->part_offset),
offset2sector(disk_car,partition->part_offset));
#if !defined(SINGLE_PARTITION_TYPE) || defined(SINGLE_PARTITION_SUN)
{
int i;
partition_t *new_partition=partition_new(NULL);
for(i=0;i<16;i++)
{
if (sunlabel->partitions[i].num_sectors > 0
&& sunlabel->partitions[i].id > 0)
// && sunlabel->partitions[i].id != WHOLE_DISK)
{
partition_reset(new_partition, &arch_sun);
new_partition->order=i;
new_partition->part_type_sun=sunlabel->partitions[i].id;
new_partition->part_offset=partition->part_offset+(uint64_t)le32(sunlabel->partitions[i].start_sector) * le16(sunlabel->sector_size);
new_partition->part_size=(uint64_t)le32(sunlabel->partitions[i].num_sectors) * le16(sunlabel->sector_size);
new_partition->status=STATUS_PRIM;
log_partition(disk_car,new_partition);
}
}
free(new_partition);
}
#endif
return 0;
}
int recover_sun_i386(const disk_t *disk_car, const sun_partition_i386 *sunlabel, partition_t *partition,const int verbose, const int dump_ind)
{
if(test_sun_i386(disk_car, sunlabel, partition, verbose)!=0)
return 1;
if(verbose>0 || dump_ind!=0)
{
log_info("\nrecover_sun\n");
if(dump_ind!=0)
{
dump_log(sunlabel,sizeof(*sunlabel));
}
}
partition->part_size=(uint64_t)le32(sunlabel->partitions[2].num_sectors) * le16(sunlabel->sector_size);
set_sun_info_i386(partition);
partition->part_type_i386 = P_SUN;
partition->part_type_gpt=GPT_ENT_TYPE_SOLARIS_ROOT;
return 0;
}
static void set_sun_info_i386(partition_t *partition)
{
partition->upart_type = UP_SUN;
partition->info[0]='\0';
partition->fsname[0]='\0';
}
|