platform/kernel/linux-starfive.git
3 years agofs/ntfs3: Keep prealloc for all types of files
Konstantin Komarov [Fri, 1 Oct 2021 15:48:49 +0000 (18:48 +0300)]
fs/ntfs3: Keep prealloc for all types of files

Before we haven't kept prealloc for sparse files because we thought that
it will speed up create / write operations.
It lead to situation, when user reserved some space for sparse file,
filled volume, and wasn't able to write in reserved file.
With this commit we keep prealloc.
Now xfstest generic/274 pass.
Fixes: be71b5cba2e6 ("fs/ntfs3: Add attrib operations")

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove unnecessary functions
Konstantin Komarov [Tue, 5 Oct 2021 14:22:29 +0000 (17:22 +0300)]
fs/ntfs3: Remove unnecessary functions

We don't need ntfs_xattr_get_acl and ntfs_xattr_set_acl.
There are ntfs_get_acl_ex and ntfs_set_acl_ex.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Forbid FALLOC_FL_PUNCH_HOLE for normal files
Konstantin Komarov [Tue, 28 Sep 2021 17:04:10 +0000 (20:04 +0300)]
fs/ntfs3: Forbid FALLOC_FL_PUNCH_HOLE for normal files

FALLOC_FL_PUNCH_HOLE isn't allowed with normal files.
Filesystem must remember info about hole, but for normal file
we can only zero it and forget.

Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Now xfstests generic/016 generic/021 generic/022 pass.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Refactoring of ntfs_set_ea
Konstantin Komarov [Fri, 24 Sep 2021 14:53:56 +0000 (17:53 +0300)]
fs/ntfs3: Refactoring of ntfs_set_ea

Make code more readable.
Don't try to read zero bytes.
Add warning when size of exteneded attribute exceeds limit.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove locked argument in ntfs_set_ea
Konstantin Komarov [Fri, 24 Sep 2021 14:50:22 +0000 (17:50 +0300)]
fs/ntfs3: Remove locked argument in ntfs_set_ea

We always need to lock now, because locks became smaller
(see d562e901f25d
"fs/ntfs3: Move ni_lock_dir and ni_unlock into ntfs_create_inode").

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Use available posix_acl_release instead of ntfs_posix_acl_release
Konstantin Komarov [Fri, 24 Sep 2021 14:47:04 +0000 (17:47 +0300)]
fs/ntfs3: Use available posix_acl_release instead of ntfs_posix_acl_release

We don't need to maintain ntfs_posix_acl_release.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Check for NULL if ATTR_EA_INFO is incorrect
Konstantin Komarov [Wed, 29 Sep 2021 16:29:52 +0000 (19:29 +0300)]
fs/ntfs3: Check for NULL if ATTR_EA_INFO is incorrect

This can be reason for reported panic
https://lore.kernel.org/ntfs3/f9de5807-2311-7374-afb0-bc5dffb522c0@gmail.com/
Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")

Reported-by: Mohammad Rasim <mohammad.rasim96@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Refactoring of ntfs_init_from_boot
Konstantin Komarov [Tue, 28 Sep 2021 16:19:49 +0000 (19:19 +0300)]
fs/ntfs3: Refactoring of ntfs_init_from_boot

Remove ntfs_sb_info members sector_size and sector_bits.
Print details why mount failed.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Reject mount if boot's cluster size < media sector size
Konstantin Komarov [Tue, 28 Sep 2021 16:19:17 +0000 (19:19 +0300)]
fs/ntfs3: Reject mount if boot's cluster size < media sector size

If we continue to work in this case, then we can corrupt fs.
Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block").

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Refactoring lock in ntfs_init_acl
Konstantin Komarov [Wed, 22 Sep 2021 15:50:58 +0000 (18:50 +0300)]
fs/ntfs3: Refactoring lock in ntfs_init_acl

This is possible because of moving lock into ntfs_create_inode.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Change posix_acl_equiv_mode to posix_acl_update_mode
Konstantin Komarov [Wed, 22 Sep 2021 15:46:14 +0000 (18:46 +0300)]
fs/ntfs3: Change posix_acl_equiv_mode to posix_acl_update_mode

Right now ntfs3 uses posix_acl_equiv_mode instead of
posix_acl_update_mode like all other fs.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Pass flags to ntfs_set_ea in ntfs_set_acl_ex
Konstantin Komarov [Wed, 22 Sep 2021 15:33:38 +0000 (18:33 +0300)]
fs/ntfs3: Pass flags to ntfs_set_ea in ntfs_set_acl_ex

In case of removing of xattr there must be XATTR_REPLACE flag and
zero length. We already check XATTR_REPLACE in ntfs_set_ea, so
now we pass XATTR_REPLACE to ntfs_set_ea.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Refactor ntfs_get_acl_ex for better readability
Konstantin Komarov [Wed, 22 Sep 2021 15:28:36 +0000 (18:28 +0300)]
fs/ntfs3: Refactor ntfs_get_acl_ex for better readability

We can safely move set_cached_acl because it works with NULL acl too.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Move ni_lock_dir and ni_unlock into ntfs_create_inode
Konstantin Komarov [Thu, 23 Sep 2021 15:04:26 +0000 (18:04 +0300)]
fs/ntfs3: Move ni_lock_dir and ni_unlock into ntfs_create_inode

Now ntfs3 locks mutex for smaller time.
Theoretically in successful cases those locks aren't needed at all.
But proving the same for error cases is difficult.
So instead of removing them we just move them.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix logical error in ntfs_create_inode
Konstantin Komarov [Thu, 23 Sep 2021 15:05:36 +0000 (18:05 +0300)]
fs/ntfs3: Fix logical error in ntfs_create_inode

We need to always call indx_delete_entry after indx_insert_entry
if error occurred.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove deprecated mount options nls
Kari Argillander [Tue, 21 Sep 2021 17:19:01 +0000 (20:19 +0300)]
fs/ntfs3: Remove deprecated mount options nls

Some discussion has been spoken that this deprecated mount options
should be removed before 5.15 lands. This driver is not never seen day
light so it was decided that nls mount option has to be removed. We have
always possibility to add this if needed.

One possible need is example if current ntfs driver will be taken out of
kernel and ntfs3 needs to support mount options what it has.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove a useless shadowing variable
Christophe JAILLET [Sat, 18 Sep 2021 19:56:28 +0000 (21:56 +0200)]
fs/ntfs3: Remove a useless shadowing variable

There is already a 'u8 mask' defined at the top of the function.
There is no need to define a new one here.

Remove the useless and shadowing new 'mask' variable.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove a useless test in 'indx_find()'
Christophe JAILLET [Sat, 18 Sep 2021 19:56:19 +0000 (21:56 +0200)]
fs/ntfs3: Remove a useless test in 'indx_find()'

'fnd' has been dereferenced several time before, so testing it here is
pointless.
Moreover, all callers of 'indx_find()' already have some error handling
code that makes sure that no NULL 'fnd' is passed.

So, remove the useless test.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Add sync flag to ntfs_sb_write_run and al_update
Konstantin Komarov [Thu, 9 Sep 2021 10:15:20 +0000 (13:15 +0300)]
fs/ntfs3: Add sync flag to ntfs_sb_write_run and al_update

This allows to wait only when it's requested.
It speeds up creation of hardlinks.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Change max hardlinks limit to 4000
Konstantin Komarov [Thu, 9 Sep 2021 10:12:41 +0000 (13:12 +0300)]
fs/ntfs3: Change max hardlinks limit to 4000

xfstest generic/041 works with 3003 hardlinks.
Because of this we raise hardlinks limit to 4000.
There are no drawbacks or regressions.
Theoretically we can raise all the way up to ffff,
but there is no practical use for this.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix insertion of attr in ni_ins_attr_ext
Konstantin Komarov [Wed, 8 Sep 2021 15:39:53 +0000 (18:39 +0300)]
fs/ntfs3: Fix insertion of attr in ni_ins_attr_ext

Do not try to insert attribute if there is no room in record.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix a memory leak on object opts
Colin Ian King [Fri, 10 Sep 2021 10:02:02 +0000 (11:02 +0100)]
fs/ntfs3: Fix a memory leak on object opts

Currently a failed allocation on sbi->upcase will cause an exit via
the label free_sbi causing a memory leak on object opts. Fix this by
re-ordering the exit paths free_opts and free_sbi so that kfree's occur
in the reverse allocation order.

Addresses-Coverity: ("Resource leak")
Fixes: 27fac77707a1 ("fs/ntfs3: Init spi more in init_fs_context than fill_super")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agoDoc/fs/ntfs3: Fix rst format and make it cleaner
Kari Argillander [Thu, 9 Sep 2021 21:57:53 +0000 (00:57 +0300)]
Doc/fs/ntfs3: Fix rst format and make it cleaner

Current ntfs3 rst documentation is broken. I turn table to list table as
this is current Linux documentation quide line. Simple table also did
not quite work in our situation as we need to span rows together.

It still look quite good as text so we did not loss anything. This will
also make diffing quite bit more pleasure.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Initiliaze sb blocksize only in one place + refactor
Kari Argillander [Thu, 9 Sep 2021 18:09:42 +0000 (21:09 +0300)]
fs/ntfs3: Initiliaze sb blocksize only in one place + refactor

Right now sb blocksize first get initiliazed in fill_super but in can be
changed in helper function. It makes more sense to that this happened
only in one place.

Because we move this to helper function it makes more sense that
s_maxbytes will also be there. I rather have every sb releted thing in
fill_super, but because there is already sb releted stuff in this
helper. This will have to do for now.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Initialize pointer before use place in fill_super
Kari Argillander [Thu, 9 Sep 2021 18:09:41 +0000 (21:09 +0300)]
fs/ntfs3: Initialize pointer before use place in fill_super

Initializing should be as close as possible when we use it so that
we do not need to scroll up to see what is happening.

Also bdev_get_queue() can never return NULL so we do not need to check
for !rq.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove tmp pointer upcase in fill_super
Kari Argillander [Thu, 9 Sep 2021 18:09:40 +0000 (21:09 +0300)]
fs/ntfs3: Remove tmp pointer upcase in fill_super

We can survive without this tmp point upcase. So remove it we don't have
so many tmp pointer in this function.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove tmp pointer bd_inode in fill_super
Kari Argillander [Thu, 9 Sep 2021 18:09:39 +0000 (21:09 +0300)]
fs/ntfs3: Remove tmp pointer bd_inode in fill_super

Drop tmp pointer bd_inode because this is only used ones in fill_super.
Also we have so many initializing happening at the beginning that it is
already way too much to follow.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove tmp var is_ro in ntfs_fill_super
Kari Argillander [Thu, 9 Sep 2021 18:09:38 +0000 (21:09 +0300)]
fs/ntfs3: Remove tmp var is_ro in ntfs_fill_super

We only use this in two places so we do not really need it. Also
wrapper sb_rdonly() is pretty self explanatory. This will make little
bit easier to read this super long variable list in the beginning of
ntfs_fill_super().

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Use sb instead of sbi->sb in fill_super
Kari Argillander [Thu, 9 Sep 2021 18:09:37 +0000 (21:09 +0300)]
fs/ntfs3: Use sb instead of sbi->sb in fill_super

Use sb instead of sbi->sb in fill_super. We have sb so why not use
it. Also makes code more readable.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove unnecessary variable loading in fill_super
Kari Argillander [Thu, 9 Sep 2021 18:09:36 +0000 (21:09 +0300)]
fs/ntfs3: Remove unnecessary variable loading in fill_super

Remove some unnecessary variable loading. These look like copy paste
work and they are not used to anything.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Return straight without goto in fill_super
Kari Argillander [Thu, 9 Sep 2021 18:09:35 +0000 (21:09 +0300)]
fs/ntfs3: Return straight without goto in fill_super

In many places it is not needed to use goto out. We can just return
right away. This will make code little bit more cleaner as we won't
need to check error path.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove impossible fault condition in fill_super
Kari Argillander [Thu, 9 Sep 2021 18:09:34 +0000 (21:09 +0300)]
fs/ntfs3: Remove impossible fault condition in fill_super

Remove root drop when we fault out. This can never happened because
when we allocate root we eather fault when no root or success.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Change EINVAL to ENOMEM when d_make_root fails
Kari Argillander [Thu, 9 Sep 2021 18:09:33 +0000 (21:09 +0300)]
fs/ntfs3: Change EINVAL to ENOMEM when d_make_root fails

Change EINVAL to ENOMEM when d_make_root fails because that is right
errno.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix wrong error message $Logfile -> $UpCase
Kari Argillander [Thu, 9 Sep 2021 18:09:32 +0000 (21:09 +0300)]
fs/ntfs3: Fix wrong error message $Logfile -> $UpCase

Fix wrong error message $Logfile -> $UpCase. Probably copy paste.

Fixes: 203c2b3a406a ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Use min/max macros instated of ternary operators
Kari Argillander [Tue, 7 Sep 2021 14:28:42 +0000 (17:28 +0300)]
fs/ntfs3: Use min/max macros instated of ternary operators

We can make code little bit more readable by using min/max macros.

These were found with Coccinelle.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Use clamp/max macros instead of comparisons
Kari Argillander [Tue, 7 Sep 2021 14:28:41 +0000 (17:28 +0300)]
fs/ntfs3: Use clamp/max macros instead of comparisons

We can make code little more readable by using kernel macros clamp/max.

This were found with kernel included Coccinelle minmax script.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove always false condition check
Kari Argillander [Tue, 7 Sep 2021 14:28:40 +0000 (17:28 +0300)]
fs/ntfs3: Remove always false condition check

We do not need this check as this is same thing as
NTFS_MIN_MFT_ZONE > zlen. We already check NTFS_MIN_MFT_ZONE <= zlen and
exit because is too big request. Remove it so code is cleaner.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix ntfs_look_for_free_space() does only report -ENOSPC
Kari Argillander [Tue, 7 Sep 2021 14:28:39 +0000 (17:28 +0300)]
fs/ntfs3: Fix ntfs_look_for_free_space() does only report -ENOSPC

If ntfs_refresh_zone() returns error it will be changed to -ENOSPC. It
is not right. Also caller of this functions also check other errors.

Fixes: 78ab59fee07f ("fs/ntfs3: Rework file operations")
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove tabs before spaces from comment
Kari Argillander [Tue, 7 Sep 2021 08:34:41 +0000 (11:34 +0300)]
fs/ntfs3: Remove tabs before spaces from comment

Remove tabs before spaces from comment as recommended by kernel coding
style. Checkpatch also warn about these.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove braces from single statment block
Kari Argillander [Tue, 7 Sep 2021 08:34:40 +0000 (11:34 +0300)]
fs/ntfs3: Remove braces from single statment block

Remove braces from single statment block as they are not needed. Also
Linux kernel coding style guide recommend this and checkpatch warn about
this.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Place Comparisons constant right side of the test
Kari Argillander [Tue, 7 Sep 2021 08:34:39 +0000 (11:34 +0300)]
fs/ntfs3: Place Comparisons constant right side of the test

For better code readability place constant always right side of the
test. This will also address checkpatch warning.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove '+' before constant in ni_insert_resident()
Kari Argillander [Tue, 7 Sep 2021 08:34:38 +0000 (11:34 +0300)]
fs/ntfs3: Remove '+' before constant in ni_insert_resident()

No need for plus sign here. So remove it. Checkpatch will also be happy.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Always use binary search with entry search
Kari Argillander [Thu, 2 Sep 2021 15:40:50 +0000 (18:40 +0300)]
fs/ntfs3: Always use binary search with entry search

We do not have any reason to keep old linear search in. Before this was
used for error path or if table was so big that it cannot be allocated.
Current binary search implementation won't need error path. Remove old
references to linear entry search.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Make binary search to search smaller chunks in beginning
Kari Argillander [Thu, 2 Sep 2021 15:40:49 +0000 (18:40 +0300)]
fs/ntfs3: Make binary search to search smaller chunks in beginning

We could try to optimize algorithm to first fill just small table and
after that use bigger table all the way up to ARRAY_SIZE(offs). This
way we can use bigger search array, but not lose benefits with entry
count smaller < ARRAY_SIZE(offs).

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Limit binary search table size
Kari Argillander [Thu, 2 Sep 2021 15:40:48 +0000 (18:40 +0300)]
fs/ntfs3: Limit binary search table size

Current binary search allocates memory for table and fill whole table
before we start actual binary search. This is quite inefficient because
table fill will always be O(n). Also if table is huge we need to
reallocate memory which is costly.

This implementation use just stack memory and always when table is full
we will check if last element is <= and if not start table fill again.
The idea was that it would be same cost as table reallocation.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove unneeded header files from c files
Kari Argillander [Thu, 2 Sep 2021 16:15:28 +0000 (19:15 +0300)]
fs/ntfs3: Remove unneeded header files from c files

We have lot of unnecessary headers in these files. Remove them so that
we help compiler a little bit.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Change right headers to lznt.c
Kari Argillander [Thu, 2 Sep 2021 16:15:27 +0000 (19:15 +0300)]
fs/ntfs3: Change right headers to lznt.c

There is lot of headers which we do not need in this file. Delete them
and add what we really need. Here is list which identify why we need
this header.

