int j4fs_readpage_nolock(struct file *f, struct page *page) { /* Lifted from yaffs2 */ unsigned char *page_buf; int ret; struct address_space *mapping = page->mapping; struct inode *inode; j4fs_ctrl ctl; T(J4FS_TRACE_FS_READ,("%s %d\n",__FUNCTION__,__LINE__)); BUG_ON(!PageLocked(page)); if (!mapping) BUG(); inode = mapping->host; if (!inode) BUG(); page_buf = kmap(page); /* FIXME: Can kmap fail? */ j4fs_GrossLock(); ctl.buffer=page_buf; ctl.count=PAGE_CACHE_SIZE; ctl.id=inode->i_ino; ctl.index=page->index << PAGE_CACHE_SHIFT; ret=fsd_read(&ctl); j4fs_GrossUnlock(); if (ret >= 0) ret = 0; if (ret) { ClearPageUptodate(page); SetPageError(page); } else { SetPageUptodate(page); ClearPageError(page); } flush_dcache_page(page); kunmap(page); return ret; }
int j4fs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos) { int nWritten, ipos; struct inode *inode; j4fs_ctrl ctl; if(j4fs_panic==1) { J4FS_T(J4FS_TRACE_ALWAYS,("%s %d: j4fs panic\n",__FUNCTION__,__LINE__)); return -ENOSPC; } j4fs_GrossLock(); inode = f->f_dentry->d_inode; if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) ipos = inode->i_size; else ipos = *pos; J4FS_T(J4FS_TRACE_FS,("j4fs_file_write: %zu bytes to ino %ld at %d\n", n, inode->i_ino, ipos)); // write file ctl.buffer=(BYTE *)buf; ctl.count=n; ctl.id=inode->i_ino; ctl.index=ipos; nWritten=fsd_write(&ctl); if(nWritten==J4FS_RETRY_WRITE) nWritten=fsd_write(&ctl); if(nWritten==J4FS_RETRY_WRITE || error(nWritten)) { J4FS_T(J4FS_TRACE_ALWAYS,("%s %d: Error(nWritten=0x%x)\n",__FUNCTION__,__LINE__,nWritten)); j4fs_GrossUnlock(); return -ENOSPC; } if (nWritten > 0) { ipos += nWritten; *pos = ipos; if (ipos > inode->i_size) { inode->i_size = ipos; inode->i_blocks = (ipos + 511) >> 9; }
int j4fs_writepage(struct page *page, struct writeback_control *wbc) { struct address_space *mapping = page->mapping; loff_t offset = (loff_t) page->index << PAGE_CACHE_SHIFT; struct inode *inode; unsigned long end_index; char *buffer; int nWritten = 0; unsigned nBytes; j4fs_ctrl ctl; int nErr; if(j4fs_panic==1) { J4FS_T(J4FS_TRACE_ALWAYS,("%s %d: j4fs panic\n",__FUNCTION__,__LINE__)); return -ENOSPC; } J4FS_T(J4FS_TRACE_FS,("%s %d\n",__FUNCTION__,__LINE__)); if (!mapping) BUG(); inode = mapping->host; if (!inode) BUG(); if (offset > inode->i_size) { J4FS_T(J4FS_TRACE_FS, ("j4fs_writepage at %08x, inode size = %08x!!!\n", (unsigned)(page->index << PAGE_CACHE_SHIFT), (unsigned)inode->i_size)); J4FS_T(J4FS_TRACE_FS, (" -> don't care!!\n")); unlock_page(page); return 0; } 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); get_page(page); buffer = kmap(page); j4fs_GrossLock(); J4FS_T(J4FS_TRACE_FS, ("j4fs_writepage: index=%08x,nBytes=%08x,inode.i_size=%05x\n", (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes,(int)inode->i_size)); // write file ctl.buffer=buffer; ctl.count=nBytes; ctl.id=inode->i_ino; ctl.index=offset; nErr=fsd_write(&ctl); if(nErr==J4FS_RETRY_WRITE) nErr=fsd_write(&ctl); J4FS_T(J4FS_TRACE_FS, ("j4fs_writepage: index=%08x,nBytes=%08x,inode.i_size=%05x\n", (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes,(int)inode->i_size)); j4fs_GrossUnlock(); kunmap(page); SetPageUptodate(page); unlock_page(page); put_page(page); return (nWritten == nBytes) ? 0 : -ENOSPC; }