How to get file info of a directory in linux kernel space?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi, all

you know in the linux userspace , i can compile and run the following
program to get the name or inode number of the files in the /bin directory.

i want to know how to do this in linux kernelspace ? thank you very much!

/*********************************************************************/

#include <unistd.h>

#include <sys/stat.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <dirent.h>



void printdir(char *dir, int depth){

    DIR *dp;

    struct dirent *entry;

    struct stat statbuf;

    if((dp = opendir(dir)) == NULL){

        fprintf(stderr,"cannot open directory: %s\n",dir);

        return;

    }

    chdir(dir);

    while((entry = readdir(dp)) != NULL){

        lstat(entry->d_name,&statbuf);

        if(S_ISDIR(statbuf.st_mode)){

            if(strcmp("..",entry->d_name) == 0||

            strcmp(".",entry->d_name) == 0)

                continue;

            printf("%*s%s/\n",depth,"",entry->d_name);

            printdir(entry->d_name,depth+4);

        }

        else printf("%*s%s\n",depth,"",entry->d_name);

    }

    chdir("..");

    closedir(dp);

}

int main(){

    printdir("/bin",0);
}

/*************************************************************************************************/

-- 
Best regards,
张树坤
北京理工大学,计算机科学技术学院
Sucan
Computer Department,Beijing Institute of Technology,China
_______________________________________________
Fedora-kernel-list mailing list
Fedora-kernel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/fedora-kernel-list


[Index of Archives]     [Fedora General Discussion]     [Older Fedora Users Archive]     [Fedora Advisory Board]     [Fedora Security]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Mentors]     [Fedora Package Announce]     [Fedora Package Review]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Coolkey]     [Yum Users]     [Tux]     [Yosemite News]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [USB]     [Asterisk PBX]

  Powered by Linux