fs/ntfs3: Reformat code and update terminology

Reformatted the driver code according to the current .clang-format rules
and updated description of used terminology. No functional changes
intended.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
pull/1354/merge
Konstantin Komarov 2025-09-01 12:00:43 +03:00
parent 5180138604
commit a846cd0d0a
No known key found for this signature in database
GPG Key ID: A9B0331F832407B6
7 changed files with 42 additions and 38 deletions

View File

@ -332,8 +332,7 @@ static inline bool ntfs_dir_emit(struct ntfs_sb_info *sbi,
* It does additional locks/reads just to get the type of name. * It does additional locks/reads just to get the type of name.
* Should we use additional mount option to enable branch below? * Should we use additional mount option to enable branch below?
*/ */
if (fname->dup.extend_data && if (fname->dup.extend_data && ino != ni->mi.rno) {
ino != ni->mi.rno) {
struct inode *inode = ntfs_iget5(sbi->sb, &e->ref, NULL); struct inode *inode = ntfs_iget5(sbi->sb, &e->ref, NULL);
if (!IS_ERR_OR_NULL(inode)) { if (!IS_ERR_OR_NULL(inode)) {
dt_type = fs_umode_to_dtype(inode->i_mode); dt_type = fs_umode_to_dtype(inode->i_mode);

View File

@ -503,8 +503,6 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size)
if (dirty) if (dirty)
mark_inode_dirty(inode); mark_inode_dirty(inode);
/*ntfs_flush_inodes(inode->i_sb, inode, NULL);*/
return 0; return 0;
} }
@ -1114,8 +1112,8 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
size_t cp, tail = PAGE_SIZE - off; size_t cp, tail = PAGE_SIZE - off;
folio = page_folio(pages[ip]); folio = page_folio(pages[ip]);
cp = copy_folio_from_iter_atomic(folio, off, cp = copy_folio_from_iter_atomic(
min(tail, bytes), from); folio, off, min(tail, bytes), from);
flush_dcache_folio(folio); flush_dcache_folio(folio);
copied += cp; copied += cp;
@ -1312,7 +1310,7 @@ static int ntfs_file_release(struct inode *inode, struct file *file)
if (sbi->options->prealloc && if (sbi->options->prealloc &&
((file->f_mode & FMODE_WRITE) && ((file->f_mode & FMODE_WRITE) &&
atomic_read(&inode->i_writecount) == 1) atomic_read(&inode->i_writecount) == 1)
/* /*
* The only file when inode->i_fop = &ntfs_file_operations and * The only file when inode->i_fop = &ntfs_file_operations and
* init_rwsem(&ni->file.run_lock) is not called explicitly is MFT. * init_rwsem(&ni->file.run_lock) is not called explicitly is MFT.
* *

View File

@ -3026,8 +3026,8 @@ int ni_rename(struct ntfs_inode *dir_ni, struct ntfs_inode *new_dir_ni,
err = ni_add_name(new_dir_ni, ni, new_de); err = ni_add_name(new_dir_ni, ni, new_de);
if (!err) { if (!err) {
err = ni_remove_name(dir_ni, ni, de, &de2, &undo); err = ni_remove_name(dir_ni, ni, de, &de2, &undo);
WARN_ON(err && ni_remove_name(new_dir_ni, ni, new_de, &de2, WARN_ON(err &&
&undo)); ni_remove_name(new_dir_ni, ni, new_de, &de2, &undo));
} }
/* /*
@ -3127,7 +3127,8 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,
if (attr) { if (attr) {
const struct REPARSE_POINT *rp; const struct REPARSE_POINT *rp;
rp = resident_data_ex(attr, sizeof(struct REPARSE_POINT)); rp = resident_data_ex(attr,
sizeof(struct REPARSE_POINT));
/* If ATTR_REPARSE exists 'rp' can't be NULL. */ /* If ATTR_REPARSE exists 'rp' can't be NULL. */
if (rp) if (rp)
dup->extend_data = rp->ReparseTag; dup->extend_data = rp->ReparseTag;

View File

@ -975,9 +975,9 @@ out:
/* /*
* ntfs_write_end - Address_space_operations::write_end. * ntfs_write_end - Address_space_operations::write_end.
*/ */
int ntfs_write_end(const struct kiocb *iocb, int ntfs_write_end(const struct kiocb *iocb, struct address_space *mapping,
struct address_space *mapping, loff_t pos, loff_t pos, u32 len, u32 copied, struct folio *folio,
u32 len, u32 copied, struct folio *folio, void *fsdata) void *fsdata)
{ {
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
struct ntfs_inode *ni = ntfs_i(inode); struct ntfs_inode *ni = ntfs_i(inode);
@ -1099,7 +1099,7 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
typeof(rp->SymbolicLinkReparseBuffer) *rs; typeof(rp->SymbolicLinkReparseBuffer) *rs;
bool is_absolute; bool is_absolute;
is_absolute = (strlen(symname) > 1 && symname[1] == ':'); is_absolute = symname[0] && symname[1] == ':';
rp = kzalloc(ntfs_reparse_bytes(2 * size + 2, is_absolute), GFP_NOFS); rp = kzalloc(ntfs_reparse_bytes(2 * size + 2, is_absolute), GFP_NOFS);
if (!rp) if (!rp)
@ -1136,17 +1136,19 @@ ntfs_create_reparse_buffer(struct ntfs_sb_info *sbi, const char *symname,
/* PrintName + SubstituteName. */ /* PrintName + SubstituteName. */
rs->SubstituteNameOffset = cpu_to_le16(sizeof(short) * err); rs->SubstituteNameOffset = cpu_to_le16(sizeof(short) * err);
rs->SubstituteNameLength = cpu_to_le16(sizeof(short) * err + (is_absolute ? 8 : 0)); rs->SubstituteNameLength =
cpu_to_le16(sizeof(short) * err + (is_absolute ? 8 : 0));
rs->PrintNameLength = rs->SubstituteNameOffset; rs->PrintNameLength = rs->SubstituteNameOffset;
/* /*
* TODO: Use relative path if possible to allow Windows to * TODO: Use relative path if possible to allow Windows to
* parse this path. * parse this path.
* 0-absolute path 1- relative path (SYMLINK_FLAG_RELATIVE). * 0-absolute path, 1- relative path (SYMLINK_FLAG_RELATIVE).
*/ */
rs->Flags = cpu_to_le32(is_absolute ? 0 : SYMLINK_FLAG_RELATIVE); rs->Flags = cpu_to_le32(is_absolute ? 0 : SYMLINK_FLAG_RELATIVE);
memmove(rp_name + err + (is_absolute ? 4 : 0), rp_name, sizeof(short) * err); memmove(rp_name + err + (is_absolute ? 4 : 0), rp_name,
sizeof(short) * err);
if (is_absolute) { if (is_absolute) {
/* Decorate SubstituteName. */ /* Decorate SubstituteName. */
@ -1635,7 +1637,8 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
* Use ni_find_attr cause layout of MFT record may be changed * Use ni_find_attr cause layout of MFT record may be changed
* in ntfs_init_acl and ntfs_save_wsl_perm. * in ntfs_init_acl and ntfs_save_wsl_perm.
*/ */
attr = ni_find_attr(ni, NULL, NULL, ATTR_NAME, NULL, 0, NULL, NULL); attr = ni_find_attr(ni, NULL, NULL, ATTR_NAME, NULL, 0, NULL,
NULL);
if (attr) { if (attr) {
struct ATTR_FILE_NAME *fn; struct ATTR_FILE_NAME *fn;

View File

@ -207,13 +207,13 @@ static int ntfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
} }
/* /*
* ntfs_mkdir- inode_operations::mkdir * ntfs_mkdir - inode_operations::mkdir
*/ */
static struct dentry *ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, static struct dentry *ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode) struct dentry *dentry, umode_t mode)
{ {
return ERR_PTR(ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0, return ERR_PTR(ntfs_create_inode(idmap, dir, dentry, NULL,
NULL, 0, NULL)); S_IFDIR | mode, 0, NULL, 0, NULL));
} }
/* /*

View File

@ -584,7 +584,8 @@ int ni_add_name(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
struct NTFS_DE *de); struct NTFS_DE *de);
int ni_rename(struct ntfs_inode *dir_ni, struct ntfs_inode *new_dir_ni, int ni_rename(struct ntfs_inode *dir_ni, struct ntfs_inode *new_dir_ni,
struct ntfs_inode *ni, struct NTFS_DE *de, struct NTFS_DE *new_de); struct ntfs_inode *ni, struct NTFS_DE *de,
struct NTFS_DE *new_de);
bool ni_is_dirty(struct inode *inode); bool ni_is_dirty(struct inode *inode);
@ -709,8 +710,7 @@ int ntfs_set_size(struct inode *inode, u64 new_size);
int ntfs_get_block(struct inode *inode, sector_t vbn, int ntfs_get_block(struct inode *inode, sector_t vbn,
struct buffer_head *bh_result, int create); struct buffer_head *bh_result, int create);
int ntfs_write_begin(const struct kiocb *iocb, struct address_space *mapping, int ntfs_write_begin(const struct kiocb *iocb, struct address_space *mapping,
loff_t pos, u32 len, struct folio **foliop, loff_t pos, u32 len, struct folio **foliop, void **fsdata);
void **fsdata);
int ntfs_write_end(const struct kiocb *iocb, struct address_space *mapping, int ntfs_write_end(const struct kiocb *iocb, struct address_space *mapping,
loff_t pos, u32 len, u32 copied, struct folio *folio, loff_t pos, u32 len, u32 copied, struct folio *folio,
void *fsdata); void *fsdata);

View File

@ -16,6 +16,13 @@
* mi - MFT inode - One MFT record(usually 1024 bytes or 4K), consists of attributes. * mi - MFT inode - One MFT record(usually 1024 bytes or 4K), consists of attributes.
* ni - NTFS inode - Extends linux inode. consists of one or more mft inodes. * ni - NTFS inode - Extends linux inode. consists of one or more mft inodes.
* index - unit inside directory - 2K, 4K, <=page size, does not depend on cluster size. * index - unit inside directory - 2K, 4K, <=page size, does not depend on cluster size.
* resident attribute - Attribute with content stored directly in the MFT record
* non-resident attribute - Attribute with content stored in clusters
* data_size - Size of attribute content in bytes. Equal to inode->i_size
* valid_size - Number of bytes written to the non-resident attribute
* allocated_size - Total size of clusters allocated for non-resident content
* total_size - Actual size of allocated clusters for sparse or compressed attributes
* - Constraint: valid_size <= data_size <= allocated_size
* *
* WSL - Windows Subsystem for Linux * WSL - Windows Subsystem for Linux
* https://docs.microsoft.com/en-us/windows/wsl/file-permissions * https://docs.microsoft.com/en-us/windows/wsl/file-permissions
@ -288,10 +295,8 @@ static const struct fs_parameter_spec ntfs_fs_parameters[] = {
/* /*
* Load nls table or if @nls is utf8 then return NULL. * Load nls table or if @nls is utf8 then return NULL.
* *
* It is good idea to use here "const char *nls".
* But load_nls accepts "char*".
*/ */
static struct nls_table *ntfs_load_nls(char *nls) static struct nls_table *ntfs_load_nls(const char *nls)
{ {
struct nls_table *ret; struct nls_table *ret;
@ -566,10 +571,8 @@ static void ntfs_create_procdir(struct super_block *sb)
if (e) { if (e) {
struct ntfs_sb_info *sbi = sb->s_fs_info; struct ntfs_sb_info *sbi = sb->s_fs_info;
proc_create_data("volinfo", 0444, e, proc_create_data("volinfo", 0444, e, &ntfs3_volinfo_fops, sb);
&ntfs3_volinfo_fops, sb); proc_create_data("label", 0644, e, &ntfs3_label_fops, sb);
proc_create_data("label", 0644, e,
&ntfs3_label_fops, sb);
sbi->procdir = e; sbi->procdir = e;
} }
} }
@ -600,10 +603,12 @@ static void ntfs_remove_proc_root(void)
} }
} }
#else #else
static void ntfs_create_procdir(struct super_block *sb) {} // clang-format off
static void ntfs_remove_procdir(struct super_block *sb) {} static void ntfs_create_procdir(struct super_block *sb){}
static void ntfs_create_proc_root(void) {} static void ntfs_remove_procdir(struct super_block *sb){}
static void ntfs_remove_proc_root(void) {} static void ntfs_create_proc_root(void){}
static void ntfs_remove_proc_root(void){}
// clang-format on
#endif #endif
static struct kmem_cache *ntfs_inode_cachep; static struct kmem_cache *ntfs_inode_cachep;
@ -1223,8 +1228,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
sb->s_export_op = &ntfs_export_ops; sb->s_export_op = &ntfs_export_ops;
sb->s_time_gran = NTFS_TIME_GRAN; // 100 nsec sb->s_time_gran = NTFS_TIME_GRAN; // 100 nsec
sb->s_xattr = ntfs_xattr_handlers; sb->s_xattr = ntfs_xattr_handlers;
if (options->nocase) set_default_d_op(sb, options->nocase ? &ntfs_dentry_ops : NULL);
set_default_d_op(sb, &ntfs_dentry_ops);
options->nls = ntfs_load_nls(options->nls_name); options->nls = ntfs_load_nls(options->nls_name);
if (IS_ERR(options->nls)) { if (IS_ERR(options->nls)) {
@ -1643,7 +1647,6 @@ put_inode_out:
out: out:
ntfs3_put_sbi(sbi); ntfs3_put_sbi(sbi);
kfree(boot2); kfree(boot2);
ntfs3_put_sbi(sbi);
return err; return err;
} }