Skip to content

Commit 88db845

Browse files
committed
Merge tag 'exfat-for-5.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat
Pull exfat updates from Namjae Jeon: - Fix ->i_blocks truncation issue that still exists elsewhere. - Four cleanups & typos fixes. - Move super block magic number to magic.h - Fix missing REQ_SYNC in exfat_update_bhs(). * tag 'exfat-for-5.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat: exfat: fix missing REQ_SYNC in exfat_update_bhs() exfat: remove argument 'sector' from exfat_get_dentry() exfat: move super block magic number to magic.h exfat: fix i_blocks for files truncated over 4 GiB exfat: reuse exfat_inode_info variable instead of calling EXFAT_I() exfat: make exfat_find_location() static exfat: fix typos in comments exfat: simplify is_valid_cluster()
2 parents 175398a + 3d96652 commit 88db845

File tree

11 files changed

+65
-87
lines changed

11 files changed

+65
-87
lines changed

fs/exfat/balloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int exfat_load_bitmap(struct super_block *sb)
105105
struct exfat_dentry *ep;
106106
struct buffer_head *bh;
107107

108-
ep = exfat_get_dentry(sb, &clu, i, &bh, NULL);
108+
ep = exfat_get_dentry(sb, &clu, i, &bh);
109109
if (!ep)
110110
return -EIO;
111111

fs/exfat/dir.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
6464
{
6565
int i, dentries_per_clu, dentries_per_clu_bits = 0, num_ext;
6666
unsigned int type, clu_offset, max_dentries;
67-
sector_t sector;
6867
struct exfat_chain dir, clu;
6968
struct exfat_uni_name uni_name;
7069
struct exfat_dentry *ep;
@@ -115,7 +114,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
115114
i = dentry & (dentries_per_clu - 1);
116115

117116
for ( ; i < dentries_per_clu; i++, dentry++) {
118-
ep = exfat_get_dentry(sb, &clu, i, &bh, &sector);
117+
ep = exfat_get_dentry(sb, &clu, i, &bh);
119118
if (!ep)
120119
return -EIO;
121120

@@ -156,7 +155,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
156155
dir_entry->namebuf.lfnbuf_len);
157156
brelse(bh);
158157

159-
ep = exfat_get_dentry(sb, &clu, i + 1, &bh, NULL);
158+
ep = exfat_get_dentry(sb, &clu, i + 1, &bh);
160159
if (!ep)
161160
return -EIO;
162161
dir_entry->size =
@@ -445,15 +444,14 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir,
445444
struct super_block *sb = inode->i_sb;
446445
struct exfat_sb_info *sbi = EXFAT_SB(sb);
447446
struct timespec64 ts = current_time(inode);
448-
sector_t sector;
449447
struct exfat_dentry *ep;
450448
struct buffer_head *bh;
451449

452450
/*
453451
* We cannot use exfat_get_dentry_set here because file ep is not
454452
* initialized yet.
455453
*/
456-
ep = exfat_get_dentry(sb, p_dir, entry, &bh, &sector);
454+
ep = exfat_get_dentry(sb, p_dir, entry, &bh);
457455
if (!ep)
458456
return -EIO;
459457

@@ -477,7 +475,7 @@ int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir,
477475
exfat_update_bh(bh, IS_DIRSYNC(inode));
478476
brelse(bh);
479477

480-
ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh, &sector);
478+
ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh);
481479
if (!ep)
482480
return -EIO;
483481

@@ -496,20 +494,19 @@ int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir,
496494
struct super_block *sb = inode->i_sb;
497495
int ret = 0;
498496
int i, num_entries;
499-
sector_t sector;
500497
u16 chksum;
501498
struct exfat_dentry *ep, *fep;
502499
struct buffer_head *fbh, *bh;
503500

504-
fep = exfat_get_dentry(sb, p_dir, entry, &fbh, &sector);
501+
fep = exfat_get_dentry(sb, p_dir, entry, &fbh);
505502
if (!fep)
506503
return -EIO;
507504

