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
32 static int unlink_proc(struct ext2_dir_entry *dirent,
38 struct link_struct *ls = (struct link_struct *) priv_data;
40 if (ls->name && ((dirent->name_len & 0xFF) != ls->namelen))
42 if (ls->name && strncmp(ls->name, dirent->name,
43 dirent->name_len & 0xFF))
45 if (ls->inode && (dirent->inode != ls->inode))
50 return DIRENT_ABORT|DIRENT_CHANGED;
56 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir,
57 const char *name, ext2_ino_t ino,
61 struct link_struct ls;
63 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
65 if (!(fs->flags & EXT2_FLAG_RW))
66 return EXT2_ET_RO_FILSYS;
69 ls.namelen = name ? strlen(name) : 0;
74 retval = ext2fs_dir_iterate(fs, dir, 0, 0, unlink_proc, &ls);
78 return (ls.done) ? 0 : EXT2_ET_DIR_NO_SPACE;