<linux/kernel.h> // min()
<linux/slab.h> // kzalloc()
<linux/stddef.h> // offsetof()
<linux/string.h> // memcpy(), memset()
<linux/types.h> // u8, size_t, etc.

"debug.h" // PtrOffset()

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Change right headers to upcase.c
Kari Argillander [Thu, 2 Sep 2021 16:15:26 +0000 (19:15 +0300)]
fs/ntfs3: Change right headers to upcase.c

There is no headers. They will be included through ntfs_fs.c, but that
is not right thing to do. Let's include headers what this file need
straight away.

types.h is needed for __le16, u8 etc.
kernel.h is needed for le16_to_cpu()

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Change right headers to bitfunc.c
Kari Argillander [Thu, 2 Sep 2021 16:15:25 +0000 (19:15 +0300)]
fs/ntfs3: Change right headers to bitfunc.c

We only need linux/types.h for types like u8 etc. So we can remove rest
and help compiler a little bit.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Add missing header and guards to lib/ headers
Kari Argillander [Thu, 2 Sep 2021 16:15:24 +0000 (19:15 +0300)]
fs/ntfs3: Add missing header and guards to lib/ headers

size_t needs header. Add missing header guards so that compiler will
only include these ones.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Add missing headers and forward declarations to ntfs_fs.h
Kari Argillander [Thu, 2 Sep 2021 16:15:23 +0000 (19:15 +0300)]
fs/ntfs3: Add missing headers and forward declarations to ntfs_fs.h

We do not have headers at all in this file. We should have them so that
not every .c file needs to include all of the stuff which this file need
for building. This way we can remove some headers from other files and
get better picture what is needed. This can save some compilation time.
And this can help if we sometimes want to separate this one big header.

Also use forward declarations for structs and enums when it not included
straight with include and it is used in function declarations input.
This will prevent possible compiler warning:
  xxx declared inside parameter list will not be visible
  outside of this definition or declaration

Here is list which I made when parsing this. There is not necessarily
all example from this header file, but this just proofs we need it.

<linux/blkdev.h> SECTOR_SHIFT
<linux/buffer_head.h> sb_bread(), put_bh
<linux/cleancache.h> put_page()
<linux/fs.h> struct inode (Just struct ntfs_inode need it)
<linux/highmem.h> kunmap(), kmap()
<linux/kernel.h> cpu_to_leXX() ALIGN
<linux/mm.h> kvfree()
<linux/mutex.h> struct mutex, mutex_(un/try)lock()
<linux/page-flags.h> PageError()
<linux/pagemap.h> read_mapping_page()
<linux/rbtree.h> struct rb_root
<linux/rwsem.h> struct rw_semaphore
<linux/slab.h> krfree(), kzalloc()
<linux/string.h> memset()
<linux/time64.h> struct timespec64
<linux/types.h> uXX, __leXX
<linux/uidgid.h> kuid_t, kgid_t
<asm/div64.h> do_div()
<asm/page.h> PAGE_SIZE

"debug.h" ntfs_err() (Just one entry. Maybe we can drop this)
"ntfs.h" Do you even ask?

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Add missing header files to ntfs.h
Kari Argillander [Thu, 2 Sep 2021 16:15:22 +0000 (19:15 +0300)]
fs/ntfs3: Add missing header files to ntfs.h

We do not have header files at all in this file. Add following headers
and there is also explanation which for it was added. Note that
explanation might not be complete, but it just proofs it is needed.

<linux/blkdev.h> // SECTOR_SHIFT
<linux/build_bug.h> // static_assert()
<linux/kernel.h> // cpu_to_le64, cpu_to_le32, ALIGN
<linux/stddef.h> // offsetof()
<linux/string.h> // memcmp()
<linux/types.h> //__le32, __le16

"debug.h" // PtrOffset(), Add2Ptr()

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3. Add forward declarations for structs to debug.h
Kari Argillander [Thu, 2 Sep 2021 16:15:21 +0000 (19:15 +0300)]
fs/ntfs3. Add forward declarations for structs to debug.h

Add forward declarations for structs so that we can include this file
without warnings even without linux/fs.h

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove redundant initialization of variable err
Colin Ian King [Fri, 3 Sep 2021 13:24:58 +0000 (14:24 +0100)]
fs/ntfs3: Remove redundant initialization of variable err

The variable err is being initialized with a value that is never read, it
is being updated later on. The assignment is redundant and can be removed.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Show uid/gid always in show_options()
Kari Argillander [Tue, 7 Sep 2021 15:35:57 +0000 (18:35 +0300)]
fs/ntfs3: Show uid/gid always in show_options()

Show options should show option according documentation when some value
is not default or when ever coder wants. Uid/gid are problematic because
it is hard to know which are defaults. In file system there is many
different implementation for this problem.

Some file systems show uid/gid when they are different than root, some
when user has set them and some show them always. There is also problem
that what if root uid/gid change. This code just choose to show them
always. This way we do not need to think this any more.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Rename mount option no_acs_rules > (no)acsrules
Kari Argillander [Tue, 7 Sep 2021 15:35:56 +0000 (18:35 +0300)]
fs/ntfs3: Rename mount option no_acs_rules > (no)acsrules

Rename mount option no_acs_rules to (no)acsrules. This allow us to use
possibility to mount with options noaclrules or aclrules.

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Add iocharset= mount option as alias for nls=
Kari Argillander [Tue, 7 Sep 2021 15:35:55 +0000 (18:35 +0300)]
fs/ntfs3: Add iocharset= mount option as alias for nls=

Other fs drivers are using iocharset= mount option for specifying charset.
So add it also for ntfs3 and mark old nls= mount option as deprecated.

Reviewed-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Make mount option nohidden more universal
Kari Argillander [Tue, 7 Sep 2021 15:35:54 +0000 (18:35 +0300)]
fs/ntfs3: Make mount option nohidden more universal

