有什么方法可以使用给定的inode编号搜索文件或文件名? [英] Is there any way that I can search for a file or a filename using a given inode number?
本文介绍了有什么方法可以使用给定的inode编号搜索文件或文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要从用户那里获取一个索引节点号,我必须在文件系统中搜索该文件.如何搜索inode编号.我必须使用C和Unix来做到这一点.
I am taking in an inode number from a user and I have to search the file system for that file. How do I search through inode numbers. I have to do this using C and unix.
到目前为止,这是我的代码:
Here is my code so far:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
int main(){
int inodeNumber;
printf("Please enter the inode you wish to view:\n");
scanf("%d",&inodeNumber);
struct stat fileStat;
int temp_file;
temp_file = system("find/fs/root -inum inodeNumber");
fstat(temp_file, &fileStat);
//printf("Information for %s\n",argv[1]);
printf("---------------------------\n");
printf("File Size: \t\t%d bytes\n",(int)fileStat.st_size);
printf("Number of Links: \t%d\n",(int)fileStat.st_nlink);
printf("File inode: \t\t%d\n",(int)fileStat.st_ino);
}
谢谢
推荐答案
递归遍历文件系统的目录,对每个文件执行stat
(或者可能是lstat
),将struct stat
的st_ino
成员与inode进行比较您要搜索的号码.
Traverse your filesystem's directories recursively, doing stat
(or probably lstat
) on each file, comparing st_ino
member of struct stat
to the inode number you're searching.
如果您不必在C语言中执行此操作,那么我建议您使用find /fs/root -inum N
.
If you didn't have to do it in C, I would recommend find /fs/root -inum N
instead.
这篇关于有什么方法可以使用给定的inode编号搜索文件或文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文