blob: a3abe366e71d74f8461c315394ef26a5fd13ed2a (
plain)
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
|
#include <stdio.h>
#include <malloc.h>
extern int fd;
void * getonesec(int sector)
{
void *data;
int bytes_read;
if ( lseek(fd, sector * 512, SEEK_SET) < 0) {/* ... */
printf("seek file ext2.img error....\n");
return NULL;
}
data = malloc(512);
if ( (bytes_read = read(fd, data, 512)) < 512 )
printf("read %d bytes less than 512B...\n", bytes_read);
return data;
}
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);
}
|