If we call Opt_nohidden with just keyword hidden, then we can use
hidden/nohidden when mounting. We already use this method for almoust
all other parameters so it is just logical that this will use same
method.

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Init spi more in init_fs_context than fill_super
Kari Argillander [Tue, 7 Sep 2021 15:35:53 +0000 (18:35 +0300)]
fs/ntfs3: Init spi more in init_fs_context than fill_super

init_fs_context() is meant to initialize s_fs_info (spi). Move spi
initializing code there which we can initialize before fill_super().

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Use new api for mounting
Kari Argillander [Tue, 7 Sep 2021 15:35:52 +0000 (18:35 +0300)]
fs/ntfs3: Use new api for mounting

We have now new mount api as described in Documentation/filesystems. We
should use it as it gives us some benefits which are desribed here
lore.kernel.org/linux-fsdevel/159646178122.1784947.11705396571718464082.stgit@warthog.procyon.org.uk/

Nls loading is changed a to load with string. This did make code also
little cleaner.

Also try to use fsparam_flag_no as much as possible. This is just nice
little touch and is not mandatory but it should not make any harm. It
is just convenient that we can use example acl/noacl mount options.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Convert mount options to pointer in sbi
Kari Argillander [Tue, 7 Sep 2021 15:35:51 +0000 (18:35 +0300)]
fs/ntfs3: Convert mount options to pointer in sbi

Use pointer to mount options. We want to do this because we will use new
mount api which will benefit that we have spi and mount options in
different allocations. When we remount we do not have to make whole new
spi it is enough that we will allocate just mount options.

Please note that we can do example remount lot cleaner but things will
change in next patch so this should be just functional.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove unnecesarry remount flag handling
Kari Argillander [Tue, 7 Sep 2021 15:35:50 +0000 (18:35 +0300)]
fs/ntfs3: Remove unnecesarry remount flag handling

Remove unnecesarry remount flag handling. This does not do anything for
this driver. We have already set SB_NODIRATIME when we fill super. Also
noatime should be set from mount option. Now for some reson we try to
set it when remounting.

Lazytime part looks like it is copied from f2fs and there is own mount
parameter for it. That is why they use it. We do not set lazytime
anywhere in our code. So basically this just blocks lazytime when
remounting.

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove unnecesarry mount option noatime
Kari Argillander [Tue, 7 Sep 2021 15:35:49 +0000 (18:35 +0300)]
fs/ntfs3: Remove unnecesarry mount option noatime

Remove unnecesarry mount option noatime because this will be handled
by VFS. Our option parser will never get opt like this.

Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Change how module init/info messages are displayed
Kari Argillander [Sun, 29 Aug 2021 14:42:39 +0000 (17:42 +0300)]
fs/ntfs3: Change how module init/info messages are displayed

Usually in file system init() messages are only displayed in info level.
Change level from notice to info, but keep CONFIG_NTFS3_64BIT_CLUSTER in
notice level. Also this need even more attention so let's put big
warning here so that nobody will not try accidentally use it.

There is also no good reason to display internal stuff like binary tree
search. This is always on option which can only disabled for debugging
purposes by developer. Also this message does not even check if
developer has disabled it or not so it is useless info.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove GPL boilerplates from decompress lib files
Kari Argillander [Thu, 26 Aug 2021 21:44:41 +0000 (00:44 +0300)]
fs/ntfs3: Remove GPL boilerplates from decompress lib files

Files already have SDPX identifier so no reason to keep boilerplates in
these files anymore.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Acked-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove unnecessary condition checking from ntfs_file_read_iter
Kari Argillander [Wed, 25 Aug 2021 18:25:22 +0000 (21:25 +0300)]
fs/ntfs3: Remove unnecessary condition checking from ntfs_file_read_iter

This check will be also performed in generic_file_read_iter() so we do
not want to check this two times in a row.

This was founded with Smatch
fs/ntfs3/file.c:803 ntfs_file_read_iter()
warn: unused return: count = iov_iter_count()

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix integer overflow in ni_fiemap with fiemap_prep()
Kari Argillander [Wed, 25 Aug 2021 18:24:35 +0000 (21:24 +0300)]
fs/ntfs3: Fix integer overflow in ni_fiemap with fiemap_prep()

Use fiemap_prep() to check valid flags. It also shrink request scope
(@len) to what the fs can actually handle.

This address following Smatch static checker warning:
fs/ntfs3/frecord.c:1894 ni_fiemap()
warn: potential integer overflow from user 'vbo + len'

Because fiemap_prep() shrinks @len this cannot happened anymore.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: lore.kernel.org/ntfs3/20210825080440.GA17407@kili/

Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Restyle comments to better align with kernel-doc
Konstantin Komarov [Tue, 31 Aug 2021 13:57:40 +0000 (16:57 +0300)]
fs/ntfs3: Restyle comments to better align with kernel-doc

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Rework file operations
Konstantin Komarov [Tue, 31 Aug 2021 15:52:39 +0000 (18:52 +0300)]
fs/ntfs3: Rework file operations

Rename now works "Add new name and remove old name".
"Remove old name and add new name" may result in bad inode
if we can't add new name and then can't restore (add) old name.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove fat ioctl's from ntfs3 driver for now
Kari Argillander [Tue, 24 Aug 2021 18:20:20 +0000 (21:20 +0300)]
fs/ntfs3: Remove fat ioctl's from ntfs3 driver for now

For some reason we have FAT ioctl calls. Even old ntfs driver did not
use these. We should not use these because it his hard to get things out
of kernel when they are upstream. That's why we remove these for now.

More discussion is needed what ioctl should be implemented and what is
important.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Restyle comments to better align with kernel-doc
Kari Argillander [Tue, 3 Aug 2021 11:57:09 +0000 (14:57 +0300)]
fs/ntfs3: Restyle comments to better align with kernel-doc

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 <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix error handling in indx_insert_into_root()
Dan Carpenter [Tue, 24 Aug 2021 07:51:04 +0000 (10:51 +0300)]
fs/ntfs3: Fix error handling in indx_insert_into_root()

