patch-2.2.10 linux/fs/sysv/namei.c
Next file: linux/include/asm-alpha/atomic.h
Previous file: linux/fs/super.c
Back to the patch index
Back to the overall index
- Lines: 154
- Date:
Thu May 13 23:25:58 1999
- Orig file:
v2.2.9/linux/fs/sysv/namei.c
- Orig date:
Tue May 11 13:10:31 1999
diff -u --recursive --new-file v2.2.9/linux/fs/sysv/namei.c linux/fs/sysv/namei.c
@@ -144,8 +144,6 @@
*res_buf = NULL;
*res_dir = NULL;
- if (!dir)
- return -ENOENT;
sb = dir->i_sb;
if (namelen > SYSV_NAMELEN) {
if (sb->sv_truncate)
@@ -334,8 +332,6 @@
struct buffer_head * bh;
struct sysv_dir_entry * de;
- if (!inode)
- return 1;
block = 0;
bh = NULL;
pos = offset = 2*SYSV_DIRSIZE;
@@ -391,22 +387,16 @@
struct buffer_head * bh;
struct sysv_dir_entry * de;
- inode = NULL;
- bh = sysv_find_entry(dir, dentry->d_name.name,
- dentry->d_name.len, &de);
+ inode = dentry->d_inode;
+ bh = sysv_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
retval = -ENOENT;
- if (!bh)
+ if (!bh || de->inode != inode->i_ino)
goto end_rmdir;
- inode = dentry->d_inode;
if (!empty_dir(inode)) {
retval = -ENOTEMPTY;
goto end_rmdir;
}
- if (de->inode != inode->i_ino) {
- retval = -ENOENT;
- goto end_rmdir;
- }
if (!list_empty(&dentry->d_hash)) {
retval = -EBUSY;
goto end_rmdir;
@@ -416,9 +406,9 @@
de->inode = 0;
mark_buffer_dirty(bh, 1);
inode->i_nlink=0;
- mark_inode_dirty(inode);
dir->i_nlink--;
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
+ mark_inode_dirty(inode);
mark_inode_dirty(dir);
d_delete(dentry);
retval = 0;
@@ -434,26 +424,11 @@
struct buffer_head * bh;
struct sysv_dir_entry * de;
-repeat:
retval = -ENOENT;
- inode = NULL;
- bh = sysv_find_entry(dir, dentry->d_name.name,
- dentry->d_name.len, &de);
- if (!bh)
- goto end_unlink;
inode = dentry->d_inode;
-
- retval = -EPERM;
- if (de->inode != inode->i_ino) {
- brelse(bh);
- current->counter = 0;
- schedule();
- goto repeat;
- }
- if (de->inode != inode->i_ino) {
- retval = -ENOENT;
+ bh = sysv_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
+ if (!bh || de->inode != inode->i_ino)
goto end_unlink;
- }
if (!inode->i_nlink) {
printk("Deleting nonexistent file (%s:%lu), %d\n",
kdevname(inode->i_dev), inode->i_ino, inode->i_nlink);
@@ -572,12 +547,6 @@
(((struct sysv_dir_entry *) ((buffer) + 1*SYSV_DIRSIZE))->inode)
/*
- * rename uses retrying to avoid race-conditions: at least they should be minimal.
- * it tries to allocate all the blocks, then sanity-checks, and if the sanity-
- * checks fail, it tries to restart itself again. Very practical - no changes
- * are done until we know everything works ok.. and then all the changes can be
- * done in one fell swoop when we have claimed all the buffers needed.
- *
* Anybody can rename anything with this: the permission checks are left to the
* higher-level routines.
*/
@@ -589,24 +558,15 @@
struct sysv_dir_entry * old_de, * new_de;
int retval;
- goto start_up;
-try_again:
- brelse(old_bh);
- brelse(new_bh);
- brelse(dir_bh);
- current->counter = 0;
- schedule();
-start_up:
- old_inode = new_inode = NULL;
- old_bh = new_bh = dir_bh = NULL;
+ old_inode = old_dentry->d_inode;
+ new_inode = new_dentry->d_inode;
+ new_bh = dir_bh = NULL;
old_bh = sysv_find_entry(old_dir, old_dentry->d_name.name,
old_dentry->d_name.len, &old_de);
retval = -ENOENT;
- if (!old_bh)
+ if (!old_bh || old_de->inode != old_inode->i_ino)
goto end_rename;
- old_inode = old_dentry->d_inode; /* don't cross mnt-points */
retval = -EPERM;
- new_inode = new_dentry->d_inode;
new_bh = sysv_find_entry(new_dir, new_dentry->d_name.name,
new_dentry->d_name.len, &new_de);
if (new_bh) {
@@ -628,7 +588,8 @@
if (PARENT_INO(dir_bh->b_data) != old_dir->i_ino)
goto end_rename;
retval = -EMLINK;
- if (!new_inode && new_dir->i_nlink >= new_dir->i_sb->sv_link_max)
+ if (!new_inode && new_dir != old_dir &&
+ new_dir->i_nlink >= new_dir->i_sb->sv_link_max)
goto end_rename;
}
if (!new_bh) {
@@ -637,16 +598,8 @@
if (retval)
goto end_rename;
}
-/* sanity checking before doing the rename - avoid races */
- if (new_inode && (new_de->inode != new_inode->i_ino))
- goto try_again;
- if (new_de->inode && !new_inode)
- goto try_again;
- if (old_de->inode != old_inode->i_ino)
- goto try_again;
-/* ok, that's it */
- old_de->inode = 0;
new_de->inode = old_inode->i_ino;
+ old_de->inode = 0;
old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
mark_inode_dirty(old_dir);
new_dir->i_ctime = new_dir->i_mtime = CURRENT_TIME;
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)