Sent: 3/29/2007 (木) 10:11 午後
To: kernelnewbies; newbie
Subject: "struct file" - per process per file?
Hi,
This has reference to LDD3 chap3 - Char drivers (Pg
60).
The following is my understanding which seems to be incorrect.
Can
somebody please point out what am I missing?
LDD3 states that the
fops->open() and fops->release() methods are
called only when "struct
file" is created / destroyed. It further says
that "struct file" is created
ONLY when a process calls open() system
all on a file. To give an example, it
also says that if process 1
opens file A and then forks another process B,
then A and B will share
the same struct file??
GD> This is correct. whenever a process opens the file, corresponding "struct file" structure is created in kernel. As you might be knowing that this is just a virtual file in kernel which keeps track of attributes of actual file, like where to read/write, pointer to file operation structures etc. Theseattributes makes sense when a file is opened, till the file is not closed, at which time fops->release() function is called.
This seems quite strange to me as I had an understanding that
two
processes working on the same file will always have different
file
structure. Also, this would mean that a read by one of the
processes
on the file would affect the file position pointer in the
other
process?
GD> Wherever a process forks another process all the "struct file" strucutres are shared between both processes unless and untill any one of those processes does not write to it at which time a seperate copy is created, this is also know as COW (Copy On Write). When a process is forked, no other "struct file" structure is created, rather the refference count for the "struct file" structures are incremented and there pointers are also saved in new process's file table (struct file_struct).
I am sure I am missing something here. What is
it?
Thanks,
Rajat
--
To unsubscribe from this list: send
an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please
read the FAQ at http://kernelnewbies.org/FAQ