LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-03-2009, 12:20 AM   #1
bitzsk
LQ Newbie
 
Registered: Apr 2009
Posts: 15

Rep: Reputation: 0
How to get file info of a directory in linux kernel space?


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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
in linux kernel,how to get the sector info of a file? bitzsk Linux - Kernel 2 06-04-2009 12:23 AM
Gnome/Nautilus issues Beagle-Tracker, file transfer info, replace file info, popup. Mysticle31 Linux - Software 0 01-08-2008 05:30 PM
remove directory info from tar file splunk Linux - Software 2 08-22-2007 03:24 PM
Does the kernel cache directory info? ('find' command runs quicker after first use) sixerjman Linux - Kernel 2 10-26-2006 12:31 AM
info problem "info: dir: No such file or directory" EAD Linux - Software 0 03-22-2006 02:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration