Giter Club home page Giter Club logo

Comments (2)

linD026 avatar linD026 commented on June 1, 2024 1

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.

franzwong avatar franzwong commented on June 1, 2024 1

I understand now. Thanks for the detailed explanation.

from lkmpg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.