File: test.c

package info (click to toggle)
lilo 21-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 812 kB
  • ctags: 895
  • sloc: ansic: 3,420; asm: 2,546; sh: 767; perl: 607; makefile: 193; cpp: 3
file content (46 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (2)
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
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/fs.h>


int main(int argc,char **argv)
{
    int fd,i,block;
    struct phyloc_result phyloc;
    struct stat st;

printf("%d %d\n",sizeof(off_t),sizeof(loff_t));
    fd = open(argv[1],O_RDONLY);
    if (fd < 0) {
	perror(argv[1]);
	return 1;
    }
    if (fstat(fd,&st) < 0) {
	perror("stat");
	return 1;
    }
    for (i = 0; i < (st.st_size >> 10); i++) {
	block = i;
	if (ioctl(fd,FIBMAP,&block) < 0) {
	    perror("FIBMAP");
	    break;
	}
	printf("%d ",block);
    }
    putchar('\n');
lseek(fd,100,SEEK_SET);
    while (1) {
	if (ioctl(fd,FIPHYLOC,&phyloc) < 0) {
	    perror("FIPHYLOC");
	    return 1;
	}
	if (!phyloc.size) break;
	printf("0x%04x(%d,%d) ",phyloc.device,(int) phyloc.start,
	  (int) phyloc.size);
    }
    putchar('\n');
    return 0;
}