EXT2 Directory Content
Hi I reached inode 2 , the root directory.开发者_如何学Python I know the direct block number of it, which is 265. How can I list the content of the root directory in C?
This should work. I suggest looking up the man pages for opendir() and readdir(). This is not based on inodes. Do you require to be able to look up directories based on inode?
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
int main() {
DIR *dir = opendir("/");
if(dir==NULL) {
perror("Couldn't open dir");
exit(1);
}
printf("opened\n");
struct dirent * entry;
while((entry = readdir(dir))) {
printf("%s\n", entry->d_name);
}
return 0;
}
精彩评论