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 Public
26 struct ext2_dir_entry *prev;
33 static int unlink_proc(struct ext2_dir_entry *dirent,
34 int offset EXT2FS_ATTR((unused)),
35 int blocksize EXT2FS_ATTR((unused)),
36 char *buf EXT2FS_ATTR((unused)),
39 struct link_struct *ls = (struct link_struct *) priv_data;
40 struct ext2_dir_entry *prev;
46 if ((dirent->name_len & 0xFF) != ls->namelen)
48 if (strncmp(ls->name, dirent->name, dirent->name_len & 0xFF))
52 if (dirent->inode != ls->inode)
60 prev->rec_len += dirent->rec_len;
64 return DIRENT_ABORT|DIRENT_CHANGED;
70 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir,
71 const char *name, ext2_ino_t ino,
72 int flags EXT2FS_ATTR((unused)))
75 struct link_struct ls;
77 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
80 return EXT2_ET_INVALID_ARGUMENT;
82 if (!(fs->flags & EXT2_FLAG_RW))
83 return EXT2_ET_RO_FILSYS;
86 ls.namelen = name ? strlen(name) : 0;
92 retval = ext2fs_dir_iterate(fs, dir, DIRENT_FLAG_INCLUDE_EMPTY,
97 return (ls.done) ? 0 : EXT2_ET_DIR_NO_SPACE;