1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 2 /* 3 * Copyright (C) 2024, SUSE LLC 4 * 5 * Authors: Enzo Matsumiya <ematsumiya@suse.de 6 * 7 * This file implements I/O compression suppor 8 * See compress/ for implementation details of 9 * 10 * References: 11 * MS-SMB2 "3.1.4.4 Compressing the Message" - 12 * MS-SMB2 "3.1.5.3 Decompressing the Chained 13 * MS-XCA - for details of the supported algor 14 */ 15 #ifndef _SMB_COMPRESS_H 16 #define _SMB_COMPRESS_H 17 18 #include <linux/uio.h> 19 #include <linux/kernel.h> 20 #include "../common/smb2pdu.h" 21 #include "cifsglob.h" 22 23 /* sizeof(smb2_compression_hdr) - sizeof(Origi 24 #define SMB_COMPRESS_HDR_LEN 16 25 /* sizeof(smb2_compression_payload_hdr) - size 26 #define SMB_COMPRESS_PAYLOAD_HDR_LEN 8 27 #define SMB_COMPRESS_MIN_LEN PAGE_S 28 29 #ifdef CONFIG_CIFS_COMPRESSION 30 typedef int (*compress_send_fn)(struct TCP_Ser 31 32 int smb_compress(struct TCP_Server_Info *serve 33 34 /** 35 * should_compress() - Determines if a request 36 * request (read) should b 37 * @tcon: tcon of the request is being sent to 38 * @rqst: request to evaluate 39 * 40 * Return: true iff: 41 * - compression was successfully negotiated w 42 * - server has enabled compression for the sh 43 * - it's a read or write request 44 * - (write only) request length is >= SMB_COM 45 * - (write only) is_compressible() returns 1 46 * 47 * Return false otherwise. 48 */ 49 bool should_compress(const struct cifs_tcon *t 50 51 /** 52 * smb_compress_alg_valid() - Validate a compr 53 * @alg: Compression algorithm to check. 54 * @valid_none: Conditional check whether NONE 55 * considered valid or not. 56 * 57 * If @alg is SMB3_COMPRESS_NONE, this functio 58 * 59 * Note that 'NONE' (0) compressor type is con 60 * negotiation, as it's never requested to/ret 61 * 62 * Return: true if @alg is valid/supported, fa 63 */ 64 static __always_inline int smb_compress_alg_va 65 { 66 if (alg == SMB3_COMPRESS_NONE) 67 return valid_none; 68 69 if (alg == SMB3_COMPRESS_LZ77 || alg = 70 return true; 71 72 return false; 73 } 74 #else /* !CONFIG_CIFS_COMPRESSION */ 75 static inline int smb_compress(void *unused1, 76 { 77 return -EOPNOTSUPP; 78 } 79 80 static inline bool should_compress(void *unuse 81 { 82 return false; 83 } 84 85 static inline int smb_compress_alg_valid(__le1 86 { 87 return -EOPNOTSUPP; 88 } 89 #endif /* !CONFIG_CIFS_COMPRESSION */ 90 #endif /* _SMB_COMPRESS_H */ 91
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.