There are three bugs in this code:
1) If indx_get_root() fails, then return -EINVAL instead of success.
2) On the "/* make root external */" -EOPNOTSUPP; error path it should
   free "re" but it has a memory leak.
3) If indx_new() fails then it will lead to an error pointer dereference
   when we call put_indx_node().

I've re-written the error handling to be more clear.

Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Potential NULL dereference in hdr_find_split()
Dan Carpenter [Tue, 24 Aug 2021 07:50:15 +0000 (10:50 +0300)]
fs/ntfs3: Potential NULL dereference in hdr_find_split()

The "e" pointer is dereferenced before it has been checked for NULL.
Move the dereference after the NULL check to prevent an Oops.

Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix error code in indx_add_allocate()
Dan Carpenter [Tue, 24 Aug 2021 07:49:32 +0000 (10:49 +0300)]
fs/ntfs3: Fix error code in indx_add_allocate()

Return -EINVAL if ni_find_attr() fails.  Don't return success.

Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: fix an error code in ntfs_get_acl_ex()
Dan Carpenter [Tue, 24 Aug 2021 11:48:58 +0000 (14:48 +0300)]
fs/ntfs3: fix an error code in ntfs_get_acl_ex()

The ntfs_get_ea() function returns negative error codes or on success
it returns the length.  In the original code a zero length return was
treated as -ENODATA and results in a NULL return.  But it should be
treated as an invalid length and result in an PTR_ERR(-EINVAL) return.

Fixes: be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: add checks for allocation failure
Dan Carpenter [Tue, 24 Aug 2021 11:52:36 +0000 (14:52 +0300)]
fs/ntfs3: add checks for allocation failure

Add a check for when the kzalloc() in init_rsttbl() fails.  Some of
the callers checked for NULL and some did not.  I went down the call
tree and added NULL checks where ever they were missing.

Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Use kcalloc/kmalloc_array over kzalloc/kmalloc
Kari Argillander [Tue, 24 Aug 2021 18:37:08 +0000 (21:37 +0300)]
fs/ntfs3: Use kcalloc/kmalloc_array over kzalloc/kmalloc

Use kcalloc/kmalloc_array over kzalloc/kmalloc when we allocate array.
Checkpatch found these after we did not use our own defined allocation
wrappers.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Do not use driver own alloc wrappers
Kari Argillander [Tue, 24 Aug 2021 18:37:07 +0000 (21:37 +0300)]
fs/ntfs3: Do not use driver own alloc wrappers

Problem with these wrapper is that we cannot take off example GFP_NOFS
flag. It is not recomended use those in all places. Also if we change
one driver specific wrapper to kernel wrapper then it would look really
weird. People should be most familiar with kernel wrappers so let's just
use those ones.

Driver specific alloc wrapper also confuse some static analyzing tools,
good example is example kernels checkpatch tool. After we converter
these to kernel specific then warnings is showed.

Following Coccinelle script was used to automate changing.

virtual patch

@alloc depends on patch@
expression x;
expression y;
@@
(
- ntfs_malloc(x)
+ kmalloc(x, GFP_NOFS)
|
- ntfs_zalloc(x)
+ kzalloc(x, GFP_NOFS)
|
- ntfs_vmalloc(x)
+ kvmalloc(x, GFP_NOFS)
|
- ntfs_free(x)
+ kfree(x)
|
- ntfs_vfree(x)
+ kvfree(x)
|
- ntfs_memdup(x, y)
+ kmemdup(x, y, GFP_NOFS)
)

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Use kernel ALIGN macros over driver specific
Kari Argillander [Thu, 26 Aug 2021 08:56:29 +0000 (11:56 +0300)]
fs/ntfs3: Use kernel ALIGN macros over driver specific

The static checkers (Smatch) were complaining because QuadAlign() was
buggy.  If you try to align something higher than UINT_MAX it got
truncated to a u32.

Smatch warning was:
fs/ntfs3/attrib.c:383 attr_set_size_res()
warn: was expecting a 64 bit value instead of '~7'

So that this will not happen again we will change all these macros to
kernel made ones. This can also help some other static analyzing tools
to give us better warnings.

Patch was generated with Coccinelle script and after that some style
issue was hand fixed.

Coccinelle script:

virtual patch

@alloc depends on patch@
expression x;
@@
(
- #define QuadAlign(n) (((n) + 7u) & (~7u))
|
- QuadAlign(x)
+ ALIGN(x, 8)
|
- #define IsQuadAligned(n) (!((size_t)(n)&7u))
|
- IsQuadAligned(x)
+ IS_ALIGNED(x, 8)
|
- #define Quad2Align(n) (((n) + 15u) & (~15u))
|
- Quad2Align(x)
+ ALIGN(x, 16)
|
- #define IsQuad2Aligned(n) (!((size_t)(n)&15u))
|
- IsQuad2Aligned(x)
+ IS_ALIGNED(x, 16)
|
- #define Quad4Align(n) (((n) + 31u) & (~31u))
|
- Quad4Align(x)
+ ALIGN(x, 32)
|
- #define IsSizeTAligned(n) (!((size_t)(n) & (sizeof(size_t) - 1)))
|
- IsSizeTAligned(x)
+ IS_ALIGNED(x, sizeof(size_t))
|
- #define DwordAlign(n) (((n) + 3u) & (~3u))
|
- DwordAlign(x)
+ ALIGN(x, 4)
|
- #define IsDwordAligned(n) (!((size_t)(n)&3u))
|
- IsDwordAligned(x)
+ IS_ALIGNED(x, 4)
|
- #define WordAlign(n) (((n) + 1u) & (~1u))
|
- WordAlign(x)
+ ALIGN(x, 2)
|
- #define IsWordAligned(n) (!((size_t)(n)&1u))
|
- IsWordAligned(x)
+ IS_ALIGNED(x, 2)
|
)

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Restyle comment block in ni_parse_reparse()
Kari Argillander [Tue, 24 Aug 2021 18:37:06 +0000 (21:37 +0300)]
fs/ntfs3: Restyle comment block in ni_parse_reparse()

