Skip to contentSkip to conversation

ntfs: add Windows system compression support

PATCH Superseded Hyunchul Lee 1 participant 10 messages Aug 20 NTFS filesystem

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Hyunchul Lee

author maintainer
#0 lore raw

v3 cover ntfs: add Windows system compression support

This series adds Windows system compression support to the NTFS driver.

Windows system compression more aggressively compresses system files, such as binaries and DLLs, using XPRESS or LZX. It is intended for files that are rarely modified.

The series adds a CONFIG_NTFS_FS_WOF_COMPRESSION option, parses WOF reparse points, and adds XPRESS and LZX codec support. It handles both resident and non-resident WOF metadata and compressed data.

The first two patches introduce the generic compression codec interface and bind the existing LZNT1 implementation. The remaining patches add the configuration option, WOF parsing, decompression libraries, codec operations, and WOF decompression support.

Changes in v3:
* Patch 4: Added to make ntfs_attr_readall() return errors, including -ENOMEM, so transient read failures are not reported as filesystem corruption.
* Patch 8: derive WOF chunk table entry width from the base file size and fold this fix into the non-resident WOF decompression patch.
Changes in v2:
* Patch 3: fix the missing space in the WOF Kconfig help text.
* Patch 4: validate WOF reparse data and retain WOF state without a decoder, returning -EOPNOTSUPP for unsupported providers or formats.
* Patch 7: reject WOF direct I/O and data-changing paths, report WOF files as compressed without DIO alignment, serialize runlist access, and avoid sibling-page lock cycles with private-buffer/direct-folio fallback.
* Patch 8: derive offset width from the base file size, handle one-chunk streams, validate chunk sizes while parsing, and use the base inode's MFT-record lock for resident metadata lookups.

---
Hyunchul Lee (9):
ntfs: introduce transparent compression codec interface
ntfs: define LZNT1 codec ops under transparent codec interface
ntfs: add WOF compression config option
ntfs: return errors from ntfs_attr_readall
ntfs: parse REPARSE_TAG_WOF
ntfs: port lzx/xpress decompressors from ntfs-3g-system-compression
ntfs: implement codec ops for LZX and XPRESS
ntfs: add non-resident WOF decompression
ntfs: support resident WOF decompression

 fs/ntfs/Kconfig                 |  11 +
 fs/ntfs/Makefile                |   3 +
 fs/ntfs/aops.c                  |  19 +-
 fs/ntfs/attrib.c                |  10 +-
 fs/ntfs/bdev-io.c               |   4 +-
 fs/ntfs/compress.c              |  12 +-
 fs/ntfs/ea.c                    |  66 +++-
 fs/ntfs/file.c                  |  47 ++-
 fs/ntfs/index.c                 |   4 +-
 fs/ntfs/inode.c                 |  16 +-
 fs/ntfs/inode.h                 |   2 +
 fs/ntfs/lib/decompress_common.c | 200 +++++++++++
 fs/ntfs/lib/decompress_common.h | 444 +++++++++++++++++++++++++
 fs/ntfs/lib/lib.h               |  29 ++
 fs/ntfs/lib/lzx_decompress.c    | 631 +++++++++++++++++++++++++++++++++++
 fs/ntfs/lib/xpress_decompress.c | 154 +++++++++
 fs/ntfs/ntfs.h                  |   4 +
 fs/ntfs/ntfs_codec.h            |  54 +++
 fs/ntfs/reparse.c               |  98 +++++-
 fs/ntfs/reparse.h               |   2 +-
 fs/ntfs/super.c                 |   3 +
 fs/ntfs/wof.c                   | 720 ++++++++++++++++++++++++++++++++++++++++
 22 files changed, 2486 insertions(+), 47 deletions(-)

---
base-commit: df7dce2090342170b7643d36f694204cae7792a9
change-id: 20260818-topic-wof-v2-53051d7f0848

Best regards,

Signature · 2 lines
Thanks,
Hyunchul
author maintainer
#1 lore raw

PATCH v3 1/9 ntfs: introduce transparent compression codec interface

Introduce struct ntfs_codec_ops and enum ntfs_codec_id to provide a unified interface for compression and decompression algorithms. This interface supports WOF and LZNT1 decompression.

---
 fs/ntfs/ntfs_codec.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
fs/ntfs/ntfs_codec.h new file +46 -0
new file mode 100644
index 000000000000..14a69d1e4d7f
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Transparent compression codec interface.
+ *
+ * Copyright (c) 2026 LG Electronics Co., Ltd.
+ */
+
+#ifndef _NTFS_CODEC_H
+#define _NTFS_CODEC_H
+
+#include <linux/types.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+
+struct compress_context;
+
+enum ntfs_codec_id {
+	NTFS_CODEC_LZNT1,
+#ifdef CONFIG_NTFS_FS_WOF_COMPRESSION
+	NTFS_CODEC_XPRESS4K,
+	NTFS_CODEC_XPRESS8K,
+	NTFS_CODEC_XPRESS16K,
+	NTFS_CODEC_LZX32K,
+#endif
+};
+
+struct ntfs_codec_ops {
+	enum ntfs_codec_id id;
+	const char *name;
+	size_t (*scratch_size)(u32 chunk_size);
+	int (*decompress_chunk)(void *scratch,
+				const void *src, size_t src_len,
+				void *dst, size_t dst_len,
+				u32 chunk_size);
+	int (*decompress_pages)(struct page *dest_pages[],
+				int completed_pages[],
+				int *dest_index, int *dest_ofs,
+				int dest_max_index, int dest_max_ofs,
+				int xpage, char *xpage_done,
+				u8 *cb_start, u32 cb_size,
+				loff_t i_size, s64 initialized_size);
+	int (*compress_subblock)(struct compress_context *pctx,
+				 const char *inbuf, int bufsize, char *outbuf);
+};
+
+#endif /* _NTFS_CODEC_H */
Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH v3 2/9 ntfs: define LZNT1 codec ops under transparent codec interface

In reply to Hyunchul Lee

Define the ntfs_lznt1_codec_ops structure containing decompress_pages and compress_subblock callbacks in compress.c, and export it in ntfs_codec.h. This structure binds existing LZNT1 decompress and compress helper functions under the unified transparent compression interface.

---
 fs/ntfs/compress.c   | 12 ++++++++++--
 fs/ntfs/ntfs_codec.h |  2 ++
 2 files changed, 12 insertions(+), 2 deletions(-)
fs/ntfs/compress.c +10 -2
index ea29fade9b9b..f980e0610a8f 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 
 #include "attrib.h"
+#include "ntfs_codec.h"
 #include "inode.h"
 #include "debug.h"
 #include "ntfs.h"
@@ -774,7 +775,7 @@ int ntfs_read_compressed_block(struct folio *folio)
 		unsigned int prev_cur_page = cur_page;
 
 		ntfs_debug("Found compressed compression block.");
-		err = ntfs_decompress(pages, completed_pages, &cur_page,
+		err = ntfs_lznt1_codec_ops.decompress_pages(pages, completed_pages, &cur_page,
 				&cur_ofs, cb_max_page, cb_max_ofs, xpage,
 				&xpage_done, cb_pos, cb_size - (cb_pos - cb),
 				i_size, initialized_size);
@@ -1351,7 +1352,7 @@ static int ntfs_write_cb(struct ntfs_inode *ni, loff_t pos, struct page **pages,
 		pbuf = &outbuf[compsz];
 		addr = kmap_local_page(pages[page_idx]);
 		input = addr + offset_in_page(input_offset);
-		sz = ntfs_compress_block(ctx, input, bsz, pbuf);
+		sz = ntfs_lznt1_codec_ops.compress_subblock(ctx, input, bsz, pbuf);
 		kunmap_local(addr);
 		if (sz < 0) {
 			err = sz;
@@ -1609,3 +1610,10 @@ int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
 
 	return written;
 }
+
+const struct ntfs_codec_ops ntfs_lznt1_codec_ops = {
+	.id = NTFS_CODEC_LZNT1,
+	.name = "lznt1",
+	.decompress_pages = ntfs_decompress,
+	.compress_subblock = ntfs_compress_block,
+};
fs/ntfs/ntfs_codec.h +2 -0
index 14a69d1e4d7f..408b18561a03 100644
@@ -43,4 +43,6 @@ struct ntfs_codec_ops {
 				 const char *inbuf, int bufsize, char *outbuf);
 };
 
+extern const struct ntfs_codec_ops ntfs_lznt1_codec_ops;
+
 #endif /* _NTFS_CODEC_H */
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH v3 3/9 ntfs: add WOF compression config option

In reply to Hyunchul Lee

Add CONFIG_NTFS_FS_WOF_COMPRESSION for Windows system compression.

Build XPRESS and LZX decoding code only when requested.

---
 fs/ntfs/Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
fs/ntfs/Kconfig +11 -0
index 6a6acde9ba91..f88f4138f921 100644
@@ -10,6 +10,17 @@ config NTFS_FS
 	  To compile this as a module, choose M here: the module will be called
 	  ntfs.
 
+config NTFS_FS_WOF_COMPRESSION
+	bool "NTFS Windows system compression support"
+	depends on NTFS_FS
+	help
+	  Enable read support for Windows system-compressed files.
+	  Windows more aggressively compresses system files such as binaries
+	  and DLLs using system compression. It is optimized for files that
+	  are rarely modified.
+	  Enabling this option builds the decompression support into the NTFS
+	  module.
+
 config NTFS_DEBUG
 	bool "NTFS debugging support"
 	depends on NTFS_FS
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH v3 4/9 ntfs: return errors from ntfs_attr_readall

In reply to Hyunchul Lee

ntfs_attr_readall() currently loses the failure reason for attribute lookup, allocation, and read failures by returning NULL. Return ERR_PTR() with the original error instead.

The reparse parser can then propagate allocation and I/O errors without treating them as filesystem corruption.

---
 fs/ntfs/attrib.c  |  8 +++++++-
 fs/ntfs/ea.c      | 38 +++++++++++++++++++++++++++++++-------
 fs/ntfs/index.c   |  4 ++--
 fs/ntfs/reparse.c |  4 ++++
 4 files changed, 44 insertions(+), 10 deletions(-)
fs/ntfs/attrib.c +7 -1
index 990c3937a551..d9e844c481d8 100644
@@ -5296,6 +5296,7 @@ int ntfs_attr_remove(struct ntfs_inode *ni, const __le32 type, __le16 *name,
  * On success a buffer is allocated with the content of the attribute
  * and which needs to be freed when it's not needed anymore. If the
  * @data_size parameter is non-NULL then the data size is set there.
+ * On error, an ERR_PTR() containing the negative error code is returned.
  */
 void *ntfs_attr_readall(struct ntfs_inode *ni, const __le32 type,
 		__le16 *name, u32 name_len, s64 *data_size)
@@ -5310,6 +5311,7 @@ void *ntfs_attr_readall(struct ntfs_inode *ni, const __le32 type,
 
 	bmp_vi = ntfs_attr_iget(VFS_I(ni), type, name, name_len);
 	if (IS_ERR(bmp_vi)) {
+		ret = ERR_PTR(PTR_ERR(bmp_vi));
 		ntfs_debug("ntfs_attr_iget failed");
 		goto err_exit;
 	}
@@ -5319,17 +5321,21 @@ void *ntfs_attr_readall(struct ntfs_inode *ni, const __le32 type,
 		(bmp_ni->type != AT_BITMAP ||
 		bmp_ni->data_size > ((ni->vol->nr_clusters + 7) >> 3))) {
 		ntfs_error(sb, "Invalid attribute data size");
+		ret = ERR_PTR(-EIO);
 		goto out;
 	}
 
 	data = kvmalloc(bmp_ni->data_size, GFP_NOFS);
-	if (!data)
+	if (!data) {
+		ret = ERR_PTR(-ENOMEM);
 		goto out;
+	}
 
 	size = ntfs_inode_attr_pread(VFS_I(bmp_ni), 0, bmp_ni->data_size,
 			(u8 *)data);
 	if (size != bmp_ni->data_size) {
 		ntfs_error(sb, "ntfs_attr_pread failed");
+		ret = size < 0 ? ERR_PTR((int)size) : ERR_PTR(-EIO);
 		kvfree(data);
 		goto out;
 	}
fs/ntfs/ea.c +31 -7
index fc6cec7ce130..c8a3d9f07dc4 100644
@@ -122,17 +122,19 @@ static int ntfs_get_ea(struct inode *inode, const char *name, size_t name_len,
 
 	p_ea_info = ntfs_attr_readall(ni, AT_EA_INFORMATION, NULL, 0,
 			&ea_info_size);
-	if (!p_ea_info || ea_info_size != sizeof(struct ea_information)) {
+	if (IS_ERR(p_ea_info))
+		return PTR_ERR(p_ea_info);
+	if (ea_info_size != sizeof(struct ea_information)) {
 		kvfree(p_ea_info);
-		return -ENODATA;
+		return -EIO;
 	}
 
 	ea_info_qlen = le32_to_cpu(p_ea_info->ea_query_length);
 	kvfree(p_ea_info);
 
 	ea_buf = ntfs_attr_readall(ni, AT_EA, NULL, 0, &all_ea_size);
-	if (!ea_buf)
-		return -ENODATA;
+	if (IS_ERR(ea_buf))
+		return PTR_ERR(ea_buf);
 
 	if (ea_info_qlen > all_ea_size) {
 		err = -EIO;
@@ -208,10 +210,22 @@ static int ntfs_set_ea(struct inode *inode, const char *name, size_t name_len,
 	if (ntfs_attr_exist(ni, AT_EA_INFORMATION, AT_UNNAMED, 0)) {
 		p_ea_info = ntfs_attr_readall(ni, AT_EA_INFORMATION, NULL, 0,
 						&ea_info_size);
-		if (!p_ea_info || ea_info_size != sizeof(struct ea_information))
+		if (IS_ERR(p_ea_info)) {
+			err = PTR_ERR(p_ea_info);
+			p_ea_info = NULL;
 			goto out;
+		}
+		if (ea_info_size != sizeof(struct ea_information)) {
+			err = -EIO;
+			goto out;
+		}
 
 		ea_buf = ntfs_attr_readall(ni, AT_EA, NULL, 0, &all_ea_size);
+		if (IS_ERR(ea_buf)) {
+			err = PTR_ERR(ea_buf);
+			ea_buf = NULL;
+			goto out;
+		}
 		if (!ea_buf) {
 			ea_info_qsize = 0;
 			kvfree(p_ea_info);
@@ -514,14 +528,24 @@ ssize_t ntfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
 	mutex_lock(&NTFS_I(inode)->mrec_lock);
 	ea_info = ntfs_attr_readall(ni, AT_EA_INFORMATION, NULL, 0,
 			&ea_info_size);
-	if (!ea_info || ea_info_size != sizeof(struct ea_information))
+	if (IS_ERR(ea_info)) {
+		err = PTR_ERR(ea_info);
+		ea_info = NULL;
 		goto out;
+	}
+	if (ea_info_size != sizeof(struct ea_information)) {
+		err = -EIO;
+		goto out;
+	}
 
 	ea_info_qsize = le32_to_cpu(ea_info->ea_query_length);
 
 	ea_buf = ntfs_attr_readall(ni, AT_EA, NULL, 0, &ea_buf_size);
-	if (!ea_buf)
+	if (IS_ERR(ea_buf)) {
+		err = PTR_ERR(ea_buf);
+		ea_buf = NULL;
 		goto out;
+	}
 
 	if (ea_info_qsize > ea_buf_size || ea_info_qsize == 0)
 		goto out;
fs/ntfs/index.c +2 -2
index 8c8eb13859ab..46a8b19c0723 100644
@@ -1108,8 +1108,8 @@ static s64 ntfs_ibm_get_free(struct ntfs_index_context *icx)
 
 	bm = ntfs_attr_readall(icx->idx_ni, AT_BITMAP,  icx->name, icx->name_len,
 			&size);
-	if (!bm)
-		return -EIO;
+	if (IS_ERR(bm))
+		return PTR_ERR(bm);
 
 	for (byte = 0; byte < size; byte++) {
 		if (bm[byte] == 255)
fs/ntfs/reparse.c +4 -0
index 0d3988992119..b8d601f5500f 100644
@@ -256,6 +256,8 @@ unsigned int ntfs_make_symlink(struct ntfs_inode *ni)
 
 	reparse_attr = ntfs_attr_readall(ni, AT_REPARSE_POINT, NULL, 0,
 					 &attr_size);
+	if (IS_ERR(reparse_attr))
+		reparse_attr = NULL;
 	if (reparse_attr &&
 	    valid_reparse_data(ni, reparse_attr, attr_size)) {
 		err = -EINVAL;
@@ -335,6 +337,8 @@ unsigned int ntfs_reparse_tag_dt_types(struct ntfs_volume *vol, unsigned long mr
 
 	reparse_attr = (struct reparse_point *)ntfs_attr_readall(NTFS_I(vi),
 			AT_REPARSE_POINT, NULL, 0, &attr_size);
+	if (IS_ERR(reparse_attr))
+		reparse_attr = NULL;
 
 	if (reparse_attr && attr_size >= sizeof(*reparse_attr)) {
 		switch (reparse_attr->reparse_tag) {
Signature · 1 line
2.43.0
author maintainer
#5 lore raw

PATCH v3 5/9 ntfs: parse REPARSE_TAG_WOF

In reply to Hyunchul Lee

Introduce parsing support for REPARSE_TAG_WOF reparse points. Rename ntfs_make_symlink() to ntfs_parse_reparse() since it now handles both symlinks and WOF reparse tags. Introduce NI_WofCompressed flag to indicate files compressed via Windows System Compression (WOF), and configure compressed block size accordingly (12 to 15 bits based on the format).

---
 fs/ntfs/inode.c   |   7 ++--
 fs/ntfs/inode.h   |   2 ++
 fs/ntfs/reparse.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++-------
 fs/ntfs/reparse.h |   2 +-
 4 files changed, 96 insertions(+), 16 deletions(-)
fs/ntfs/inode.c +5 -2
index 46be4514b60f..45e013eb3541 100644
@@ -869,7 +869,9 @@ static int ntfs_read_locked_inode(struct inode *vi)
 	if (ni->flags & FILE_ATTR_REPARSE_POINT) {
 		unsigned int mode;
 
-		mode = ntfs_make_symlink(ni);
+		err = ntfs_parse_reparse(ni, &mode);
+		if (err)
+			goto unm_err_out;
 		if (mode)
 			vi->i_mode |= mode;
 		else {
@@ -1214,7 +1216,8 @@ static int ntfs_read_locked_inode(struct inode *vi)
 	 * sizes of all non-resident attributes present to give us the Linux
 	 * correct size that should go into i_blocks (after division by 512).
 	 */
-	if (S_ISREG(vi->i_mode) && (NInoCompressed(ni) || NInoSparse(ni)))
+	if (S_ISREG(vi->i_mode) &&
+	    (NInoCompressed(ni) || (NInoSparse(ni) && !NInoWofCompressed(ni))))
 		vi->i_blocks = ni->itype.compressed.size >> 9;
 	else
 		vi->i_blocks = ni->allocated_size >> 9;
fs/ntfs/inode.h +2 -0
index aee1c1fdb609..ff61bd402df0 100644
@@ -189,6 +189,7 @@ enum {
 	NI_NonResident,
 	NI_IndexAllocPresent,
 	NI_Compressed,
+	NI_WofCompressed,
 	NI_Encrypted,
 	NI_Sparse,
 	NI_SparseDisabled,
@@ -248,6 +249,7 @@ NINO_FNS(MstProtected)
 NINO_FNS(NonResident)
 NINO_FNS(IndexAllocPresent)
 NINO_FNS(Compressed)
+NINO_FNS(WofCompressed)
 NINO_FNS(Encrypted)
 NINO_FNS(Sparse)
 NINO_FNS(SparseDisabled)
fs/ntfs/reparse.c +88 -13

148 lines not on this page · raw message

fs/ntfs/reparse.h +1 -1
index c11a5bb7e6a5..b6360b0452e6 100644
@@ -9,7 +9,7 @@
 
 extern __le16 reparse_index_name[];
 
-unsigned int ntfs_make_symlink(struct ntfs_inode *ni);
+int ntfs_parse_reparse(struct ntfs_inode *ni, unsigned int *mode);
 unsigned int ntfs_reparse_tag_dt_types(struct ntfs_volume *vol, unsigned long mref);
 int ntfs_translate_symlink_path(struct dentry *dentry, const char *target,
 				char **translated);
Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH v3 6/9 ntfs: port lzx/xpress decompressors from ntfs-3g-system-compression

In reply to Hyunchul Lee

Port the LZX and XPRESS decompressors from the userspace ntfs-3g-system-compression plugin (Eric Biggers,
https://github.com/ebiggers/ntfs-3g-system-compression) into the in-tree NTFS driver under lib/, and adapt them to the kernel environment.

The upstream plugin implements WOF ("Windows Overlay Filesystem", a.k.a. system compression / "Compact OS") decompression for the NTFS-3G FUSE driver, and itself borrows the LZX/XPRESS decompressors that the same author wrote for wimlib (https://wimlib.net/). The XPRESS and LZX formats used here are identical to those used in WIM archives. This commit is the kernel-side port that lets fs/ntfs/wof.c read system-compressed files.

The library keeps the upstream subtable-based Huffman decoder (root table + contiguous subtables decoded with MAKE_DECODE_TABLE_ENTRY()), so long codewords only need one extra lookup instead of bit-by-bit tree traversal. The ntfs_codec_ops interface exported to fs/ntfs/wof.c (ntfs_lzx32k_codec_ops and ntfs_xpress{4k,8k,16k}_codec_ops) matches what the WOF layer expects.

Modifications made while porting from the upstream plugin:

- Replace the variable LZX window order (2^15..2^21) with a fixed 32768-byte window, which is the only size WOF uses

- Simplify the bitstream helper:
- bitstream_ensure_bits() now guarantees 16 valid bits instead of the carried-over 17-bit refill path from wimlib. Neither LZX (max codeword length 16) nor XPRESS (max 15) needs more than 16 bits.

- Refactor codes to satisfy checkpatch.

Assisted-by Copilot:gpt-5.6
---
 fs/ntfs/Makefile                |   3 +
 fs/ntfs/lib/decompress_common.c | 200 +++++++++++++
 fs/ntfs/lib/decompress_common.h | 444 +++++++++++++++++++++++++++++
 fs/ntfs/lib/lib.h               |  29 ++
 fs/ntfs/lib/lzx_decompress.c    | 610 ++++++++++++++++++++++++++++++++++++++++
 fs/ntfs/lib/xpress_decompress.c | 120 ++++++++
 6 files changed, 1406 insertions(+)
fs/ntfs/Makefile +3 -0
index e120c2e69862..5e5fd05f5863 100644
@@ -7,4 +7,7 @@ ntfs-y := aops.o attrib.o collate.o dir.o file.o index.o inode.o \
 	  upcase.o bitmap.o lcnalloc.o logfile.o reparse.o compress.o \
 	  iomap.o debug.o sysctl.o object_id.o bdev-io.o
 
+ntfs-$(CONFIG_NTFS_FS_WOF_COMPRESSION) += \
+	lib/decompress_common.o lib/lzx_decompress.o lib/xpress_decompress.o
+
 ccflags-$(CONFIG_NTFS_DEBUG) += -DDEBUG
fs/ntfs/lib/decompress_common.c new file +200 -0

200 lines not on this page · raw message

fs/ntfs/lib/decompress_common.h new file +444 -0

444 lines not on this page · raw message

fs/ntfs/lib/lib.h new file +29 -0
new file mode 100644
index 000000000000..a684d600fd3c
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * lib.h - Public declarations for the LZX and XPRESS decompressors.
+ *
+ * Adapted for the linux kernel.  These are the low-level decompressor
+ * allocations; WOF (system-compressed) access goes through the
+ * ntfs_codec_ops interface declared in "../ntfs_codec.h".
+ */
+
+#ifndef _LINUX_NTFS_LIB_LIB_H
+#define _LINUX_NTFS_LIB_LIB_H
+
+#include <linux/types.h>
+
+/* globals from xpress_decompress.c */
+struct xpress_decompressor *xpress_allocate_decompressor(void);
+void xpress_free_decompressor(struct xpress_decompressor *d);
+int xpress_decompress(struct xpress_decompressor *d,
+		      const void *compressed_data, size_t compressed_size,
+		      void *uncompressed_data, size_t uncompressed_size);
+
+/* globals from lzx_decompress.c */
+struct lzx_decompressor *lzx_allocate_decompressor(void);
+void lzx_free_decompressor(struct lzx_decompressor *d);
+int lzx_decompress(struct lzx_decompressor *d, const void *compressed_data,
+		   size_t compressed_size, void *uncompressed_data,
+		   size_t uncompressed_size);
+
+#endif /* _LINUX_NTFS_LIB_LIB_H */
fs/ntfs/lib/lzx_decompress.c new file +610 -0

610 lines not on this page · raw message

fs/ntfs/lib/xpress_decompress.c new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH v3 7/9 ntfs: implement codec ops for LZX and XPRESS

In reply to Hyunchul Lee

Implement the transparent compression codec ops for XPRESS (4K, 8K, 16K) and LZX (32K) algorithms. The xpress_scratch_size, lzx_scratch_size, xpress_decompress_chunk, and lzx_decompress_chunk wrappers provide unified interfaces and use per-call dynamic scratch state allocation (avoiding global mutexed singletons).

---
 fs/ntfs/lib/lzx_decompress.c    | 21 +++++++++++++++++++++
 fs/ntfs/lib/xpress_decompress.c | 34 ++++++++++++++++++++++++++++++++++
 fs/ntfs/ntfs_codec.h            |  6 ++++++
 3 files changed, 61 insertions(+)
fs/ntfs/lib/lzx_decompress.c +21 -0
index 3b3c198d07e4..be040dce6e23 100644
@@ -14,6 +14,7 @@
 
 #include "decompress_common.h"
 #include "lib.h"
+#include "../ntfs_codec.h"
 
 /* Number of literal byte values. */
 #define LZX_NUM_CHARS		256
@@ -608,3 +609,23 @@ void lzx_free_decompressor(struct lzx_decompressor *d)
 {
 	kfree(d);
 }
+
+static size_t lzx_scratch_size(u32 chunk_size)
+{
+	return sizeof(struct lzx_decompressor);
+}
+
+static int lzx_decompress_chunk(void *scratch, const void *src, size_t src_len,
+				void *dst, size_t dst_len, u32 chunk_size)
+{
+	struct lzx_decompressor *d = scratch;
+
+	return lzx_decompress(d, src, src_len, dst, dst_len);
+}
+
+const struct ntfs_codec_ops ntfs_lzx32k_codec_ops = {
+	.id = NTFS_CODEC_LZX32K,
+	.name = "lzx32k",
+	.scratch_size = lzx_scratch_size,
+	.decompress_chunk = lzx_decompress_chunk,
+};
fs/ntfs/lib/xpress_decompress.c +34 -0
index 7066810ee6cd..cb212543268d 100644
@@ -15,6 +15,7 @@
 
 #include "decompress_common.h"
 #include "lib.h"
+#include "../ntfs_codec.h"
 
 #define XPRESS_NUM_CHARS	256
 #define XPRESS_NUM_SYMBOLS	512
@@ -118,3 +119,36 @@ void xpress_free_decompressor(struct xpress_decompressor *d)
 {
 	kfree(d);
 }
+
+static size_t xpress_scratch_size(u32 chunk_size)
+{
+	return sizeof(struct xpress_decompressor);
+}
+
+static int xpress_decompress_chunk(void *scratch, const void *src,
+				   size_t src_len, void *dst, size_t dst_len,
+				   u32 chunk_size)
+{
+	return xpress_decompress(scratch, src, src_len, dst, dst_len);
+}
+
+const struct ntfs_codec_ops ntfs_xpress4k_codec_ops = {
+	.id = NTFS_CODEC_XPRESS4K,
+	.name = "xpress4k",
+	.scratch_size = xpress_scratch_size,
+	.decompress_chunk = xpress_decompress_chunk,
+};
+
+const struct ntfs_codec_ops ntfs_xpress8k_codec_ops = {
+	.id = NTFS_CODEC_XPRESS8K,
+	.name = "xpress8k",
+	.scratch_size = xpress_scratch_size,
+	.decompress_chunk = xpress_decompress_chunk,
+};
+
+const struct ntfs_codec_ops ntfs_xpress16k_codec_ops = {
+	.id = NTFS_CODEC_XPRESS16K,
+	.name = "xpress16k",
+	.scratch_size = xpress_scratch_size,
+	.decompress_chunk = xpress_decompress_chunk,
+};
fs/ntfs/ntfs_codec.h +6 -0
index 408b18561a03..6030055fb0c1 100644
@@ -44,5 +44,11 @@ struct ntfs_codec_ops {
 };
 
 extern const struct ntfs_codec_ops ntfs_lznt1_codec_ops;
+#ifdef CONFIG_NTFS_FS_WOF_COMPRESSION
+extern const struct ntfs_codec_ops ntfs_xpress4k_codec_ops;
+extern const struct ntfs_codec_ops ntfs_xpress8k_codec_ops;
+extern const struct ntfs_codec_ops ntfs_xpress16k_codec_ops;
+extern const struct ntfs_codec_ops ntfs_lzx32k_codec_ops;
+#endif
 
 #endif /* _NTFS_CODEC_H */
Signature · 1 line
2.43.0
author maintainer
#8 lore raw

PATCH v3 8/9 ntfs: add non-resident WOF decompression

In reply to Hyunchul Lee

Introduce non-resident Windows System Compression (WOF) decompression support. Add wof.c containing parse_wof_chunk_table() and ntfs_read_wof_compressed_block(), and routing them via transparent codec ops table with dynamic scratch memory allocation. Hook up ntfs_readpage/read_folio paths in aops.c to delegate to the WOF block reader when NInoWofCompressed is set.

---
 fs/ntfs/Makefile  |   2 +-
 fs/ntfs/aops.c    |  19 +-
 fs/ntfs/attrib.c  |   2 +-
 fs/ntfs/bdev-io.c |   4 +-
 fs/ntfs/ea.c      |  28 ++-
 fs/ntfs/file.c    |  47 +++-
 fs/ntfs/inode.c   |   9 +-
 fs/ntfs/ntfs.h    |   4 +
 fs/ntfs/reparse.c |  59 +++--
 fs/ntfs/super.c   |   3 +
 fs/ntfs/wof.c     | 668 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 11 files changed, 792 insertions(+), 53 deletions(-)
fs/ntfs/Makefile +1 -1
index 5e5fd05f5863..ee8987e496a8 100644
@@ -7,7 +7,7 @@ ntfs-y := aops.o attrib.o collate.o dir.o file.o index.o inode.o \
 	  upcase.o bitmap.o lcnalloc.o logfile.o reparse.o compress.o \
 	  iomap.o debug.o sysctl.o object_id.o bdev-io.o
 
-ntfs-$(CONFIG_NTFS_FS_WOF_COMPRESSION) += \
+ntfs-$(CONFIG_NTFS_FS_WOF_COMPRESSION) += wof.o \
 	lib/decompress_common.o lib/lzx_decompress.o lib/xpress_decompress.o
 
 ccflags-$(CONFIG_NTFS_DEBUG) += -DDEBUG
fs/ntfs/aops.c +16 -3
index 173de4cbee0f..517d9a1563e7 100644
@@ -90,6 +90,14 @@ static int ntfs_read_folio(struct file *file, struct folio *folio)
 			folio_unlock(folio);
 			return -EOPNOTSUPP;
 		}
+		if (NInoWofCompressed(ni)) {
+#ifdef CONFIG_NTFS_FS_WOF_COMPRESSION
+			return ntfs_read_wof_compressed_block(folio);
+#else
+			folio_unlock(folio);
+			return -EOPNOTSUPP;
+#endif
+		}
 		/* Compressed data streams are handled in compress.c. */
 		if (NInoNonResident(ni) && NInoCompressed(ni))
 			return ntfs_read_compressed_block(folio);
@@ -136,11 +144,12 @@ static sector_t ntfs_bmap(struct address_space *mapping, sector_t block)
 	ntfs_debug("Entering for mft_no 0x%llx, logical block 0x%llx.",
 			ni->mft_no, (unsigned long long)block);
 	if (ni->type != AT_DATA || !NInoNonResident(ni) || NInoEncrypted(ni) ||
-	    NInoMstProtected(ni)) {
+	    NInoWofCompressed(ni) || NInoMstProtected(ni)) {
 		ntfs_error(vol->sb, "BMAP does not make sense for %s attributes, returning 0.",
 				(ni->type != AT_DATA) ? "non-data" :
 				(!NInoNonResident(ni) ? "resident" :
-				"encrypted"));
+				(NInoWofCompressed(ni) ? "WOF-compressed" :
+				"encrypted")));
 		return 0;
 	}
 	/* None of these can happen. */
@@ -234,7 +243,8 @@ static void ntfs_readahead(struct readahead_control *rac)
 	 * Resident files are not cached in the page cache,
 	 * and readahead is not implemented for compressed files.
 	 */
-	if (!NInoNonResident(ni) || NInoCompressed(ni))
+	if (!NInoNonResident(ni) || NInoCompressed(ni) ||
+	    NInoWofCompressed(ni))
 		return;
 	iomap_readahead(&ntfs_read_iomap_ops, &ctx, NULL);
 }
@@ -286,6 +296,9 @@ static int ntfs_writepages(struct address_space *mapping,
 static int ntfs_swap_activate(struct swap_info_struct *sis,
 		struct file *swap_file, sector_t *span)
 {
+	if (NInoWofCompressed(NTFS_I(file_inode(swap_file))))
+		return -EOPNOTSUPP;
+
 	return iomap_swapfile_activate(sis, swap_file, span,
 			&ntfs_read_iomap_ops);
 }
fs/ntfs/attrib.c +1 -1
index d9e844c481d8..60264833bb63 100644
@@ -2137,7 +2137,7 @@ int ntfs_attr_make_non_resident(struct ntfs_inode *ni, const u32 data_size)
 		ni->runlist.count = 0;
 	write_lock_irqsave(&ni->size_lock, flags);
 	ni->allocated_size = new_size;
-	if (NInoSparse(ni) || NInoCompressed(ni)) {
+	if ((NInoSparse(ni) && !NInoWofCompressed(ni)) || NInoCompressed(ni)) {
 		ni->itype.compressed.size = ni->allocated_size;
 		if (a->data.non_resident.compression_unit) {
 			ni->itype.compressed.block_size = 1U <<
fs/ntfs/bdev-io.c +2 -2
index 27d7c2767a33..86db4d9298ed 100644
@@ -33,7 +33,7 @@ int ntfs_bdev_read(struct block_device *bdev, char *data, loff_t start, size_t s
 	unsigned int done = 0, added;
 	int error;
 	struct bio *bio;
-	enum req_op op;
+	blk_opf_t op;
 	sector_t sector = start >> SECTOR_SHIFT;
 
 	if (start & (SECTOR_SIZE - 1))
@@ -66,7 +66,7 @@ int ntfs_bdev_read(struct block_device *bdev, char *data, loff_t start, size_t s
 	error = submit_bio_wait(bio);
 	bio_put(bio);
 
-	if (op == REQ_OP_READ)
+	if ((op & REQ_OP_MASK) == REQ_OP_READ)
 		invalidate_kernel_vmap_range(data, size);
 	return error;
 }
fs/ntfs/ea.c +25 -3
index c8a3d9f07dc4..74995a84c88c 100644
@@ -838,6 +838,17 @@ static bool ntfs_is_reserved_lxattr(const char *name)
 	       !strcmp(name, "$LXMOD") || !strcmp(name, "$LXDEV");
 }
 
+static int ntfs_validate_fattr(struct ntfs_inode *ni, __le32 fattr)
+{
+	const __le32 wof_flags = FILE_ATTR_SPARSE_FILE |
+				 FILE_ATTR_REPARSE_POINT;
+
+	if (NInoWofCompressed(ni) && ((ni->flags ^ fattr) & wof_flags))
+		return -EPERM;
+
+	return 0;
+}
+
 static int ntfs_setxattr(const struct xattr_handler *handler,
 		struct mnt_idmap *idmap, struct dentry *unused,
 		struct inode *inode, const char *name, const void *value,
@@ -858,7 +869,8 @@ static int ntfs_setxattr(const struct xattr_handler *handler,
 			err = -EINVAL;
 			goto out;
 		}
-		fattr = cpu_to_le32(*(u8 *)value);
+		fattr = cpu_to_le32((le32_to_cpu(ni->flags) & ~0xffU) |
+				    *(u8 *)value);
 		goto set_fattr;
 	}
 
@@ -873,6 +885,10 @@ static int ntfs_setxattr(const struct xattr_handler *handler,
 		else
 			fattr = cpu_to_le32(*(u32 *)value);
 
+		err = ntfs_validate_fattr(ni, fattr);
+		if (err)
+			goto out;
+
 		if (S_ISREG(inode->i_mode)) {
 			mutex_lock(&ni->mrec_lock);
 			err = ntfs_new_attr_flags(ni, fattr);
@@ -887,6 +903,10 @@ static int ntfs_setxattr(const struct xattr_handler *handler,
 		else
 			fattr &= ~FILE_ATTR_DIRECTORY;
 
+		err = ntfs_validate_fattr(ni, fattr);
+		if (err)
+			goto out;
+
 		if (ni->flags != fattr) {
 			ni->flags = fattr;
 			if (fattr & FILE_ATTR_READONLY)
@@ -905,8 +925,10 @@ static int ntfs_setxattr(const struct xattr_handler *handler,
 	mutex_unlock(&ni->mrec_lock);
 
 out:
-	inode_set_ctime_current(inode);
-	mark_inode_dirty(inode);
+	if (!err) {
+		inode_set_ctime_current(inode);
+		mark_inode_dirty(inode);
+	}
 	return err;
 }
 
fs/ntfs/file.c +37 -10

125 lines not on this page · raw message

fs/ntfs/inode.c +7 -2
index 45e013eb3541..591dc63cb24c 100644
@@ -1091,6 +1091,11 @@ static int ntfs_read_locked_inode(struct inode *vi)
 		/* Setup the state. */
 		if (a->flags & (ATTR_COMPRESSION_MASK | ATTR_IS_SPARSE)) {
 			if (a->flags & ATTR_COMPRESSION_MASK) {
+				if (NInoWofCompressed(ni)) {
+					ntfs_error(vi->i_sb,
+						"Found native compression on a WOF file.");
+					goto unm_err_out;
+				}
 				NInoSetCompressed(ni);
 				ni->flags |= FILE_ATTR_COMPRESSED;
 				if (vol->cluster_size > 4096) {
@@ -1121,7 +1126,7 @@ static int ntfs_read_locked_inode(struct inode *vi)
 		}
 		if (a->non_resident) {
 			NInoSetNonResident(ni);
-			if (NInoCompressed(ni) || NInoSparse(ni)) {
+			if (NInoCompressed(ni) || (NInoSparse(ni) && !NInoWofCompressed(ni))) {
 				if (NInoCompressed(ni) &&
 				    a->data.non_resident.compression_unit != 4) {
 					ntfs_error(vi->i_sb,
@@ -1400,7 +1405,7 @@ static int ntfs_read_locked_attr_inode(struct inode *base_vi, struct inode *vi)
 				"Attribute name is placed after the mapping pairs array.");
 			goto unm_err_out;
 		}
-		if (NInoCompressed(ni) || NInoSparse(ni)) {
+		if (NInoCompressed(ni) || (NInoSparse(ni) && !NInoWofCompressed(ni))) {
 			if (NInoCompressed(ni) && a->data.non_resident.compression_unit != 4) {
 				ntfs_error(vi->i_sb,
 					"Found non-standard compression unit (%u instead of 4).  Cannot handle this.",
fs/ntfs/ntfs.h +4 -0
index 45064dbcc2e4..df5a75d506f6 100644
@@ -202,6 +202,10 @@ static inline struct ntfs_volume *NTFS_SB(struct super_block *sb)
 
 /* From fs/ntfs/compress.c */
 int ntfs_read_compressed_block(struct folio *folio);
+#ifdef CONFIG_NTFS_FS_WOF_COMPRESSION
+int ntfs_read_wof_compressed_block(struct folio *folio);
+void ntfs_wof_free_workspaces(void);
+#endif
 int allocate_compression_buffers(void);
 void free_compression_buffers(void);
 int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
fs/ntfs/reparse.c +28 -31

75 lines not on this page · raw message

fs/ntfs/super.c +3 -0
index 8abe7bee4c0d..ab3f9847eea3 100644
@@ -2691,6 +2691,9 @@ static void __exit exit_ntfs_fs(void)
 	 * destroy cache.
 	 */
 	rcu_barrier();
+#ifdef CONFIG_NTFS_FS_WOF_COMPRESSION
+	ntfs_wof_free_workspaces();
+#endif
 	kmem_cache_destroy(ntfs_big_inode_cache);
 	kmem_cache_destroy(ntfs_inode_cache);
 	kmem_cache_destroy(ntfs_name_cache);
fs/ntfs/wof.c new file +668 -0

668 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#9 lore raw

PATCH v3 9/9 ntfs: support resident WOF decompression

In reply to Hyunchul Lee

Extend WOF decompression to support files where the reparse named data attribute or the compressed chunks themselves are resident. Retrieve resident metadata using ntfs_attr_lookup() and copy compressed chunks directly from the resident attribute payload.

---
 fs/ntfs/wof.c | 136 ++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 94 insertions(+), 42 deletions(-)
fs/ntfs/wof.c +94 -42
index 444b7c4ee0d6..2b4a8ae73889 100644
@@ -244,9 +244,9 @@ static int ntfs_bdev_read_from_rl(struct ntfs_volume *vol,
 
 static int parse_wof_chunk_table(struct ntfs_inode *base_ni,
 				 struct ntfs_inode *ni, u64 chunk_idx,
-				 u64 chunk_count, u64 *chunk_offset,
-				 u32 *chunk_size, void *table_buf,
-				 size_t table_buf_size)
+				 u64 chunk_count, u32 decomp_size,
+				 u64 *chunk_offset, u32 *chunk_size,
+				 void *table_buf, size_t table_buf_size)
 {
 	u8 bytes_per_off;
 	u8 *buf;
@@ -269,11 +269,11 @@ static int parse_wof_chunk_table(struct ntfs_inode *base_ni,
 	chunk_data_size = ni->data_size - table_size;
 
 	if (chunk_count == 1) {
-		if (chunk_data_size > U32_MAX)
+		if (chunk_data_size > decomp_size)
 			return -EINVAL;
 		*chunk_offset = 0;
 		*chunk_size = chunk_data_size;
-		return 0;
+		goto out;
 	}
 
 	byte_off = chunk_idx ? (chunk_idx - 1) * bytes_per_off : 0;
@@ -281,10 +281,7 @@ static int parse_wof_chunk_table(struct ntfs_inode *base_ni,
 				bytes_per_off :
 				(chunk_idx ? 2 : 1) * bytes_per_off;
 
-	if (!NInoNonResident(ni))
-		return -EOPNOTSUPP;
-
-	{
+	if (NInoNonResident(ni)) {
 		sector_t start_sector = byte_off >> 9;
 		u32 sector_off = byte_off & ((1 << 9) - 1);
 		u32 sectors = DIV_ROUND_UP(sector_off + bytes_to_read, 512);
@@ -294,11 +291,45 @@ static int parse_wof_chunk_table(struct ntfs_inode *base_ni,
 		buf = table_buf;
 		ret = ntfs_bdev_read_from_rl(ni->vol, &ni->runlist,
 					     start_sector, sectors, buf);
-		if (ret) {
-			ret = -EIO;
-			return ret;
-		}
+		if (ret)
+			return -EIO;
 		buf += sector_off;
+	} else {
+		struct ntfs_attr_search_ctx *ctx;
+		u32 value_length;
+		u16 value_offset;
+
+		if (bytes_to_read > table_buf_size)
+			return -EINVAL;
+
+		mutex_lock(&base_ni->mrec_lock);
+		ctx = ntfs_attr_get_search_ctx(base_ni, NULL);
+		if (!ctx) {
+			ret = -ENOMEM;
+			goto out_unlock_mrec;
+		}
+		ret = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
+				       CASE_SENSITIVE, 0, NULL, 0, ctx);
+		if (ret)
+			goto out_put_ctx;
+
+		value_length =
+			le32_to_cpu(ctx->attr->data.resident.value_length);
+		value_offset =
+			le16_to_cpu(ctx->attr->data.resident.value_offset);
+		if (byte_off + bytes_to_read > value_length) {
+			ret = -EINVAL;
+			goto out_put_ctx;
+		}
+		memcpy(table_buf, (u8 *)ctx->attr + value_offset + byte_off,
+		       bytes_to_read);
+		buf = table_buf;
+out_put_ctx:
+		ntfs_attr_put_search_ctx(ctx);
+out_unlock_mrec:
+		mutex_unlock(&base_ni->mrec_lock);
+		if (ret)
+			return ret;
 	}
 
 	if (bytes_per_off == sizeof(__le32)) {
@@ -314,14 +345,15 @@ static int parse_wof_chunk_table(struct ntfs_inode *base_ni,
 	}
 
 	if (off[1] <= off[0] || off[1] > chunk_data_size ||
-	    off[1] - off[0] > U32_MAX) {
-		ret = -EINVAL;
-		return ret;
-	}
+	    off[1] - off[0] > decomp_size)
+		return -EINVAL;
 
 	*chunk_offset = table_size + off[0];
 	*chunk_size = off[1] - off[0];
-	return ret;
+out:
+	if (!*chunk_size)
+		return -EINVAL;
+	return 0;
 }
 
 static int ntfs_read_wof_chunk(struct ntfs_volume *vol,
@@ -329,23 +361,54 @@ static int ntfs_read_wof_chunk(struct ntfs_volume *vol,
 			       u32 chunk_size, void *input, size_t input_size,
 			       char **chunk_mem)
 {
+	struct ntfs_inode *base_ni = wof_ni->ext.base_ntfs_ino;
+	struct ntfs_attr_search_ctx *ctx;
 	u32 input_offset = chunk_offset & 511;
 	u32 input_size_aligned;
+	u32 value_length;
+	u16 value_offset;
 	int err;
 
 	input_size_aligned = round_up(chunk_size + input_offset, 512);
 	if (input_size_aligned > input_size)
 		return -EINVAL;
 
-	if (!NInoNonResident(wof_ni))
-		return -EOPNOTSUPP;
+	if (NInoNonResident(wof_ni)) {
+		err = ntfs_bdev_read_from_rl(vol, &wof_ni->runlist,
+					     chunk_offset >> 9,
+					     input_size_aligned >> 9, input);
+		if (err)
+			return err;
+		*chunk_mem = (u8 *)input + input_offset;
+		return 0;
+	}
+
+	mutex_lock(&base_ni->mrec_lock);
+	ctx = ntfs_attr_get_search_ctx(base_ni, NULL);
+	if (!ctx) {
+		err = -ENOMEM;
+		goto out_unlock_mrec;
+	}
 
-	err = ntfs_bdev_read_from_rl(vol, &wof_ni->runlist, chunk_offset >> 9,
-				     input_size_aligned >> 9, input);
+	err = ntfs_attr_lookup(wof_ni->type, wof_ni->name, wof_ni->name_len,
+			       CASE_SENSITIVE, 0, NULL, 0, ctx);
 	if (err)
-		return err;
-	*chunk_mem = (u8 *)input + input_offset;
-	return 0;
+		goto out_put_ctx;
+
+	value_length = le32_to_cpu(ctx->attr->data.resident.value_length);
+	value_offset = le16_to_cpu(ctx->attr->data.resident.value_offset);
+	if (chunk_offset + chunk_size > value_length) {
+		err = -EINVAL;
+		goto out_put_ctx;
+	}
+	memcpy(input, (u8 *)ctx->attr + value_offset + chunk_offset,
+	       chunk_size);
+	*chunk_mem = input;
+out_put_ctx:
+	ntfs_attr_put_search_ctx(ctx);
+out_unlock_mrec:
+	mutex_unlock(&base_ni->mrec_lock);
+	return err;
 }
 
 struct ntfs_wof_dest {
@@ -574,11 +637,7 @@ int ntfs_read_wof_compressed_block(struct folio *folio)
 		err = -EIO;
 		goto out_iput;
 	}
-	if (!NInoNonResident(wof_ni)) {
-		err = -EOPNOTSUPP;
-		goto out_iput;
-	}
-	if (!NInoFullyMapped(wof_ni)) {
+	if (NInoNonResident(wof_ni) && !NInoFullyMapped(wof_ni)) {
 		down_write(&wof_ni->runlist.lock);
 		if (!NInoFullyMapped(wof_ni))
 			err = ntfs_attr_map_whole_runlist(wof_ni);
@@ -601,22 +660,15 @@ int ntfs_read_wof_compressed_block(struct folio *folio)
 		u64 chunk_file_offset;
 		loff_t chunk_end, copy_start, copy_end;
 
-		err = parse_wof_chunk_table(ni, wof_ni, chunk_idx, chunk_count,
-					    &chunk_offset, &chunk_size,
-					    ws->input, ws->input_size);
-		if (err)
-			goto out_unlock_ws;
 		decomp_size = chunk_idx + 1 == chunk_count ?
 				      i_size - chunk_idx * ws->comp_unit :
 				      ws->comp_unit;
-		if (!chunk_size || chunk_size > decomp_size) {
-			ntfs_error(
-				vol->sb,
-				"Invalid compressed size (%u) for frame size (%u)",
-				chunk_size, decomp_size);
-			err = -EINVAL;
+		err = parse_wof_chunk_table(ni, wof_ni, chunk_idx, chunk_count,
+					    decomp_size, &chunk_offset,
+					    &chunk_size, ws->input,
+					    ws->input_size);
+		if (err)
 			goto out_unlock_ws;
-		}
 
 		err = ntfs_read_wof_chunk(vol, wof_ni, chunk_offset, chunk_size,
 					  ws->input, ws->input_size,
Signature · 1 line
2.43.0