Comments (2)
Hi,
It's just making sure that every time we read to the end of the buffer we go back to the beginning.
Even though, in most cases, we just open (create the empty file) the file, read it, and close it once time, the reset might be unnecessary.
When we open the file, the function calls in v5.4 will be like this:
[113739.851760] device_open.cold+0x18/0x4b [chardev]
[113739.851762] chrdev_open+0xd3/0x1c0
[113739.851764] ? cdev_default_release+0x20/0x20
[113739.851765] do_dentry_open+0x143/0x3a0
[113739.851767] vfs_open+0x2d/0x30
[113739.851769] do_last+0x194/0x900
[113739.851770] path_openat+0x8d/0x290
[113739.851771] do_filp_open+0x91/0x100
[113739.851774] ? __alloc_fd+0x46/0x150
[113739.851775] do_sys_open+0x17e/0x290
[113739.851777] __x64_sys_openat+0x20/0x30
[113739.851779] do_syscall_64+0x57/0x190
[113739.851780] entry_SYSCALL_64_after_hwframe+0x44/0xa9
See the path_openat(), it will allocate the empty file:
static struct file *path_openat(struct nameidata *nd,
const struct open_flags *op, unsigned flags)
{
struct file *file;
int error;
file = alloc_empty_file(op->open_flag, current_cred());
if (IS_ERR(file))
return file;
So, every time we do the open-read-close, the offset will be reset implicitly.
However, if we do something like open-read-read-close, we need to reset the offset by ourselves, otherwise, we will not get any data on the subsequent read calls.
Hopefully, this will help you.
Thanks :)
from lkmpg.
I understand now. Thanks for the detailed explanation.
from lkmpg.
Related Issues (20)
- procfs2.c vs. procfs3.c HOT 1
- 11.1 Sleep chapter. API module_interruptible_sleep_on HOT 1
- Smatch repository is unavailable HOT 1
- Build kernel module for Rpi3MB HOT 1
- Building kernel modules in RpiOS32bit/Rpi3MB platform HOT 2
- lkmpg on RpiOsLite/rpi3MB HOT 1
- Consistent usage of __init and __exit HOT 1
- About 16.2 Symmetric key encryption sample code HOT 2
- examples/kbleds.c:64:55: error: ‘struct tty_driver’ has no member named ‘magic’
- Building kbleds.ko on RpiOSLite64bit (Linux 6.1.21-v8+) HOT 4
- examples/sched.ko HOT 4
- Module parameters callback : be notified when a parameter is updated
- Little introduction to debugfs
- About /proc, try_module_get and python3 HOT 3
- If you want to build device drivers for an cross target (yocto build) ... HOT 1
- typo
- Linux HOT 1
- Talking to other subsystems
- Libro linux HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lkmpg.