ntfs3: Add magic and fix swapfile creation
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
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
@@ -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
@@ -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
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
PATCH 2/2 tse_swap: Fill swapfile with zeroes on ntfs3
In reply to Brian Mak via ltpOn 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
@@ -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
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 withgeneric_swapfile_activate()and ->bmap(). Since ntfs3 was converted to iomap in v7.0,ntfs_bmap()callsiomap_bmap(), which only returns a block number forIOMAP_MAPPEDextents, while ntfs3 reports the range beyond the valid data length asIOMAP_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