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

[Xen-devel] How to get file info of a directory in linux kernel space?


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
  • From: Zhang Shukun <bitzsk@xxxxxxxxx>
  • Date: Wed, 3 Jun 2009 13:14:10 +0800
  • Delivery-date: Tue, 02 Jun 2009 22:14:57 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=D7b0xrt5m6mbMCKpd3E0q9N64kxkPbvKWesSlyj03Bv41fVC7xo4IeUUTZ72hUr1fd 0N2QbmknXhGhytG/nfZGgWyNzVMyEQYPbVbJHabhDLdEbmGczGJXXV9Sqh16PHs1nnhH WlIdAt+9LF9E7RLuSwrGxhLEeIOAfPuk5sONg=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>



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
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.