Created
February 18, 2015 22:07
-
-
Save eerpini/91297ecf46d5e6f3a8ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main (int argc, char **argv) | |
{ | |
int fd, i, block, blocksize, bcount, prev_block, frag_count=0; | |
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)); | |
} | |
if(block != (prev_block + 1)){ | |
frag_count++; | |
printf ("\n\033[31m %3d %10d \033[0;39m \n", i, block); | |
fprintf(stderr, "\n\033[31m %3d %10d \033[0;39m \n", i, block); | |
} | |
else | |
printf("\r\033[1;36m %3d %10d \033[0;39m ", i, block); | |
prev_block = block; | |
} | |
printf("Number of fragmented blocks : %4d\n",frag_count); | |
close (fd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment