linux gcc编程中如何得到某个文件对应的inode结构
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h>
int stat(const char *path, struct stat *buf); int fstat(int fd, struct stat *buf); int lstat(const char *path, struct stat *buf); 看这些函数,就是用来取inode等信息的。
struct file *filp = filp_open(path, O_RDONLY, 0); if (!IS_ERR(filp)) { struct dentry *dentry = dget(filp->f_dentry); if (dentry) { struct inode *inode = dentry->d_inode; dput(dentry); } filp_close(filp, NULL); }
|