开发者

EXT2 Directory Content

开发者 https://www.devze.com 2023-03-07 22:58 出处:网络
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 look

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消