[Tux3] [PATCH] rename and rmdir

Pranith Kumar bobby.prani at gmail.com
Mon Dec 8 05:44:23 PST 2008


Hello,

Sorry to hijack this but I cleaned it up for rmdir.

Regards,
Pranith.

--- user/kernel/namei.c.orig	2008-12-08 18:26:26.186324000 +0530
+++ user/kernel/namei.c	2008-12-08 18:55:13.633735000 +0530
@@ -31,6 +31,19 @@ static int tux_add_dirent(struct inode *
 	return 0;
 }

+static int tux_del_dirent(struct inode *dir, struct dentry *dentry)
+{
+	struct buffer_head *buffer;
+	tux_dirent *entry;
+	int err = -ENOENT;
+
+	entry = tux_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
+			       &buffer);
+	if (entry)
+		err = tux_delete_entry(buffer, entry);
+	return err;
+}
+
 static int tux3_create(struct inode *dir, struct dentry *dentry, int mode,
 		       struct nameidata *nd)
 {
@@ -98,19 +111,11 @@ static int tux3_symlink(struct inode *di
 static int tux3_unlink(struct inode *dir, struct dentry *dentry)
 {
 	struct inode *inode = dentry->d_inode;
-	struct buffer_head *buffer;
-	tux_dirent *entry;
-	int err = -ENOENT;
+	int err = tux_del_dirent(dir, dentry);

-	entry = tux_find_entry(dir, dentry->d_name.name, dentry->d_name.len,
-			       &buffer);
-	if (entry) {
-		err = tux_delete_entry(buffer, entry);
-		if (!err) {
-			inode->i_ctime = dir->i_ctime;
-			inode_dec_link_count(inode);
-			err = 0;
-		}
+	if (!err) {
+		inode->i_ctime = dir->i_ctime;
+		inode_dec_link_count(inode);
 	}
 	return err;
 }
@@ -173,13 +178,13 @@ static int tux3_rmdir(struct inode *dir,
 {
 	struct inode *inode = dentry->d_inode;
 	int err = -ENOTEMPTY;
-	struct buffer_head *buffer;
-	tux_dirent *de;
+
 	if (tux_dir_is_empty(inode)) {
-		de = tux_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &buffer);
-		err = tux_delete_entry(buffer, de);
+
+		err = tux_del_dirent(dir, dentry);

 		if (!err) {
+			inode->i_ctime = dir->i_ctime;
 			inode->i_size = 0;
 			inode_dec_link_count(inode);
 			inode_dec_link_count(dir);

_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://mailman.tux3.org/cgi-bin/mailman/listinfo/tux3



More information about the Tux3 mailing list