2021-09-02 20:08:49

by Kari Argillander

[permalink] [raw]
Subject: [PATCH v2 0/8] fs/ntfs3: Refactor header includes

Right now header includes are big mess with ntfs3 imo. We cannot example
include ntfs3 headers without need of punch of includes to source file.
This patch set try to address that. When this patch series is applied we
can include any header file without need of include anything else. This
does not mean source file should rely what header file includes. Instead
it should include them by self also if it needs them.

When some include is added I have write why this is needed to commit
message. Hopefully this will help when someone wants to correct them
again. I have also just delete unnecessary headers from some .c files
and not added what is needed. Usually deleted headers where there
because ntfs_fs.h need them not file itself. When file was simple enough
I added all necessary linux headers.

I did not add linux/headers to all files yet. That is big job. This is
good starting point. I did try to build every file itself so this will
build like it should.

Please do not hesitate to tell if there is something wrong with this
series or somethings could be done better.

V2:
Add missing first patch
Rebase
Use base-commit with format-patch

Kari Argillander (8):
fs/ntfs3. Add forward declarations for structs to debug.h
fs/ntfs3: Add missing header files to ntfs.h
fs/ntfs3: Add missing headers and forward declarations to ntfs_fs.h
fs/ntfs3: Add missing header and guards to lib/ headers
fs/ntfs3: Change right headers to bitfunc.c
fs/ntfs3: Change right headers to upcase.c
fs/ntfs3: Change right headers to lznt.c
fs/ntfs3: Remove unneeded header files from c files

fs/ntfs3/attrib.c | 5 -----
fs/ntfs3/attrlist.c | 3 ---
fs/ntfs3/bitfunc.c | 7 +------
fs/ntfs3/bitmap.c | 3 ---
fs/ntfs3/debug.h | 3 +++
fs/ntfs3/dir.c | 3 ---
fs/ntfs3/file.c | 1 -
fs/ntfs3/frecord.c | 3 ---
fs/ntfs3/fslog.c | 4 ----
fs/ntfs3/fsntfs.c | 1 -
fs/ntfs3/index.c | 1 -
fs/ntfs3/inode.c | 2 --
fs/ntfs3/lib/decompress_common.h | 5 +++++
fs/ntfs3/lib/lib.h | 6 ++++++
fs/ntfs3/lznt.c | 10 +++++-----
fs/ntfs3/namei.c | 4 ----
fs/ntfs3/ntfs.h | 9 +++++++++
fs/ntfs3/ntfs_fs.h | 31 +++++++++++++++++++++++++++++++
fs/ntfs3/record.c | 3 ---
fs/ntfs3/run.c | 2 --
fs/ntfs3/super.c | 2 --
fs/ntfs3/upcase.c | 8 ++------
fs/ntfs3/xattr.c | 3 ---
23 files changed, 62 insertions(+), 57 deletions(-)


base-commit: d3624466b56dd5b1886c1dff500525b544c19c83
--
2.25.1


2021-09-02 23:29:02

by Kari Argillander

[permalink] [raw]
Subject: [PATCH v2 4/8] 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 <[email protected]>
---
fs/ntfs3/lib/decompress_common.h | 5 +++++
fs/ntfs3/lib/lib.h | 6 ++++++
2 files changed, 11 insertions(+)

diff --git a/fs/ntfs3/lib/decompress_common.h b/fs/ntfs3/lib/decompress_common.h
index 66297f398403..a2a858d4bf35 100644
--- a/fs/ntfs3/lib/decompress_common.h
+++ b/fs/ntfs3/lib/decompress_common.h
@@ -19,6 +19,9 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

+#ifndef _LINUX_NTFS3_LIB_DECOMPRESS_COMMON_H
+#define _LINUX_NTFS3_LIB_DECOMPRESS_COMMON_H
+
#include <linux/string.h>
#include <linux/compiler.h>
#include <linux/types.h>
@@ -350,3 +353,5 @@ static forceinline u8 *lz_copy(u8 *dst, u32 length, u32 offset, const u8 *bufend

return dst;
}
+
+#endif /* _LINUX_NTFS3_LIB_DECOMPRESS_COMMON_H */
diff --git a/fs/ntfs3/lib/lib.h b/fs/ntfs3/lib/lib.h
index f508fbad2e71..90309a5ae59c 100644
--- a/fs/ntfs3/lib/lib.h
+++ b/fs/ntfs3/lib/lib.h
@@ -7,6 +7,10 @@
* - linux kernel code style
*/

+#ifndef _LINUX_NTFS3_LIB_LIB_H
+#define _LINUX_NTFS3_LIB_LIB_H
+
+#include <linux/types.h>

/* globals from xpress_decompress.c */
struct xpress_decompressor *xpress_allocate_decompressor(void);
@@ -24,3 +28,5 @@ int lzx_decompress(struct lzx_decompressor *__restrict d,
const void *__restrict compressed_data,
size_t compressed_size, void *__restrict uncompressed_data,
size_t uncompressed_size);
+
+#endif /* _LINUX_NTFS3_LIB_LIB_H */
--
2.25.1

