From d1199f80fc3b0f152003ac175d644345edcf66f9 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Fri, 6 Feb 2004 15:29:22 +0000 Subject: [PATCH] fix --- ChangeLog | 4 ++++ kernel/dir.c | 8 ++++---- kernel/file.c | 16 +++++++++------- kernel/fuse_i.h | 5 +++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7fd958..2a569ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ * Fixed writing >= 2G files * Check file size on open (with generic_file_open()) + + * Readpage calls flush_dcache_page() after storing data + + * Use i_size_read/write for accessing inode->i_size 2004-02-04 Miklos Szeredi diff --git a/kernel/dir.c b/kernel/dir.c index 739b677..0fffcab 100644 --- a/kernel/dir.c +++ b/kernel/dir.c @@ -30,7 +30,7 @@ static struct dentry_operations fuse_dentry_operations; static void change_attributes(struct inode *inode, struct fuse_attr *attr) { - if(S_ISREG(inode->i_mode) && inode->i_size != attr->size) { + if(S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size) { #ifdef KERNEL_2_6 invalidate_inode_pages(inode->i_mapping); #else @@ -42,7 +42,7 @@ static void change_attributes(struct inode *inode, struct fuse_attr *attr) inode->i_nlink = attr->nlink; inode->i_uid = attr->uid; inode->i_gid = attr->gid; - inode->i_size = attr->size; + i_size_write(inode, attr->size); inode->i_blksize = PAGE_CACHE_SIZE; inode->i_blocks = attr->blocks; #ifdef KERNEL_2_6 @@ -62,7 +62,7 @@ static void change_attributes(struct inode *inode, struct fuse_attr *attr) static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr) { inode->i_mode = attr->mode & S_IFMT; - inode->i_size = attr->size; + i_size_write(inode, attr->size); if(S_ISREG(inode->i_mode)) { inode->i_op = &fuse_file_inode_operations; fuse_init_file_inode(inode); @@ -619,7 +619,7 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr) if(!out.h.error) { if(attr->ia_valid & ATTR_SIZE && - outarg.attr.size < inode->i_size) + outarg.attr.size < i_size_read(inode)) vmtruncate(inode, outarg.attr.size); change_attributes(inode, &outarg.attr); diff --git a/kernel/file.c b/kernel/file.c index afb09eb..afad649 100644 --- a/kernel/file.c +++ b/kernel/file.c @@ -142,6 +142,7 @@ static int fuse_readpage(struct file *file, struct page *page) size_t outsize = out.args[0].size; if(outsize < PAGE_CACHE_SIZE) memset(buffer + outsize, 0, PAGE_CACHE_SIZE - outsize); + flush_dcache_page(page); SetPageUptodate(page); } @@ -156,7 +157,7 @@ static int fuse_is_block_uptodate(struct address_space *mapping, { size_t index = bl_index << FUSE_BLOCK_PAGE_SHIFT; size_t end_index = ((bl_index + 1) << FUSE_BLOCK_PAGE_SHIFT) - 1; - size_t file_end_index = inode->i_size >> PAGE_CACHE_SHIFT; + size_t file_end_index = i_size_read(inode) >> PAGE_CACHE_SHIFT; if (end_index > file_end_index) end_index = file_end_index; @@ -185,7 +186,7 @@ static int fuse_cache_block(struct address_space *mapping, { size_t start_index = bl_index << FUSE_BLOCK_PAGE_SHIFT; size_t end_index = ((bl_index + 1) << FUSE_BLOCK_PAGE_SHIFT) - 1; - size_t file_end_index = inode->i_size >> PAGE_CACHE_SHIFT; + size_t file_end_index = i_size_read(inode) >> PAGE_CACHE_SHIFT; int i; @@ -254,7 +255,7 @@ static void fuse_file_bigread(struct address_space *mapping, { size_t bl_index = pos >> FUSE_BLOCK_SHIFT; size_t bl_end_index = (pos + count) >> FUSE_BLOCK_SHIFT; - size_t bl_file_end_index = inode->i_size >> FUSE_BLOCK_SHIFT; + size_t bl_file_end_index = i_size_read(inode) >> FUSE_BLOCK_SHIFT; if (bl_end_index > bl_file_end_index) bl_end_index = bl_file_end_index; @@ -321,13 +322,14 @@ static int write_buffer(struct inode *inode, struct page *page, static int get_write_count(struct inode *inode, struct page *page) { unsigned long end_index; + loff_t size = i_size_read(inode); int count; - end_index = inode->i_size >> PAGE_CACHE_SHIFT; + end_index = size >> PAGE_CACHE_SHIFT; if(page->index < end_index) count = PAGE_CACHE_SIZE; else { - count = inode->i_size & (PAGE_CACHE_SIZE - 1); + count = size & (PAGE_CACHE_SIZE - 1); if(page->index > end_index || count == 0) return 0; } @@ -452,8 +454,8 @@ static int fuse_commit_write(struct file *file, struct page *page, err = write_buffer(inode, page, offset, to - offset); if(!err) { loff_t pos = (page->index << PAGE_CACHE_SHIFT) + to; - if(pos > inode->i_size) - inode->i_size = pos; + if(pos > i_size_read(inode)) + i_size_write(inode, pos); } return err; } diff --git a/kernel/fuse_i.h b/kernel/fuse_i.h index cc386ac..1dbb17f 100644 --- a/kernel/fuse_i.h +++ b/kernel/fuse_i.h @@ -31,6 +31,11 @@ #include #include +#ifndef KERNEL_2_6 +#define i_size_read(inode) ((inode)->i_size)) +#define i_size_write(inode, size) do { (inode)->i_size = size; } while(0) +#endif + /** Read combining parameters */ #define FUSE_BLOCK_SHIFT 16 #define FUSE_BLOCK_SIZE 65536 -- 2.30.2