WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

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

To: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] How to get file info of a directory in linux kernel space?
From: Zhang Shukun <bitzsk@xxxxxxxxx>
Date: Wed, 3 Jun 2009 13:14:10 +0800
Delivery-date: Tue, 02 Jun 2009 22:14:57 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type; bh=k25s+b/HwTLD7vDecfkZ/YOlY3V/oyr0Fm/wUarhR0k=; b=ZL68YXqnMPHdcfi8bSj3NWIpwM70Kafhav4XtnQccCzwIdrbgvetPzv8aHOmGBH2JK yWSoT4qsM7L+uHHFqWNjw6VPiovyXYckFYKxn8kYq+jilq4JlAJ/nOZHUonVHrZ2vDbP TDZgWOfjQQexbfv0ZFQMKFUhnMNN652cFfe2o=
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=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <a160a7d60906022213r21ee3310n774c0b14a5768079@xxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <a160a7d60906022213r21ee3310n774c0b14a5768079@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx


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
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] How to get file info of a directory in linux kernel space?, Zhang Shukun <=