Skip to content

Commit de30c57

Browse files
committed
Merge branch 'melt-rebase-ntfs3' into melt-rebase
2 parents 5cc1554 + 45f6af8 commit de30c57

File tree

6 files changed

+44
-31
lines changed

6 files changed

+44
-31
lines changed

fs/ntfs3/bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits)
661661
wnd->total_zeroes = nbits;
662662
wnd->extent_max = MINUS_ONE_T;
663663
wnd->zone_bit = wnd->zone_end = 0;
664-
wnd->nwnd = bytes_to_block(sb, bitmap_size(nbits));
664+
wnd->nwnd = bytes_to_block(sb, ntfs3_bitmap_size(nbits));
665665
wnd->bits_last = nbits & (wbits - 1);
666666
if (!wnd->bits_last)
667667
wnd->bits_last = wbits;
@@ -1325,7 +1325,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
13251325
return -EINVAL;
13261326

13271327
/* Align to 8 byte boundary. */
1328-
new_wnd = bytes_to_block(sb, bitmap_size(new_bits));
1328+
new_wnd = bytes_to_block(sb, ntfs3_bitmap_size(new_bits));
13291329
new_last = new_bits & (wbits - 1);
13301330
if (!new_last)
13311331
new_last = wbits;

fs/ntfs3/dir.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,12 @@ struct inode *dir_search_u(struct inode *dir, const struct cpu_str *uni,
272272
return err == -ENOENT ? NULL : err ? ERR_PTR(err) : inode;
273273
}
274274