2021-09-02 23:29:28

by Kari Argillander

[permalink] [raw]
Subject: [PATCH v2 8/8] 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 <[email protected]>
---
fs/ntfs3/attrib.c | 5 -----
fs/ntfs3/attrlist.c | 3 ---
fs/ntfs3/bitmap.c | 3 ---
fs/ntfs3/dir.c | 3 ---
fs/ntfs3/file.c | 1 -
fs/ntfs3/frecord.c | 3 ---
fs/ntfs3/fslog.c | 4 ----
fs/ntfs3/fsntfs.c | 1 -
fs/ntfs3/index.c | 1 -
fs/ntfs3/inode.c | 2 --
fs/ntfs3/namei.c | 4 ----
fs/ntfs3/record.c | 3 ---
fs/ntfs3/run.c | 2 --
fs/ntfs3/super.c | 2 --
fs/ntfs3/xattr.c | 3 ---
15 files changed, 40 deletions(-)

diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c
index 34c4cbf7e29b..456251210c1c 100644
--- a/fs/ntfs3/attrib.c
+++ b/fs/ntfs3/attrib.c
@@ -6,12 +6,7 @@
* TODO: Merge attr_set_size/attr_data_get_block/attr_allocate_frame?
*/

-#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/hash.h>
-#include <linux/nls.h>
-#include <linux/ratelimit.h>
#include <linux/slab.h>

#include "debug.h"
diff --git a/fs/ntfs3/attrlist.c b/fs/ntfs3/attrlist.c
index fa32399eb517..b9da527b96aa 100644
--- a/fs/ntfs3/attrlist.c
+++ b/fs/ntfs3/attrlist.c
@@ -5,10 +5,7 @@
*
*/

-#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/nls.h>

#include "debug.h"
#include "ntfs.h"
diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c
index 831501555009..a03584674fea 100644
--- a/fs/ntfs3/bitmap.c
+++ b/fs/ntfs3/bitmap.c
@@ -10,12 +10,9 @@
*
*/

-#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/nls.h>

-#include "debug.h"
#include "ntfs.h"
#include "ntfs_fs.h"

diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c
index 93f6d485564e..76697ec3c146 100644
--- a/fs/ntfs3/dir.c
+++ b/fs/ntfs3/dir.c
@@ -7,10 +7,7 @@
*
*/

-#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/iversion.h>
#include <linux/nls.h>

#include "debug.h"
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index 89557d60a9b0..4aab7de1886e 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -12,7 +12,6 @@
#include <linux/compat.h>
#include <linux/falloc.h>
#include <linux/fiemap.h>
-#include <linux/nls.h>

#include "debug.h"
#include "ntfs.h"
diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index 938b12d56ca6..080264ced909 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -5,11 +5,8 @@
*
*/

-#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fiemap.h>
#include <linux/fs.h>
-#include <linux/nls.h>
#include <linux/vmalloc.h>

#include "debug.h"
diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index b5853aed0e25..6e7f9b72792b 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -6,12 +6,8 @@
*/

#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/hash.h>
-#include <linux/nls.h>
#include <linux/random.h>
-#include <linux/ratelimit.h>
#include <linux/slab.h>

#include "debug.h"
diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c
index 91e3743e1442..9232a7f410c6 100644
--- a/fs/ntfs3/fsntfs.c
+++ b/fs/ntfs3/fsntfs.c
@@ -8,7 +8,6 @@
#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/nls.h>

#include "debug.h"
#include "ntfs.h"
diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index 0daca9adc54c..affae36d0bc9 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -8,7 +8,6 @@
#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/nls.h>

#include "debug.h"
#include "ntfs.h"
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index db2a5a4c38e4..b474aa352056 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -5,10 +5,8 @@
*
*/

-#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/iversion.h>
#include <linux/mpage.h>
#include <linux/namei.h>
#include <linux/nls.h>
diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index e58415d07132..1c475da4e19d 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -5,11 +5,7 @@
*
*/

-#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/iversion.h>
-#include <linux/namei.h>
#include <linux/nls.h>

#include "debug.h"
diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index 103705c86772..861e35791506 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -5,10 +5,7 @@
*
*/

-#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/nls.h>

#include "debug.h"
#include "ntfs.h"
diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c
index 26ed2b64345e..a8fec651f973 100644
--- a/fs/ntfs3/run.c
+++ b/fs/ntfs3/run.c
@@ -7,10 +7,8 @@
*/

#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fs.h>
#include <linux/log2.h>
-#include <linux/nls.h>

#include "debug.h"
#include "ntfs.h"
diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index dbecf095da59..cfacba61d41d 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -23,12 +23,10 @@
*
*/

-#include <linux/backing-dev.h>
#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/exportfs.h>
#include <linux/fs.h>
-#include <linux/iversion.h>
#include <linux/log2.h>
#include <linux/module.h>
#include <linux/nls.h>
diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c
index b15d532e4a17..7ec7e09031aa 100644
--- a/fs/ntfs3/xattr.c
+++ b/fs/ntfs3/xattr.c
@@ -5,10 +5,7 @@
*
*/

