什么时候使用 fcheck() 或 fcheck_files() 以及为了什么?
When to use fcheck() or fcheck_files() and for what?
在Linux内核模块中,通过文件描述符计算绝对路径时,fcheck()或fcheck_files()被使用。我没有得到太多关于这些功能的信息。我需要知道哪种功能适合哪种情况。这些功能何时失效?在哪里可以找到有关此类功能的文档?如所述 here、
... To look up the file structure given an fd, a reader must use either fcheck() or fcheck_files() APIs....
但是没有给出关于应该在何时何地使用哪个函数的信息。
提前致谢!
fcheck()
在 include/linux/fdtable.h, line 90 中被定义为预处理器宏:
#define fcheck(fd) fcheck_files(current->files, fd)
而fcheck_files()
在include/linux/fdtable.h, line 77中被定义为一个函数为:
static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
{
struct file * file = NULL;
struct fdtable *fdt = files_fdtable(files);
if (fd < fdt->max_fds)
file = rcu_dereference_check_fdtable(files, fdt->fd[fd]);
return file;
}
它们不是两个函数,因此无需混淆哪个适合哪个函数。
fcheck()
函数用于
Check whether the specified fd has an open file.
在Linux内核模块中,通过文件描述符计算绝对路径时,fcheck()或fcheck_files()被使用。我没有得到太多关于这些功能的信息。我需要知道哪种功能适合哪种情况。这些功能何时失效?在哪里可以找到有关此类功能的文档?如所述 here、
... To look up the file structure given an fd, a reader must use either fcheck() or fcheck_files() APIs....
但是没有给出关于应该在何时何地使用哪个函数的信息。
提前致谢!
fcheck()
在 include/linux/fdtable.h, line 90 中被定义为预处理器宏:
#define fcheck(fd) fcheck_files(current->files, fd)
而fcheck_files()
在include/linux/fdtable.h, line 77中被定义为一个函数为:
static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
{
struct file * file = NULL;
struct fdtable *fdt = files_fdtable(files);
if (fd < fdt->max_fds)
file = rcu_dereference_check_fdtable(files, fdt->fd[fd]);
return file;
}
它们不是两个函数,因此无需混淆哪个适合哪个函数。
fcheck()
函数用于
Check whether the specified fd has an open file.