mtd/fs/jffs2/ecos/src fs-ecos.c,1.15,1.16 file-ecos.c,1.8,NONE

David Woodhouse dwmw2 at infradead.org
Mon Nov 24 11:09:23 EST 2003


Update of /home/cvs/mtd/fs/jffs2/ecos/src
In directory phoenix.infradead.org:/tmp/cvs-serv3370/src

Modified Files:
	fs-ecos.c 
Removed Files:
	file-ecos.c 
Log Message:
Clean up file writing; abolish Linux-like page operations

Index: fs-ecos.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/fs-ecos.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- fs-ecos.c	24 Nov 2003 14:54:39 -0000	1.15
+++ fs-ecos.c	24 Nov 2003 16:09:21 -0000	1.16
@@ -20,6 +20,7 @@
 #include <linux/jffs2_fs_sb.h>
 #include <linux/jffs2_fs_i.h>
 #include <linux/pagemap.h>
+#include <linux/crc32.h>
 #include "nodelist.h"
 
 #include <errno.h>
@@ -143,7 +144,6 @@
 //==========================================================================
 // STATIC VARIABLES !!!
 
-static char read_write_buffer[PAGE_CACHE_SIZE];	//avoids malloc when user may be under memory pressure
 static unsigned char gc_buffer[PAGE_CACHE_SIZE];	//avoids malloc when user may be under memory pressure
 static unsigned char n_fs_mounted = 0;  // a counter to track the number of jffs2 instances mounted
 
@@ -1292,31 +1292,102 @@
 	return ENOERR;
 }
 
+
 // -------------------------------------------------------------------------
 // jffs2_fo_write()
 // Write data to file.