508505
num_entries = fep->dentry.file.num_ext + 1;
509506
chksum = exfat_calc_chksum16(fep, DENTRY_SIZE, 0, CS_DIR_ENTRY);
510507

511508
for (i = 1; i < num_entries; i++) {
512-
ep = exfat_get_dentry(sb, p_dir, entry + i, &bh, NULL);
509+
ep = exfat_get_dentry(sb, p_dir, entry + i, &bh);
513510
if (!ep) {
514511
ret = -EIO;
515512
goto release_fbh;
@@ -531,21 +528,20 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
531528
{
532529
struct super_block *sb = inode->i_sb;
533530
int i;
534-
sector_t sector;
535531
unsigned short *uniname = p_uniname->name;
536532
struct exfat_dentry *ep;
537533
struct buffer_head *bh;
538534
int sync = IS_DIRSYNC(inode);
539535

540-
ep = exfat_get_dentry(sb, p_dir, entry, &bh, &sector);
536+
ep = exfat_get_dentry(sb, p_dir, entry, &bh);
541537
if (!ep)
542538
return -EIO;
543539

544540
ep->dentry.file.num_ext = (unsigned char)(num_entries - 1);
545541
exfat_update_bh(bh, sync);
546542
brelse(bh);
547543

548-
ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh, &sector);
544+
ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh);
549545
if (!ep)
550546
return -EIO;
551547

@@ -555,7 +551,7 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir,
555551
brelse(bh);
556552

557553
for (i = EXFAT_FIRST_CLUSTER; i < num_entries; i++) {
558-
ep = exfat_get_dentry(sb, p_dir, entry + i, &bh, &sector);
554+
ep = exfat_get_dentry(sb, p_dir, entry + i, &bh);
559555
if (!ep)
560556
return -EIO;
561557

@@ -574,12 +570,11 @@ int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir,
574570
{
575571
struct super_block *sb = inode->i_sb;
576572
int i;
577-
sector_t sector;
578573
struct exfat_dentry *ep;
579574
struct buffer_head *bh;
580575

581576
for (i = order; i < num_entries; i++) {
582-
ep = exfat_get_dentry(sb, p_dir, entry + i, &bh, &sector);
577+
ep = exfat_get_dentry(sb, p_dir, entry + i, &bh);
583578
if (!ep)
584579
return -EIO;
585580

@@ -656,8 +651,8 @@ static int exfat_walk_fat_chain(struct super_block *sb,
656651
return 0;
657652
}
658653

659-
int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir,
660-
int entry, sector_t *sector, int *offset)
654+
static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir,
655+
int entry, sector_t *sector, int *offset)
661656
{
662657
int ret;
663658
unsigned int off, clu = 0;
@@ -717,8 +712,7 @@ static int exfat_dir_readahead(struct super_block *sb, sector_t sec)
717712
}
718713

719714
struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
720-
struct exfat_chain *p_dir, int entry, struct buffer_head **bh,
721-
sector_t *sector)
715+
struct exfat_chain *p_dir, int entry, struct buffer_head **bh)
722716
{
723717
unsigned int dentries_per_page = EXFAT_B_TO_DEN(PAGE_SIZE);
724718
int off;
@@ -740,8 +734,6 @@ struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
740734
if (!*bh)
741735
return NULL;
742736

743-
if (sector)
744-
*sector = sec;
745737
return (struct exfat_dentry *)((*bh)->b_data + off);
746738
}
747739

@@ -892,7 +884,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
892884
es->bh[es->num_bh++] = bh;
893885
}
894886

895-
/* validiate cached dentries */
887+
/* validate cached dentries */
896888
for (i = 1; i < num_entries; i++) {
897889
ep = exfat_get_dentry_cached(es, i);
898890
if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode))
@@ -960,7 +952,7 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
960952
if (rewind && dentry == end_eidx)
961953
goto not_found;
962954

963-
ep = exfat_get_dentry(sb, &clu, i, &bh, NULL);
955+
ep = exfat_get_dentry(sb, &clu, i, &bh);
964956
if (!ep)
965957
return -EIO;
966958

