From b76883dc84e1a5df853dbf4bc247afa6a9e797fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Pierre=20Andr=C3=A9?= Date: Fri, 4 Nov 2011 11:01:11 +0100 Subject: [PATCH] major : Fixed computation of index block size (Anton Altaparmakov) When the cluster size is bigger than the index block size, the index block size unit is 512 (not the sector size) instead of the cluster size. The partitions formatted by mkntfs and used by ntfs-3g were not interoperable with Windows when the cluster size is bigger than 4K and the sector size is not 512. --- libntfs-3g/dir.c | 6 +++--- libntfs-3g/index.c | 2 +- ntfsprogs/mkntfs.c | 6 +++--- ntfsprogs/ntfsinfo.c | 8 +++++++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 1838849c..ccae47c3 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -380,7 +380,7 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, if (vol->cluster_size <= index_block_size) { index_vcn_size_bits = vol->cluster_size_bits; } else { - index_vcn_size_bits = vol->sector_size_bits; + index_vcn_size_bits = NTFS_BLOCK_SIZE_BITS; } /* Get the starting vcn of the index_block holding the child node. */ @@ -1131,7 +1131,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, if (vol->cluster_size <= index_block_size) { index_vcn_size_bits = vol->cluster_size_bits; } else { - index_vcn_size_bits = vol->sector_size_bits; + index_vcn_size_bits = NTFS_BLOCK_SIZE_BITS; } /* Are we jumping straight into the index allocation attribute? */ @@ -1513,7 +1513,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, else ir->clusters_per_index_block = ni->vol->indx_record_size >> - ni->vol->sector_size_bits; + NTFS_BLOCK_SIZE_BITS; ir->index.entries_offset = cpu_to_le32(sizeof(INDEX_HEADER)); ir->index.index_length = cpu_to_le32(index_len); ir->index.allocated_size = cpu_to_le32(index_len); diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index 01438a08..d498dde4 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -701,7 +701,7 @@ int ntfs_index_lookup(const void *key, const int key_len, ntfs_index_context *ic if (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; /* get the appropriate collation function */ icx->collate = ntfs_get_collate_function(ir->collation_rule); if (!icx->collate) { diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index e3078b8d..d8a6b3c2 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -1,7 +1,7 @@ /** * mkntfs - Part of the Linux-NTFS project. * - * Copyright (c) 2000-2007 Anton Altaparmakov + * Copyright (c) 2000-2011 Anton Altaparmakov * Copyright (c) 2001-2005 Richard Russon * Copyright (c) 2002-2006 Szabolcs Szakacsits * Copyright (c) 2005 Erik Sornes @@ -2242,8 +2242,8 @@ static int add_attr_index_root(MFT_RECORD *m, const char *name, free(r); return -EINVAL; } - r->clusters_per_index_block = index_block_size / - opts.sector_size; + r->clusters_per_index_block = index_block_size + >> NTFS_BLOCK_SIZE_BITS; } memset(&r->reserved, 0, sizeof(r->reserved)); r->index.entries_offset = const_cpu_to_le32(sizeof(INDEX_HEADER)); diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index e513e29b..7f89378b 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -415,6 +415,7 @@ static void ntfs_dump_volume(ntfs_volume *vol) printf("\tVolume Version: %u.%u\n", vol->major_ver, vol->minor_ver); printf("\tSector Size: %hu\n", vol->sector_size); printf("\tCluster Size: %u\n", (unsigned int)vol->cluster_size); + printf("\tIndex Block Size: %u\n", (unsigned int)vol->indx_record_size); printf("\tVolume Size in Clusters: %lld\n", (long long)vol->nr_clusters); @@ -1752,7 +1753,12 @@ static void ntfs_dump_attr_index_root(ATTR_RECORD *attr, ntfs_inode *ni) printf("\tIndex Block Size:\t %u (0x%x)\n", (unsigned)le32_to_cpu(index_root->index_block_size), (unsigned)le32_to_cpu(index_root->index_block_size)); - printf("\tClusters Per Block:\t %u (0x%x)\n", + if (le32_to_cpu(index_root->index_block_size) < ni->vol->cluster_size) + printf("\t512-byte Units Per Block:\t %u (0x%x)\n", + (unsigned)index_root->clusters_per_index_block, + (unsigned)index_root->clusters_per_index_block); + else + printf("\tClusters Per Block:\t %u (0x%x)\n", (unsigned)index_root->clusters_per_index_block, (unsigned)index_root->clusters_per_index_block); -- 2.11.0