Re: [PATCH] ufs: do not treat unreadable directory blocks as empty

Jan Kara <[email protected]>
Newsgroups gmane.linux.file-systems,gmane.linux.kernel
Message-ID <jub6jswxsoov3ytgo2ga4m7pa7yjraltf7vznyvc4pmfzeuexh@vstvw6p7whsl>
On Sat 01-08-26 04:39:32, Ali Ahmet Memis wrote:
> ufs_empty_dir() scans every directory block to decide whether a
> directory is empty before rmdir() removes it. When ufs_get_folio()
> cannot read or validate a block it returns an error pointer, and the
> loop currently skips that block with continue and keeps scanning the
> remaining blocks.
> 
> If none of the readable blocks hold an entry, the function returns 1
> and the caller unlinks the directory. A directory whose contents live
> in a block that cannot be read, for example because of an I/O error or
> corrupted directory metadata, is therefore seen as empty and removed,
> losing the entries it still holds.
> 
> Follow the ext2 behaviour and treat an unreadable block as a reason to
> consider the directory not empty, so rmdir() fails instead of
> discarding data that could not be verified.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Ali Ahmet Memis <[email protected]>

Fair. Feel free to add:

Reviewed-by: Jan Kara <[email protected]>

								Honza

> ---
>  fs/ufs/dir.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ufs/dir.c b/fs/ufs/dir.c
> index e62fe5667..ce43cf20b 100644
> --- a/fs/ufs/dir.c
> +++ b/fs/ufs/dir.c
> @@ -590,7 +590,7 @@ int ufs_empty_dir(struct inode * inode)
>  
>  		kaddr = ufs_get_folio(inode, i, &folio);
>  		if (IS_ERR(kaddr))
> -			continue;
> +			return 0;
>  
>  		de = (struct ufs_dir_entry *)kaddr;
>  		kaddr += ufs_last_byte(inode, i) - UFS_DIR_REC_LEN(1);
> -- 
> 2.54.0
> 
-- 
Jan Kara <[email protected]>
SUSE Labs, CR
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.