@@ -1145,7 +1137,7 @@ int exfat_count_ext_entries(struct super_block *sb, struct exfat_chain *p_dir,
11451137
struct buffer_head *bh;
11461138

11471139
for (i = 0, entry++; i < ep->dentry.file.num_ext; i++, entry++) {
1148-
ext_ep = exfat_get_dentry(sb, p_dir, entry, &bh, NULL);
1140+
ext_ep = exfat_get_dentry(sb, p_dir, entry, &bh);
11491141
if (!ext_ep)
11501142
return -EIO;
11511143

@@ -1175,7 +1167,7 @@ int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir)
11751167

11761168
while (clu.dir != EXFAT_EOF_CLUSTER) {
11771169
for (i = 0; i < dentries_per_clu; i++) {
1178-
ep = exfat_get_dentry(sb, &clu, i, &bh, NULL);
1170+
ep = exfat_get_dentry(sb, &clu, i, &bh);
11791171
if (!ep)
11801172
return -EIO;
11811173
entry_type = exfat_get_entry_type(ep);

fs/exfat/exfat_fs.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <linux/ratelimit.h>
1111
#include <linux/nls.h>
1212

13-
#define EXFAT_SUPER_MAGIC 0x2011BAB0UL
1413
#define EXFAT_ROOT_INO 1
1514

1615
#define EXFAT_CLUSTERS_UNTRACKED (~0u)
@@ -459,11 +458,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
459458
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
460459
int num_entries, unsigned int type, struct exfat_hint *hint_opt);
461460
int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu);
462-
int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir,
463-
int entry, sector_t *sector, int *offset);
464461
struct exfat_dentry *exfat_get_dentry(struct super_block *sb,
465-
struct exfat_chain *p_dir, int entry, struct buffer_head **bh,
466-
sector_t *sector);
462+
struct exfat_chain *p_dir, int entry, struct buffer_head **bh);
467463
struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
468464
int num);
469465
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,