-#include <linux/blkdev.h>
-#include <linux/buffer_head.h>
#include <linux/fs.h>
-#include <linux/nls.h>
#include <linux/posix_acl.h>
#include <linux/posix_acl_xattr.h>
#include <linux/xattr.h>
--
2.25.1

2021-09-02 23:30:31

by Kari Argillander

[permalink] [raw]
Subject: [PATCH v2 3/8] 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 <[email protected]>
---
fs/ntfs3/ntfs_fs.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)

diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index 97e682ebcfb9..149d60e29728 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -9,6 +9,37 @@
#ifndef _LINUX_NTFS3_NTFS_FS_H
#define _LINUX_NTFS3_NTFS_FS_H

+#include <linux/blkdev.h>
+#include <linux/buffer_head.h>
+#include <linux/cleancache.h>
+#include <linux/fs.h>
+#include <linux/highmem.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/mutex.h>
+#include <linux/page-flags.h>
+#include <linux/pagemap.h>
+#include <linux/rbtree.h>
+#include <linux/rwsem.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/time64.h>
+#include <linux/types.h>
+#include <linux/uidgid.h>
+#include <asm/div64.h>
+#include <asm/page.h>
+
+#include "debug.h"
+#include "ntfs.h"
+
+struct dentry;
+struct fiemap_extent_info;
+struct user_namespace;
+struct page;
+struct writeback_control;
+enum utf16_endian;
+
+
#define MINUS_ONE_T ((size_t)(-1))
/* Biggest MFT / smallest cluster */
#define MAXIMUM_BYTES_PER_MFT 4096
--
2.25.1

2021-09-14 00:45:05

by Konstantin Komarov

[permalink] [raw]
Subject: Re: [PATCH v2 0/8] fs/ntfs3: Refactor header includes



On 02.09.2021 19:15, Kari Argillander wrote:
> Right now header includes are big mess with ntfs3 imo. We cannot example
> include ntfs3 headers without need of punch of includes to source file.
> This patch set try to address that. When this patch series is applied we
> can include any header file without need of include anything else. This
> does not mean source file should rely what header file includes. Instead
> it should include them by self also if it needs them.
>
> When some include is added I have write why this is needed to commit
> message. Hopefully this will help when someone wants to correct them
> again. I have also just delete unnecessary headers from some .c files
> and not added what is needed. Usually deleted headers where there
> because ntfs_fs.h need them not file itself. When file was simple enough
> I added all necessary linux headers.
>
> I did not add linux/headers to all files yet. That is big job. This is
> good starting point. I did try to build every file itself so this will
> build like it should.
>
> Please do not hesitate to tell if there is something wrong with this
> series or somethings could be done better.
>
> V2:
> Add missing first patch
> Rebase
> Use base-commit with format-patch
>
> Kari Argillander (8):
> fs/ntfs3. Add forward declarations for structs to debug.h
> fs/ntfs3: Add missing header files to ntfs.h
> fs/ntfs3: Add missing headers and forward declarations to ntfs_fs.h
> fs/ntfs3: Add missing header and guards to lib/ headers
> fs/ntfs3: Change right headers to bitfunc.c
> fs/ntfs3: Change right headers to upcase.c
> fs/ntfs3: Change right headers to lznt.c
> fs/ntfs3: Remove unneeded header files from c files
>
> fs/ntfs3/attrib.c | 5 -----
> fs/ntfs3/attrlist.c | 3 ---
> fs/ntfs3/bitfunc.c | 7 +------
> fs/ntfs3/bitmap.c | 3 ---
> fs/ntfs3/debug.h | 3 +++
> fs/ntfs3/dir.c | 3 ---
> fs/ntfs3/file.c | 1 -
> fs/ntfs3/frecord.c | 3 ---
> fs/ntfs3/fslog.c | 4 ----
> fs/ntfs3/fsntfs.c | 1 -
> fs/ntfs3/index.c | 1 -
> fs/ntfs3/inode.c | 2 --
> fs/ntfs3/lib/decompress_common.h | 5 +++++
> fs/ntfs3/lib/lib.h | 6 ++++++
> fs/ntfs3/lznt.c | 10 +++++-----
> fs/ntfs3/namei.c | 4 ----
> fs/ntfs3/ntfs.h | 9 +++++++++
> fs/ntfs3/ntfs_fs.h | 31 +++++++++++++++++++++++++++++++
> fs/ntfs3/record.c | 3 ---
> fs/ntfs3/run.c | 2 --
> fs/ntfs3/super.c | 2 --
> fs/ntfs3/upcase.c | 8 ++------
> fs/ntfs3/xattr.c | 3 ---
> 23 files changed, 62 insertions(+), 57 deletions(-)
>
>
> base-commit: d3624466b56dd5b1886c1dff500525b544c19c83
>

Hi Kari!

Thanks for work - applied!