为什么关闭功能在Linux内核的`struct file_operations`中被称为release? [英] Why is the close function is called release in `struct file_operations` in the Linux kernel?

查看:142
本文介绍了为什么关闭功能在Linux内核的`struct file_operations`中被称为release?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to make a linux kernel module, which supports open, close, read and write operations. So I want to register these functions via struct file_operations, however I can't find 'close' entry in the struct. I think I should use 'release' instead of 'close', but I wonder why the name is 'release' and not 'close'?

推荐答案

因为文件可能会多次打开,所以当您关闭描述符时,仅在最后一次关闭调用时才对文件的最后引用调用release.因此,关闭和释放之间是有区别的.

Because the file may be opened multiple times, when you close a descriptor, only on the last close call for the last reference to the file invokes release. So there is a difference between close and release.

release:在此文件的最后一个close(2)调用,即 file-> f_count达到0.尽管定义为return int,但return VFS会忽略该值(请参阅fs/file_table.c:__ fput()). 更多

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内核的`struct file_operations`中被称为release?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