热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何确定打开的文件是套接字还是管道?-Howtodetermineifanopenfileisasocketorapipe?

Iamtryingtofindwhatmember(s)ofthestructfdtableorstructfilewillletmedeterminewhethe

I am trying to find what member(s) of the struct fdtable or struct file will let me determine whether or not an open file is a socket or a pipe.

我试图找到struct fdtable或struct file的成员将让我确定打开的文件是套接字还是管道。

the only path I can seem to find is:

我能找到的唯一途径是:

struct file f ....;
f.path->mnt->mnt_devname

This returns the device name at the mountpoint, all sockets/pipes apparently belong to sockfs or pipefs respectively.

这将返回挂载点处的设备名称,所有套接字/管道分别显然属于sockfs或pipefs。

Is there a faster way to check to see if an open file is a socket or pipe using a different member of the struct file or fdtable?

是否有更快的方法来检查打开的文件是使用struct文件或fdtable的不同成员的套接字还是管道?

Note: I am using the kernel definitions from 2.6.24

注意:我使用的是2.6.24中的内核定义

1 个解决方案

#1


10  

There are special macro definitions at linux/stat.h that checks inode->i_mode:

linux / stat.h中有一些特殊的宏定义,用于检查inode-> i_mode:

  #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)

It seems that you'll need to use 2 of them - S_ISFIFO and S_ISSOCK in a such way:

您似乎需要使用其中的两个 - S_ISFIFO和S_ISSOCK以这种方式:

if (S_ISFIFO(file->f_path.dentry->d_inode->i_mode)) {...}
if (S_ISSOCK(file->f_path.dentry->d_inode->i_mode)) {...}

推荐阅读
author-avatar
关圣钊
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有