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
18 #if EXT2_FLAT_INCLUDES
21 #include <linux/ext2_fs.h>
37 static int unlink_proc(struct ext2_dir_entry *dirent,
43 struct link_struct *ls = (struct link_struct *) priv_data;
45 if (ls->name && ((dirent->name_len & 0xFF) != ls->namelen))
47 if (ls->name && strncmp(ls->name, dirent->name,
48 dirent->name_len & 0xFF))
50 if (ls->inode && (dirent->inode != ls->inode))
55 return DIRENT_ABORT|DIRENT_CHANGED;
61 errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name, ino_t ino,
65 struct link_struct ls;
67 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
69 if (!(fs->flags & EXT2_FLAG_RW))
70 return EXT2_ET_RO_FILSYS;
73 ls.namelen = name ? strlen(name) : 0;
78 retval = ext2fs_dir_iterate(fs, dir, 0, 0, unlink_proc, &ls);
82 return (ls.done) ? 0 : EXT2_ET_DIR_NO_SPACE;