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
|
#include "disklab.h"
#include <stdio.h>
#include <malloc.h>
extern int fd;
extern int blk_size;
void* getoneblk(__u32 block)
{
int bytes_read;
char *buf;
if ( lseek(fd, block * blk_size, SEEK_SET) < 0) {/* ... */
printf("seek file ext2.img error....\n");
return NULL;
}
buf = malloc(blk_size);
if ( (bytes_read = read(fd, buf, blk_size)) < blk_size )
printf("read %d bytes less than %dB..\n", bytes_read, blk_size);
return buf;
}
void getlinsec(char *buf, int sector, int sector_cnt)
{
int bytes_read;
if ( lseek(fd, sector*512, SEEK_SET) < 0 ) {
printf("seek file ext2.img error ....\n");
return;
}
if ( (bytes_read = read(fd, buf, 512*sector_cnt)) < 512*sector_cnt)
printf("read %d bytes less than %d bytes..\n",
bytes_read, 512 * sector_cnt);
}
|