Skip to content

Commit 4ebcf3f

Browse files
hcleenamjaejeon
authored andcommitted
ntfs: drop nlink once for WIN32/DOS aliases
NTFS could store a filename as paired WIN32 and DOS $FILE_NAME attributes for directories. But ntfs_delete() deleted both attributes for unlinking a directory, but it also called drop_nlink() for each attributes. This could trigger warnings when unlinking directories. Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent d986ba0 commit 4ebcf3f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

fs/ntfs/namei.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,8 @@ static int ntfs_delete(struct ntfs_inode *ni, struct ntfs_inode *dir_ni,
945945

946946
ni_mrec = actx->base_mrec ? actx->base_mrec : actx->mrec;
947947
ni_mrec->link_count = cpu_to_le16(le16_to_cpu(ni_mrec->link_count) - 1);
948-
drop_nlink(VFS_I(ni));
948+
if (!S_ISDIR(VFS_I(ni)->i_mode))
949+
drop_nlink(VFS_I(ni));
949950

950951
mark_mft_record_dirty(ni);
951952
if (looking_for_dos_name) {
@@ -955,6 +956,13 @@ static int ntfs_delete(struct ntfs_inode *ni, struct ntfs_inode *dir_ni,
955956
goto search;
956957
}
957958

959+
/*
960+
* For directories, Drop VFS nlink only when mft record link count
961+
* becomes zero. Because we fixes VFS nlink to 1 for directories.
962+
*/
963+
if (S_ISDIR(VFS_I(ni)->i_mode) && !le16_to_cpu(ni_mrec->link_count))
964+
drop_nlink(VFS_I(ni));
965+
958966
/*
959967
* If hard link count is not equal to zero then we are done. In other
960968
* case there are no reference to this inode left, so we should free all
@@ -1221,7 +1229,8 @@ static int __ntfs_link(struct ntfs_inode *ni, struct ntfs_inode *dir_ni,
12211229
}
12221230
/* Increment hard links count. */
12231231
ni_mrec->link_count = cpu_to_le16(le16_to_cpu(ni_mrec->link_count) + 1);
1224-
inc_nlink(VFS_I(ni));
1232+
if (!S_ISDIR(vi->i_mode))
1233+
inc_nlink(VFS_I(ni));
12251234

12261235
/* Done! */
12271236
mark_mft_record_dirty(ni);

0 commit comments

Comments
 (0)