r/linux • u/0xdeadbeef0000 • Jan 25 '20
Kernel LDD3 Linux drivee question
/r/linuxdev/comments/etbp45/ldd3_linux_drivee_question/[removed] — view removed post
•
Jan 25 '20
Your post was removed for being a support request or support related question such as which distro to use or application suggestions.
We get a lot of question posts on r/linux but the subreddit is considered a news/discussion sub. Luckily there are multiple communities you can post to for help on GNU/Linux issues 24/7: /r/linuxquestions, /r/linux4noobs, or /r/findmeadistro just to name a few.
You may also post on the "Weekly Questions and Hardware Thread" which is stickied on r/linux on Wednesdays.
Please make your post in /r/linuxquestions or /r/linux4noobs. Looking for a distro? Try r/findmeadistro.
Rule:
This is not a support forum! Head to /r/linuxquestions or /r/linux4noobs for support or help. Looking for a distro? Try r/findmeadistro.
2
u/Nnarol Jan 25 '20
I do not know what the heck f_ops means, or what any of this is supposed to do, but the code snippet in itself is actually understandable despite the short variable names:
dev->size seems to be most likely to be the size of some device.
f_ops is a pointer to some value which is comparable to dev->size. You even mentioned it is a pointer to type "loff_t", which souds like something something "offset type", probably "long offset type", due to the "l".
But it doesn't really matter. Being comparable to a "device size" alone and the fact that the first "if" has a "goto out" - which seems to be an exit point from something - suggests that it measures size in some way, be it in bytes, blocks, kilobytes, whatever. So if *f_ops already exceeds the device size, we abort this calculation with "count".So the device could be a disk, although it could probably be some other device with a countable, limited resource. I'll assume a disk.
If *f_ops is still below the device size, the next "if" basically rounds down "count" to the space left between *f_ops and the device's size if it would exceed that space.
It is hard for me to guess why any of this is needed though, since I am neither reading the book, nor have the slightest idea of drivers, and have no more context than what you provided. Maybe wherever "count" is used, the space within the device that *f_ops (apparently an offset) covers is unusable for that purpose.
Very naively, I would suspect that this algorithm is used to determine the available space on a device when something is to be stored on it, and *f_ops marks the part of the device that is full, whilst count is the size of the next chunk of data to be added. I'd have to assume that in that case, "*f_ops += count" takes place somewhere next.
It also might be the case that "*f_ops" is the space that is reserved by the filesystem for purposes such as defining the GPT, journaling, etc. and is not increased during regular write operations, but it still needs to be calculated whether the "count"-sized chunk would fit on disk.