Is it guaranteed that a struct file pointer won't be deallocated and reallocated somewhere else in memory during its open to close lifecycle?

I want to uniquely identify file structs that are passed to a device driver (through read/write/open etc) and was wondering if I could just use the pointer to the file struct for identification. The only other alternative I see would be to store a unique identifier in private_data, if it is not guaranteed that the struct file pointer will not change.

share|improve this question

76% accept rate
I assume you mean just through the lifecycle (open->close) of a file, and not, as in, will it never be deallocated? – Ben Zotto 1 hour ago
Yeah just through the lifecycle. – Michael 1 hour ago
IIUC, the {devicenumber,inodenumber} is the natural key for files. In a datamodelling sense, the pointers are functionally dependent on them. The raw pointer value could be stable in time, but I would not trust on it. Disclaimer: Dammit, Jim, I am a DBA, not a kernel hacker. – wildplasser 1 hour ago
The file struct indicate an open file in a process, not the actual file in the filesystem which is indicated by devnumber/inodenumber. So you could have multiple file structs pointing to the same device/inode. – Michael 1 hour ago
In that case (I think) you have a hierarchy inversion. The file structure should not exist at the device driver level, it is a different level of abstraction, IMHO. – wildplasser 32 mins ago
show 2 more comments
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.