First of this fix one none utf8 char in this comment block. Maybe
this happened because error in filesystem ;)

Also this block was hard to read because long lines so make it max 80
long. And while we doing this stuff make little better grammer.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove unused including <linux/version.h>
Jiapeng Chong [Thu, 19 Aug 2021 08:23:37 +0000 (16:23 +0800)]
fs/ntfs3: Remove unused including <linux/version.h>

Eliminate the follow versioncheck warning:

./fs/ntfs3/inode.c: 16 linux/version.h not needed.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix fall-through warnings for Clang
Gustavo A. R. Silva [Wed, 18 Aug 2021 22:21:46 +0000 (17:21 -0500)]
fs/ntfs3: Fix fall-through warnings for Clang

Fix the following fallthrough warnings:

fs/ntfs3/inode.c:1792:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
fs/ntfs3/index.c:178:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]

This helps with the ongoing efforts to globally enable
-Wimplicit-fallthrough for Clang.

Link: https://github.com/KSPP/linux/issues/115
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix one none utf8 char in source file
Kari Argillander [Wed, 18 Aug 2021 01:06:47 +0000 (04:06 +0300)]
fs/ntfs3: Fix one none utf8 char in source file

In one source file there is for some reason non utf8 char. But hey this
is fs development so this kind of thing might happen.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Remove unused variable cnt in ntfs_security_init()
Nathan Chancellor [Mon, 16 Aug 2021 19:30:41 +0000 (12:30 -0700)]
fs/ntfs3: Remove unused variable cnt in ntfs_security_init()

Clang warns:

fs/ntfs3/fsntfs.c:1874:9: warning: variable 'cnt' set but not used
[-Wunused-but-set-variable]
        size_t cnt, off;
               ^
1 warning generated.

It is indeed unused so remove it.

Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix integer overflow in multiplication
Colin Ian King [Mon, 16 Aug 2021 16:30:25 +0000 (17:30 +0100)]
fs/ntfs3: Fix integer overflow in multiplication

The multiplication of the u32 data_size with a int is being performed
using 32 bit arithmetic however the results is being assigned to the
variable nbits that is a size_t (64 bit) value. Fix a potential
integer overflow by casting the u32 value to a size_t before the
multiply to use a size_t sized bit multiply operation.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Add ifndef + define to all header files
Kari Argillander [Mon, 16 Aug 2021 12:01:56 +0000 (15:01 +0300)]
fs/ntfs3: Add ifndef + define to all header files

Add guards so that compiler will only include header files once.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Use linux/log2 is_power_of_2 function
Kari Argillander [Mon, 16 Aug 2021 10:37:32 +0000 (13:37 +0300)]
fs/ntfs3: Use linux/log2 is_power_of_2 function

We do not need our own implementation for this function in this
driver. It is much better to use generic one.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agofs/ntfs3: Fix various spelling mistakes
Colin Ian King [Mon, 16 Aug 2021 10:13:08 +0000 (11:13 +0100)]
fs/ntfs3: Fix various spelling mistakes

There is a spelling mistake in a ntfs_err error message. Also
fix various spelling mistakes in comments.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
3 years agoMerge branch 'torvalds:master' into master
aalexandrovich [Mon, 23 Aug 2021 13:44:22 +0000 (16:44 +0300)]
Merge branch 'torvalds:master' into master

3 years agoLinux 5.14-rc7
Linus Torvalds [Sun, 22 Aug 2021 21:24:56 +0000 (14:24 -0700)]
Linux 5.14-rc7

3 years agoMerge tag 'powerpc-5.14-6' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
Linus Torvalds [Sun, 22 Aug 2021 16:49:31 +0000 (09:49 -0700)]
Merge tag 'powerpc-5.14-6' of git://git./linux/kernel/git/powerpc/linux

Pull powerpc fixes from Michael Ellerman:

 - Fix random crashes on some 32-bit CPUs by adding isync() after
   locking/unlocking KUEP

 - Fix intermittent crashes when loading modules with strict module RWX

 - Fix a section mismatch introduce by a previous fix.

Thanks to Christophe Leroy, Fabiano Rosas, Laurent Vivier, Murilo
Opsfelder Araújo, Nathan Chancellor, and Stan Johnson.

h# -----BEGIN PGP SIGNATURE-----

* tag 'powerpc-5.14-6' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux:
  powerpc/mm: Fix set_memory_*() against concurrent accesses
  powerpc/32s: Fix random crashes by adding isync() after locking/unlocking KUEP
  powerpc/xive: Do not mark xive_request_ipi() as __init

3 years agoMerge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
Linus Torvalds [Sat, 21 Aug 2021 18:27:16 +0000 (11:27 -0700)]
Merge tag 'clk-fixes-for-linus' of git://git./linux/kernel/git/clk/linux

Pull clk driver fixes from Stephen Boyd:

 - Make the regulator state match the GDSC power domain state at boot on
   Qualcomm SoCs so that the regulator isn't turned off inadvertently.

 - Fix earlycon on i.MX6Q SoCs

* tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux:
  clk: qcom: gdsc: Ensure regulator init state matches GDSC state
  clk: imx6q: fix uart earlycon unwork

3 years agoMerge tag 'char-misc-5.14-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregk...
Linus Torvalds [Sat, 21 Aug 2021 18:22:10 +0000 (11:22 -0700)]
Merge tag 'char-misc-5.14-rc7' of git://git./linux/kernel/git/gregkh/char-misc

