Created
July 23, 2010 10:06
-
-
Save zed9h/487240 to your computer and use it in GitHub Desktop.
list ext2 data blocks from a filesystem and file path through it's inode, using two methods
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
// gcc -l ext2fs % -pg && ./a.out dummy.ext2 a/4 | |
#include <ext2fs/ext2fs.h> | |
#include <stdio.h> | |
int blk_iterate(ext2_filsys fs, blk_t *blocknr, int blockcnt, void *priv_data) | |
{ | |
printf("blk(%d)=%d\n", blockcnt, *blocknr); | |
return 0; | |
} | |
void do_block_iterate(ext2_filsys fs, ext2_ino_t ino) | |
{ | |
printf("block_iterate\n"); | |
ext2fs_block_iterate(fs, ino, 0, 0, blk_iterate, 0); | |
} | |
void do_bmap(ext2_filsys fs, ext2_ino_t ino) | |
{ | |
printf("bmap\n"); | |
blk_t blk=0, pblk=-1; | |
while((ext2fs_bmap(fs, ino, 0, 0, 0, blk, &pblk) == 0) && pblk) { | |
printf("blk(%d)=%d\n", blk, pblk); | |
++blk; | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
if(argc<2) | |
return 1; | |
char * fs_path = argv[1]; | |
char * file_path = argv[2]; | |
ext2_filsys fs = NULL; | |
ext2fs_open(fs_path, 0, 0, 0, unix_io_manager, &fs); | |
//ext2fs_read_bitmaps(fs); | |
ext2_ino_t ino; | |
ext2fs_namei(fs, EXT2_ROOT_INO, EXT2_ROOT_INO, file_path, &ino); | |
printf("ino=%d\n",ino); | |
#if 0 | |
struct ext2_inode ei; | |
ext2fs_read_inode(fs, ino, &ei); | |
uint nblk = ext2fs_inode_data_blocks(fs, &ei); | |
printf("nblk=%d\n",nblk); | |
#endif | |
do_bmap(fs, ino); | |
do_block_iterate(fs, ino); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment