Skip to contentSkip to conversation

ntfs3: Add magic and fix swapfile creation

PATCH In review Brian Mak via ltp 2 participants 5 messages Nov 23 Library code

lore
Share & tools
lore
#0 lore raw

cover ntfs3: Add magic and fix swapfile creation

This patch series adds the ntfs3 magic, allowing prints to show the correct filesystem name. It also fixes swapfile creation on ntfs3, which fixes the following test cases on ntfs3: swapon01-03 and swapoff01-02.

These tests fail with:
swapon: swapfile has holes
tse_swap.c:228: TFAIL: swapon() on unknown failed: EINVAL (22)

Brian Mak (2):
lib: Add ntfs3 magic
tse_swap: Fill swapfile with zeroes on ntfs3

 include/tst_fs.h     | 1 +
 lib/tst_fs_type.c    | 2 ++
 libs/swap/tse_swap.c | 8 ++++++--
 3 files changed, 9 insertions(+), 2 deletions(-)

base-commit: 3b962a950b3f37153a45bf1240d07d73ab07676e

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/2 lib: Add ntfs3 magic

Tests currently running on ntfs3 print "unknown" as the filesystem name:
tse_swap.c:228: TFAIL: swapon() on unknown failed: EINVAL (22)

Add TST_NTFS3_MAGIC and map it to "ntfs3".

---
 include/tst_fs.h  | 1 +
 lib/tst_fs_type.c | 2 ++
 2 files changed, 3 insertions(+)
include/tst_fs.h +1 -0
index 80eb1292e..0a6c863cb 100644
@@ -34,6 +34,7 @@
 #define TST_FUSE_MAGIC     0x65735546
 #define TST_VFAT_MAGIC     0x4d44 /* AKA MSDOS */
 #define TST_EXFAT_MAGIC    0x2011BAB0UL
+#define TST_NTFS3_MAGIC    0x7366746e
 
 /* fs/bcachefs/bcachefs_format.h */
 #define TST_BCACHE_MAGIC		0xca451a4e
lib/tst_fs_type.c +2 -0
index e9efb89dc..703225c09 100644
@@ -74,6 +74,8 @@ const char *tst_fs_type_name(long f_type)
 		return "vfat";
 	case TST_EXFAT_MAGIC:
 		return "exfat";
+	case TST_NTFS3_MAGIC:
+		return "ntfs3";
 	default:
 		return "unknown";
 	}
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] [PATCH 1/2] lib: Add ntfs3 magic

Hi!
Applied, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH 2/2 tse_swap: Fill swapfile with zeroes on ntfs3

In reply to Brian Mak via ltp

On ntfs3, fallocate() allocates clusters but does not change the valid data length.

ntfs3 has no ->swap_activate(), so swapon() maps the file with generic_swapfile_activate() and ->bmap(). Since ntfs3 was converted to iomap in v7.0, ntfs_bmap() calls iomap_bmap(), which only returns a block number for IOMAP_MAPPED extents, while ntfs3 reports the range beyond the valid data length as IOMAP_UNWRITTEN. swapon() therefore rejects the file, and swapon01-03 and swapoff01-02 fail on ntfs3 with:

swapon: swapfile has holes
tse_swap.c:228: TFAIL: swapon() on unknown failed: EINVAL (22)

Fill the swapfile with zeroes on ntfs3, as is already done for old XFS, so that the whole file is written before mkswap and swapon().

---
 libs/swap/tse_swap.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
libs/swap/tse_swap.c +6 -2
index ae3c19313..a19e97556 100644
@@ -145,6 +145,7 @@ int make_swapfile(const char *file, const int lineno,
 	unsigned int blocks = 0;
 	size_t pg_size = sysconf(_SC_PAGESIZE);
 	char mnt_path[PATH_MAX];
+	long fs_type;
 
 	safe_statvfs(file, lineno, ".", &fs_info);
 
@@ -177,8 +178,11 @@ int make_swapfile(const char *file, const int lineno,
 	if (prealloc_contiguous_file(swapfile, blk_size, blocks) != 0)
 		tst_brk_(file, lineno, TBROK, "Failed to create swapfile");
 
-	/* Fill the file if needed (specific to old xfs filesystems) */
-	if (tst_fs_type(swapfile) == TST_XFS_MAGIC) {
+	/*
+	 * Fill the file if needed (specific to old XFS and ntfs3)
+	 */
+	fs_type = tst_fs_type(swapfile);
+	if (fs_type == TST_XFS_MAGIC || fs_type == TST_NTFS3_MAGIC) {
 		if (tst_fill_file(swapfile, 0, blk_size, blocks) != 0)
 			tst_brk_(file, lineno, TBROK, "Failed to fill swapfile");
 	}
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH 2/2] tse_swap: Fill swapfile with zeroes on ntfs3

Hi!

Quoted 9 lines

On ntfs3, fallocate() allocates clusters but does not change the valid data length.

ntfs3 has no ->swap_activate(), so swapon() maps the file with generic_swapfile_activate() and ->bmap(). Since ntfs3 was converted to iomap in v7.0, ntfs_bmap() calls iomap_bmap(), which only returns a block number for IOMAP_MAPPED extents, while ntfs3 reports the range beyond the valid data length as IOMAP_UNWRITTEN. swapon() therefore rejects the file, and swapon01-03 and swapoff01-02 fail on ntfs3 with:

We had similar bug introduced in exfat code and it was fixed in kernel:

commit 03a43677ca91e3997355a13b1da6e47329b025e1

Author: Jan Polensky <[email protected]>
Date:   Tue Jun 9 18:21:49 2026 +0900

exfat: add swap_activate support

Commit 07d67f3e9083 ("exfat: add iomap buffered I/O support") converted exfat buffered I/O to iomap, but did not add a .swap_activate handler to the address_space_operations.

Hence I assume this is a kernel bug.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp