首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

请教Linux怎么区分目录和文件

2012-04-23 
请问Linux如何区分目录和文件?Linux中目录和文件都是用inode结构表示的?struct inode结构中有区分的么?和s

请问Linux如何区分目录和文件?
Linux中目录和文件都是用inode结构表示的?
struct inode结构中有区分的么?
和struct dentry目录项结构有关系么?
附上struct inode结构前几个变量:
struct inode {
struct hlist_nodei_hash;
struct list_headi_list;/* backing dev IO list */
struct list_headi_sb_list;
struct list_headi_dentry; /*目录项链表*/??
unsigned longi_ino;
atomic_ti_count;
unsigned inti_nlink;
uid_ti_uid;
gid_ti_gid;
dev_ti_rdev;

[解决办法]
通过struct stat.st_mode 来区分的吧

有一个宏,可以判断是否目录
S_ISDIR(st.st_mode)
[解决办法]
这个结构体中的i_mode中有此节点所对应的结构是文件还是目录。
内核中用宏区分如下:
#define S_IFMT 00170000
#define S_IFSOCK 0140000
#define S_IFLNK 0120000
#define S_IFREG 0100000//常规文件
#define S_IFBLK 0060000
#define S_IFDIR 0040000//目录
#define S_IFCHR 0020000
#define S_IFIFO 0010000
#define S_ISUID 0004000
#define S_ISGID 0002000
#define S_ISVTX 0001000

#define S_ISLNK(m)(((m) & S_IFMT) == S_IFLNK)
#define S_ISREG(m)(((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m)(((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m)(((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m)(((m) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(m)(((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m)(((m) & S_IFMT) == S_IFSOCK)

热点排行