summaryrefslogtreecommitdiff
path: root/libdiskfs/dir-clear.c
diff options
context:
space:
mode:
authorMichael I. Bushnell <mib@gnu.org>1994-02-02 20:54:20 +0000
committerMichael I. Bushnell <mib@gnu.org>1994-02-02 20:54:20 +0000
commitb5a27b1c53875dbb25c33a735b9bc22ac044ebba (patch)
treeabb964fbf8b7ced86aff12488c8e49f4ef0446fb /libdiskfs/dir-clear.c
parent206638f48ebfb6850b3a7a34eda132e057179d44 (diff)
Formerly dir-clear.c.~2~
Diffstat (limited to 'libdiskfs/dir-clear.c')
-rw-r--r--libdiskfs/dir-clear.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/libdiskfs/dir-clear.c b/libdiskfs/dir-clear.c
new file mode 100644
index 00000000..4b48b38c
--- /dev/null
+++ b/libdiskfs/dir-clear.c
@@ -0,0 +1,62 @@
+/*
+ Copyright (C) 1994 Free Software Foundation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "priv.h"
+
+/* Clear the `.' and `..' entries from directory DP. Its parent is PDP,
+ and the user responsible for this is identified by CRED. Both
+ directories must be locked. */
+error_t
+diskfs_clear_directory (struct node *dp,
+ struct node *pdp,
+ struct protid *cred)
+{
+ error_t err;
+ struct dirstat *ds = alloca (diskfs_dirstat_size);
+
+ /* Find and remove the `.' entry. */
+ err = diskfs_lookup (dp, ".", REMOVE, 0, ds, cred);
+ assert (err != ENOENT);
+ if (!err)
+ err = diskfs_dirremove (dp, ds);
+ else
+ diskfs_drop_dirstat (ds);
+ if (err)
+ return err;
+
+ /* Decrement the link count */
+ dp->dn_stat.st_nlink--;
+ dp->dn_set_ctime = 1;
+
+ /* Find and remove the `..' entry. */
+ err = ufs_checkdirmod (dp, dp->dn_stat.st_mode, pdp, cred);
+ if (!err)
+ err = diskfs_lookup (dp, "..", REMOVE | SPEC_DOTDOT, 0, ds, cred);
+ assert (err != ENOENT);
+ if (!err)
+ err = diskfs_dirremove (dp, ds);
+ else
+ diskfs_drop_dirstat (ds);
+ if (err)
+ return err;
+
+ /* Decrement the link count on the parent */
+ pdp->dn_stat.st_nlink--;
+ pdp->dn_set_ctime = 1;
+
+ return err;
+}