xref: /linux/fs/smb/client/compress.h (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2024, SUSE LLC
4  *
5  * Authors: Enzo Matsumiya <ematsumiya@suse.de>
6  *
7  * This file implements I/O compression support for SMB2 messages (SMB 3.1.1 only).
8  * See compress/ for implementation details of each algorithm.
9  *
10  * References:
11  * MS-SMB2 "3.1.4.4 Compressing the Message" - for compression details
12  * MS-SMB2 "3.1.5.3 Decompressing the Chained Message" - for decompression details
13  * MS-XCA - for details of the supported algorithms
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 "../common/compress/compress.h"
22 #include "cifsglob.h"
23 
24 /* sizeof(smb2_compression_hdr) - sizeof(OriginalPayloadSize) */
25 #define SMB_COMPRESS_HDR_LEN		16
26 /* sizeof(smb2_compression_payload_hdr) - sizeof(OriginalPayloadSize) */
27 #define SMB_COMPRESS_PAYLOAD_HDR_LEN	8
28 #define SMB_COMPRESS_MIN_LEN		PAGE_SIZE
29 
30 #ifdef CONFIG_CIFS_COMPRESSION
31 typedef int (*compress_send_fn)(struct TCP_Server_Info *, int, struct smb_rqst *);
32 
33 
34 int smb_compress(struct TCP_Server_Info *server, struct smb_rqst *rq,
35 		 compress_send_fn send_fn);
36 bool should_compress(const struct cifs_tcon *tcon, const struct smb_rqst *rq);
37 
38 #else /* !CONFIG_CIFS_COMPRESSION */
39 static inline int smb_compress(void *unused1, void *unused2, void *unused3)
40 {
41 	return -EOPNOTSUPP;
42 }
43 
44 static inline bool should_compress(void *unused1, void *unused2)
45 {
46 	return false;
47 }
48 
49 #endif /* !CONFIG_CIFS_COMPRESSION */
50 #endif /* _SMB_COMPRESS_H */
51