+static int jffs2_extend_file (struct _inode *inode, struct jffs2_raw_inode *ri,
+		       unsigned long offset)
+{
+	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
+	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
+	struct jffs2_full_dnode *fn;
+	uint32_t phys_ofs, alloc_len;
+	int ret = 0;
+
+	/* Make new hole frag from old EOF to new page */
+	D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
+		  (unsigned int)inode->i_size, offset));
+
+	ret = jffs2_reserve_space(c, sizeof(ri), &phys_ofs, &alloc_len, ALLOC_NORMAL);
+	if (ret)
+		return ret;
+
+	down(&f->sem);
+
+	ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
+	ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
+	ri->totlen = cpu_to_je32(sizeof(ri));
+	ri->hdr_crc = cpu_to_je32(crc32(0, &ri, sizeof(struct jffs2_unknown_node)-4));
+
+	ri->version = cpu_to_je32(++f->highest_version);
+	ri->isize = cpu_to_je32(max((uint32_t)inode->i_size, offset));
+
+	ri->offset = cpu_to_je32(inode->i_size);
+	ri->dsize = cpu_to_je32(offset - inode->i_size);
+	ri->csize = cpu_to_je32(0);
+	ri->compr = JFFS2_COMPR_ZERO;
+	ri->node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
+	ri->data_crc = cpu_to_je32(0);
+		
+	fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL);
+	jffs2_complete_reservation(c);
+	if (IS_ERR(fn)) {
+		ret = PTR_ERR(fn);
+		up(&f->sem);
+		return ret;
+	}
+	ret = jffs2_add_full_dnode_to_inode(c, f, fn);
+	if (f->metadata) {
+		jffs2_mark_node_obsolete(c, f->metadata->raw);
+		jffs2_free_full_dnode(f->metadata);
+		f->metadata = NULL;
+	}
+	if (ret) {
+		D1(printk(KERN_DEBUG "Eep. add_full_dnode_to_inode() failed in prepare_write, returned %d\n", ret));
+		jffs2_mark_node_obsolete(c, fn->raw);
+		jffs2_free_full_dnode(fn);
+		up(&f->sem);
+		return ret;
+	}
+	inode->i_size = offset;
+	up(&f->sem);
+	return 0;
+}
 
 static int jffs2_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
 {
-	struct page write_page;
-	off_t page_start_pos;
-	struct _inode *node = (struct _inode *) fp->f_data;
+	struct _inode *inode = (struct _inode *) fp->f_data;
 	off_t pos = fp->f_offset;
 	ssize_t resid = uio->uio_resid;
+	struct jffs2_raw_inode ri;
+	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
+	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
 	int i;
 
-	memset(&read_write_buffer, 0, PAGE_CACHE_SIZE);
-	write_page.virtual = &read_write_buffer;
-
 	// If the APPEND mode bit was supplied, force all writes to
 	// the end of the file.
 	if (fp->f_flag & CYG_FAPPEND)
-		pos = fp->f_offset = node->i_size;
+		pos = fp->f_offset = inode->i_size;
 
-	// Check that pos is within current file size, or at the very end.
-	if (pos < 0 || pos > node->i_size)
+	if (pos < 0)
 		return EINVAL;
 
+	memset(&ri, 0, sizeof(ri));
+
+	ri.ino = cpu_to_je32(f->inocache->ino);
+	ri.mode = cpu_to_jemode(inode->i_mode);
+	ri.uid = cpu_to_je16(inode->i_uid);
+	ri.gid = cpu_to_je16(inode->i_gid);
+	ri.atime = ri.ctime = ri.mtime = cpu_to_je32(cyg_timestamp());
+
+	if (pos > inode->i_size) {
+		ri.version = cpu_to_je32(++f->highest_version);
+		int err = jffs2_extend_file(inode, &ri, pos);
+		if (err)
+			return -err;
+	}
+
 	// Now loop over the iovecs until they are all done, or
 	// we get an error.
 	for (i = 0; i < uio->uio_iovcnt; i++) {
@@ -1324,67 +1395,30 @@
 		char *buf = (char *) iov->iov_base;
 		off_t len = iov->iov_len;
 
-		// loop over the vector writing it to the file until it has
-		// all been done.
-		while (len > 0) {
-			//cyg_uint8 *fbuf;
-			//size_t bsize;
-			size_t writtenlen;
-			off_t l = len;
-			int err;
-
-			write_page.index = 0;
-
-			page_start_pos = pos;
-			while (page_start_pos >= (PAGE_CACHE_SIZE)) {
-				write_page.index++;
-				page_start_pos -= PAGE_CACHE_SIZE;
-			}
-
-			if (l > PAGE_CACHE_SIZE - page_start_pos)
-				l = PAGE_CACHE_SIZE - page_start_pos;
-
-			D2(printf
-			   ("jffs2_fo_write write_page.index %d\n",
-			    write_page.index));
-			D2(printf
-			   ("jffs2_fo_write page_start_pos %d\n",
-			    page_start_pos));
-			D2(printf("jffs2_fo_write transfer size %d\n", l));
-
-			err =
-			    jffs2_prepare_write(node, &write_page,
-						page_start_pos,
-						page_start_pos + l);
+		size_t writtenlen;
+		int err;
 
-			if (err != 0)
-				return err;
+		D2(printf("jffs2_fo_write page_start_pos %d\n", pos));
+		D2(printf("jffs2_fo_write transfer size %d\n", l));
 
-			// copy data in
-			memcpy(&read_write_buffer[page_start_pos], buf, l);
+		err = jffs2_write_inode_range(c, f, &ri, buf,
+					      pos, len, &writtenlen);
+		if (err)
+			return -err;
+		
+		if (writtenlen != len)
+			return ENOSPC;
 
-			writtenlen =
-			    jffs2_commit_write(node, &write_page,
-					       page_start_pos,
-					       page_start_pos + l);
-
-			if (writtenlen != l)
-				return ENOSPC;
-
-			// Update working vars
-			len -= l;
-			buf += l;
-			pos += l;
-			resid -= l;
-		}
+		pos += len;
+		resid -= len;
 	}
 
 	// We wrote some data successfully, update the modified and access
-	// times of the node, increase its size appropriately, and update
+	// times of the inode, increase its size appropriately, and update
 	// the file offset and transfer residue.
-	node->i_mtime = node->i_ctime = cyg_timestamp();
-	if (pos > node->i_size)
-		node->i_size = pos;
+	inode->i_mtime = inode->i_ctime = je32_to_cpu(ri.mtime);
+	if (pos > inode->i_size)
+		inode->i_size = pos;
 
 	uio->uio_resid = resid;
 	fp->f_offset = pos;

--- file-ecos.c DELETED ---




More information about the linux-mtd-cvs mailing list