Bug 218830
Summary: | lseek on closed file does not trigger an error and affect other files | ||
---|---|---|---|
Product: | File System | Reporter: | Chi (zhangchi_seg) |
Component: | ext4 | Assignee: | fs_ext4 (fs_ext4) |
Status: | RESOLVED INVALID | ||
Severity: | normal | CC: | tytso |
Priority: | P3 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | Subsystem: | ||
Regression: | No | Bisected commit-id: | |
Attachments: | reproduce.c |
Description
Chi
2024-05-13 02:39:59 UTC
This is a test/programming bug. If you change reproduce.c so that it prints fd_a and fd_b, you'll see that they have the same value. So the reason why lseek didn't fail is because fd_a has the same integer value as fd_b --- and so lseek didn't fail and affected the current position of fd_b. This is a documented feature of the Linux/Unix/Posix interface. File descriptors are small integers, and if you close a file descriptor, it releases that integer ---- think of it as an index in an array, i.e., struct file *fd_array[MAX_FDS]. When you call open, it will find the first NULL pointer in fd_array, and installs a pointer to the struct file, and returns that integer as the file descriptor. Hi Theodore Tso, Thank you for your quick response, I'm very sorry for making this incorrect bug report, I will read the documentation carefully. |