aboutsummaryrefslogtreecommitdiff
path: root/libdiskfs/dir-rmdir.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdiskfs/dir-rmdir.c')
-rw-r--r--libdiskfs/dir-rmdir.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/libdiskfs/dir-rmdir.c b/libdiskfs/dir-rmdir.c
index 70c87d03..a90ff07b 100644
--- a/libdiskfs/dir-rmdir.c
+++ b/libdiskfs/dir-rmdir.c
@@ -1,5 +1,5 @@
/* libdsikfs implementation of fs.defs: dir_rmdir
- Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation
+ Copyright (C) 1992,93,94,95,96,97,99 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -25,13 +25,27 @@ diskfs_S_dir_rmdir (struct protid *dircred,
char *name)
{
struct node *dnp;
- struct node *np = 0;
+ struct node *np;
struct dirstat *ds = alloca (diskfs_dirstat_size);
error_t error;
+ /* This routine cleans up the state we have after calling diskfs_lookup.
+ After that call, all returns are done with `return done (ERROR, NP);'. */
+ inline error_t done (error_t error, struct node *np)
+ {
+ if (np)
+ diskfs_nput (np);
+
+ if (ds)
+ diskfs_drop_dirstat (dnp, ds);
+ mutex_unlock (&dnp->lock);
+
+ return error;
+ }
+
if (!dircred)
return EOPNOTSUPP;
-
+
dnp = dircred->po->np;
if (diskfs_check_readonly ())
return EROFS;
@@ -39,44 +53,32 @@ diskfs_S_dir_rmdir (struct protid *dircred,
mutex_lock (&dnp->lock);
error = diskfs_lookup (dnp, name, REMOVE, &np, ds, dircred);
- if (error == EAGAIN)
- error = ENOTEMPTY;
if (error)
- {
- mutex_unlock (&dnp->lock);
- diskfs_drop_dirstat (dnp, ds);
- return error;
- }
+ return done (error == EAGAIN ? ENOTEMPTY : error, 0);
- /* Attempt to rmdir(".") */
if (dnp == np)
{
+ /* Attempt to rmdir(".") */
diskfs_nrele (np);
diskfs_drop_dirstat (dnp, ds);
mutex_unlock (&dnp->lock);
return EINVAL;
}
- if (np->istranslated || fshelp_translated (&np->transbox))
- {
- diskfs_drop_dirstat (dnp, ds);
- diskfs_nput (np);
- mutex_unlock (&dnp->lock);
- return EBUSY;
- }
+ if ((np->dn_stat.st_mode & S_IPTRANS) || fshelp_translated (&np->transbox))
+ /* Attempt to rmdir a translated node. */
+ return done (EBUSY, np);
+
+ if (!S_ISDIR (np->dn_stat.st_mode))
+ return done (ENOTDIR, np);
- /* Verify the directory is empty (and valid). (Rmdir ".." won't be
- valid since ".." will contain a reference to the current directory and
- thus be non-empty). */
if (!diskfs_dirempty (np, dircred))
- {
- diskfs_nput (np);
- diskfs_drop_dirstat (dnp, ds);
- mutex_unlock (&dnp->lock);
- return ENOTEMPTY;
- }
+ return done (ENOTEMPTY, np);
+ /* Here we go! */
error = diskfs_dirremove (dnp, np, name, ds);
+ ds = 0;
+
if (!error)
{
np->dn_stat.st_nlink--;
@@ -88,7 +90,5 @@ diskfs_S_dir_rmdir (struct protid *dircred,
if (diskfs_synchronous)
diskfs_file_update (dnp, 1);
- diskfs_nput (np);
- mutex_unlock (&dnp->lock);
- return 0;
+ return done (error, np);
}