Skip to content

Commit 96de65a

Browse files
fs/ntfs3: Code formatting and refactoring
Added minor refactoring. Added and fixed some comments. In some places, the code has been reformatted to fit into 80 columns. clang-format-12 was used to format code according kernel's .clang-format. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 75c5e0c commit 96de65a

15 files changed

Lines changed: 186 additions & 178 deletions

File tree

fs/ntfs3/attrib.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
405405
int err = 0;
406406
struct ntfs_sb_info *sbi = ni->mi.sbi;
407407
u8 cluster_bits = sbi->cluster_bits;
408-
bool is_mft =
409-
ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA && !name_len;
408+
bool is_mft = ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA &&
409+
!name_len;
410410
u64 old_valid, old_size, old_alloc, new_alloc, new_alloc_tmp;
411411
struct ATTRIB *attr = NULL, *attr_b;
412412
struct ATTR_LIST_ENTRY *le, *le_b;
@@ -531,11 +531,10 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
531531
pre_alloc = 0;
532532
if (type == ATTR_DATA && !name_len &&
533533
sbi->options->prealloc) {
534-
pre_alloc =
535-
bytes_to_cluster(
536-
sbi,
537-
get_pre_allocated(new_size)) -
538-
new_alen;
534+
pre_alloc = bytes_to_cluster(
535+
sbi, get_pre_allocated(
536+
new_size)) -
537+
new_alen;
539538
}
540539

