Skip to content

Commit fd40282

Browse files
namjaejeon1Naim
authored andcommitted
ntfs: change mft_no type to u64
Changes the type of ntfs_inode::mft_no from unsigned long to u64 to safely handle the full 48-bit range without truncation risk, especially in preparation for broader VFS inode number type (i_ino:u64) and to improve consistency with ntfs driver practices. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent e9e4d5a commit fd40282

10 files changed

Lines changed: 119 additions & 128 deletions

File tree

fs/ntfs/aops.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static sector_t ntfs_bmap(struct address_space *mapping, sector_t block)
9696
unsigned int delta;
9797
unsigned char blocksize_bits;
9898

99-
ntfs_debug("Entering for mft_no 0x%lx, logical block 0x%llx.",
99+
ntfs_debug("Entering for mft_no 0x%llx, logical block 0x%llx.",
100100
ni->mft_no, (unsigned long long)block);
101101
if (ni->type != AT_DATA || !NInoNonResident(ni) || NInoEncrypted(ni) ||
102102
NInoMstProtected(ni)) {
@@ -144,12 +144,12 @@ static sector_t ntfs_bmap(struct address_space *mapping, sector_t block)
144144
goto hole;
145145
case LCN_ENOMEM:
146146
ntfs_error(vol->sb,
147-
"Not enough memory to complete mapping for inode 0x%lx. Returning 0.",
147+
"Not enough memory to complete mapping for inode 0x%llx. Returning 0.",
148148
ni->mft_no);
149149
break;
150150
default:
151151
ntfs_error(vol->sb,
152-
"Failed to complete mapping for inode 0x%lx. Run chkdsk. Returning 0.",
152+
"Failed to complete mapping for inode 0x%llx. Run chkdsk. Returning 0.",
153153
ni->mft_no);
154154
break;
155155
}

fs/ntfs/attrib.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ s64 ntfs_attr_vcn_to_lcn_nolock(struct ntfs_inode *ni, const s64 vcn,
370370
unsigned long flags;
371371
bool is_retry = false;
372372

373-
ntfs_debug("Entering for i_ino 0x%lx, vcn 0x%llx, %s_locked.",
373+
ntfs_debug("Entering for i_ino 0x%llx, vcn 0x%llx, %s_locked.",
374374
ni->mft_no, (unsigned long long)vcn,
375375
write_locked ? "write" : "read");
376376
if (!ni->runlist.rl) {
@@ -521,7 +521,7 @@ struct runlist_element *ntfs_attr_find_vcn_nolock(struct ntfs_inode *ni, const s
521521
int err = 0;
522522
bool is_retry = false;
523523

524-
ntfs_debug("Entering for i_ino 0x%lx, vcn 0x%llx, with%s ctx.",
524+
ntfs_debug("Entering for i_ino 0x%llx, vcn 0x%llx, with%s ctx.",
525525
ni->mft_no, (unsigned long long)vcn, ctx ? "" : "out");
526526
if (!ni->runlist.rl) {
527527
read_lock_irqsave(&ni->size_lock, flags);
@@ -679,8 +679,8 @@ static int ntfs_attr_find(const __le32 type, const __le16 *name,
679679
if (a->name_length && ((le16_to_cpu(a->name_offset) +
680680
a->name_length * sizeof(__le16)) >
681681
le32_to_cpu(a->length))) {
682-
ntfs_error(vol->sb, "Corrupt attribute name in MFT record %lld\n",
683-
(long long)ctx->ntfs_ino->mft_no);
682+
ntfs_error(vol->sb, "Corrupt attribute name in MFT record %llu\n",
683+
ctx->ntfs_ino->mft_no);
684684
break;
685685
}
686686

@@ -790,15 +790,15 @@ int load_attribute_list(struct ntfs_inode *base_ni, u8 *al_start, const s64 size
790790
attr_vi = ntfs_attr_iget(VFS_I(base_ni), AT_ATTRIBUTE_LIST, AT_UNNAMED, 0);
791791
if (IS_ERR(attr_vi)) {
792792
ntfs_error(base_ni->vol->sb,
793-
"Failed to open an inode for Attribute list, mft = %ld",
793+
"Failed to open an inode for Attribute list, mft = %llu",
794794
base_ni->mft_no);
795795
return PTR_ERR(attr_vi);
796796
}
797797

798798
if (ntfs_inode_attr_pread(attr_vi, 0, size, al_start) != size) {
799799
iput(attr_vi);
800800
ntfs_error(base_ni->vol->sb,
801-
"Failed to read attribute list, mft = %ld",
801+
"Failed to read attribute list, mft = %llu",
802802
base_ni->mft_no);
803803
return -EIO;
804804
}
@@ -817,7 +817,7 @@ int load_attribute_list(struct ntfs_inode *base_ni, u8 *al_start, const s64 size
817817
break;
818818
}
819819
if (al != al_start + size) {
820-
ntfs_error(base_ni->vol->sb, "Corrupt attribute list, mft = %ld",
820+
ntfs_error(base_ni->vol->sb, "Corrupt attribute list, mft = %llu",
821821
base_ni->mft_no);
822822
return -EIO;
823823
}
@@ -890,7 +890,7 @@ static int ntfs_external_attr_find(const __le32 type,
890890
int err = 0;
891891
static const char *es = " Unmount and run chkdsk.";
892892

893-
ntfs_debug("Entering for inode 0x%lx, type 0x%x.", ni->mft_no, type);
893+
ntfs_debug("Entering for inode 0x%llx, type 0x%x.", ni->mft_no, type);
894894
if (!base_ni) {
895895
/* First call happens with the base mft record. */
896896
base_ni = ctx->base_ntfs_ino = ctx->ntfs_ino;
@@ -1090,7 +1090,7 @@ static int ntfs_external_attr_find(const __le32 type,
10901090
if (MREF_LE(al_entry->mft_reference) == ni->mft_no) {
10911091
if (MSEQNO_LE(al_entry->mft_reference) != ni->seq_no) {
10921092
ntfs_error(vol->sb,
1093-
"Found stale mft reference in attribute list of base inode 0x%lx.%s",
1093+
"Found stale mft reference in attribute list of base inode 0x%llx.%s",
10941094
base_ni->mft_no, es);
10951095
err = -EIO;
10961096
break;
@@ -1112,7 +1112,7 @@ static int ntfs_external_attr_find(const __le32 type,
11121112
al_entry->mft_reference), &ni);
11131113
if (IS_ERR(ctx->mrec)) {
11141114
ntfs_error(vol->sb,
1115-
"Failed to map extent mft record 0x%lx of base inode 0x%lx.%s",
1115+
"Failed to map extent mft record 0x%lx of base inode 0x%llx.%s",
11161116
MREF_LE(al_entry->mft_reference),
11171117
base_ni->mft_no, es);
11181118
err = PTR_ERR(ctx->mrec);
@@ -1201,7 +1201,7 @@ static int ntfs_external_attr_find(const __le32 type,
12011201

12021202
if (!err) {
12031203
ntfs_error(vol->sb,
1204-
"Base inode 0x%lx contains corrupt attribute list attribute.%s",
1204+
"Base inode 0x%llx contains corrupt attribute list attribute.%s",
12051205
base_ni->mft_no, es);
12061206
err = -EIO;
12071207
}
@@ -3497,7 +3497,7 @@ int ntfs_attr_update_mapping_pairs(struct ntfs_inode *ni, s64 from_vcn)
34973497
* delete extent) and continue search.
34983498
*/
34993499
if (finished_build) {
3500-
ntfs_debug("Mark attr 0x%x for delete in inode 0x%lx.\n",
3500+
ntfs_debug("Mark attr 0x%x for delete in inode 0x%llx.\n",
35013501
(unsigned int)le32_to_cpu(a->type), ctx->ntfs_ino->mft_no);
35023502
a->data.non_resident.highest_vcn = cpu_to_le64(NTFS_VCN_DELETE_MARK);
35033503
mark_mft_record_dirty(ctx->ntfs_ino);
@@ -4728,7 +4728,7 @@ int ntfs_attr_map_cluster(struct ntfs_inode *ni, s64 vcn_start, s64 *lcn_start,
47284728
CASE_SENSITIVE, vcn, NULL, 0, ctx);
47294729
if (err) {
47304730
ntfs_error(vol->sb,
4731-
"ntfs_attr_lookup failed, ntfs inode(mft_no : %ld) type : 0x%x, err : %d",
4731+
"ntfs_attr_lookup failed, ntfs inode(mft_no : %llu) type : 0x%x, err : %d",
47324732
ni->mft_no, ni->type, err);
47334733
goto out;
47344734
}

fs/ntfs/compress.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ int ntfs_read_compressed_block(struct folio *folio)
797797
*/
798798
if (err) {
799799
ntfs_error(vol->sb,
800-
"ntfs_decompress() failed in inode 0x%lx with error code %i. Skipping this compression block.",
800+
"ntfs_decompress() failed in inode 0x%llx with error code %i. Skipping this compression block.",
801801
ni->mft_no, -err);
802802
/* Release the unfinished pages. */
803803
for (; prev_cur_page < cur_page; prev_cur_page++) {
@@ -823,7 +823,7 @@ int ntfs_read_compressed_block(struct folio *folio)
823823
page = pages[cur_page];
824824
if (page) {
825825
ntfs_error(vol->sb,
826-
"Still have pages left! Terminating them with extreme prejudice. Inode 0x%lx, page index 0x%lx.",
826+
"Still have pages left! Terminating them with extreme prejudice. Inode 0x%llx, page index 0x%lx.",
827827
ni->mft_no, page->__folio_index);
828828
flush_dcache_page(page);
829829
kunmap_local(page_address(page));

fs/ntfs/dir.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname,
102102
if (unlikely(err)) {
103103
if (err == -ENOENT) {
104104
ntfs_error(sb,
105-
"Index root attribute missing in directory inode 0x%lx.",
105+
"Index root attribute missing in directory inode 0x%llx.",
106106
dir_ni->mft_no);
107107
err = -EIO;
108108
}
@@ -338,45 +338,45 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname,
338338
/* Bounds checks. */
339339
if ((u8 *)ia < kaddr || (u8 *)ia > kaddr + PAGE_SIZE) {
340340
ntfs_error(sb,
341-
"Out of bounds check failed. Corrupt directory inode 0x%lx or driver bug.",
341+
"Out of bounds check failed. Corrupt directory inode 0x%llx or driver bug.",
342342
dir_ni->mft_no);
343343
goto unm_err_out;
344344
}
345345
/* Catch multi sector transfer fixup errors. */
346346
if (unlikely(!ntfs_is_indx_record(ia->magic))) {
347347
ntfs_error(sb,
348-
"Directory index record with vcn 0x%llx is corrupt. Corrupt inode 0x%lx. Run chkdsk.",
349-
(unsigned long long)vcn, dir_ni->mft_no);
348+
"Directory index record with vcn 0x%llx is corrupt. Corrupt inode 0x%llx. Run chkdsk.",
349+
vcn, dir_ni->mft_no);
350350
goto unm_err_out;
351351
}
352352
if (le64_to_cpu(ia->index_block_vcn) != vcn) {
353353
ntfs_error(sb,
354-
"Actual VCN (0x%llx) of index buffer is different from expected VCN (0x%llx). Directory inode 0x%lx is corrupt or driver bug.",
355-
(unsigned long long)le64_to_cpu(ia->index_block_vcn),
356-
(unsigned long long)vcn, dir_ni->mft_no);
354+
"Actual VCN (0x%llx) of index buffer is different from expected VCN (0x%llx). Directory inode 0x%llx is corrupt or driver bug.",
355+
le64_to_cpu(ia->index_block_vcn),
356+
vcn, dir_ni->mft_no);
357357
goto unm_err_out;
358358
}
359359
if (le32_to_cpu(ia->index.allocated_size) + 0x18 !=
360360
dir_ni->itype.index.block_size) {
361361
ntfs_error(sb,
362-
"Index buffer (VCN 0x%llx) of directory inode 0x%lx has a size (%u) differing from the directory specified size (%u). Directory inode is corrupt or driver bug.",
363-
(unsigned long long)vcn, dir_ni->mft_no,
362+
"Index buffer (VCN 0x%llx) of directory inode 0x%llx has a size (%u) differing from the directory specified size (%u). Directory inode is corrupt or driver bug.",
363+
vcn, dir_ni->mft_no,
364364
le32_to_cpu(ia->index.allocated_size) + 0x18,
365365
dir_ni->itype.index.block_size);
366366
goto unm_err_out;
367367
}
368368
index_end = (u8 *)ia + dir_ni->itype.index.block_size;
369369
if (index_end > kaddr + PAGE_SIZE) {
370370
ntfs_error(sb,
371-
"Index buffer (VCN 0x%llx) of directory inode 0x%lx crosses page boundary. Impossible! Cannot access! This is probably a bug in the driver.",
372-
(unsigned long long)vcn, dir_ni->mft_no);
371+
"Index buffer (VCN 0x%llx) of directory inode 0x%llx crosses page boundary. Impossible! Cannot access! This is probably a bug in the driver.",
372+
vcn, dir_ni->mft_no);
373373
goto unm_err_out;
374374
}
375375
index_end = (u8 *)&ia->index + le32_to_cpu(ia->index.index_length);
376376
if (index_end > (u8 *)ia + dir_ni->itype.index.block_size) {
377377
ntfs_error(sb,
378-
"Size of index buffer (VCN 0x%llx) of directory inode 0x%lx exceeds maximum size.",
379-
(unsigned long long)vcn, dir_ni->mft_no);
378+
"Size of index buffer (VCN 0x%llx) of directory inode 0x%llx exceeds maximum size.",
379+
vcn, dir_ni->mft_no);
380380
goto unm_err_out;
381381
}
382382
/* The first index entry. */
@@ -393,7 +393,7 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname,
393393
(u8 *)ie + sizeof(struct index_entry_header) > index_end ||
394394
(u8 *)ie + sizeof(struct index_entry_header) + le16_to_cpu(ie->key_length) >
395395
index_end || (u8 *)ie + le16_to_cpu(ie->length) > index_end) {
396-
ntfs_error(sb, "Index entry out of bounds in directory inode 0x%lx.",
396+
ntfs_error(sb, "Index entry out of bounds in directory inode 0x%llx.",
397397
dir_ni->mft_no);
398398
goto unm_err_out;
399399
}
@@ -546,7 +546,7 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname,
546546
if (ie->flags & INDEX_ENTRY_NODE) {
547547
if ((ia->index.flags & NODE_MASK) == LEAF_NODE) {
548548
ntfs_error(sb,
549-
"Index entry with child node found in a leaf node in directory inode 0x%lx.",
549+
"Index entry with child node found in a leaf node in directory inode 0x%llx.",
550550
dir_ni->mft_no);
551551
goto unm_err_out;
552552
}
@@ -566,7 +566,7 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_ni, const __le16 *uname,
566566
kaddr = NULL;
567567
goto descend_into_child_node;
568568
}
569-
ntfs_error(sb, "Negative child node vcn in directory inode 0x%lx.",
569+
ntfs_error(sb, "Negative child node vcn in directory inode 0x%llx.",
570570
dir_ni->mft_no);
571571
goto unm_err_out;
572572
}
@@ -863,7 +863,7 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
863863
/* Find the index root attribute in the mft record. */
864864
if (ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL, 0,
865865
ctx)) {
866-
ntfs_error(sb, "Index root attribute missing in directory inode %ld",
866+
ntfs_error(sb, "Index root attribute missing in directory inode %llu",
867867
ndir->mft_no);
868868
ntfs_attr_put_search_ctx(ctx);
869869
err = -ENOMEM;
@@ -1062,8 +1062,8 @@ int ntfs_check_empty_dir(struct ntfs_inode *ni, struct mft_record *ni_mrec)
10621062
ret = ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
10631063
0, ctx);
10641064
if (ret) {
1065-
ntfs_error(ni->vol->sb, "Index root attribute missing in directory inode %lld",
1066-
(unsigned long long)ni->mft_no);
1065+
ntfs_error(ni->vol->sb, "Index root attribute missing in directory inode %llu",
1066+
ni->mft_no);
10671067
ntfs_attr_put_search_ctx(ctx);
10681068
return ret;
10691069
}

0 commit comments

Comments
 (0)