linux - 为什么在Linux内核中close函数在 `struct file_operations`调用release?

标签 linux linux-kernel kernel

我正在尝试制作一个支持打开、关闭、读取和写入操作的 linux 内核模块。 所以我想通过 struct file_operations 注册这些函数,但是我在结构中找不到“关闭”条目。 我想我应该使用'release'而不是'close',但我想知道为什么名称是'release'而不是'close'?

最佳答案

因为文件可能被打开多次,当你关闭一个描述符时,只有在最后一次关闭调用文件的最后一次引用时才会调用 release。所以close和release是有区别的。

release: called at the last close(2) of this file, i.e. when file->f_count reaches 0. Although defined as returning int, the return value is ignored by VFS (see fs/file_table.c:__fput()). more

关于linux - 为什么在Linux内核中close函数在 `struct file_operations`调用release?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11393674/

相关文章:

linux - 脚本检查文件是否存在

c - 使用 libxml 的 XML 解析器

linux-kernel - 内核哎呀哎呀 : 80000005 on arm embedded system

linux - cdev_add() 在 117 上向 major 成功注册后,字符设备出现在哪里。

linux-kernel - 设备驱动程序中的中断处理

使用KGDB远程调试Linux内核: GDB does not recognize functions?

linux - 如何在编译中使用 -rpath 设置可执行文件在同一目录中搜索共享库

linux - 如何在 Linux 上获取/etc/ld.so.conf 中的路径列表

linux - KFIFO API : Difference kfifo_put and kfifo_in (or kfifo_get and kfifo_out)

c - 如何优化 U-boot 到内核的切换代码?