Skip to content
Advertisement

Why is the close function is called release in `struct file_operations` in the Linux kernel?

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’?

Advertisement

Answer

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: 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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement