In chapter 3 of the third edition of linux Device Drivers, item = (long) * f_pos/itemsize in the read Method

Source: Internet
Author: User
For details about item (long) * f_positemsize in the read method in chapter 3 of the third edition of linux device driver program-Linux general technology-Linux technology and application information, see below. One of your scull stores a linked list scull_qset. A linked list contains many items, each item contains 1000 pointers (that is, the size of the array quanset in this item). In these pointers, each pointer can point to a piece of memory, the memory size is quantum (4000 in the book), so the memory size of this item can be operated itemsize = (number of pointers in item) * (the memory size that each pointer can point to, that is, the quantum size) = quanset * quantum = 1000*4000, right? Should this be understandable?
Next let's take a look at (long) * f_pos. This pointer variable is the offset of our file relative to the starting position of the file. (long) * f_pos indicates a long integer, the available size is 0-2 ^ 64-1, which is the maximum file range. Note that it cannot be exceeded; otherwise, goto out; if the number is not exceeded, think about the memory size that each item in the linked list can operate on?
Is it itemsize?
What if your (long) * f_pos exceeds an itemsize? For example, now (long) * f_pos = 4 000 001, when the program reads 4000 000 bytes from the first item, it will start reading the second item of the linked list item! Right? So how do we know I want to read from the first few linked list items?
It is calculated by using (long) * f_pos/itemsize, or the assumption just now, (long) * f_pos = 4 000 001, And because itemsize = 4000 000
So (long) * f_pos/itemsize =? It should be 1. Isn't that the second linked list item? Note that the C language starts counting from 0 (we all know this, huh, huh ).
Note that (long) * f_pos/itemsize = 1, then (long) * f_pos % itemsize = ?, It is also 1. This is the offset of the item. You can think of the offset of the pointer array. It will take the number from the first pointer, the first pointer points to the first quantum of the second item. OK


Statement: I am a newbie, so I may not be right. I hope prawns will correct me. Thank you!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.