2 * unlink.c --- delete links in a ext2fs directory
4 * Copyright (C) 1993, 1994, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
27 struct ext2_dir_entry *prev;
34 static int unlink_proc(struct ext2_dir_entry *dirent,
36 int blocksize EXT2FS_ATTR((unused)),
37 char *buf EXT2FS_ATTR((unused)),
40 struct link_struct *ls = (struct link_struct *) priv_data;
41 struct ext2_dir_entry *prev;
47 if (ext2fs_dirent_name_len(dirent) != ls->namelen)
49 if (strncmp(ls->name, dirent->name, ext2fs_dirent_name_len(dirent)))
52 if (!(ls->flags & EXT2FS_UNLINK_FORCE) && ls->inode) {
53 if (dirent->inode != ls->inode)
61 prev->rec_len += dirent->rec_len;
65 return DIRENT_ABORT|DIRENT_CHANGED;
71 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir,
72 const char *name, ext2_ino_t ino,
76 struct link_struct ls;
78 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
81 return EXT2_ET_INVALID_ARGUMENT;
83 if (!(fs->flags & EXT2_FLAG_RW))
84 return EXT2_ET_RO_FILSYS;
87 ls.namelen = name ? strlen(name) : 0;
93 retval = ext2fs_dir_iterate(fs, dir, DIRENT_FLAG_INCLUDE_EMPTY,
98 return (ls.done) ? 0 : EXT2_ET_DIR_NO_SPACE;