forked from umaprograms/ext4_start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgd_ext4.c
49 lines (31 loc) · 797 Bytes
/
gd_ext4.c
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
#include "ext4.h"
int main (int argc, char *argv[])
{
int f;
int index = 0;
struct ext4_group_desc gd ;
if (argc < 2) {
printf ("Give me Disk name \n");
return -1;
}
f = open(DISK_NAME, O_RDONLY);
if ( f == -1 ) {
printf ("run with root permissions\n");
return -1;
}
int gd_count = get_gd_count(f);
memset(&gd, 0 , (sizeof(struct ext4_group_desc)));
//printf ("gd size %d\n", gd_count);
lseek(f, 1024+1024, SEEK_CUR);
// leave out these x86 boot sector and padding && //readout superblock
lseek(f, 32 * (sizeof(struct ext4_group_desc)), SEEK_CUR);
int size_of_gd = get_desc_size(f);
for (; index < gd_count; index++){
read(f, &gd, size_of_gd);
if (gd.bg_checksum) {
print_gd_info(index, &gd) ;
memset(&gd, 0, sizeof (gd));
}
}
return 0;
}