fs/exfat/fatent.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ int exfat_ent_set(struct super_block *sb, unsigned int loc,
8484
static inline bool is_valid_cluster(struct exfat_sb_info *sbi,
8585
unsigned int clus)
8686
{
87-
if (clus < EXFAT_FIRST_CLUSTER || sbi->num_clusters <= clus)
88-
return false;
89-
return true;
87+
return clus >= EXFAT_FIRST_CLUSTER && clus < sbi->num_clusters;
9088
}
9189

9290
int exfat_ent_get(struct super_block *sb, unsigned int loc,

fs/exfat/file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
110110
exfat_set_volume_dirty(sb);
111111

112112
num_clusters_new = EXFAT_B_TO_CLU_ROUND_UP(i_size_read(inode), sbi);
113-
num_clusters_phys =
114-
EXFAT_B_TO_CLU_ROUND_UP(EXFAT_I(inode)->i_size_ondisk, sbi);
113+
num_clusters_phys = EXFAT_B_TO_CLU_ROUND_UP(ei->i_size_ondisk, sbi);
115114

116115
exfat_chain_set(&clu, ei->start_clu, num_clusters_phys, ei->flags);
117116

@@ -228,12 +227,13 @@ void exfat_truncate(struct inode *inode, loff_t size)
228227
{
229228
struct super_block *sb = inode->i_sb;
230229
struct exfat_sb_info *sbi = EXFAT_SB(sb);
230+
struct exfat_inode_info *ei = EXFAT_I(inode);
231231
unsigned int blocksize = i_blocksize(inode);
232232
loff_t aligned_size;
233233
int err;
234234

235235
mutex_lock(&sbi->s_lock);
236-
if (EXFAT_I(inode)->start_clu == 0) {
236+
if (ei->start_clu == 0) {
237237
/*
238238
* Empty start_clu != ~0 (not allocated)
239239
*/
@@ -251,20 +251,20 @@ void exfat_truncate(struct inode *inode, loff_t size)
251251
else
252252
mark_inode_dirty(inode);
253253

254-
inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1)) &
255-
~(sbi->cluster_size - 1)) >> inode->i_blkbits;
254+
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
255+
inode->i_blkbits;
256256
write_size:
257257
aligned_size = i_size_read(inode);
258258
if (aligned_size & (blocksize - 1)) {
259259
aligned_size |= (blocksize - 1);
260260
aligned_size++;
261261
}
262262

263-
if (EXFAT_I(inode)->i_size_ondisk > i_size_read(inode))
264-
EXFAT_I(inode)->i_size_ondisk = aligned_size;
263+
if (ei->i_size_ondisk > i_size_read(inode))
264+
ei->i_size_ondisk = aligned_size;
265265

266-
if (EXFAT_I(inode)->i_size_aligned > i_size_read(inode))
267-
EXFAT_I(inode)->i_size_aligned = aligned_size;
266+
if (ei->i_size_aligned > i_size_read(inode))
267+
ei->i_size_aligned = aligned_size;
268268
mutex_unlock(&sbi->s_lock);
269269
}
270270

fs/exfat/inode.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int __exfat_write_inode(struct inode *inode, int sync)
3131
return 0;
3232

3333
/*
34-
* If the indode is already unlinked, there is no need for updating it.
34+
* If the inode is already unlinked, there is no need for updating it.
3535
*/
3636
if (ei->dir.dir == DIR_DELETED)
3737
return 0;
@@ -114,10 +114,9 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
114114
unsigned int local_clu_offset = clu_offset;
115115
unsigned int num_to_be_allocated = 0, num_clusters = 0;
116116

117-
if (EXFAT_I(inode)->i_size_ondisk > 0)
117+
if (ei->i_size_ondisk > 0)
118118
num_clusters =
119-
EXFAT_B_TO_CLU_ROUND_UP(EXFAT_I(inode)->i_size_ondisk,
120-
sbi);
119+
EXFAT_B_TO_CLU_ROUND_UP(ei->i_size_ondisk, sbi);
121120

122121
if (clu_offset >= num_clusters)
123122
num_to_be_allocated = clu_offset - num_clusters + 1;
@@ -416,10 +415,10 @@ static int exfat_write_end(struct file *file, struct address_space *mapping,
416415

417416
err = generic_write_end(file, mapping, pos, len, copied, pagep, fsdata);
418417

419-
if (EXFAT_I(inode)->i_size_aligned < i_size_read(inode)) {
418+
if (ei->i_size_aligned < i_size_read(inode)) {
420419
exfat_fs_error(inode->i_sb,
421420
"invalid size(size(%llu) > aligned(%llu)\n",
422-
i_size_read(inode), EXFAT_I(inode)->i_size_aligned);
421+
i_size_read(inode), ei->i_size_aligned);
423422
return -EIO;
424423
}
425424

@@ -603,8 +602,8 @@ static int exfat_fill_inode(struct inode *inode, struct exfat_dir_entry *info)
603602

604603
exfat_save_attr(inode, info->attr);
605604

606-
inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1)) &
607-
~((loff_t)sbi->cluster_size - 1)) >> inode->i_blkbits;
605+
inode->i_blocks = round_up(i_size_read(inode), sbi->cluster_size) >>
606+
inode->i_blkbits;
608607
inode->i_mtime = info->mtime;
609608
inode->i_ctime = info->mtime;
610609
ei->i_crtime = info->crtime;

fs/exfat/misc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/fs.h>
1111
#include <linux/slab.h>
1212
#include <linux/buffer_head.h>
13+
#include <linux/blk_types.h>
1314

1415
#include "exfat_raw.h"
1516
#include "exfat_fs.h"
@@ -180,7 +181,7 @@ int exfat_update_bhs(struct buffer_head **bhs, int nr_bhs, int sync)
180181
set_buffer_uptodate(bhs[i]);
181182
mark_buffer_dirty(bhs[i]);
182183
if (sync)
183-
write_dirty_buffer(bhs[i], 0);
184+
write_dirty_buffer(bhs[i], REQ_SYNC);
184185
}
185186

186187
for (i = 0; i < nr_bhs && sync; i++) {

0 commit comments

Comments
 (0)