Hi I reached inode 2 , the root directory. I know the direct block number of it, which is 265. How can I list the content of the root directory in C?
Asked
Active
Viewed 809 times
2
-
This question is badly written. It should be made clear that it is about **directly** editing a partition by editing the block-special file, without even mounting the partition. Also, WHY? :-) – Aaron McDaid Jun 22 '11 at 23:16
1 Answers
-1
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;
}

Aaron McDaid
- 26,501
- 9
- 66
- 88
-
I need to directly modify the low level filesystem without OS calls, do you know how to access directory inodes? See: [My Question](http://stackoverflow.com/questions/6287606/how-do-i-read-and-traverse-inodes) – Eric Fossum Jun 18 '11 at 00:07