Pull char/misc driver fixes from Greg KH:
 "Here are some small driver fixes for 5.14-rc7.

  They consist of:

   - revert for an interconnect patch that was found to have problems

   - ipack tpci200 driver fixes for reported problems

   - slimbus messaging and ngd fixes for reported problems

  All are small and have been in linux-next for a while with no reported
  issues"

* tag 'char-misc-5.14-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc:
  ipack: tpci200: fix memory leak in the tpci200_register
  ipack: tpci200: fix many double free issues in tpci200_pci_probe
  slimbus: ngd: reset dma setup during runtime pm
  slimbus: ngd: set correct device for pm
  slimbus: messaging: check for valid transaction id
  slimbus: messaging: start transaction ids from 1 instead of zero
  Revert "interconnect: qcom: icc-rpmh: Add BCMs to commit list in pre_aggregate"

3 years agoMerge tag 'usb-5.14-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Linus Torvalds [Sat, 21 Aug 2021 18:10:06 +0000 (11:10 -0700)]
Merge tag 'usb-5.14-rc7' of git://git./linux/kernel/git/gregkh/usb

Pull USB fix from Greg KH:
 "Here is a single USB typec tcpm fix for a reported problem for
  5.14-rc7. It showed up in 5.13 and resolves an issue that Hans found.
  It has been in linux-next this week with no reported problems"

* tag 'usb-5.14-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb:
  usb: typec: tcpm: Fix VDMs sometimes not being forwarded to alt-mode drivers

3 years agoMerge tag 'riscv-for-linus-5.14-rc7' of git://git.kernel.org/pub/scm/linux/kernel...
Linus Torvalds [Sat, 21 Aug 2021 18:04:26 +0000 (11:04 -0700)]
Merge tag 'riscv-for-linus-5.14-rc7' of git://git./linux/kernel/git/riscv/linux

Pull RISC-V fixes from Palmer Dabbelt:

 - fix the sifive-l2-cache device tree bindings for json-schema
   compatibility. This does not change the intended behavior of the
   binding.

 - avoid improperly freeing necessary resources during early boot.

* tag 'riscv-for-linus-5.14-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux:
  riscv: Fix a number of free'd resources in init_resources()
  dt-bindings: sifive-l2-cache: Fix 'select' matching

3 years agoMerge tag 's390-5.14-5' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
Linus Torvalds [Sat, 21 Aug 2021 17:56:06 +0000 (10:56 -0700)]
Merge tag 's390-5.14-5' of git://git./linux/kernel/git/s390/linux

Pull s390 fix from Vasily Gorbik:

 - fix use after free of zpci_dev in pci code

* tag 's390-5.14-5' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux:
  s390/pci: fix use after free of zpci_dev

3 years agoMerge tag 'locks-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton...
Linus Torvalds [Sat, 21 Aug 2021 17:50:22 +0000 (10:50 -0700)]
Merge tag 'locks-v5.14' of git://git./linux/kernel/git/jlayton/linux

Pull mandatory file locking deprecation warning from Jeff Layton:
 "As discussed on the list, this patch just adds a new warning for folks
  who still have mandatory locking enabled and actually mount with '-o
  mand'. I'd like to get this in for v5.14 so we can push this out into
  stable kernels and hopefully reach folks who have mounts with -o mand.

  For now, I'm operating under the assumption that we'll fully remove
  this support in v5.15, but we can move that out if any legitimate
  users of this facility speak up between now and then"

* tag 'locks-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux:
  fs: warn about impending deprecation of mandatory locks

3 years agoMerge tag 'block-5.14-2021-08-20' of git://git.kernel.dk/linux-block
Linus Torvalds [Sat, 21 Aug 2021 15:11:22 +0000 (08:11 -0700)]
Merge tag 'block-5.14-2021-08-20' of git://git.kernel.dk/linux-block

Pull block fixes from Jens Axboe:
 "Three fixes from Ming Lei that should go into 5.14:

   - Fix for a kernel panic when iterating over tags for some cases
     where a flush request is present, a regression in this cycle.

   - Request timeout fix

   - Fix flush request checking"

* tag 'block-5.14-2021-08-20' of git://git.kernel.dk/linux-block:
  blk-mq: fix is_flush_rq
  blk-mq: fix kernel panic during iterating over flush request
  blk-mq: don't grab rq's refcount in blk_mq_check_expired()

3 years agoMerge tag 'io_uring-5.14-2021-08-20' of git://git.kernel.dk/linux-block
Linus Torvalds [Sat, 21 Aug 2021 15:06:26 +0000 (08:06 -0700)]
Merge tag 'io_uring-5.14-2021-08-20' of git://git.kernel.dk/linux-block

Pull io_uring fixes from Jens Axboe:
 "A few small fixes that should go into this release:

   - Fix never re-assigning an initial error value for io_uring_enter()
     for SQPOLL, if asked to do nothing

   - Fix xa_alloc_cycle() return value checking, for cases where we have
     wrapped around

   - Fix for a ctx pin issue introduced in this cycle (Pavel)"

* tag 'io_uring-5.14-2021-08-20' of git://git.kernel.dk/linux-block:
  io_uring: fix xa_alloc_cycle() error return value check
  io_uring: pin ctx on fallback execution
  io_uring: only assign io_uring_enter() SQPOLL error in actual error case

3 years agofs: warn about impending deprecation of mandatory locks
Jeff Layton [Fri, 20 Aug 2021 13:29:50 +0000 (09:29 -0400)]
fs: warn about impending deprecation of mandatory locks

We've had CONFIG_MANDATORY_FILE_LOCKING since 2015 and a lot of distros
have disabled it. Warn the stragglers that still use "-o mand" that
we'll be dropping support for that mount option.

Cc: stable@vger.kernel.org
Signed-off-by: Jeff Layton <jlayton@kernel.org>