linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anton Altaparmakov <aia21@cam.ac.uk>
To: Martin Jambor <jamborm@gmail.com>
Cc: "Kathy KN (HK)" <kathy.kn@gmail.com>,
	Jeff Mahoney <jeffm@suse.com>,
	linux-fsdevel@vger.kernel.org
Subject: Re: Access content of file via inodes
Date: Sat, 28 May 2005 16:57:21 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.60.0505281648170.3686@hermes-1.csi.cam.ac.uk> (raw)
In-Reply-To: <8e70aacf0505271213a6834ee@mail.gmail.com>

Hi Martin,

On Fri, 27 May 2005, Martin Jambor wrote:
> On 4/8/05, Anton Altaparmakov <aia21@cam.ac.uk> wrote:
> > On Fri, 2005-04-08 at 14:01 +0800, Kathy KN (HK) wrote:
> > > Hi Jeff,
> > >
> > > Is it possible to modify the cached page, and invalidate it back
> > > to update the page cache of the new page? I did a recursive grep
> > > and could only find functions that let you read or grab pages in the
> > > cache.
> > 
> > Once you have the page (via read_cache_page() or whatever) you can
> > simply write to it, then do a flush_dcache_page(page), then
> > set_page_dirty(page) and finally do the page_cache_release().  Oh, and
> > don't forget to unmap the page.  Usually done straight after the
> > flush_dcache_page().  And example from ntfs where we get a page, memset
> > it to a value (val), and then mark it dirty for later write out:
> > 
> >         page = read_cache_page(mapping, idx,
> >                         (filler_t*)mapping->a_ops->readpage, NULL);
> >         if (IS_ERR(page)) {
> >                 ntfs_error(vol->sb, "Failed to read first partial "
> >                                 "page (sync error, index 0x%lx).", idx);
> >                 return PTR_ERR(page);
> >         }
> >         wait_on_page_locked(page);
> >         if (unlikely(!PageUptodate(page))) {
> >                 ntfs_error(vol->sb, "Failed to read first partial page "
> >                                 "(async error, index 0x%lx).", idx);
> >                 page_cache_release(page);
> >                 return PTR_ERR(page);
> >         }
> >         size = PAGE_CACHE_SIZE;
> >         if (idx == end)
> >                 size = end_ofs;
> >         kaddr = kmap_atomic(page, KM_USER0);
> >         memset(kaddr + start_ofs, val, size - start_ofs);
> >         flush_dcache_page(page);
> >         kunmap_atomic(kaddr, KM_USER0);
> >         set_page_dirty(page);
> >         page_cache_release(page);
> > 
> > Of course you need to serialise access in some way so multiple writers
> > do not step on each other's toes, etc...
> 
> What do I have to do to when I need to append something to a file?
> BTW, if that matters, I'll be implementing the adress_space_operations
> of that file as well...

That depends on where you want to do that from and what that file is.

If it is a file accessible from user space the size modification should be 
done under i_sem protection which is tricky from address space operations 
but fine from other parts of the kernel.

If it is a private file to you you need to serialize access with your own 
lock then it does not matter from where you do this (well, unless you try 
to do it from an atomic region/with spinlocks held or something).

Basically there are all sorts of considerations.

Could you explain where in the kernel and in what context you need to do 
the file append?  And whether the file is private to you or accessible 
from user space?

It would be easier to explain what you need/can do if I knew exactly what 
you are trying to do.

Best regards,

	Anton
-- 
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/

  reply	other threads:[~2005-05-28 15:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-05  1:23 Access content of file via inodes Kathy KN
2005-04-05  7:22 ` Christoph Hellwig
2005-04-05 17:53 ` Bryan Henderson
2005-04-06  1:27   ` Kathy KN (HK)
2005-04-06  1:53     ` Jeff Mahoney
2005-04-06 17:57       ` Bryan Henderson
2005-04-06  7:54     ` Anton Altaparmakov
2005-04-06 11:33     ` Anton Altaparmakov
2005-04-06 13:09       ` Jeffrey Mahoney
2005-04-07  5:25       ` Kathy KN (HK)
2005-04-07  6:47         ` Jeffrey Mahoney
2005-04-07  8:09           ` Anton Altaparmakov
2005-04-05 19:01 ` Jeff Mahoney
2005-04-06  1:32   ` Kathy KN (HK)
2005-04-06  1:50     ` Jeff Mahoney
2005-04-08  6:01   ` Kathy KN (HK)
2005-04-08  8:17     ` Anton Altaparmakov
2005-05-27 19:13       ` Martin Jambor
2005-05-28 15:57         ` Anton Altaparmakov [this message]
2005-05-28 21:44           ` Martin Jambor
2005-05-29  7:26             ` Anton Altaparmakov
2005-05-30 21:51               ` Martin Jambor
2005-05-30 22:19                 ` Anton Altaparmakov

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=Pine.LNX.4.60.0505281648170.3686@hermes-1.csi.cam.ac.uk \
    --to=aia21@cam.ac.uk \
    --cc=jamborm@gmail.com \
    --cc=jeffm@suse.com \
    --cc=kathy.kn@gmail.com \
    --cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).