541540
/* Get the last LCN to allocate from. */
@@ -573,8 +572,8 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
573572
err = attr_allocate_clusters(
574573
sbi, run, vcn, lcn, to_allocate, &pre_alloc,
575574
is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen,
576-
is_mft ? 0
577-
: (sbi->record_size -
575+
is_mft ? 0 :
576+
(sbi->record_size -
578577
le32_to_cpu(rec->used) + 8) /
579578
3 +
580579
1,

fs/ntfs3/bitmap.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ static struct kmem_cache *ntfs_enode_cachep;
4040

4141
int __init ntfs3_init_bitmap(void)
4242
{
43-
ntfs_enode_cachep =
44-
kmem_cache_create("ntfs3_enode_cache", sizeof(struct e_node), 0,
45-
SLAB_RECLAIM_ACCOUNT, NULL);
43+
ntfs_enode_cachep = kmem_cache_create("ntfs3_enode_cache",
44+
sizeof(struct e_node), 0,
45+
SLAB_RECLAIM_ACCOUNT, NULL);
4646
return ntfs_enode_cachep ? 0 : -ENOMEM;
4747
}
4848

@@ -286,9 +286,9 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
286286
if (wnd->uptodated != 1) {
287287
/* Check bits before 'bit'. */
288288
ib = wnd->zone_bit == wnd->zone_end ||
289-
bit < wnd->zone_end
290-
? 0
291-
: wnd->zone_end;
289+
bit < wnd->zone_end ?
290+
0 :
291+
wnd->zone_end;
292292

293293
while (bit > ib && wnd_is_free_hlp(wnd, bit - 1, 1)) {
294294
bit -= 1;
@@ -297,9 +297,9 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
297297

298298
/* Check bits after 'end_in'. */
299299
ib = wnd->zone_bit == wnd->zone_end ||
300-
end_in > wnd->zone_bit
301-
? wnd->nbits
302-
: wnd->zone_bit;
300+
end_in > wnd->zone_bit ?
301+
wnd->nbits :
302+
wnd->zone_bit;
303303

304304
while (end_in < ib && wnd_is_free_hlp(wnd, end_in, 1)) {
305305
end_in += 1;
@@ -417,8 +417,8 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
417417
return;
418418
n3 = rb_first(&wnd->count_tree);
419419
wnd->extent_max =
420-
n3 ? rb_entry(n3, struct e_node, count.node)->count.key
421-
: 0;
420+
n3 ? rb_entry(n3, struct e_node, count.node)->count.key :
421+
0;
422422
return;
423423
}
424424

fs/ntfs3/file.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@ static int ntfs_ioctl_fitrim(struct ntfs_sb_info *sbi, unsigned long arg)
2222
{
2323
struct fstrim_range __user *user_range;
2424
struct fstrim_range range;
25+
struct block_device *dev;
2526
int err;
2627

2728
if (!capable(CAP_SYS_ADMIN))
2829
return -EPERM;
2930

30-
if (!bdev_max_discard_sectors(sbi->sb->s_bdev))
31+
dev = sbi->sb->s_bdev;
32+
if (!bdev_max_discard_sectors(dev))
3133
return -EOPNOTSUPP;
3234

3335
user_range = (struct fstrim_range __user *)arg;
3436
if (copy_from_user(&range, user_range, sizeof(range)))
3537
return -EFAULT;
3638

37-
range.minlen = max_t(u32, range.minlen,
38-
bdev_discard_granularity(sbi->sb->s_bdev));
39+
range.minlen = max_t(u32, range.minlen, bdev_discard_granularity(dev));
3940

4041
err = ntfs_trim_fs(sbi, &range);
4142
if (err < 0)
@@ -190,8 +191,8 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)
190191

191192
for (; idx < idx_end; idx += 1, from = 0) {
192193
page_off = (loff_t)idx << PAGE_SHIFT;
193-
to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off)
194-
: PAGE_SIZE;
194+
to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off) :
195+
PAGE_SIZE;
195196
iblock = page_off >> inode->i_blkbits;
196197

197198
page = find_or_create_page(mapping, idx,
@@ -564,13 +565,14 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
564565
ni_unlock(ni);
565566
} else {
566567
/* Check new size. */
568+
u8 cluster_bits = sbi->cluster_bits;
567569

568570
/* generic/213: expected -ENOSPC instead of -EFBIG. */
569571
if (!is_supported_holes) {
570572
loff_t to_alloc = new_size - inode_get_bytes(inode);
571573

572574
if (to_alloc > 0 &&
573-
(to_alloc >> sbi->cluster_bits) >
575+
(to_alloc >> cluster_bits) >
574576
wnd_zeroes(&sbi->used.bitmap)) {
575577
err = -ENOSPC;
576578
goto out;
@@ -591,7 +593,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
591593
}
592594

593595
if (is_supported_holes) {
594-
CLST vcn = vbo >> sbi->cluster_bits;
596+
CLST vcn = vbo >> cluster_bits;
595597
CLST cend = bytes_to_cluster(sbi, end);
596598
CLST cend_v = bytes_to_cluster(sbi, ni->i_valid);
597599
CLST lcn, clen;
@@ -1049,8 +1051,8 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
10491051
if (ret)
10501052
goto out;
10511053

1052-
ret = is_compressed(ni) ? ntfs_compress_write(iocb, from)
1053-
: __generic_file_write_iter(iocb, from);
1054+
ret = is_compressed(ni) ? ntfs_compress_write(iocb, from) :
1055+
__generic_file_write_iter(iocb, from);
10541056

10551057
out:
10561058
inode_unlock(inode);
@@ -1102,8 +1104,9 @@ static int ntfs_file_release(struct inode *inode, struct file *file)
11021104
int err = 0;
11031105

11041106
/* If we are last writer on the inode, drop the block reservation. */
1105-
if (sbi->options->prealloc && ((file->f_mode & FMODE_WRITE) &&
1106-
atomic_read(&inode->i_writecount) == 1)) {
1107+
if (sbi->options->prealloc &&
1108+
((file->f_mode & FMODE_WRITE) &&
1109+
atomic_read(&inode->i_writecount) == 1)) {
11071110
ni_lock(ni);
11081111
down_write(&ni->file.run_lock);
11091112

fs/ntfs3/frecord.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ struct ATTR_STD_INFO *ni_std(struct ntfs_inode *ni)
7676
const struct ATTRIB *attr;
7777

7878
attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
79-
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO))
80-
: NULL;
79+
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO)) :
80+
NULL;
8181
}
8282

8383
/*
@@ -91,8 +91,8 @@ struct ATTR_STD_INFO5 *ni_std5(struct ntfs_inode *ni)
9191

9292
attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL);
9393

94-
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5))
95-
: NULL;
94+
return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5)) :
95+
NULL;
9696
}
9797

9898
/*
@@ -1439,8 +1439,8 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type,
14391439
int err;
14401440
CLST plen;
14411441
struct ATTRIB *attr;
1442-
bool is_ext =
1443-
(flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED)) && !svcn;
1442+
bool is_ext = (flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED)) &&
1443+
!svcn;
14441444
u32 name_size = ALIGN(name_len * sizeof(short), 8);
14451445
u32 name_off = is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT;
14461446
u32 run_off = name_off + name_size;
@@ -1756,9 +1756,9 @@ int ni_new_attr_flags(struct ntfs_inode *ni, enum FILE_ATTRIBUTE new_fa)
17561756
}
17571757

17581758
/* Resize nonresident empty attribute in-place only. */
1759-
new_asize = (new_aflags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED))
1760-
? (SIZEOF_NONRESIDENT_EX + 8)
1761-
: (SIZEOF_NONRESIDENT + 8);
1759+
new_asize = (new_aflags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ?
1760+
(SIZEOF_NONRESIDENT_EX + 8) :
1761+
(SIZEOF_NONRESIDENT + 8);
17621762

17631763
if (!mi_resize_attr(mi, attr, new_asize - le32_to_cpu(attr->size)))
17641764
return -EOPNOTSUPP;
@@ -2965,14 +2965,14 @@ bool ni_remove_name_undo(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
29652965
{
29662966
struct ntfs_sb_info *sbi = ni->mi.sbi;
29672967
struct ATTRIB *attr;
2968-
u16 de_key_size = de2 ? le16_to_cpu(de2->key_size) : 0;
2968+
u16 de_key_size;
29692969

29702970
switch (undo_step) {
29712971
case 4:
2972+
de_key_size = le16_to_cpu(de2->key_size);
29722973
if (ni_insert_resident(ni, de_key_size, ATTR_NAME, NULL, 0,
2973-
&attr, NULL, NULL)) {
2974+
&attr, NULL, NULL))
29742975
return false;
2975-
}
29762976
memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), de2 + 1, de_key_size);
29772977

29782978
mi_get_ref(&ni->mi, &de2->ref);
@@ -2981,19 +2981,16 @@ bool ni_remove_name_undo(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
29812981
de2->flags = 0;
29822982
de2->res = 0;
29832983

2984-
if (indx_insert_entry(&dir_ni->dir, dir_ni, de2, sbi, NULL,
2985-
1)) {
2984+
if (indx_insert_entry(&dir_ni->dir, dir_ni, de2, sbi, NULL, 1))
29862985
return false;
2987-
}
29882986
fallthrough;
29892987

29902988
case 2:
29912989
de_key_size = le16_to_cpu(de->key_size);
29922990

29932991
if (ni_insert_resident(ni, de_key_size, ATTR_NAME, NULL, 0,
2994-
&attr, NULL, NULL)) {
2992+
&attr, NULL, NULL))
29952993
return false;
2996-
}
29972994

29982995
memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), de + 1, de_key_size);
29992996
mi_get_ref(&ni->mi, &de->ref);
@@ -3162,9 +3159,9 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,
31623159
u64 data_size = le64_to_cpu(attr->nres.data_size);
31633160
__le64 valid_le;
31643161

3165-
dup->alloc_size = is_attr_ext(attr)
3166-
? attr->nres.total_size
3167-
: attr->nres.alloc_size;
3162+
dup->alloc_size = is_attr_ext(attr) ?
3163+
attr->nres.total_size :
3164+
attr->nres.alloc_size;
31683165
dup->data_size = attr->nres.data_size;
31693166

31703167
if (new_valid > data_size)

0 commit comments

Comments
 (0)