Zhang Shukun
2009-Jun-03 05:13 UTC
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);
}
/*************************************************************************************************/
--
Best regards,
???
????????????????
Sucan
Computer Department,Beijing Institute of Technology,China
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://listman.redhat.com/archives/ext3-users/attachments/20090603/a448205c/attachment.htm>
Zhang Shukun
2009-Jun-03 05:14 UTC
[Xen-devel] 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);
}
/*************************************************************************************************/
--
Best regards,
张树坤
北京理工大学,计算机科学技术学院
Sucan
Computer Department,Beijing Institute of Technology,China
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Zhang Shukun
2009-Jun-03 05:15 UTC
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);
}
/*************************************************************************************************/
--
Best regards,
张树坤
北京理工大学,计算机科学技术学院
Sucan
Computer Department,Beijing Institute of Technology,China
Jon Masters
2009-Jun-04 14:11 UTC
Re: How to get file info of a directory in linux kernel space?
On Wed, 2009-06-03 at 13:15 +0800, Zhang Shukun wrote:> 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!Hi, Please see the following helpful reference topic: http://kernelnewbies.org/FAQ/WhyWritingFilesFromKernelIsBad It''s likely that you can do what you need but without opening files from within the kernel. If it''s simply an academic project or for interest, then I suggest asking the kernelnewbies.org folks for help. Jon.
Seemingly Similar Threads
- How to get file info of a directory in linux kernel space?
- Re: [PATCH nbdkit 4/4] Add floppy plugin.
- Re: [PATCH nbdkit 4/4] Add floppy plugin.
- [PATCH supermin] init: Delete initramfs files before chrooting into the appliance.
- How to get all the sectors of a file in domU?