From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anton Altaparmakov Subject: Re: Access content of file via inodes Date: Thu, 07 Apr 2005 09:09:56 +0100 Message-ID: <1112861396.2842.7.camel@imp.csi.cam.ac.uk> References: <1112787226.21605.27.camel@imp.csi.cam.ac.uk> <4254D78F.9030705@suse.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: Jeffrey Mahoney , Bryan Henderson , linux-fsdevel@vger.kernel.org Return-path: Received: from ppsw-2.csi.cam.ac.uk ([131.111.8.132]:25309 "EHLO ppsw-2.csi.cam.ac.uk") by vger.kernel.org with ESMTP id S262239AbVDGIKw (ORCPT ); Thu, 7 Apr 2005 04:10:52 -0400 To: "Kathy KN (HK)" In-Reply-To: <4254D78F.9030705@suse.com> Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Thu, 2005-04-07 at 02:47 -0400, Jeffrey Mahoney wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Kathy KN (HK) wrote: > > Just wondering. Say, reiserfs/r4, how is it possible to access > > the tail which contain the data of the file, since most of our > > production boxes uses either reiserfs and/or reiser4. > > Hi Kathy - > > Using vfs_read or the page cache functions will allow you access to the > tail since they will map it in as part of the file. You'd only run into > that problem if you were trying to access the data block-by-block as you > were initially. Exactly the same for ntfs in case you care. (-: Btw. Kathy, if you want examples how to do page cache reads you could look at the ntfs driver. It does them all over the place (because metadata is in the page cache). So for example fs/ntfs/aops.c::ntfs_map_page() is (with comments): static inline struct page *ntfs_map_page(struct address_space *mapping, unsigned long index) // mapping is the address space mapping, i.e. struct inode *->i_mapping // index is file position you want to access >> PAGE_CACHE_SHIFT { struct page *page = read_cache_page(mapping, index, (filler_t*)mapping->a_ops->readpage, NULL); // the above read_cache_page initiates the page to be read asynchronously so it is not finished when the call returns. if (!IS_ERR(page)) { // if no synchronous error occured: wait_on_page_locked(page); // wait that the page becomes unlocked, which implies that either an asynchronous error occured or that the page has been read successfully kmap(page); // map the page so can read the contents, you could do this much later and only use kmap_atomic() depending on when/how you need to read/write from/to the page if (PageUptodate(page) && !PageError(page)) return page; // if the page is now uptodate and it does not have the error bit set the read was successful! ntfs_unmap_page(page); // ouch. asynchronous error occured. ntfs_unmap_page simply does a "kunmap(page)" and a "page_cache_release(page)". return ERR_PTR(-EIO); // return -EIO error code encoded as a pointer. } return page; // ouch synchronous error. "page" contains the error code encoded as a pointer. } When you are finished accessing the page contents, simply unmap the page if you have mapped it and do a "page_cache_release()" on the page. Hope this helps. Best regards, Anton -- Anton Altaparmakov (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/