ntfs: fix incorrect VCN units for index blocks in large clusters
Subsystems (2)
Hyunchul Lee
maintainerPATCH v2 1/1 ntfs: fix incorrect VCN units for index blocks in large clusters
NTFS stores VCNs for index blocks smaller than their cluster in fixed 512-byte units, independent of logical sector size. Use correct block units when initializing and traversing these indexes so directory indexes are located correctly.
Verified on a Windows-created 4Kn/32KB-cluster NTFS volume that when the index block is smaller than the cluster, the VCN unit is 512 bytes.
---
Changes in v2:
- Add a Fixes and Cc tags
--- fs/ntfs/index.c | 2 +- fs/ntfs/index.h | 2 +- fs/ntfs/inode.c | 8 ++++---- fs/ntfs/layout.h | 6 +++--- fs/ntfs/namei.c | 7 +++---- 5 files changed, 12 insertions(+), 13 deletions(-)
fs/ntfs/index.c +1 -1
@@ -852,7 +852,7 @@ int ntfs_index_lookup(const void *key, const u32 key_len, struct ntfs_index_contif (ni->vol->cluster_size <= icx->block_size) icx->vcn_size_bits = ni->vol->cluster_size_bits;else - icx->vcn_size_bits = ni->vol->sector_size_bits; + icx->vcn_size_bits =NTFS_BLOCK_SIZE_BITS ; icx->cr = ir->collation_rule;if (!ntfs_is_collation_rule_supported (icx->cr)) {
fs/ntfs/index.h +1 -1
@@ -37,7 +37,7 @@* (maximum is MAX_PARENT_VCN) * @ib_dirty: true if the current index block (@ia/@ib) was modified * @block_size: size of index blocks in bytes (from $INDEX_ROOT or $Boot) -* @vcn_size_bits: log2(cluster size) +* @vcn_size_bits: log2 of the VCN unit size * @sync_write: true if synchronous writeback is requested for this context * * @idx_ni is the index inode this context belongs to.
fs/ntfs/inode.c +4 -4
@@ -1021,8 +1021,8 @@ static int ntfs_read_locked_inode(struct inode *vi) ni->itype.index.vcn_size = vol->cluster_size; ni->itype.index.vcn_size_bits = vol->cluster_size_bits; }else { - ni->itype.index.vcn_size = vol->sector_size; - ni->itype.index.vcn_size_bits = vol->sector_size_bits; + ni->itype.index.vcn_size =NTFS_BLOCK_SIZE ; + ni->itype.index.vcn_size_bits =NTFS_BLOCK_SIZE_BITS ; }/* Setup the index allocation attribute, even if not present. */
@@ -1612,8 +1612,8 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi) ni->itype.index.vcn_size = vol->cluster_size; ni->itype.index.vcn_size_bits = vol->cluster_size_bits; }else { - ni->itype.index.vcn_size = vol->sector_size; - ni->itype.index.vcn_size_bits = vol->sector_size_bits; + ni->itype.index.vcn_size =NTFS_BLOCK_SIZE ; + ni->itype.index.vcn_size_bits =NTFS_BLOCK_SIZE_BITS ; }/* Find index allocation attribute. */
fs/ntfs/layout.h +3 -3
@@ -1880,8 +1880,8 @@ struct index_header {* @index_block_size: Size of each index block in bytes * (in $INDEX_ALLOCATION). * @clusters_per_index_block: -* Clusters per index block (or log2(bytes) -* if < cluster). +* Clusters per index block, or 512-byte units when +* the index block is smaller than a cluster. * Power of 2; used for encoding block size. * @reserved: 3 bytes reserved/alignment (zero). * @index: Index header for root entries (entries follow
@@ -1921,7 +1921,7 @@ struct index_root {* @lsn: Log sequence number of last modification. * @index_block_vcn: VCN of this index block. * Units: clusters if cluster_size <= index_block_size; -* sectors otherwise. +* 512-byte blocks otherwise. * @index: Index header describing entries in this block. * * When creating the index block, we place the update sequence array at this
fs/ntfs/namei.c +3 -4
@@ -433,9 +433,8 @@ static struct ntfs_inode *__ntfs_create(struct mnt_idmap *idmap, struct inode *d ni->itype.index.vcn_size_bits = vol->cluster_size_bits; }else { - ni->itype.index.vcn_size = vol->sector_size; - ni->itype.index.vcn_size_bits = - vol->sector_size_bits; + ni->itype.index.vcn_size =NTFS_BLOCK_SIZE ; + ni->itype.index.vcn_size_bits =NTFS_BLOCK_SIZE_BITS ; } }
@@ -569,7 +568,7 @@ static struct ntfs_inode *__ntfs_create(struct mnt_idmap *idmap, struct inode *dNTFS_B_TO_CLU (vol, ni->vol->index_record_size); else ir->clusters_per_index_block = - ni->vol->index_record_size >> ni->vol->sector_size_bits; + ni->vol->index_record_size >>NTFS_BLOCK_SIZE_BITS ; ir->index.entries_offset =cpu_to_le32 (sizeof (struct index_header )); ir->index.index_length =cpu_to_le32 (index_len); ir->index.allocated_size =cpu_to_le32 (index_len);
---
base-commit: 27d5cd2d940b53718f66fb682475587aa993d760
change-id: 20260918-fix-c8k-index-e91b078b1290
Best regards,
Signature · 2 lines
Thanks, Hyunchul
Quoted 128 lines · Hyunchul Lee
NTFS stores VCNs for index blocks smaller than their cluster in fixed 512-byte units, independent of logical sector size. Use correct block units when initializing and traversing these indexes so directory indexes are located correctly.
Verified on a Windows-created 4Kn/32KB-cluster NTFS volume that when the index block is smaller than the cluster, the VCN unit is 512 bytes.
Fixes 27d5cd2d940b ("ntfs: fix directory lookup on large-page systems")Signed-off-by Hyunchul Lee <[email protected]>---
Changes in v2:
- Add a Fixes and Cc tags--- fs/ntfs/index.c | 2 +- fs/ntfs/index.h | 2 +- fs/ntfs/inode.c | 8 ++++---- fs/ntfs/layout.h | 6 +++--- fs/ntfs/namei.c | 7 +++---- 5 files changed, 12 insertions(+), 13 deletions(-)fs/ntfs/index.c +1
-1@@ -852,7 +852,7 @@ int ntfs_index_lookup(const void *key, const u32 key_len, struct ntfs_index_contif (ni->vol->cluster_size <= icx->block_size) icx->vcn_size_bits = ni->vol->cluster_size_bits;else - icx->vcn_size_bits = ni->vol->sector_size_bits; + icx->vcn_size_bits =NTFS_BLOCK_SIZE_BITS ; icx->cr = ir->collation_rule;if (!ntfs_is_collation_rule_supported (icx->cr)) {fs/ntfs/index.h +1
-1@@ -37,7 +37,7 @@* (maximum is MAX_PARENT_VCN) * @ib_dirty: true if the current index block (@ia/@ib) was modified * @block_size: size of index blocks in bytes (from $INDEX_ROOT or $Boot) -* @vcn_size_bits: log2(cluster size) +* @vcn_size_bits: log2 of the VCN unit size * @sync_write: true if synchronous writeback is requested for this context * * @idx_ni is the index inode this context belongs to. fs/ntfs/inode.c +4
-4@@ -1021,8 +1021,8 @@ static int ntfs_read_locked_inode(struct inode *vi) ni->itype.index.vcn_size = vol->cluster_size; ni->itype.index.vcn_size_bits = vol->cluster_size_bits; }else { - ni->itype.index.vcn_size = vol->sector_size; - ni->itype.index.vcn_size_bits = vol->sector_size_bits; + ni->itype.index.vcn_size =NTFS_BLOCK_SIZE ; + ni->itype.index.vcn_size_bits =NTFS_BLOCK_SIZE_BITS ; }/* Setup the index allocation attribute, even if not present. */ @@ -1612,8 +1612,8 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi) ni->itype.index.vcn_size = vol->cluster_size; ni->itype.index.vcn_size_bits = vol->cluster_size_bits; }else { - ni->itype.index.vcn_size = vol->sector_size; - ni->itype.index.vcn_size_bits = vol->sector_size_bits; + ni->itype.index.vcn_size =NTFS_BLOCK_SIZE ; + ni->itype.index.vcn_size_bits =NTFS_BLOCK_SIZE_BITS ; }/* Find index allocation attribute. */ fs/ntfs/layout.h +3
-3@@ -1880,8 +1880,8 @@ struct index_header {* @index_block_size: Size of each index block in bytes * (in $INDEX_ALLOCATION). * @clusters_per_index_block: -* Clusters per index block (or log2(bytes) -* if < cluster). +* Clusters per index block, or 512-byte units when +* the index block is smaller than a cluster. * Power of 2; used for encoding block size. * @reserved: 3 bytes reserved/alignment (zero). * @index: Index header for root entries (entries follow @@ -1921,7 +1921,7 @@ struct index_root {* @lsn: Log sequence number of last modification. * @index_block_vcn: VCN of this index block. * Units: clusters if cluster_size <= index_block_size; -* sectors otherwise. +* 512-byte blocks otherwise. * @index: Index header describing entries in this block. * * When creating the index block, we place the update sequence array at this fs/ntfs/namei.c +3
-5@@ -433,9 +433,8 @@ static struct ntfs_inode *__ntfs_create(struct mnt_idmap *idmap, struct inode *d ni->itype.index.vcn_size_bits = vol->cluster_size_bits; }else { - ni->itype.index.vcn_size = vol->sector_size; - ni->itype.index.vcn_size_bits = - vol->sector_size_bits; + ni->itype.index.vcn_size =NTFS_BLOCK_SIZE ; + ni->itype.index.vcn_size_bits =NTFS_BLOCK_SIZE_BITS ; } }@@ -569,7 +568,7 @@ static struct ntfs_inode *__ntfs_create(struct mnt_idmap *idmap, struct inode *dNTFS_B_TO_CLU (vol, ni->vol->index_record_size); else ir->clusters_per_index_block = - ni->vol->index_record_size >> ni->vol->sector_size_bits; + ni->vol->index_record_size >>NTFS_BLOCK_SIZE_BITS ; ir->index.entries_offset =cpu_to_le32 (sizeof (struct index_header )); ir->index.index_length =cpu_to_le32 (index_len); ir->index.allocated_size =cpu_to_le32 (index_len); ---base-commit:
27d5cd2d940b53718f66fb682475587aa993d760
change-id: 20260918-fix-c8k-index-e91b078b1290
Quoted 1 line
Best regards,
Looks good to me.
Quoted 6 lines · Hyunchul Lee
NTFS stores VCNs for index blocks smaller than their cluster in fixed 512-byte units, independent of logical sector size. Use correct block units when initializing and traversing these indexes so directory indexes are located correctly.
Quoted 6 lines
Verified on a Windows-created 4Kn/32KB-cluster NTFS volume that when the index block is smaller than the cluster, the VCN unit is 512 bytes.
Fixes 27d5cd2d940b ("ntfs: fix directory lookup on large-page systems")Signed-off-by Hyunchul Lee <[email protected]>
Applied it to #ntfs-next.
Thanks.