#include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { int fd, i, block, blocksize, bcount; struct stat st; assert(argv[1] != NULL); assert(fd=open(argv[1], O_RDONLY)); assert(ioctl(fd, FIGETBSZ, &blocksize) == 0); assert(!fstat(fd, &st)); bcount = (st.st_size + blocksize - 1) / blocksize; printf("File: %s Size: %d Blocks: %d Blocksize: %d\n", argv[1], st.st_size, bcount, blocksize); for(i=0;i < bcount;i++) { block=i; if (ioctl(fd, FIBMAP, &block)) { printf("FIBMAP ioctl failed - errno: %s\n", strerror(errno)); } printf("%d\t%d\n", i, block); } close(fd); }