Capitalize comments and end with period for better reading.
Also function comments are now little more kernel-doc style. This way we
can easily convert them to kernel-doc style if we want. Note that these
are not yet complete with this style. Example function comments start
with /* and in kernel-doc style they start /**.
Use imperative mood in function descriptions.
Change words like ntfs -> NTFS, linux -> Linux.
Use "we" not "I" when commenting code.
Signed-off-by: Kari Argillander <kar...@gm...>
---
Yes I know that this patch is quite monster. That's why I try to send this
now before patch series get merged. After that this patch probebly needs to
be splitted more and sended in patch series.
If someone thinks this should not be added now it is ok. I have try to read
what is kernel philosophy in case "patch to patch" but haven't found any
good information about it. It is no big deal to add later. In my own mind I
do not want to touch so much comments after code is in.
I also don't know how easy this kind of patch is apply top of the patch
series.
---
fs/ntfs3/attrib.c | 232 +++++++-------
fs/ntfs3/attrlist.c | 64 ++--
fs/ntfs3/bitfunc.c | 7 +-
fs/ntfs3/bitmap.c | 203 ++++++------
fs/ntfs3/debug.h | 5 +-
fs/ntfs3/dir.c | 61 ++--
fs/ntfs3/file.c | 98 +++---
fs/ntfs3/frecord.c | 413 ++++++++++++-------------
fs/ntfs3/fslog.c | 728 +++++++++++++++++++++++---------------------
fs/ntfs3/fsntfs.c | 244 +++++++--------
fs/ntfs3/index.c | 400 ++++++++++++------------
fs/ntfs3/inode.c | 243 ++++++++-------
fs/ntfs3/lznt.c | 86 +++---
fs/ntfs3/namei.c | 72 ++---
fs/ntfs3/ntfs.h | 517 +++++++++++++++----------------
fs/ntfs3/ntfs_fs.h | 198 ++++++------
fs/ntfs3/record.c | 60 ++--
fs/ntfs3/run.c | 187 ++++++------
fs/ntfs3/super.c | 160 +++++-----
fs/ntfs3/upcase.c | 9 +-
fs/ntfs3/xattr.c | 107 +++----
21 files changed, 2008 insertions(+), 2086 deletions(-)
diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c
index bca85e7b6eaf..4dc630b28817 100644
--- a/fs/ntfs3/attrib.c
+++ b/fs/ntfs3/attrib.c
@@ -3,7 +3,7 @@
*
* Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
*
- * TODO: merge attr_set_size/attr_data_get_block/attr_allocate_frame?
+ * TODO: Merge attr_set_size/attr_data_get_block/attr_allocate_frame?
*/
#include <linux/blkdev.h>
@@ -20,7 +20,7 @@
/*
* You can set external NTFS_MIN_LOG2_OF_CLUMP/NTFS_MAX_LOG2_OF_CLUMP to manage
- * preallocate algorithm
+ * preallocate algorithm.
*/
#ifndef NTFS_MIN_LOG2_OF_CLUMP
#define NTFS_MIN_LOG2_OF_CLUMP 16
@@ -35,10 +35,6 @@
// 16G
#define NTFS_CLUMP_MAX (1ull << (NTFS_MAX_LOG2_OF_CLUMP + 8))
-/*
- * get_pre_allocated
- *
- */
static inline u64 get_pre_allocated(u64 size)
{
u32 clump;
@@ -65,7 +61,7 @@ static inline u64 get_pre_allocated(u64 size)
/*
* attr_must_be_resident
*
- * returns true if attribute must be resident
+ * Return: True if attribute must be resident.
*/
static inline bool attr_must_be_resident(struct ntfs_sb_info *sbi,
enum ATTR_TYPE type)
@@ -90,9 +86,7 @@ static inline bool attr_must_be_resident(struct ntfs_sb_info *sbi,
}
/*
- * attr_load_runs
- *
- * load all runs stored in 'attr'
+ * attr_load_runs - Load all runs stored in @attr.
*/
int attr_load_runs(struct ATTRIB *attr, struct ntfs_inode *ni,
struct runs_tree *run, const CLST *vcn)
@@ -121,9 +115,7 @@ int attr_load_runs(struct ATTRIB *attr, struct ntfs_inode *ni,
}
/*
- * int run_deallocate_ex
- *
- * Deallocate clusters
+ * run_deallocate_ex - Deallocate clusters.
*/
static int run_deallocate_ex(struct ntfs_sb_info *sbi, struct runs_tree *run,
CLST vcn, CLST len, CLST *done, bool trim)
@@ -163,7 +155,7 @@ static int run_deallocate_ex(struct ntfs_sb_info *sbi, struct runs_tree *run,
vcn_next = vcn + clen;
if (!run_get_entry(run, ++idx, &vcn, &lcn, &clen) ||
vcn != vcn_next) {
- // save memory - don't load entire run
+ /* Save memory - don't load entire run. */
goto failed;
}
}
@@ -176,9 +168,7 @@ static int run_deallocate_ex(struct ntfs_sb_info *sbi, struct runs_tree *run,
}
/*
- * attr_allocate_clusters
- *
- * find free space, mark it as used and store in 'run'
+ * attr_allocate_clusters - Find free space, mark it as used and store in @run.
*/
int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run,
CLST vcn, CLST lcn, CLST len, CLST *pre_alloc,
@@ -207,7 +197,7 @@ int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run,
if (new_lcn && vcn == vcn0)
*new_lcn = lcn;
- /* Add new fragment into run storage */
+ /* Add new fragment into run storage. */
if (!run_add_entry(run, vcn, lcn, flen, opt == ALLOCATE_MFT)) {
down_write_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS);
wnd_set_free(wnd, lcn, flen);
@@ -228,7 +218,7 @@ int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run,
}
out:
- /* undo */
+ /* Undo. */
run_deallocate_ex(sbi, run, vcn0, vcn - vcn0, NULL, false);
run_truncate(run, vcn0);
@@ -236,8 +226,10 @@ int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run,
}
/*
- * if page is not NULL - it is already contains resident data
- * and locked (called from ni_write_frame)
+ * attr_make_nonresident
+ *
+ * If page is not NULL - it is already contains resident data
+ * and locked (called from ni_write_frame()).
*/
int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
struct ATTR_LIST_ENTRY *le, struct mft_inode *mi,
@@ -275,7 +267,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
run_init(run);
- /* make a copy of original attribute */
+ /* Make a copy of original attribute. */
attr_s = ntfs_memdup(attr, asize);
if (!attr_s) {
err = -ENOMEM;
@@ -283,7 +275,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
}
if (!len) {
- /* empty resident -> empty nonresident */
+ /* Empty resident -> Empty nonresident. */
alen = 0;
} else {
const char *data = resident_data(attr);
@@ -294,7 +286,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
goto out1;
if (!rsize) {
- /* empty resident -> non empty nonresident */
+ /* Empty resident -> Non empty nonresident. */
} else if (!is_data) {
err = ntfs_sb_write_run(sbi, run, 0, data, rsize);
if (err)
@@ -319,7 +311,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
}
}
- /* remove original attribute */
+ /* Remove original attribute. */
used -= asize;
memmove(attr, Add2Ptr(attr, asize), used - aoff);
rec->used = cpu_to_le32(used);
@@ -342,7 +334,7 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
if (is_data)
ni->ni_flags &= ~NI_FLAG_RESIDENT;
- /* Resident attribute becomes non resident */
+ /* Resident attribute becomes non resident. */
return 0;
out3:
@@ -352,20 +344,18 @@ int attr_make_nonresident(struct ntfs_inode *ni, struct ATTRIB *attr,
rec->used = cpu_to_le32(used + asize);
mi->dirty = true;
out2:
- /* undo: do not trim new allocated clusters */
+ /* Undo: Do not trim new allocated clusters. */
run_deallocate(sbi, run, false);
run_close(run);
out1:
ntfs_free(attr_s);
- /*reinsert le*/
+ /* Reinsert le. */
out:
return err;
}
/*
- * attr_set_size_res
- *
- * helper for attr_set_size
+ * attr_set_size_res - Helper for attr_set_size().
*/
static int attr_set_size_res(struct ntfs_inode *ni, struct ATTRIB *attr,
struct ATTR_LIST_ENTRY *le, struct mft_inode *mi,
@@ -407,14 +397,13 @@ static int attr_set_size_res(struct ntfs_inode *ni, struct ATTRIB *attr,
}
/*
- * attr_set_size
+ * attr_set_size - Change the size of attribute.
*
- * change the size of attribute
* Extend:
- * - sparse/compressed: no allocated clusters
- * - normal: append allocated and preallocated new clusters
+ * - Sparse/compressed: No allocated clusters.
+ * - Normal: Append allocated and preallocated new clusters.
* Shrink:
- * - no deallocate if keep_prealloc is set
+ * - No deallocate if @keep_prealloc is set.
*/
int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
const __le16 *name, u8 name_len, struct runs_tree *run,
@@ -451,7 +440,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
if (err || !attr_b->non_res)
goto out;
- /* layout of records may be changed, so do a full search */
+ /* Layout of records may be changed, so do a full search. */
goto again;
}
@@ -530,10 +519,10 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
add_alloc_in_same_attr_seg:
lcn = 0;
if (is_mft) {
- /* mft allocates clusters from mftzone */
+ /* MFT allocates clusters from MFT zone. */
pre_alloc = 0;
} else if (is_ext) {
- /* no preallocate for sparse/compress */
+ /* No preallocate for sparse/compress. */
pre_alloc = 0;
} else if (pre_alloc == -1) {
pre_alloc = 0;
@@ -544,7 +533,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
pre_alloc = new_alen2 - new_alen;
}
- /* Get the last lcn to allocate from */
+ /* Get the last LCN to allocate from. */
if (old_alen &&
!run_lookup_entry(run, vcn, &lcn, NULL, NULL)) {
lcn = SPARSE_LCN;
@@ -575,7 +564,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
}
alen = to_allocate;
} else {
- /* ~3 bytes per fragment */
+ /* ~3 bytes per fragment. */
err = attr_allocate_clusters(
sbi, run, vcn, lcn, to_allocate, &pre_alloc,
is_mft ? ALLOCATE_MFT : 0, &alen,
@@ -607,12 +596,12 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
mi_b->dirty = true;
if (next_svcn >= vcn && !to_allocate) {
- /* Normal way. update attribute and exit */
+ /* Normal way. Update attribute and exit. */
attr_b->nres.data_size = cpu_to_le64(new_size);
goto ok;
}
- /* at least two mft to avoid recursive loop*/
+ /* At least two MFT to avoid recursive loop. */
if (is_mft && next_svcn == vcn &&
((u64)done << sbi->cluster_bits) >= 2 * sbi->record_size) {
new_size = new_alloc_tmp;
@@ -637,7 +626,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
if (next_svcn < vcn)
goto pack_runs;
- /* layout of records is changed */
+ /* Layout of records is changed. */
goto again;
}
@@ -645,15 +634,15 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
err = ni_create_attr_list(ni);
if (err)
goto out;
- /* layout of records is changed */
+ /* Layout of records is changed. */
}
if (next_svcn >= vcn) {
- /* this is mft data, repeat */
+ /* This is MFT data, repeat. */
goto again;
}
- /* insert new attribute segment */
+ /* Insert new attribute segment. */
err = ni_insert_nonresident(ni, type, name, name_len, run,
next_svcn, vcn - next_svcn,
attr_b->flags, &attr, &mi);
@@ -667,8 +656,10 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
evcn = le64_to_cpu(attr->nres.evcn);
le_b = NULL;
- /* layout of records maybe changed */
- /* find base attribute to update*/
+ /*
+ * Layout of records maybe changed.
+ * Find base attribute to update.
+ */
attr_b = ni_find_attr(ni, NULL, &le_b, type, name, name_len,
NULL, &mi_b);
if (!attr_b) {
@@ -704,11 +695,11 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
u16 le_sz = le16_to_cpu(le->size);
/*
- * NOTE: list entries for one attribute are always
+ * NOTE: List entries for one attribute are always
* the same size. We deal with last entry (vcn==0)
* and it is not first in entries array
- * (list entry for std attribute always first)
- * So it is safe to step back
+ * (list entry for std attribute always first).
+ * So it is safe to step back.
*/
mi_remove_attr(mi, attr);
@@ -793,7 +784,7 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,
if (!err && attr_b && ret)
*ret = attr_b;
- /* update inode_set_bytes*/
+ /* Update inode_set_bytes. */
if (!err && ((type == ATTR_DATA && !name_len) ||
(type == ATTR_ALLOC && name == I30_NAME))) {
bool dirty = false;
@@ -843,7 +834,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
up_read(&ni->file.run_lock);
if (ok && (*lcn != SPARSE_LCN || !new)) {
- /* normal way */
+ /* Normal way. */
return 0;
}
@@ -909,7 +900,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
if (!ok) {
ok = run_lookup_entry(run, vcn, lcn, len, NULL);
if (ok && (*lcn != SPARSE_LCN || !new)) {
- /* normal way */
+ /* Normal way. */
err = 0;
goto ok;
}
@@ -932,7 +923,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
goto out;
}
- /* Get the last lcn to allocate from */
+ /* Get the last LCN to allocate from. */
hint = 0;
if (vcn > evcn1) {
@@ -970,20 +961,20 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
mi_b->dirty = true;
mark_inode_dirty(&ni->vfs_inode);
- /* stored [vcn : next_svcn) from [vcn : end) */
+ /* Stored [vcn : next_svcn) from [vcn : end). */
next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
if (end <= evcn1) {
if (next_svcn == evcn1) {
- /* Normal way. update attribute and exit */
+ /* Normal way. Update attribute and exit. */
goto ok;
}
- /* add new segment [next_svcn : evcn1 - next_svcn )*/
+ /* Add new segment [next_svcn : evcn1 - next_svcn). */
if (!ni->attr_list.size) {
err = ni_create_attr_list(ni);
if (err)
goto out;
- /* layout of records is changed */
+ /* Layout of records is changed. */
le_b = NULL;
attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL,
0, NULL, &mi_b);
@@ -1001,7 +992,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
svcn = evcn1;
- /* Estimate next attribute */
+ /* Estimate next attribute. */
attr = ni_find_attr(ni, attr, &le, ATTR_DATA, NULL, 0, &svcn, &mi);
if (attr) {
@@ -1012,7 +1003,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
if (end < next_svcn)
end = next_svcn;
while (end > evcn) {
- /* remove segment [svcn : evcn)*/
+ /* Remove segment [svcn : evcn). */
mi_remove_attr(mi, attr);
if (!al_remove_le(ni, le)) {
@@ -1021,7 +1012,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
}
if (evcn + 1 >= alloc) {
- /* last attribute segment */
+ /* Last attribute segment. */
evcn1 = evcn + 1;
goto ins_ext;
}
@@ -1125,7 +1116,7 @@ int attr_data_write_resident(struct ntfs_inode *ni, struct page *page)
return -EINVAL;
if (attr->non_res) {
- /*return special error code to check this case*/
+ /* Return special error code to check this case. */
return E_NTFS_NONRESIDENT;
}
@@ -1148,9 +1139,7 @@ int attr_data_write_resident(struct ntfs_inode *ni, struct page *page)
}
/*
- * attr_load_runs_vcn
- *
- * load runs with vcn
+ * attr_load_runs_vcn - Load runs with VCN.
*/
int attr_load_runs_vcn(struct ntfs_inode *ni, enum ATTR_TYPE type,
const __le16 *name, u8 name_len, struct runs_tree *run,
@@ -1180,7 +1169,7 @@ int attr_load_runs_vcn(struct ntfs_inode *ni, enum ATTR_TYPE type,
}
/*
- * load runs for given range [from to)
+ * attr_wof_load_runs_range - Load runs for given range [from to).
*/
int attr_load_runs_range(struct ntfs_inode *ni, enum ATTR_TYPE type,
const __le16 *name, u8 name_len, struct runs_tree *run,
@@ -1199,7 +1188,7 @@ int attr_load_runs_range(struct ntfs_inode *ni, enum ATTR_TYPE type,
vcn);
if (err)
return err;
- clen = 0; /*next run_lookup_entry(vcn) must be success*/
+ clen = 0; /* Next run_lookup_entry(vcn) must be success. */
}
}
@@ -1210,7 +1199,7 @@ int attr_load_runs_range(struct ntfs_inode *ni, enum ATTR_TYPE type,
/*
* attr_wof_frame_info
*
- * read header of xpress/lzx file to get info about frame
+ * Read header of Xpress/LZX file to get info about frame.
*/
int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,
struct runs_tree *run, u64 frame, u64 frames,
@@ -1227,20 +1216,20 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,
__le64 *off64;
if (ni->vfs_inode.i_size < 0x100000000ull) {
- /* file starts with array of 32 bit offsets */
+ /* File starts with array of 32 bit offsets. */
bytes_per_off = sizeof(__le32);
vbo[1] = frame << 2;
*vbo_data = frames << 2;
} else {
- /* file starts with array of 64 bit offsets */
+ /* File starts with array of 64 bit offsets. */
bytes_per_off = sizeof(__le64);
vbo[1] = frame << 3;
*vbo_data = frames << 3;
}
/*
- * read 4/8 bytes at [vbo - 4(8)] == offset where compressed frame starts
- * read 4/8 bytes at [vbo] == offset where compressed frame ends
+ * Read 4/8 bytes at [vbo - 4(8)] == offset where compressed frame starts.
+ * Read 4/8 bytes at [vbo] == offset where compressed frame ends.
*/
if (!attr->non_res) {
if (vbo[1] + bytes_per_off > le32_to_cpu(attr->res.data_size)) {
@@ -1329,7 +1318,7 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,
off[0] = le64_to_cpu(*off64);
}
} else {
- /* two values in one page*/
+ /* Two values in one page. */
if (bytes_per_off == sizeof(__le32)) {
off32 = Add2Ptr(addr, voff);
off[0] = le32_to_cpu(off32[-1]);
@@ -1355,9 +1344,7 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,
#endif
/*
- * attr_is_frame_compressed
- *
- * This function is used to detect compressed frame
+ * attr_is_frame_compressed - Used to detect compressed frame.
*/
int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr,
CLST frame, CLST *clst_data)
@@ -1391,14 +1378,14 @@ int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr,
}
if (lcn == SPARSE_LCN) {
- /* sparsed frame */
+ /* Sparsed frame. */
return 0;
}
if (clen >= clst_frame) {
/*
* The frame is not compressed 'cause
- * it does not contain any sparse clusters
+ * it does not contain any sparse clusters.
*/
*clst_data = clst_frame;
return 0;
@@ -1409,8 +1396,8 @@ int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr,
*clst_data = clen;
/*
- * The frame is compressed if *clst_data + slen >= clst_frame
- * Check next fragments
+ * The frame is compressed if *clst_data + slen >= clst_frame.
+ * Check next fragments.
*/
while ((vcn += clen) < alen) {
vcn_next = vcn;
@@ -1433,8 +1420,8 @@ int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr,
} else {
if (slen) {
/*
- * data_clusters + sparse_clusters =
- * not enough for frame
+ * Data_clusters + sparse_clusters =
+ * not enough for frame.
*/
return -EINVAL;
}
@@ -1445,11 +1432,11 @@ int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr,
if (!slen) {
/*
* There is no sparsed clusters in this frame
- * So it is not compressed
+ * so it is not compressed.
*/
*clst_data = clst_frame;
} else {
- /*frame is compressed*/
+ /* Frame is compressed. */
}
break;
}
@@ -1459,10 +1446,9 @@ int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr,
}
/*
- * attr_allocate_frame
+ * attr_allocate_frame - Allocate/free clusters for @frame.
*
- * allocate/free clusters for 'frame'
- * assumed: down_write(&ni->file.run_lock);
+ * Assumed: down_write(&ni->file.run_lock);
*/
int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
u64 new_valid)
@@ -1538,10 +1524,10 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
goto out;
}
end = vcn + clst_data;
- /* run contains updated range [vcn + len : end) */
+ /* Run contains updated range [vcn + len : end). */
} else {
CLST alen, hint = 0;
- /* Get the last lcn to allocate from */
+ /* Get the last LCN to allocate from. */
if (vcn + clst_data &&
!run_lookup_entry(run, vcn + clst_data - 1, &hint, NULL,
NULL)) {
@@ -1555,7 +1541,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
goto out;
end = vcn + len;
- /* run contains updated range [vcn + clst_data : end) */
+ /* Run contains updated range [vcn + clst_data : end). */
}
total_size += (u64)len << sbi->cluster_bits;
@@ -1571,20 +1557,20 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
mi_b->dirty = true;
mark_inode_dirty(&ni->vfs_inode);
- /* stored [vcn : next_svcn) from [vcn : end) */
+ /* Stored [vcn : next_svcn) from [vcn : end). */
next_svcn = le64_to_cpu(attr->nres.evcn) + 1;
if (end <= evcn1) {
if (next_svcn == evcn1) {
- /* Normal way. update attribute and exit */
+ /* Normal way. Update attribute and exit. */
goto ok;
}
- /* add new segment [next_svcn : evcn1 - next_svcn )*/
+ /* Add new segment [next_svcn : evcn1 - next_svcn). */
if (!ni->attr_list.size) {
err = ni_create_attr_list(ni);
if (err)
goto out;
- /* layout of records is changed */
+ /* Layout of records is changed. */
le_b = NULL;
attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL,
0, NULL, &mi_b);
@@ -1602,7 +1588,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
svcn = evcn1;
- /* Estimate next attribute */
+ /* Estimate next attribute. */
attr = ni_find_attr(ni, attr, &le, ATTR_DATA, NULL, 0, &svcn, &mi);
if (attr) {
@@ -1613,7 +1599,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
if (end < next_svcn)
end = next_svcn;
while (end > evcn) {
- /* remove segment [svcn : evcn)*/
+ /* Remove segment [svcn : evcn). */
mi_remove_attr(mi, attr);
if (!al_remove_le(ni, le)) {
@@ -1622,7 +1608,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
}
if (evcn + 1 >= alloc) {
- /* last attribute segment */
+ /* Last attribute segment. */
evcn1 = evcn + 1;
goto ins_ext;
}
@@ -1684,7 +1670,9 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
return err;
}
-/* Collapse range in file */
+/*
+ * attr_collapse_range - Collapse range in file.
+ */
int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
{
int err = 0;
@@ -1725,7 +1713,7 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
}
if ((vbo & mask) || (bytes & mask)) {
- /* allow to collapse only cluster aligned ranges */
+ /* Allow to collapse only cluster aligned ranges. */
return -EINVAL;
}
@@ -1737,7 +1725,7 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
if (vbo + bytes >= data_size) {
u64 new_valid = min(ni->i_valid, vbo);
- /* Simple truncate file at 'vbo' */
+ /* Simple truncate file at 'vbo'. */
truncate_setsize(&ni->vfs_inode, vbo);
err = attr_set_size(ni, ATTR_DATA, NULL, 0, &ni->file.run, vbo,
&new_valid, true, NULL);
@@ -1749,7 +1737,7 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
}
/*
- * Enumerate all attribute segments and collapse
+ * Enumerate all attribute segments and collapse.
*/
alen = alloc_size >> sbi->cluster_bits;
vcn = vbo >> sbi->cluster_bits;
@@ -1782,7 +1770,7 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
for (;;) {
if (svcn >= end) {
- /* shift vcn */
+ /* Shift VCN- */
attr->nres.svcn = cpu_to_le64(svcn - len);
attr->nres.evcn = cpu_to_le64(evcn1 - 1 - len);
if (le) {
@@ -1793,7 +1781,7 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
} else if (svcn < vcn || end < evcn1) {
CLST vcn1, eat, next_svcn;
- /* collapse a part of this attribute segment */
+ /* Collapse a part of this attribute segment. */
err = attr_load_runs(attr, ni, run, &svcn);
if (err)
goto out;
@@ -1811,7 +1799,7 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
}
if (svcn >= vcn) {
- /* shift vcn */
+ /* Shift VCN */
attr->nres.svcn = cpu_to_le64(vcn);
if (le) {
le->vcn = attr->nres.svcn;
@@ -1832,7 +1820,7 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
if (err)
goto out;
- /* layout of records maybe changed */
+ /* Layout of records maybe changed. */
attr_b = NULL;
le = al_find_ex(ni, NULL, ATTR_DATA, NULL, 0,
&next_svcn);
@@ -1842,18 +1830,18 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
}
}
- /* free all allocated memory */
+ /* Free all allocated memory. */
run_truncate(run, 0);
} else {
u16 le_sz;
u16 roff = le16_to_cpu(attr->nres.run_off);
- /*run==1 means unpack and deallocate*/
+ /* run==1 means unpack and deallocate. */
run_unpack_ex(RUN_DEALLOCATE, sbi, ni->mi.rno, svcn,
evcn1 - 1, svcn, Add2Ptr(attr, roff),
le32_to_cpu(attr->size) - roff);
- /* delete this attribute segment */
+ /* Delete this attribute segment. */
mi_remove_attr(mi, attr);
if (!le)
break;
@@ -1868,13 +1856,13 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
break;
if (!svcn) {
- /* Load next record that contains this attribute */
+ /* Load next record that contains this attribute. */
if (ni_load_mi(ni, le, &mi)) {
err = -EINVAL;
goto out;
}
- /* Look for required attribute */
+ /* Look for required attribute. */
attr = mi_find_attr(mi, NULL, ATTR_DATA, NULL,
0, &le->id);
if (!attr) {
@@ -1925,7 +1913,7 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
attr_b->nres.total_size = cpu_to_le64(total_size);
mi_b->dirty = true;
- /*update inode size*/
+ /* Update inode size. */
ni->i_valid = valid_size;
ni->vfs_inode.i_size = data_size;
inode_set_bytes(&ni->vfs_inode, total_size);
@@ -1940,7 +1928,11 @@ int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
return err;
}
-/* not for normal files */
+/*
+ * attr_punch_hole
+ *
+ * Not for normal files.
+ */
int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes)
{
int err = 0;
@@ -1973,7 +1965,7 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes)
return 0;
}
- /* TODO: add support for normal files too */
+ /* TODO: Add support for normal files too. */
if (!is_attr_ext(attr_b))
return -EOPNOTSUPP;
@@ -1981,7 +1973,7 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes)
total_size = le64_to_cpu(attr_b->nres.total_size);
if (vbo >= alloc_size) {
- // NOTE: it is allowed
+ // NOTE: It is allowed.
return 0;
}
@@ -1990,7 +1982,7 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes)
down_write(&ni->file.run_lock);
/*
- * Enumerate all attribute segments and punch hole where necessary
+ * Enumerate all attribute segments and punch hole where necessary.
*/
alen = alloc_size >> sbi->cluster_bits;
vcn = vbo >> sbi->cluster_bits;
@@ -2036,7 +2028,7 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes)
goto out;
if (dealloc2 == dealloc) {
- /* looks like the required range is already sparsed */
+ /* Looks like the required range is already sparsed. */
} else {
if (!run_add_entry(run, vcn1, SPARSE_LCN, zero,
false)) {
@@ -2048,7 +2040,7 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes)
if (err)
goto out;
}
- /* free all allocated memory */
+ /* Free all allocated memory. */
run_truncate(run, 0);
if (evcn1 >= alen)
@@ -2068,7 +2060,7 @@ int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes)
attr_b->nres.total_size = cpu_to_le64(total_size);
mi_b->dirty = true;
- /*update inode size*/
+ /* Update inode size. */
inode_set_bytes(&ni->vfs_inode, total_size);
ni->ni_flags |= NI_FLAG_UPDATE_PARENT;
mark_inode_dirty(&ni->vfs_inode);
diff --git a/fs/ntfs3/attrlist.c b/fs/ntfs3/attrlist.c
index ea561361b576..5babc7d2b1b2 100644
--- a/fs/ntfs3/attrlist.c
+++ b/fs/ntfs3/attrlist.c
@@ -14,7 +14,11 @@
#include "ntfs.h"
#include "ntfs_fs.h"
-/* Returns true if le is valid */
+/*
+ * al_is_valid_le
+ *
+ * Return: True if @le is valid.
+ */
static inline bool al_is_valid_le(const struct ntfs_inode *ni,
struct ATTR_LIST_ENTRY *le)
{
@@ -101,8 +105,9 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct ATTRIB *attr)
/*
* al_enumerate
*
- * Returns the next list 'le'
- * if 'le' is NULL then returns the first 'le'
+ * Return:
+ * * The next list le.
+ * * If @le is NULL then return the first le.
*/
struct ATTR_LIST_ENTRY *al_enumerate(struct ntfs_inode *ni,
struct ATTR_LIST_ENTRY *le)
@@ -115,22 +120,22 @@ struct ATTR_LIST_ENTRY *al_enumerate(struct ntfs_inode *ni,
} else {
sz = le16_to_cpu(le->size);
if (sz < sizeof(struct ATTR_LIST_ENTRY)) {
- /* Impossible 'cause we should not return such 'le' */
+ /* Impossible 'cause we should not return such le. */
return NULL;
}
le = Add2Ptr(le, sz);
}
- /* Check boundary */
+ /* Check boundary. */
off = PtrOffset(ni->attr_list.le, le);
if (off + sizeof(struct ATTR_LIST_ENTRY) > ni->attr_list.size) {
- // The regular end of list
+ /* The regular end of list. */
return NULL;
}
sz = le16_to_cpu(le->size);
- /* Check 'le' for errors */
+ /* Check le for errors. */
if (sz < sizeof(struct ATTR_LIST_ENTRY) ||
off + sz > ni->attr_list.size ||
sz < le->name_off + le->name_len * sizeof(short)) {
@@ -143,8 +148,9 @@ struct ATTR_LIST_ENTRY *al_enumerate(struct ntfs_inode *ni,
/*
* al_find_le
*
- * finds the first 'le' in the list which matches type, name and vcn
- * Returns NULL if not found
+ * Find the first le in the list which matches type, name and VCN.
+ *
+ * Return: NULL if not found.
*/
struct ATTR_LIST_ENTRY *al_find_le(struct ntfs_inode *ni,
struct ATTR_LIST_ENTRY *le,
@@ -159,8 +165,9 @@ struct ATTR_LIST_ENTRY *al_find_le(struct ntfs_inode *ni,
/*
* al_find_ex
*
- * finds the first 'le' in the list which matches type, name and vcn
- * Returns NULL if not found
+ * Find the first le in the list which matches type, name and VCN.
+ *
+ * Return: NULL if not found.
*/
struct ATTR_LIST_ENTRY *al_find_ex(struct ntfs_inode *ni,
struct ATTR_LIST_ENTRY *le,
@@ -174,7 +181,7 @@ struct ATTR_LIST_ENTRY *al_find_ex(struct ntfs_inode *ni,
u64 le_vcn;
int diff = le32_to_cpu(le->type) - type_in;
- /* List entries are sorted by type, name and vcn */
+ /* List entries are sorted by type, name and VCN. */
if (diff < 0)
continue;
@@ -187,7 +194,7 @@ struct ATTR_LIST_ENTRY *al_find_ex(struct ntfs_inode *ni,
le_vcn = le64_to_cpu(le->vcn);
if (!le_vcn) {
/*
- * compare entry names only for entry with vcn == 0
+ * Compare entry names only for entry with vcn == 0.
*/
diff = ntfs_cmp_names(le_name(le), name_len, name,
name_len, ni->mi.sbi->upcase,
@@ -215,9 +222,9 @@ struct ATTR_LIST_ENTRY *al_find_ex(struct ntfs_inode *ni,
}
/*
- * al_find_le_to_insert
+ * al_find_le_to_insert
*
- * finds the first list entry which matches type, name and vcn
+ * Find the first list entry which matches type, name and VCN.
*/
static struct ATTR_LIST_ENTRY *al_find_le_to_insert(struct ntfs_inode *ni,
enum ATTR_TYPE type,
@@ -227,7 +234,7 @@ static struct ATTR_LIST_ENTRY *al_find_le_to_insert(struct ntfs_inode *ni,
struct ATTR_LIST_ENTRY *le = NULL, *prev;
u32 type_in = le32_to_cpu(type);
- /* List entries are sorted by type, name, vcn */
+ /* List entries are sorted by type, name and VCN. */
while ((le = al_enumerate(ni, prev = le))) {
int diff = le32_to_cpu(le->type) - type_in;
@@ -239,7 +246,7 @@ static struct ATTR_LIST_ENTRY *al_find_le_to_insert(struct ntfs_inode *ni,
if (!le->vcn) {
/*
- * compare entry names only for entry with vcn == 0
+ * Compare entry names only for entry with vcn == 0.
*/
diff = ntfs_cmp_names(le_name(le), le->name_len, name,
name_len, ni->mi.sbi->upcase,
@@ -261,7 +268,7 @@ static struct ATTR_LIST_ENTRY *al_find_le_to_insert(struct ntfs_inode *ni,
/*
* al_add_le
*
- * adds an "attribute list entry" to the list.
+ * Add an "attribute list entry" to the list.
*/
int al_add_le(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name,
u8 name_len, CLST svcn, __le16 id, const struct MFT_REF *ref,
@@ -335,9 +342,7 @@ int al_add_le(struct ntfs_inode *ni, enum ATTR_TYPE type, const __le16 *name,
}
/*
- * al_remove_le
- *
- * removes 'le' from attribute list
+ * al_remove_le - Remove @le from attribute list.
*/
bool al_remove_le(struct ntfs_inode *ni, struct ATTR_LIST_ENTRY *le)
{
@@ -361,9 +366,7 @@ bool al_remove_le(struct ntfs_inode *ni, struct ATTR_LIST_ENTRY *le)
}
/*
- * al_delete_le
- *
- * deletes from the list the first 'le' which matches its parameters.
+ * al_delete_le - Delete first le from the list which matches its parameters.
*/
bool al_delete_le(struct ntfs_inode *ni, enum ATTR_TYPE type, CLST vcn,
const __le16 *name, size_t name_len,
@@ -374,7 +377,7 @@ bool al_delete_le(struct ntfs_inode *ni, enum ATTR_TYPE type, CLST vcn,
size_t off;
typeof(ni->attr_list) *al = &ni->attr_list;
- /* Scan forward to the first 'le' that matches the input */
+ /* Scan forward to the first le that matches the input. */
le = al_find_ex(ni, NULL, type, name, name_len, &vcn);
if (!le)
return false;
@@ -405,9 +408,9 @@ bool al_delete_le(struct ntfs_inode *ni, enum ATTR_TYPE type, CLST vcn,
goto next;
}
- /* Save on stack the size of 'le' */
+ /* Save on stack the size of 'le'. */
size = le16_to_cpu(le->size);
- /* Delete 'le'. */
+ /* Delete the le. */
memmove(le, Add2Ptr(le, size), al->size - (off + size));
al->size -= size;
@@ -416,9 +419,6 @@ bool al_delete_le(struct ntfs_inode *ni, enum ATTR_TYPE type, CLST vcn,
return true;
}
-/*
- * al_update
- */
int al_update(struct ntfs_inode *ni)
{
int err;
@@ -429,8 +429,8 @@ int al_update(struct ntfs_inode *ni)
return 0;
/*
- * attribute list increased on demand in al_add_le
- * attribute list decreased here
+ * Attribute list increased on demand in al_add_le.
+ * Attribute list decreased here.
*/
err = attr_set_size(ni, ATTR_LIST, NULL, 0, &al->run, al->size, NULL,
false, &attr);
diff --git a/fs/ntfs3/bitfunc.c b/fs/ntfs3/bitfunc.c
index 2de5faef2721..ce304d40b5e1 100644
--- a/fs/ntfs3/bitfunc.c
+++ b/fs/ntfs3/bitfunc.c
@@ -4,6 +4,7 @@
* Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
*
*/
+
#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/fs.h>
@@ -32,7 +33,7 @@ static const u8 zero_mask[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0,
/*
* are_bits_clear
*
- * Returns true if all bits [bit, bit+nbits) are zeros "0"
+ * Return: True if all bits [bit, bit+nbits) are zeros "0".
*/
bool are_bits_clear(const ulong *lmap, size_t bit, size_t nbits)
{
@@ -74,14 +75,13 @@ bool are_bits_clear(const ulong *lmap, size_t bit, size_t nbits)
if (pos && (*map & fill_mask[pos]))
return false;
- // All bits are zero
return true;
}
/*
* are_bits_set
*
- * Returns true if all bits [bit, bit+nbits) are ones "1"
+ * Return: True if all bits [bit, bit+nbits) are ones "1".
*/
bool are_bits_set(const ulong *lmap, size_t bit, size_t nbits)
{
@@ -130,6 +130,5 @@ bool are_bits_set(const ulong *lmap, size_t bit, size_t nbits)
return false;
}
- // All bits are ones
return true;
}
diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c
index 32aab0031221..ff586798b62a 100644
--- a/fs/ntfs3/bitmap.c
+++ b/fs/ntfs3/bitmap.c
@@ -6,7 +6,7 @@
* This code builds two trees of free clusters extents.
* Trees are sorted by start of extent and by length of extent.
* NTFS_MAX_WND_EXTENTS defines the maximum number of elements in trees.
- * In extreme case code reads on-disk bitmap to find free clusters
+ * In extreme case code reads on-disk bitmap to find free clusters.
*
*/
@@ -29,12 +29,10 @@ struct rb_node_key {
size_t key;
};
-/*
- * Tree is sorted by start (key)
- */
+/* Tree is sorted by start (key). */
struct e_node {
- struct rb_node_key start; /* Tree sorted by start */
- struct rb_node_key count; /* Tree sorted by len*/
+ struct rb_node_key start; /* Tree sorted by start. */
+ struct rb_node_key count; /* Tree sorted by len. */
};
static int wnd_rescan(struct wnd_bitmap *wnd);
@@ -62,9 +60,12 @@ static inline u32 wnd_bits(const struct wnd_bitmap *wnd, size_t i)
}
/*
- * b_pos + b_len - biggest fragment
- * Scan range [wpos wbits) window 'buf'
- * Returns -1 if not found
+ * wnd_scan
+ *
+ * b_pos + b_len - biggest fragment.
+ * Scan range [wpos wbits) window @buf.
+ *
+ * Return: -1 if not found.
*/
static size_t wnd_scan(const ulong *buf, size_t wbit, u32 wpos, u32 wend,
size_t to_alloc, size_t *prev_tail, size_t *b_pos,
@@ -96,7 +97,7 @@ static size_t wnd_scan(const ulong *buf, size_t wbit, u32 wpos, u32 wend,
}
/*
- * Now we have a fragment [wpos, wend) staring with 0
+ * Now we have a fragment [wpos, wend) staring with 0.
*/
end = wpos + to_alloc - *prev_tail;
free_bits = find_next_bit(buf, min(end, wend), wpos);
@@ -125,9 +126,7 @@ static size_t wnd_scan(const ulong *buf, size_t wbit, u32 wpos, u32 wend,
}
/*
- * wnd_close
- *
- * Frees all resources
+ * wnd_close - Frees all resources.
*/
void wnd_close(struct wnd_bitmap *wnd)
{
@@ -170,9 +169,7 @@ static struct rb_node *rb_lookup(struct rb_root *root, size_t v)
}
/*
- * rb_insert_count
- *
- * Helper function to insert special kind of 'count' tree
+ * rb_insert_count - Helper function to insert special kind of 'count' tree.
*/
static inline bool rb_insert_count(struct rb_root *root, struct e_node *e)
{
@@ -205,9 +202,7 @@ static inline bool rb_insert_count(struct rb_root *root, struct e_node *e)
}
/*
- * inline bool rb_insert_start
- *
- * Helper function to insert special kind of 'start' tree
+ * rb_insert_start - Helper function to insert special kind of 'count' tree.
*/
static inline bool rb_insert_start(struct rb_root *root, struct e_node *e)
{
@@ -237,10 +232,8 @@ static inline bool rb_insert_start(struct rb_root *root, struct e_node *e)
}
/*
- * wnd_add_free_ext
- *
- * adds a new extent of free space
- * build = 1 when building tree
+ * wnd_add_free_ext - Adds a new extent of free space.
+ * @build: 1 when building tree.
*/
static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
bool build)
@@ -250,14 +243,14 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
struct rb_node *n;
if (build) {
- /* Use extent_min to filter too short extents */
+ /* Use extent_min to filter too short extents. */
if (wnd->count >= NTFS_MAX_WND_EXTENTS &&
len <= wnd->extent_min) {
wnd->uptodated = -1;
return;
}
} else {
- /* Try to find extent before 'bit' */
+ /* Try to find extent before 'bit'. */
n = rb_lookup(&wnd->start_tree, bit);
if (!n) {
@@ -266,7 +259,7 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
e = rb_entry(n, struct e_node, start.node);
n = rb_next(n);
if (e->start.key + e->count.key == bit) {
- /* Remove left */
+ /* Remove left. */
bit = e->start.key;
len += e->count.key;
rb_erase(&e->start.node, &wnd->start_tree);
@@ -284,7 +277,7 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
if (e->start.key > end_in)
break;
- /* Remove right */
+ /* Remove right. */
n = rb_next(n);
len += next_end - end_in;
end_in = next_end;
@@ -299,7 +292,7 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
}
if (wnd->uptodated != 1) {
- /* Check bits before 'bit' */
+ /* Check bits before 'bit'. */
ib = wnd->zone_bit == wnd->zone_end ||
bit < wnd->zone_end
? 0
@@ -310,7 +303,7 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
len += 1;
}
- /* Check bits after 'end_in' */
+ /* Check bits after 'end_in'. */
ib = wnd->zone_bit == wnd->zone_end ||
end_in > wnd->zone_bit
? wnd->nbits
@@ -322,29 +315,29 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,
}
}
}
- /* Insert new fragment */
+ /* Insert new fragment. */
if (wnd->count >= NTFS_MAX_WND_EXTENTS) {
if (e0)
kmem_cache_free(ntfs_enode_cachep, e0);
wnd->uptodated = -1;
- /* Compare with smallest fragment */
+ /* Compare with smallest fragment. */
n = rb_last(&wnd->count_tree);
e = rb_entry(n, struct e_node, count.node);
if (len <= e->count.key)
- goto out; /* Do not insert small fragments */
+ goto out; /* Do not insert small fragments. */
if (build) {
struct e_node *e2;
n = rb_prev(n);
e2 = rb_entry(n, struct e_node, count.node);
- /* smallest fragment will be 'e2->count.key' */
+ /* Smallest fragment will be 'e2->count.key'. */
wnd->extent_min = e2->count.key;
}
- /* Replace smallest fragment by new one */
+ /* Replace smallest fragment by new one. */
rb_erase(&e->start.node, &wnd->start_tree);
rb_erase(&e->count.node, &wnd->count_tree);
wnd->count -= 1;
@@ -371,9 +364,7 @@ out:;
}
/*
- * wnd_remove_free_ext
- *
- * removes a run from the cached free space
+ * wnd_remove_free_ext - Remove a run from the cached free space.
*/
static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
{
@@ -382,7 +373,7 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
size_t end_in = bit + len;
size_t end3, end, new_key, new_len, max_new_len;
- /* Try to find extent before 'bit' */
+ /* Try to find extent before 'bit'. */
n = rb_lookup(&wnd->start_tree, bit);
if (!n)
@@ -394,11 +385,11 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
new_key = new_len = 0;
len = e->count.key;
- /* Range [bit,end_in) must be inside 'e' or outside 'e' and 'n' */
+ /* Range [bit,end_in) must be inside 'e' or outside 'e' and 'n'. */
if (e->start.key > bit)
;
else if (end_in <= end) {
- /* Range [bit,end_in) inside 'e' */
+ /* Range [bit,end_in) inside 'e'. */
new_key = end_in;
new_len = end - end_in;
len = bit - e->start.key;
@@ -478,13 +469,13 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
if (wnd->count >= NTFS_MAX_WND_EXTENTS) {
wnd->uptodated = -1;
- /* Get minimal extent */
+ /* Get minimal extent. */
e = rb_entry(rb_last(&wnd->count_tree), struct e_node,
count.node);
if (e->count.key > new_len)
goto out;
- /* Replace minimum */
+ /* Replace minimum. */
rb_erase(&e->start.node, &wnd->start_tree);
rb_erase(&e->count.node, &wnd->count_tree);
wnd->count -= 1;
@@ -508,9 +499,7 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)
}
/*
- * wnd_rescan
- *
- * Scan all bitmap. used while initialization.
+ * wnd_rescan - Scan all bitmap. Used while initialization.
*/
static int wnd_rescan(struct wnd_bitmap *wnd)
{
@@ -541,7 +530,7 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
if (wnd->inited) {
if (!wnd->free_bits[iw]) {
- /* all ones */
+ /* All ones. */
if (prev_tail) {
wnd_add_free_ext(wnd,
vbo * 8 - prev_tail,
@@ -551,7 +540,7 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
goto next_wnd;
}
if (wbits == wnd->free_bits[iw]) {
- /* all zeroes */
+ /* All zeroes. */
prev_tail += wbits;
wnd->total_zeroes += wbits;
goto next_wnd;
@@ -604,14 +593,14 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
wpos = used;
if (wpos >= wbits) {
- /* No free blocks */
+ /* No free blocks. */
prev_tail = 0;
break;
}
frb = find_next_bit(buf, wbits, wpos);
if (frb >= wbits) {
- /* keep last free block */
+ /* Keep last free block. */
prev_tail += frb - wpos;
break;
}
@@ -619,9 +608,9 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
wnd_add_free_ext(wnd, wbit + wpos - prev_tail,
frb + prev_tail - wpos, true);
- /* Skip free block and first '1' */
+ /* Skip free block and first '1'. */
wpos = frb + 1;
- /* Reset previous tail */
+ /* Reset previous tail. */
prev_tail = 0;
} while (wpos < wbits);
@@ -638,15 +627,15 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
}
}
- /* Add last block */
+ /* Add last block. */
if (prev_tail)
wnd_add_free_ext(wnd, wnd->nbits - prev_tail, prev_tail, true);
/*
- * Before init cycle wnd->uptodated was 0
+ * Before init cycle wnd->uptodated was 0.
* If any errors or limits occurs while initialization then
- * wnd->uptodated will be -1
- * If 'uptodated' is still 0 then Tree is really updated
+ * wnd->uptodated will be -1.
+ * If 'uptodated' is still 0 then Tree is really updated.
*/
if (!wnd->uptodated)
wnd->uptodated = 1;
@@ -662,9 +651,6 @@ static int wnd_rescan(struct wnd_bitmap *wnd)
return err;
}
-/*
- * wnd_init
- */
int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits)
{
int err;
@@ -697,9 +683,7 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits)
}
/*
- * wnd_map
- *
- * call sb_bread for requested window
+ * wnd_map - Call sb_bread for requested window.
*/
static struct buffer_head *wnd_map(struct wnd_bitmap *wnd, size_t iw)
{
@@ -728,9 +712,7 @@ static struct buffer_head *wnd_map(struct wnd_bitmap *wnd, size_t iw)
}
/*
- * wnd_set_free
- *
- * Marks the bits range from bit to bit + bits as free
+ * wnd_set_free - Mark the bits range from bit to bit + bits as free.
*/
int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
{
@@ -783,9 +765,7 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
}
/*
- * wnd_set_used
- *
- * Marks the bits range from bit to bit + bits as used
+ * wnd_set_used - Mark the bits range from bit to bit + bits as used.
*/
int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
{
@@ -839,7 +819,7 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
/*
* wnd_is_free_hlp
*
- * Returns true if all clusters [bit, bit+bits) are free (bitmap only)
+ * Return: True if all clusters [bit, bit+bits) are free (bitmap only).
*/
static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
{
@@ -882,7 +862,7 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
/*
* wnd_is_free
*
- * Returns true if all clusters [bit, bit+bits) are free
+ * Return: True if all clusters [bit, bit+bits) are free.
*/
bool wnd_is_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
{
@@ -914,7 +894,7 @@ bool wnd_is_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
/*
* wnd_is_used
*
- * Returns true if all clusters [bit, bit+bits) are used
+ * Return: True if all clusters [bit, bit+bits) are used.
*/
bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
{
@@ -973,11 +953,11 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
}
/*
- * wnd_find
- * - flags - BITMAP_FIND_XXX flags
+ * wnd_find - Look for free space.
*
- * looks for free space
- * Returns 0 if not found
+ * - flags - BITMAP_FIND_XXX flags
+ *
+ * Return: 0 if not found.
*/
size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
size_t flags, size_t *allocated)
@@ -994,7 +974,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
bool fbits_valid;
struct buffer_head *bh;
- /* fast checking for available free space */
+ /* Fast checking for available free space. */
if (flags & BITMAP_FIND_FULL) {
size_t zeroes = wnd_zeroes(wnd);
@@ -1020,7 +1000,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
if (RB_EMPTY_ROOT(&wnd->start_tree)) {
if (wnd->uptodated == 1) {
- /* extents tree is updated -> no free space */
+ /* Extents tree is updated -> No free space. */
goto no_space;
}
goto scan_bitmap;
@@ -1030,7 +1010,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
if (!hint)
goto allocate_biggest;
- /* Use hint: enumerate extents by start >= hint */
+ /* Use hint: Enumerate extents by start >= hint. */
pr = NULL;
cr = wnd->start_tree.rb_node;
@@ -1059,7 +1039,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
goto allocate_biggest;
if (e->start.key + e->count.key > hint) {
- /* We have found extension with 'hint' inside */
+ /* We have found extension with 'hint' inside. */
size_t len = e->start.key + e->count.key - hint;
if (len >= to_alloc && hint + to_alloc <= max_alloc) {
@@ -1080,7 +1060,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
}
allocate_biggest:
- /* Allocate from biggest free extent */
+ /* Allocate from biggest free extent. */
e = rb_entry(rb_first(&wnd->count_tree), struct e_node, count.node);
if (e->count.key != wnd->extent_max)
wnd->extent_max = e->count.key;
@@ -1090,14 +1070,14 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
;
} else if (flags & BITMAP_FIND_FULL) {
if (e->count.key < to_alloc0) {
- /* Biggest free block is less then requested */
+ /* Biggest free block is less then requested. */
goto no_space;
}
to_alloc = e->count.key;
} else if (-1 != wnd->uptodated) {
to_alloc = e->count.key;
} else {
- /* Check if we can use more bits */
+ /* Check if we can use more bits. */
size_t op, max_check;
struct rb_root start_tree;
@@ -1118,7 +1098,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
to_alloc = op - e->start.key;
}
- /* Prepare to return */
+ /* Prepare to return. */
fnd = e->start.key;
if (e->start.key + to_alloc > max_alloc)
to_alloc = max_alloc - e->start.key;
@@ -1126,7 +1106,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
}
if (wnd->uptodated == 1) {
- /* extents tree is updated -> no free space */
+ /* Extents tree is updated -> no free space. */
goto no_space;
}
@@ -1140,7 +1120,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
/* At most two ranges [hint, max_alloc) + [0, hint) */
Again:
- /* TODO: optimize request for case nbits > wbits */
+ /* TODO: Optimize request for case nbits > wbits. */
iw = hint >> log2_bits;
wbits = sb->s_blocksize * 8;
wpos = hint & (wbits - 1);
@@ -1155,7 +1135,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
nwnd = likely(t > max_alloc) ? (t >> log2_bits) : wnd->nwnd;
}
- /* Enumerate all windows */
+ /* Enumerate all windows. */
for (; iw < nwnd; iw++) {
wbit = iw << log2_bits;
@@ -1165,7 +1145,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
b_len = prev_tail;
}
- /* Skip full used window */
+ /* Skip full used window. */
prev_tail = 0;
wpos = 0;
continue;
@@ -1189,25 +1169,25 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
zbit = max(wnd->zone_bit, wbit);
zend = min(wnd->zone_end, ebit);
- /* Here we have a window [wbit, ebit) and zone [zbit, zend) */
+ /* Here we have a window [wbit, ebit) and zone [zbit, zend). */
if (zend <= zbit) {
- /* Zone does not overlap window */
+ /* Zone does not overlap window. */
} else {
wzbit = zbit - wbit;
wzend = zend - wbit;
- /* Zone overlaps window */
+ /* Zone overlaps window. */
if (wnd->free_bits[iw] == wzend - wzbit) {
prev_tail = 0;
wpos = 0;
continue;
}
- /* Scan two ranges window: [wbit, zbit) and [zend, ebit) */
+ /* Scan two ranges window: [wbit, zbit) and [zend, ebit). */
bh = wnd_map(wnd, iw);
if (IS_ERR(bh)) {
- /* TODO: error */
+ /* TODO: Error */
prev_tail = 0;
wpos = 0;
continue;
@@ -1215,9 +1195,9 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
buf = (ulong *)bh->b_data;
- /* Scan range [wbit, zbit) */
+ /* Scan range [wbit, zbit). */
if (wpos < wzbit) {
- /* Scan range [wpos, zbit) */
+ /* Scan range [wpos, zbit). */
fnd = wnd_scan(buf, wbit, wpos, wzbit,
to_alloc, &prev_tail,
&b_pos, &b_len);
@@ -1229,7 +1209,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
prev_tail = 0;
- /* Scan range [zend, ebit) */
+ /* Scan range [zend, ebit). */
if (wzend < wbits) {
fnd = wnd_scan(buf, wbit,
max(wzend, wpos), wbits,
@@ -1247,24 +1227,24 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
}
}
- /* Current window does not overlap zone */
+ /* Current window does not overlap zone. */
if (!wpos && fbits_valid && wnd->free_bits[iw] == wbits) {
- /* window is empty */
+ /* Window is empty. */
if (prev_tail + wbits >= to_alloc) {
fnd = wbit + wpos - prev_tail;
goto found;
}
- /* Increase 'prev_tail' and process next window */
+ /* Increase 'prev_tail' and process next window. */
prev_tail += wbits;
wpos = 0;
continue;
}
- /* read window */
+ /* Read window */
bh = wnd_map(wnd, iw);
if (IS_ERR(bh)) {
- // TODO: error
+ // TODO: Error.
prev_tail = 0;
wpos = 0;
continue;
@@ -1272,7 +1252,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
buf = (ulong *)bh->b_data;
- /* Scan range [wpos, eBits) */
+ /* Scan range [wpos, eBits). */
fnd = wnd_scan(buf, wbit, wpos, wbits, to_alloc, &prev_tail,
&b_pos, &b_len);
put_bh(bh);
@@ -1281,15 +1261,15 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
}
if (b_len < prev_tail) {
- /* The last fragment */
+ /* The last fragment. */
b_len = prev_tail;
b_pos = max_alloc - prev_tail;
}
if (hint) {
/*
- * We have scanned range [hint max_alloc)
- * Prepare to scan range [0 hint + to_alloc)
+ * We have scanned range [hint max_alloc).
+ * Prepare to scan range [0 hint + to_alloc).
*/
size_t nextmax = hint + to_alloc;
@@ -1312,7 +1292,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
found:
if (flags & BITMAP_FIND_MARK_AS_USED) {
- /* TODO optimize remove extent (pass 'e'?) */
+ /* TODO: Optimize remove extent (pass 'e'?). */
if (wnd_set_used(wnd, fnd, to_alloc))
goto no_space;
} else if (wnd->extent_max != MINUS_ONE_T &&
@@ -1328,9 +1308,7 @@ size_t wnd_find(struct wnd_bitmap *wnd, size_t to_alloc, size_t hint,
}
/*
- * wnd_extend
- *
- * Extend bitmap ($MFT bitmap)
+ * wnd_extend - Extend bitmap ($MFT bitmap).
*/
int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
{
@@ -1347,7 +1325,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
if (new_bits <= old_bits)
return -EINVAL;
- /* align to 8 byte boundary */
+ /* Align to 8 byte boundary. */
new_wnd = bytes_to_block(sb, bitmap_size(new_bits));
new_last = new_bits & (wbits - 1);
if (!new_last)
@@ -1367,7 +1345,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
wnd->free_bits = new_free;
}
- /* Zero bits [old_bits,new_bits) */
+ /* Zero bits [old_bits,new_bits). */
bits = new_bits - old_bits;
b0 = old_bits & (wbits - 1);
@@ -1403,7 +1381,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
set_buffer_uptodate(bh);
mark_buffer_dirty(bh);
unlock_buffer(bh);
- /*err = sync_dirty_buffer(bh);*/
+ /* err = sync_dirty_buffer(bh); */
b0 = 0;
bits -= op;
@@ -1418,9 +1396,6 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits)
return 0;
}
-/*
- * wnd_zone_set
- */
void wnd_zone_set(struct wnd_bitmap *wnd, size_t lcn, size_t len)
{
size_t zlen;
@@ -1502,7 +1477,7 @@ int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range)
put_bh(bh);
}
- /* Process the last fragment */
+ /* Process the last fragment. */
if (len >= minlen) {
err = ntfs_discard(sbi, lcn, len);
if (err)
diff --git a/fs/ntfs3/debug.h b/fs/ntfs3/debug.h
index dfaa4c79dc6d..93ed80f902b3 100644
--- a/fs/ntfs3/debug.h
+++ b/fs/ntfs3/debug.h
@@ -3,7 +3,8 @@
*
* Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
*
- * useful functions for debuging
+ * Useful functions for debuging.
+ *
*/
// clang-format off
@@ -41,7 +42,7 @@ void ntfs_inode_printk(struct inode *inode, const char *fmt, ...)
#endif
/*
- * Logging macros ( thanks Joe Perches <jo...@pe...> for implementation )
+ * Logging macros. Thanks Joe Perches <jo...@pe...> for implementation.
*/
#define ntfs_err(sb, fmt, ...) ntfs_printk(sb, KERN_ERR fmt, ##__VA_ARGS__)
diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c
index 9ec6012c405b..adde2bb0deb4 100644
--- a/fs/ntfs3/dir.c
+++ b/fs/ntfs3/dir.c
@@ -3,9 +3,10 @@
*
* Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
*
- * directory handling functions for ntfs-based filesystems
+ * Directory handling functions for NTFS-based filesystems.
*
*/
+
#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/fs.h>
@@ -16,9 +17,7 @@
#include "ntfs.h"
#include "ntfs_fs.h"
-/*
- * Convert little endian utf16 to nls string
- */
+/* Convert little endian UTF-16 to NLS string. */
int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni,
u8 *buf, int buf_len)
{
@@ -30,7 +29,7 @@ int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni,
static_assert(sizeof(wchar_t) == sizeof(__le16));
if (!nls) {
- /* utf16 -> utf8 */
+ /* UTF-16 -> UTF-8 */
ret = utf16s_to_utf8s((wchar_t *)uni->name, uni->len,
UTF16_LITTLE_ENDIAN, buf, buf_len);
buf[ret] = '\0';
@@ -89,8 +88,9 @@ int ntfs_utf16_to_nls(struct ntfs_sb_info *sbi, const struct le_str *uni,
// clang-format on
/*
- * modified version of put_utf16 from fs/nls/nls_base.c
- * is sparse warnings free
+ * put_utf16 - Modified version of put_utf16 from fs/nls/nls_base.c
+ *
+ * Function is sparse warnings free.
*/
static inline void put_utf16(wchar_t *s, unsigned int c,
enum utf16_endian endian)
@@ -112,8 +112,10 @@ static inline void put_utf16(wchar_t *s, unsigned int c,
}
/*
- * modified version of 'utf8s_to_utf16s' allows to
- * detect -ENAMETOOLONG without writing out of expected maximum
+ * _utf8s_to_utf16s
+ *
+ * Modified version of 'utf8s_to_utf16s' allows to
+ * detect -ENAMETOOLONG without writing out of expected maximum.
*/
static int _utf8s_to_utf16s(const u8 *s, int inlen, enum utf16_endian endian,
wchar_t *pwcs, int maxout)
@@ -165,17 +167,18 @@ static int _utf8s_to_utf16s(const u8 *s, int inlen, enum utf16_endian endian,
}
/*
- * Convert input string to utf16
- *
- * name, name_len - input name
- * uni, max_ulen - destination memory
- * endian - endian of target utf16 string
+ * ntfs_nls_to_utf16 - Convert input string to UTF-16.
+ * @name: Input name.
+ * @name_len: Input name length.
+ * @uni: Destination memory.
+ * @max_ulen: Destination memory.
+ * @endian: Endian of target UTF-16 string.
*
* This function is called:
- * - to create ntfs name
+ * - to create NTFS name
* - to create symlink
*
- * returns utf16 string length or error (if negative)
+ * Return: UTF-16 string length or error (if negative).
*/
int ntfs_nls_to_utf16(struct ntfs_sb_info *sbi, const u8 *name, u32 name_len,
struct cpu_str *uni, u32 max_ulen,
@@ -230,7 +233,9 @@ int ntfs_nls_to_utf16(struct ntfs_sb_info *sbi, const u8 *name, u32 name_len,
return ret;
}
-/* helper function */
+/*
+ * dir_search_u - Helper function.
+ */
struct inode *dir_search_u(struct inode *dir, const struct cpu_str *uni,
struct ntfs_fnd *fnd)
{
@@ -295,7 +300,7 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
if (ino == MFT_REC_ROOT)
return 0;
- /* Skip meta files ( unless option to show metafiles is set ) */
+ /* Skip meta files. Unless option to show metafiles is set. */
if (!sbi->options.showmeta && ntfs_is_meta_file(sbi, ino))
return 0;
@@ -316,9 +321,7 @@ static inline int ntfs_filldir(struct ntfs_sb_info *sbi, struct ntfs_inode *ni,
}
/*
...
[truncated message content] |