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 #include <linux/ext2_fs.h>
33 static int unlink_proc(struct ext2_dir_entry *dirent,
39 struct link_struct *ls = (struct link_struct *) private;
41 if (ls->name && (dirent->name_len != ls->namelen))
43 if (ls->name && strncmp(ls->name, dirent->name, dirent->name_len))
45 if (ls->inode && (dirent->inode != ls->inode))
50 return DIRENT_ABORT|DIRENT_CHANGED;
56 errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name, ino_t ino,
60 struct link_struct ls;
62 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
64 if (!(fs->flags & EXT2_FLAG_RW))
65 return EXT2_ET_RO_FILSYS;
68 ls.namelen = name ? strlen(name) : 0;
73 retval = ext2fs_dir_iterate(fs, dir, 0, 0, unlink_proc, &ls);
77 return (ls.done) ? 0 : EXT2_ET_DIR_NO_SPACE;