From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Jambor Subject: Re: Access content of file via inodes Date: Fri, 27 May 2005 21:13:02 +0200 Message-ID: <8e70aacf0505271213a6834ee@mail.gmail.com> References: <4252E09B.9020606@suse.com> <1112948279.28245.4.camel@imp.csi.cam.ac.uk> Reply-To: Martin Jambor Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7BIT Cc: "Kathy KN (HK)" , Jeff Mahoney , linux-fsdevel@vger.kernel.org Return-path: Received: from zproxy.gmail.com ([64.233.162.193]:1544 "EHLO zproxy.gmail.com") by vger.kernel.org with ESMTP id S262555AbVE0TND convert rfc822-to-8bit (ORCPT ); Fri, 27 May 2005 15:13:03 -0400 Received: by zproxy.gmail.com with SMTP id 18so1498490nzp for ; Fri, 27 May 2005 12:13:02 -0700 (PDT) To: Anton Altaparmakov In-Reply-To: <1112948279.28245.4.camel@imp.csi.cam.ac.uk> Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Hi Anton, On 4/8/05, Anton Altaparmakov 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... Thanks very much in advance, Martin