275-
static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
276-
const struct NTFS_DE *e, u8 *name,
277-
struct dir_context *ctx)
275+
/*
276+
* returns false if 'ctx' if full
277+
*/
278+
static inline bool ntfs_dir_emit(struct ntfs_sb_info *sbi,
279+
struct ntfs_inode *ni, const struct NTFS_DE *e,
280+
u8 *name, struct dir_context *ctx)
278281
{
279282
const struct ATTR_FILE_NAME *fname;
280283
unsigned long ino;
@@ -284,29 +287,29 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
284287
fname = Add2Ptr(e, sizeof(struct NTFS_DE));
285288

286289
if (fname->type == FILE_NAME_DOS)
287-
return 0;
290+
return true;
288291

289292
if (!mi_is_ref(&ni->mi, &fname->home))
290-
return 0;
293+
return true;
291294

292295
ino = ino_get(&e->ref);
293296

294297
if (ino == MFT_REC_ROOT)
295-
return 0;
298+
return true;
296299

297300
/* Skip meta files. Unless option to show metafiles is set. */
298301
if (!sbi->options->showmeta && ntfs_is_meta_file(sbi, ino))
299-
return 0;
302+
return true;
300303

301304
if (sbi->options->nohidden && (fname->dup.fa & FILE_ATTRIBUTE_HIDDEN))
302-
return 0;
305+
return true;
303306

304307
name_len = ntfs_utf16_to_nls(sbi, fname->name, fname->name_len, name,
305308
PATH_MAX);
306309
if (name_len <= 0) {
307310
ntfs_warn(sbi->sb, "failed to convert name for inode %lx.",
308311
ino);
309-
return 0;
312+
return true;
310313
}
311314

312315
/*
@@ -336,30 +339,33 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
336339
}
337340
}
338341

339-
return !dir_emit(ctx, (s8 *)name, name_len, ino, dt_type);
342+
return dir_emit(ctx, (s8 *)name, name_len, ino, dt_type);
340343
}
341344

342345
/*
343346
* ntfs_read_hdr - Helper function for ntfs_readdir().
347+
*
348+
* returns 0 if ok.
349+
* returns -EINVAL if directory is corrupted.
350+
* returns +1 if 'ctx' is full.
344351
*/
345352
static int ntfs_read_hdr(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
346353
const struct INDEX_HDR *hdr, u64 vbo, u64 pos,
347354
u8 *name, struct dir_context *ctx)
348355
{
349-
int err;
350356
const struct NTFS_DE *e;
351357
u32 e_size;
352358
u32 end = le32_to_cpu(hdr->used);
353359
u32 off = le32_to_cpu(hdr->de_off);
354360

355361
for (;; off += e_size) {
356362
if (off + sizeof(struct NTFS_DE) > end)
357-
return -1;
363+
return -EINVAL;
358364

359365
e = Add2Ptr(hdr, off);
360366
e_size = le16_to_cpu(e->size);
361367
if (e_size < sizeof(struct NTFS_DE) || off + e_size > end)
362-
return -1;
368+
return -EINVAL;
363369

364370
if (de_is_last(e))
365371
return 0;
@@ -369,14 +375,15 @@ static int ntfs_read_hdr(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
369375
continue;
370376

371377
if (le16_to_cpu(e->key_size) < SIZEOF_ATTRIBUTE_FILENAME)
372-
return -1;
378+
return -EINVAL;
373379

374380
ctx->pos = vbo + off;
375381

376382
/* Submit the name to the filldir callback. */
377-
err = ntfs_filldir(sbi, ni, e, name, ctx);
378-
if (err)
379-
return err;
383+
if (!ntfs_dir_emit(sbi, ni, e, name, ctx)) {
384+
/* ctx is full. */
385+
return +1;
386+
}
380387
}
381388
}
382389

@@ -475,8 +482,6 @@ static int ntfs_readdir(struct file *file, struct dir_context *ctx)
475482

476483
vbo = (u64)bit << index_bits;
477484
if (vbo >= i_size) {
478-
ntfs_inode_err(dir, "Looks like your dir is corrupt");
479-
ctx->pos = eod;
480485
err = -EINVAL;
481486
goto out;
482487
}
@@ -499,9 +504,16 @@ static int ntfs_readdir(struct file *file, struct dir_context *ctx)
499504
__putname(name);
500505
put_indx_node(node);
501506

502-
if (err == -ENOENT) {
507+
if (err == 1) {
508+
/* 'ctx' is full. */
509+
err = 0;
510+
} else if (err == -ENOENT) {
503511
err = 0;
504512
ctx->pos = pos;
513+
} else if (err < 0) {
514+
if (err == -EINVAL)
515+
ntfs_inode_err(dir, "directory corrupted");
516+
ctx->pos = eod;
505517
}
506518

507519
return err;

fs/ntfs3/fsntfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static int ntfs_extend_mft(struct ntfs_sb_info *sbi)
493493
ni->mi.dirty = true;
494494

495495
/* Step 2: Resize $MFT::BITMAP. */
496-
new_bitmap_bytes = bitmap_size(new_mft_total);
496+
new_bitmap_bytes = ntfs3_bitmap_size(new_mft_total);
497497

498498
err = attr_set_size(ni, ATTR_BITMAP, NULL, 0, &sbi->mft.bitmap.run,
499499
new_bitmap_bytes, &new_bitmap_bytes, true, NULL);

fs/ntfs3/index.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,8 +1461,8 @@ static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
14611461

14621462
alloc->nres.valid_size = alloc->nres.data_size = cpu_to_le64(data_size);
14631463

1464-
err = ni_insert_resident(ni, bitmap_size(1), ATTR_BITMAP, in->name,
1465-
in->name_len, &bitmap, NULL, NULL);
1464+
err = ni_insert_resident(ni, ntfs3_bitmap_size(1), ATTR_BITMAP,
1465+
in->name, in->name_len, &bitmap, NULL, NULL);
14661466
if (err)
14671467
goto out2;
14681468

@@ -1523,8 +1523,9 @@ static int indx_add_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,
15231523
if (bmp) {
15241524
/* Increase bitmap. */
15251525
err = attr_set_size(ni, ATTR_BITMAP, in->name, in->name_len,
1526-
&indx->bitmap_run, bitmap_size(bit + 1),
1527-
NULL, true, NULL);
1526+
&indx->bitmap_run,
1527+
ntfs3_bitmap_size(bit + 1), NULL, true,
1528+
NULL);
15281529
if (err)
15291530
goto out1;
15301531
}
@@ -2087,7 +2088,7 @@ static int indx_shrink(struct ntfs_index *indx, struct ntfs_inode *ni,
20872088
if (err)
20882089
return err;
20892090

2090-
bpb = bitmap_size(bit);
2091+
bpb = ntfs3_bitmap_size(bit);
20912092
if (bpb * 8 == nbits)
20922093
return 0;
20932094

fs/ntfs3/ntfs_fs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,9 @@ static inline bool run_is_empty(struct runs_tree *run)
950950
}
951951

952952
/* NTFS uses quad aligned bitmaps. */
953-
static inline size_t bitmap_size(size_t bits)
953+
static inline size_t ntfs3_bitmap_size(size_t bits)
954954
{
955-
return ALIGN((bits + 7) >> 3, 8);
955+
return BITS_TO_U64(bits) * sizeof(u64);
956956
}
957957

958958
#define _100ns2seconds 10000000

fs/ntfs3/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
11031103

11041104
/* Check bitmap boundary. */
11051105
tt = sbi->used.bitmap.nbits;
1106-
if (inode->i_size < bitmap_size(tt)) {
1106+
if (inode->i_size < ntfs3_bitmap_size(tt)) {
11071107
err = -EINVAL;
11081108
goto put_inode_out;
11091109
}

0 commit comments

Comments
 (0)