summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael I. Bushnell <mib@gnu.org>1996-07-16 01:37:07 +0000
committerMichael I. Bushnell <mib@gnu.org>1996-07-16 01:37:07 +0000
commit35f1a0a133dc131cd889a3f8a3dd812d762d32f9 (patch)
tree8eef8144f6e931f9e0d0c4fe4dbc09786546df7d
parent5b46eb7b8674c23b23156c8bb6dbea8850f382f9 (diff)
(diskfs_rename_dir): When unlocking FDP, only do it if we FDP != TDP.
Also, only do step two (changing .. in the directory being moved) if FDP != TDP.
-rw-r--r--libdiskfs/dir-renamed.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/libdiskfs/dir-renamed.c b/libdiskfs/dir-renamed.c
index 1aa12ef3..6ef96ee3 100644
--- a/libdiskfs/dir-renamed.c
+++ b/libdiskfs/dir-renamed.c
@@ -100,7 +100,8 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, char *fromname,
diskfs_drop_dirstat (tdp, ds);
diskfs_nrele (tnp);
mutex_unlock (&tdp->lock);
- mutex_unlock (&fdp->lock);
+ if (fdp != tdp)
+ mutex_unlock (&fdp->lock);
return 0;
}
@@ -119,37 +120,40 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, char *fromname,
goto out;
/* 2: Set our .. to point to the new parent */
- if (tdp->dn_stat.st_nlink == diskfs_link_max - 1)
+ if (fdp != tdp)
{
- err = EMLINK;
- return EMLINK;
- }
- tdp->dn_stat.st_nlink++;
- tdp->dn_set_ctime = 1;
- if (diskfs_synchronous)
- diskfs_node_update (tdp, 1);
+ if (tdp->dn_stat.st_nlink == diskfs_link_max - 1)
+ {
+ err = EMLINK;
+ return EMLINK;
+ }
+ tdp->dn_stat.st_nlink++;
+ tdp->dn_set_ctime = 1;
+ if (diskfs_synchronous)
+ diskfs_node_update (tdp, 1);
- tmpds = alloca (diskfs_dirstat_size);
- err = diskfs_lookup (fnp, "..", RENAME | SPEC_DOTDOT,
- &tmpnp, tmpds, fromcred);
- assert (err != ENOENT);
- assert (tmpnp == fdp);
- if (err)
- {
- diskfs_drop_dirstat (fnp, tmpds);
- goto out;
- }
+ tmpds = alloca (diskfs_dirstat_size);
+ err = diskfs_lookup (fnp, "..", RENAME | SPEC_DOTDOT,
+ &tmpnp, tmpds, fromcred);
+ assert (err != ENOENT);
+ assert (tmpnp == fdp);
+ if (err)
+ {
+ diskfs_drop_dirstat (fnp, tmpds);
+ goto out;
+ }
- err = diskfs_dirrewrite (fnp, fdp, tdp, "..", tmpds);
- if (diskfs_synchronous)
- diskfs_file_update (fnp, 1);
- if (err)
- goto out;
+ err = diskfs_dirrewrite (fnp, fdp, tdp, "..", tmpds);
+ if (diskfs_synchronous)
+ diskfs_file_update (fnp, 1);
+ if (err)
+ goto out;
- fdp->dn_stat.st_nlink--;
- fdp->dn_set_ctime = 1;
- if (diskfs_synchronous)
- diskfs_node_update (fdp, 1);
+ fdp->dn_stat.st_nlink--;
+ fdp->dn_set_ctime = 1;
+ if (diskfs_synchronous)
+ diskfs_node_update (fdp, 1);
+ }
/* 3: Increment the link count on the node being moved and rewrite
@@ -214,7 +218,7 @@ diskfs_rename_dir (struct node *fdp, struct node *fnp, char *fromname,
mutex_unlock (&tdp->lock);
if (tnp)
diskfs_nput (tnp);
- if (fdp)
+ if (fdp && fdp != tdp)
mutex_unlock (&fdp->lock);
if (fnp)
mutex_unlock (&fnp->lock);