<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -92,7 +92,10 @@ static int testfs_commit_chunk(struct page *page, loff_t pos, unsigned len)
 		i_size_write(dir, pos+len);
 		mark_inode_dirty(dir);
 	}
+	//unlock_page(page);
 	err = write_one_page(page,1);
+	if (!err)
+	err = testfs_write_inode(dir,1);
 	return err;
 }
 
@@ -157,7 +160,9 @@ int testfs_add_link(struct dentry *dentry, struct inode *inode)
 			if (testfs_match(namelen, name, de))
 				/* Entry already exists */
 				goto page_unlock;
+
 			rec_len = de-&gt;rec_len;
+			/* This can be different from above if this is the last entry */
 			name_len = calc_reclen_from_len(de-&gt;name_len);
 
 			if(!de-&gt;inode &amp;&amp; rec_len &gt;= reclen) {
@@ -275,6 +280,7 @@ struct testfs_dir_entry *testfs_find_dentry(struct inode *dir,
 	struct page *page;
 	char *kaddr = NULL, *limit;
 
+	testfs_debug(&quot;Trying to find \&quot;%s\&quot; in dir ino (%u)\n&quot;,child-&gt;name, dir-&gt;i_ino);
 	for (n=0;n&lt;=pages;n++) {
 		page = testfs_get_page(dir, n);
 		if (IS_ERR(page)) {
@@ -291,6 +297,7 @@ struct testfs_dir_entry *testfs_find_dentry(struct inode *dir,
 				return -EIO;
 			}
 			if (testfs_match(child-&gt;len, child-&gt;name, de)) {
+				*respage = page;
 				return de;
 			}
 		}
@@ -315,6 +322,37 @@ unsigned int testfs_inode_by_name(struct inode *dir, struct qstr *child)
 	return ino;
 }
 
+int testfs_delete_entry (struct testfs_dir_entry *dir, struct page *page)
+{
+	struct testfs_dir_entry *old, *cur;
+	char *kaddr = page_address(page);
+	int err = -ENOENT;
+	struct address_space *mapping = page-&gt;mapping;
+	struct inode *inode = mapping-&gt;host;
+	int pos, from = (((char *)dir) - kaddr) &amp; ~(inode-&gt;i_sb-&gt;s_blocksize - 1);
+	int to = (((char *)dir) - kaddr) + calc_reclen_from_len(dir-&gt;name_len);
+	old = cur= (struct testfs_dir_entry *)kaddr;
+	testfs_debug(&quot;here\n&quot;);
+	for (;cur &lt; dir;cur= (char *)cur+ cur-&gt;rec_len) {
+		testfs_debug(&quot;ino (%lu - %s)\n&quot;,cur-&gt;inode, cur-&gt;name);
+		old = cur;
+	}
+	if ((char *)cur!= kaddr) {
+		/* This is not the first entry on page */
+		old-&gt;rec_len += cur-&gt;rec_len;
+		cur-&gt;inode = 0;
+	}
+	pos = page_offset(page) + from;
+	lock_page(page);
+	err = __testfs_write_begin(NULL, mapping, pos, to - from, 0,
+						&amp;page, NULL);
+
+	err = testfs_commit_chunk(page, pos, to - from);
+	mark_inode_dirty(inode);
+	testfs_put_page(page);
+	return err;
+}
+
 const struct file_operations testfs_dir_operations = {
 	.llseek = generic_file_llseek,
 	.read = generic_read_dir,</diff>
      <filename>dir.c</filename>
    </modified>
    <modified>
      <diff>@@ -107,6 +107,7 @@ void testfs_free_inode(struct inode *inode)
 		testfs_error(&quot;Invalid inode number to be freed %u\n&quot;,ino);
 		goto error_return;
 	}
+	clear_inode(inode);
 	bitmap_bh = read_inode_bitmap(sb);
 	if (inode_already_freed(bitmap_bh-&gt;b_data, ino)) {
 		testfs_error(&quot;Inode already free %u\n&quot;,ino);</diff>
      <filename>ialloc.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
-/***********************************************************/
+/**********************************************************/
 /*  This is the readme for the testfs filesystem           */
 /*  Author : Manish Katiyar &lt;mkatiyar@gmail.com&gt;           */
 /*  Description : A simple disk based filesystem for linux */
@@ -258,7 +258,7 @@ static int testfs_update_inode(struct inode *inode)
 		return -EIO;
 
 	/* Update the fields of on disk inode with those from memory */
-	testfs_debug(&quot;Incore size = %lld , mode = 0x%x\n&quot;,inode-&gt;i_size, inode-&gt;i_mode);
+	testfs_debug(&quot;Inode (%lu) size = %lld , mode = 0x%x\n&quot;,inode-&gt;i_ino, inode-&gt;i_size, inode-&gt;i_mode);
 	raw-&gt;size = cpu_to_le32(inode-&gt;i_size);
 	raw-&gt;atime = (inode-&gt;i_atime);
 	raw-&gt;mtime = (inode-&gt;i_mtime);
@@ -267,6 +267,7 @@ static int testfs_update_inode(struct inode *inode)
 	raw-&gt;gid = cpu_to_le32(inode-&gt;i_gid);
 	raw-&gt;uid = cpu_to_le32(inode-&gt;i_uid);
 	raw-&gt;type = cpu_to_le32(inode-&gt;i_mode);
+	testfs_debug(&quot;Data block = %u\n&quot;,tsi-&gt;i_data[0]);
 	raw-&gt;data[0] = tsi-&gt;i_data[0];
 
 	mark_buffer_dirty(bh);
@@ -279,6 +280,20 @@ static int testfs_update_inode(struct inode *inode)
 	return err;
 }
 
+void testfs_delete_inode(struct inode *inode)
+{
+	testfs_debug(&quot;Deleting inode (%lu)\n&quot;,inode-&gt;i_ino);
+	if(is_bad_inode(inode))
+		goto no_delete;
+	mark_inode_dirty(inode);
+	testfs_update_inode(inode);
+	inode-&gt;i_size = 0;
+	testfs_free_inode(inode);
+	return;
+no_delete:
+	clear_inode(inode);
+}
+
 int testfs_write_inode(struct inode *inode, int wait)
 {
 	return testfs_update_inode(inode);</diff>
      <filename>inode.c</filename>
    </modified>
    <modified>
      <diff>@@ -17,9 +17,11 @@ static int testfs_add_dentry(struct dentry *dentry, struct inode *inode)
 		 * Attach the negative dentry with the inode
 		 */
 		d_instantiate(dentry, inode);
+		unlock_new_inode(inode);
 		return 0;
 	}
 	inode_dec_link_count(inode);
+	unlock_new_inode(inode);
 	iput(inode);
 	return err;
 }
@@ -69,11 +71,33 @@ static struct dentry *testfs_lookup(struct inode *dir, struct dentry *dentry, st
 	return d_splice_alias(inode, dentry);
 }
 
+static int testfs_unlink(struct inode *dir, struct dentry *dentry)
+{
+	struct inode *inode = dentry-&gt;d_inode;
+	struct testfs_dir_entry *de;
+	struct page *page;
+	int err = -ENOENT;
+
+	testfs_debug(&quot;Deleting file \&quot;%s\&quot;\n&quot;,dentry-&gt;d_name.name);
+	de = testfs_find_dentry(dir, &amp;dentry-&gt;d_name, &amp;page);
+	if (!de) {
+		testfs_debug(&quot;Unable to find requested filename\n&quot;);
+		goto out;
+	}
+
+	err = testfs_delete_entry(de, page);
+	if (err) {
+		goto out;
+	}
+	inode_dec_link_count(inode);
+out:
+	return err;
+}
 const struct inode_operations testfs_dir_inode_operations = {
 	.create = testfs_create,
 	.lookup = testfs_lookup,
 	//.link = testfs_link,
-	//.unlink = testfs_unlink,
+	.unlink = testfs_unlink,
         //.mkdir = testfs_mkdir,
 	//.rmdir = testfs_rmdir,
 	//.rename = testfs_rename,</diff>
      <filename>namei.c</filename>
    </modified>
    <modified>
      <diff>@@ -74,6 +74,8 @@ static void testfs_destroy_inode(struct inode *inode)
 }
 static const struct super_operations testfs_sops = {
 	.alloc_inode   = testfs_alloc_inode,
+	.write_inode   = testfs_write_inode,
+	.delete_inode  = testfs_delete_inode,
 	.destroy_inode = testfs_destroy_inode,
 	.put_super     = testfs_put_super,
 	.write_super   = testfs_write_super,</diff>
      <filename>super.c</filename>
    </modified>
    <modified>
      <diff>@@ -180,13 +180,19 @@ extern int testfs_permission(struct inode *inode, int mask);
 
 /* ialloc.c */
 extern struct inode *testfs_new_inode(struct inode *dir, int mode);
+extern void testfs_free_inode (struct inode *inode);
 
 /* inode.c */
 int __testfs_write_begin(struct file *file, struct address_space *mapping,
 		loff_t pos, unsigned len, unsigned flags, struct page **pagep,
 		void **fsdata);
+int testfs_write_inode(struct inode *inode, int wait);
+void testfs_delete_inode(struct inode *inode);
 /* dir.c */
 extern unsigned int testfs_inode_by_name(struct inode *dir, struct qstr *child);
 extern int testfs_add_link(struct dentry *, struct inode *);
+struct testfs_dir_entry *testfs_find_dentry(struct inode *dir,
+	          struct qstr *child, struct page **respage);
+int testfs_delete_entry (struct testfs_dir_entry *dir, struct page *page);
 #endif
 #endif /* __TEST_FS__ */</diff>
      <filename>testfs.h</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5fd788a501230cf12b07b491c94406cd79531b77</id>
    </parent>
  </parents>
  <author>
    <name>Manish Katiyar</name>
    <email>mkatiyar@gmail.com</email>
  </author>
  <url>http://github.com/mkatiyar/testfs/commit/207a2cfe05f08ef304abbe3bb65b6b11f11835a0</url>
  <id>207a2cfe05f08ef304abbe3bb65b6b11f11835a0</id>
  <committed-date>2009-02-01T00:21:23-08:00</committed-date>
  <authored-date>2009-02-01T00:21:23-08:00</authored-date>
  <message>File deletion support</message>
  <tree>7ce5b75d8a7c36640b8a3622f328515cc9bc4903</tree>
  <committer>
    <name>Manish Katiyar</name>
    <email>mkatiyar@gmail.com</email>
  </committer>
</commit>
