X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=yaffs_fs.c;h=69039af0601f11f146d79178c650e5f12f5bde4a;hb=9cf26c629a96c44f4e4cc94832d246b5331fe75f;hp=db59c239c0972529f4073b5d01809690b411d956;hpb=2f1fbd5011ef15fa3d1c95dc24dcc656a9aa9b5f;p=yaffs%2F.git diff --git a/yaffs_fs.c b/yaffs_fs.c index db59c23..69039af 100644 --- a/yaffs_fs.c +++ b/yaffs_fs.c @@ -28,7 +28,7 @@ */ -const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.27 2003-08-16 08:17:32 charles Exp $"; +const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.31 2003-10-27 08:27:01 charles Exp $"; extern const char *yaffs_guts_c_version; @@ -142,7 +142,7 @@ static void yaffs_delete_inode(struct inode *); static void yaffs_clear_inode(struct inode *); static int yaffs_readpage(struct file *file, struct page * page); - +static int yaffs_writepage(struct page *page); static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to); static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to); @@ -154,6 +154,7 @@ static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd); static struct address_space_operations yaffs_file_address_operations = { readpage: yaffs_readpage, + writepage: yaffs_writepage, prepare_write: yaffs_prepare_write, commit_write: yaffs_commit_write }; @@ -413,12 +414,12 @@ static int yaffs_readpage_nolock(struct file *f, struct page * pg) // Lifted from jffs2 yaffs_Object *obj; - unsigned char *pg_buf; + unsigned char *pg_buf; int ret; - + yaffs_Device *dev; - - T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n", + + T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n", (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE)); obj = yaffs_DentryToObject(f->f_dentry); @@ -468,6 +469,63 @@ static int yaffs_readpage(struct file *f, struct page * pg) return yaffs_readpage_unlock(f,pg); } +// writepage inspired by/stolen from smbfs +// + +static int yaffs_writepage(struct page *page) +{ + struct address_space *mapping = page->mapping; + struct inode *inode; + unsigned long end_index; + char *buffer; + yaffs_Object *obj; + int nWritten = 0; + unsigned nBytes; + + if (!mapping) + BUG(); + inode = mapping->host; + if (!inode) + BUG(); + + end_index = inode->i_size >> PAGE_CACHE_SHIFT; + + /* easy case */ + if (page->index < end_index) + { + nBytes = PAGE_CACHE_SIZE; + } + else + { + nBytes = inode->i_size & (PAGE_CACHE_SIZE-1); + } + // What's happening here? + ///* OK, are we completely out? */ + //if (page->index >= end_index+1 || !offset) + // return -EIO; + + get_page(page); + + + buffer = kmap(page); + + obj = yaffs_InodeToObject(inode); + yaffs_GrossLock(obj->myDev); + + + nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes); + + yaffs_GrossUnlock(obj->myDev); + + kunmap(page); + SetPageUptodate(page); + UnlockPage(page); + put_page(page); + + return nWritten>0 ? nWritten : -ENOSPC; +} + + static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to) { @@ -523,7 +581,6 @@ static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj) inode->i_uid = obj->st_uid; inode->i_gid = obj->st_gid; inode->i_blksize = inode->i_sb->s_blocksize; - inode->i_blocks = 0; #if defined(CONFIG_KERNEL_2_5) inode->i_rdev = to_kdev_t(obj->st_rdev); inode->i_atime.tv_sec = (time_t)(obj->st_atime); @@ -539,6 +596,8 @@ static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj) inode->i_ctime = obj->st_ctime; #endif inode->i_size = yaffs_GetObjectFileLength(obj); + inode->i_blocks = (inode->i_size + 511) >> 9; + inode->i_nlink = yaffs_GetObjectLinkCount(obj); T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n", @@ -647,7 +706,7 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_ dev = obj->myDev; yaffs_GrossLock(dev); - + inode = f->f_dentry->d_inode; if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) @@ -679,7 +738,7 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_ if(ipos > inode->i_size) { inode->i_size = ipos; - inode->i_blocks = (ipos + inode->i_blksize - 1)/ inode->i_blksize; + inode->i_blocks = (ipos + 511)>>9; T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks))); } @@ -687,7 +746,7 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_ } yaffs_GrossUnlock(dev); - return nWritten != n ? -ENOSPC : nWritten; + return nWritten != n ? -ENOSPC : nWritten; } @@ -1246,7 +1305,13 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl printk(KERN_DEBUG "yaffs: Attempting MTD mount on %u.%u, \"%s\"\n", MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev)); - // Hope it's a NAND mtd + // Check it's an mtd device..... + if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) + { + return NULL; // This isn't an mtd device + } + + // Get the device mtd = get_mtd_device(NULL, MINOR(sb->s_dev)); if (!mtd) { @@ -1254,6 +1319,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl return NULL; } + // Check it's NAND if(mtd->type != MTD_NANDFLASH) { printk(KERN_DEBUG "yaffs: MTD device is not NAND it's type %d\n", mtd->type);