public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rajat Jain" <rajat.noida.india@gmail.com>
To: Gaurav Dhiman <gaurav.dhiman@nechclst.in>
Cc: kernelnewbies <kernelnewbies@nl.linux.org>,
	newbie <linux-newbie@vger.kernel.org>
Subject: Re: "struct file" - per process per file?
Date: Fri, 30 Mar 2007 08:04:02 +0530	[thread overview]
Message-ID: <b115cb5f0703291934v6fc18759w6fde5aec306f6143@mail.gmail.com> (raw)
In-Reply-To: <0A8CFEC45B7F4C419F7543867C47442371B37E@mailserver.nechclst.in>

> 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).
>

Hi Gaurav,

Yes I understand the CoW procedure. So what you are syaing that when
the process A forks process B, both of them point to same "struct
file" (with a ref count of 2). What I am wondering is that what
happens once both the processes actually start writing to those files.

1) In case a seperate copy is created (CoW) at this point for the
forked thread, is open() method of the driver called?

2) In case both the processes continue to use the same "struct file"
wouldn't reads of one file affect the reads of another (since the
location ptr in file will be affected)?

Thanks,

Rajat
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

  reply	other threads:[~2007-03-30  2:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-30  1:51 "struct file" - per process per file? Gaurav Dhiman
2007-03-30  2:34 ` Rajat Jain [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-03-29 16:41 Rajat Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b115cb5f0703291934v6fc18759w6fde5aec306f6143@mail.gmail.com \
    --to=rajat.noida.india@gmail.com \
    --cc=gaurav.dhiman@nechclst.in \
    --cc=kernelnewbies@nl.linux.org \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox