ntfs: add Windows system compression support
Hyunchul Lee
maintainercover 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.
---
Hyunchul Lee (8):
ntfs: introduce transparent compression codec interface
ntfs: define LZNT1 codec ops under transparent codec interface
ntfs: add WOF compression config option
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 | 7 +- fs/ntfs/attrib.c | 2 +- fs/ntfs/compress.c | 12 +- fs/ntfs/inode.c | 9 +- fs/ntfs/inode.h | 11 + 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 | 3 + fs/ntfs/ntfs_codec.h | 54 ++++ fs/ntfs/reparse.c | 77 ++++- fs/ntfs/reparse.h | 2 +- fs/ntfs/wof.c | 446 ++++++++++++++++++++++++++++ 17 files changed, 2084 insertions(+), 11 deletions(-)
---
base-commit: 5c244a0e9ca95468f4c2087b2c9269825429a13f
change-id: 20260810-topic-wof-4dd6eddbc852
Best regards,
Signature · 2 lines
Thanks, Hyunchul
Hyunchul Lee
maintainerPATCH 1/8 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
@@ -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
Hyunchul Lee
maintainerPATCH 2/8 ntfs: define LZNT1 codec ops under transparent codec interface
In reply to Hyunchul LeeDefine 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
@@ -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
@@ -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
Hyunchul Lee
maintainerPATCH 3/8 ntfs: add WOF compression config option
In reply to Hyunchul LeeAdd 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
@@ -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
Hyunchul Lee
maintainerPATCH 4/8 ntfs: parse REPARSE_TAG_WOF
In reply to Hyunchul LeeIntroduce 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 | 5 ++-- fs/ntfs/inode.h | 11 ++++++++ fs/ntfs/reparse.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- fs/ntfs/reparse.h | 2 +- 4 files changed, 90 insertions(+), 5 deletions(-)
fs/ntfs/inode.c +3 -2
@@ -869,7 +869,7 @@ static int ntfs_read_locked_inode(struct inode *vi)if (ni->flags &FILE_ATTR_REPARSE_POINT ) {unsigned int mode; - mode =ntfs_make_symlink (ni); + mode =ntfs_parse_reparse (ni);if (mode) vi->i_mode |= mode;else {
@@ -1214,7 +1214,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 +11 -0
@@ -189,6 +189,9 @@ enum { NI_NonResident, NI_IndexAllocPresent, NI_Compressed, +#ifdef CONFIG_NTFS_FS_WOF_COMPRESSION + NI_WofCompressed, +#endif NI_Encrypted, NI_Sparse, NI_SparseDisabled,
@@ -248,6 +251,14 @@ NINO_FNS(MstProtected) NINO_FNS(NonResident) NINO_FNS(IndexAllocPresent) NINO_FNS(Compressed) +#ifdef CONFIG_NTFS_FS_WOF_COMPRESSION +NINO_FNS(WofCompressed) +#else +static inline int NInoWofCompressed (struct ntfs_inode *ni) +{ +return 0 ; +} +#endif NINO_FNS(Encrypted) NINO_FNS(Sparse) NINO_FNS(SparseDisabled)
fs/ntfs/reparse.c +75 -2
102 lines not on this page · raw message
fs/ntfs/reparse.h +1 -1
@@ -9,7 +9,7 @@extern __le16 reparse_index_name[]; -unsigned int ntfs_make_symlink (struct ntfs_inode *ni); +unsigned int ntfs_parse_reparse (struct ntfs_inode *ni);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
Hyunchul Lee
maintainerPATCH 5/8 ntfs: port lzx/xpress decompressors from ntfs-3g-system-compression
In reply to Hyunchul LeePort 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.
--- 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
@@ -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
@@ -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
Hyunchul Lee
maintainerPATCH 6/8 ntfs: implement codec ops for LZX and XPRESS
In reply to Hyunchul LeeImplement 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
@@ -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
@@ -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
@@ -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
Hyunchul Lee
maintainerPATCH 7/8 ntfs: add non-resident WOF decompression
In reply to Hyunchul LeeIntroduce 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 | 7 +- fs/ntfs/attrib.c | 2 +- fs/ntfs/inode.c | 4 +- fs/ntfs/ntfs.h | 3 + fs/ntfs/wof.c | 380 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 393 insertions(+), 5 deletions(-)
fs/ntfs/Makefile +1 -1
@@ -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 +6 -1
@@ -93,6 +93,10 @@ static int ntfs_read_folio(struct file *file, struct folio *folio)/* Compressed data streams are handled in compress.c. */ if (NInoNonResident (ni) &&NInoCompressed (ni))return ntfs_read_compressed_block (folio); +#ifdef CONFIG_NTFS_FS_WOF_COMPRESSION + else if (NInoWofCompressed(ni)) + return ntfs_read_wof_compressed_block(folio); +#endif }iomap_read_folio (&ntfs_read_iomap_ops, &ctx,NULL );
@@ -234,7 +238,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 ); }
fs/ntfs/attrib.c +1 -1
@@ -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/inode.c +2 -2
@@ -1119,7 +1119,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,
@@ -1398,7 +1398,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 +3 -0
@@ -202,6 +202,9 @@ 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); +#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/wof.c new file +380 -0
380 lines not on this page · raw message
Signature · 1 line
2.43.0
Hyunchul Lee
maintainerPATCH 8/8 ntfs: support resident WOF decompression
In reply to Hyunchul LeeExtend 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 | 114 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 24 deletions(-)
fs/ntfs/wof.c +90 -24
@@ -99,7 +99,8 @@ static int parse_wof_chunk_table(struct ntfs_inode *ni, u64 chunk_idx, u64 chunk {u8 bytes_per_off;u8 *buf_aligned =NULL , *buf =NULL ; -u64 off[2 ]; +u64 addr[2 ] = {0 , }, off[2 ]; +u64 byte_off;u64 chunk_data_size;int ret =0 ;
@@ -114,16 +115,15 @@ static int parse_wof_chunk_table(struct ntfs_inode *ni, u64 chunk_idx, u64 chunkreturn -EINVAL ; chunk_data_size = ni->data_size - (chunk_count -1 ) * bytes_per_off; +if (chunk_idx >0 ) + byte_off = (chunk_idx -1 ) * bytes_per_off; +else + byte_off =0 ; +if (NInoNonResident (ni)) { -u64 byte_off;sector_t start_sector;u32 sector_off, sectors; -if (chunk_idx >0 ) - byte_off = (chunk_idx -1 ) * bytes_per_off; -else - byte_off =0 ; - start_sector = byte_off >>9 ; sector_off = byte_off & ((1 <<9 ) -1 ); sectors =DIV_ROUND_UP (sector_off +2 * bytes_per_off,512 );
@@ -139,21 +139,61 @@ static int parse_wof_chunk_table(struct ntfs_inode *ni, u64 chunk_idx, u64 chunk goto out; } buf = buf_aligned + sector_off; + }else { +struct ntfs_attr_search_ctx *ctx =NULL ; +u32 value_length; +u16 value_offset; +u8 *attr; + + ctx =ntfs_attr_get_search_ctx (ni,NULL ); +if (!ctx) { + ret = -ENOMEM ; + goto out; + } -if (chunk_idx +1 == chunk_count) { -if (bytes_per_off ==sizeof (__le32)) - ((__le32 *)buf)[1 ] = -cpu_to_le32 (ni->data_size - - (chunk_count -1 ) * bytes_per_off); -else - ((__le64 *)buf)[1 ] = -cpu_to_le64 (ni->data_size - - (chunk_count -1 ) * bytes_per_off); + ret =ntfs_attr_lookup (AT_DATA , (__le16 *)WOF_NAME , +WOF_NAME_LEN ,CASE_SENSITIVE ,0 ,NULL ,0 , + ctx); +if (ret) { +ntfs_attr_put_search_ctx (ctx); + goto out; } - }else { -/* Resident WOF chunk table logic will be added in Commit 8 */ - ret = -EOPNOTSUPP ; - goto out; + + 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_per_off > value_length || + (chunk_idx +1 != chunk_count && + byte_off +2 * bytes_per_off > value_length)) { +ntfs_attr_put_search_ctx (ctx); + ret = -EINVAL ; + goto out; + } + + attr = (u8 *)ctx->attr + value_offset; + +if (chunk_idx +1 == chunk_count) +memcpy ((u8 *)addr, attr + byte_off, bytes_per_off); +else +memcpy ((u8 *)addr, attr + byte_off,2 * bytes_per_off); + + buf = (u8 *)addr; + +ntfs_attr_put_search_ctx (ctx); + } + +/* Last chunk has an implicit end offset derived from data_size. */ +if (chunk_idx +1 == chunk_count) { +if (bytes_per_off ==sizeof (__le32)) + ((__le32 *)buf)[1 ] = +cpu_to_le32 (ni->data_size - + (chunk_count -1 ) * bytes_per_off); +else + ((__le64 *)buf)[1 ] = +cpu_to_le64 (ni->data_size - + (chunk_count -1 ) * bytes_per_off); }if (bytes_per_off ==sizeof (__le32)) {
@@ -243,7 +283,7 @@ int ntfs_read_wof_compressed_block(struct folio *folio) } wof_ni =NTFS_I (wof_inode); -if (!wof_ni->runlist.rl) { +if (NInoNonResident (wof_ni) && !NInoFullyMapped (wof_ni)) { err =ntfs_attr_map_whole_runlist (wof_ni);if (err) goto out_iput;
@@ -308,9 +348,35 @@ int ntfs_read_wof_compressed_block(struct folio *folio)/* Read compressed data from disk */ if (!NInoNonResident (wof_ni)) { -/* Resident WOF data read logic will be added in Commit 8 */ - err = -EOPNOTSUPP ; - goto out_free; +struct ntfs_attr_search_ctx *ctx =NULL ; + + ctx =ntfs_attr_get_search_ctx (wof_ni,NULL ); +if (!ctx) { + err = -ENOMEM ; + goto out_free; + } + + err =ntfs_attr_lookup (AT_DATA , (__le16 *)WOF_NAME , +WOF_NAME_LEN ,CASE_SENSITIVE , +0 ,NULL ,0 , ctx); +if (err) { +ntfs_attr_put_search_ctx (ctx); + goto out_free; + } + +if (chunk_offset + chunk_size > +le32_to_cpu (ctx->attr->data.resident.value_length)) { +ntfs_attr_put_search_ctx (ctx); + err = -EINVAL ; + goto out_free; + } + +memcpy (chunk_mem_aligned, + (u8 *)ctx->attr + +le16_to_cpu (ctx->attr->data.resident.value_offset) + + chunk_offset, chunk_size); +ntfs_attr_put_search_ctx (ctx); + chunk_mem = chunk_mem_aligned; }else { err = ntfs_bdev_read_from_rl(vol, &wof_ni->runlist, chunk_offset >> 9,
Signature · 1 line
2.43.0