gpt4 book ai didi

linux - 目录 inode 与常规文件 inode

转载 作者:太空狗 更新时间:2023-10-29 12:06:30 26 4
gpt4 key购买 nike

我可以查看 linux 内核的 inode 结构中的哪些值来判断我当前正在查看的 inode 是目录还是常规文件?

我已经搜索了 inode 但似乎真的找不到一个看起来像我想要的成员,因为我使用的是旧内核版本,我将在下面发布结构 (2.6.24)

struct inode 
{
struct hlist_node i_hash;
struct list_head i_list;
struct list_head i_sb_list;
struct list_head i_dentry;
unsigned long i_ino;
atomic_t i_count;
unsigned int i_nlink;
uid_t i_uid;
gid_t i_gid;
dev_t i_rdev;
unsigned long i_version;
loff_t i_size;
struct timespec i_atime;
struct timespec i_mtime;
struct timespec i_ctime;
unsigned int i_blkbits;
blkcnt_t i_blocks;
unsigned short i_bytes;
umode_t i_mode;
spinlock_t i_lock;
struct mutex i_mutex;
struct rw_semaphore i_alloc_sem;
const struct inode_operations *i_op;
const struct file_operations *i_fop;
struct super_block *i_sb;
struct file_lock *i_flock;
struct address_space *i_mapping;
struct address_space i_data;
struct list_head i_devices;

union {
struct pipe_inode_info *i_pipe;
struct block_device *i_bdev;
struct cdev *i_cdev;
};

int i_cindex;
__u32 i_generation;
unsigned long i_state;
unsigned long dirtied_when;
unsigned int i_flags;
atomic_t i_writecount;
void *i_private;
};

如有任何帮助,我们将不胜感激。

最佳答案

我相信这是 inode 的模式...

umode_t            i_mode;

要访问该字段,请参阅 stat(2) 手册页:

   The following POSIX macros are defined to check the file type using the st_mode field:

S_ISREG(m) is it a regular file?

S_ISDIR(m) directory?

S_ISCHR(m) character device?

S_ISBLK(m) block device?

S_ISFIFO(m) FIFO (named pipe)?

S_ISLNK(m) symbolic link? (Not in POSIX.1-1996.)

S_ISSOCK(m) socket? (Not in POSIX.1-1996.)

这是来自 Linux driver for minix FS 的一些示例代码:

434 void minix_set_inode(struct inode *inode, dev_t rdev)
435 {
436 if (S_ISREG(inode->i_mode)) {
437 inode->i_op = &minix_file_inode_operations;
438 inode->i_fop = &minix_file_operations;
439 inode->i_mapping->a_ops = &minix_aops;
440 } else if (S_ISDIR(inode->i_mode)) {
441 inode->i_op = &minix_dir_inode_operations;
442 inode->i_fop = &minix_dir_operations;
443 inode->i_mapping->a_ops = &minix_aops;
444 } else if (S_ISLNK(inode->i_mode)) {
445 inode->i_op = &minix_symlink_inode_operations;
446 inode->i_mapping->a_ops = &minix_aops;
447 } else
448 init_special_inode(inode, inode->i_mode, rdev);
449 }
450

关于linux - 目录 inode 与常规文件 inode ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9960017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com