From 3c6381db2f85c010f9a392f1a693d78eed99b8a1 Mon Sep 17 00:00:00 2001 From: cha0smaster Date: Mon, 15 Aug 2005 00:50:19 +0000 Subject: [PATCH] Thoght that FUSE will check if directory is empty, it didn't. Add such check to ntfs_delete. --- libntfs/dir.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libntfs/dir.c b/libntfs/dir.c index fdca85e4..8973a999 100644 --- a/libntfs/dir.c +++ b/libntfs/dir.c @@ -1271,6 +1271,25 @@ int ntfs_delete(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len) ni = ni->base_ni; if (dir_ni->nr_extents == -1) dir_ni = dir_ni->base_ni; + /* If deleting directory check it to be empty. */ + if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + ntfs_attr *na; + + na = ntfs_attr_open(ni, AT_INDEX_ROOT, I30, 4); + if (!na) { + ntfs_error(, "Corrupt directory or library bug."); + errno = EIO; + goto err_out; + } + if (na->data_size != sizeof(INDEX_ROOT) + + sizeof(INDEX_ENTRY_HEADER)) { + ntfs_attr_close(na); + ntfs_error(, "Directory is not empty."); + errno = ENOTEMPTY; + goto err_out; + } + ntfs_attr_close(na); + } /* * Search for FILE_NAME attribute with such name. If it's in POSIX or * WIN32_AND_DOS namespace, then simply remove it from index and inode.