summaryrefslogtreecommitdiff
path: root/fs/smb/client/compress.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/smb/client/compress.h')
-rw-r--r--fs/smb/client/compress.h44
1 files changed, 42 insertions, 2 deletions
diff --git a/fs/smb/client/compress.h b/fs/smb/client/compress.h
index f3ed1d3e52fb..717076bcd343 100644
--- a/fs/smb/client/compress.h
+++ b/fs/smb/client/compress.h
@@ -17,19 +17,48 @@
#include <linux/uio.h>
#include <linux/kernel.h>
+#include <linux/minmax.h>
+
#include "../common/smb2pdu.h"
-#include "cifsglob.h"
/* sizeof(smb2_compression_hdr) - sizeof(OriginalPayloadSize) */
#define SMB_COMPRESS_HDR_LEN 16
/* sizeof(smb2_compression_payload_hdr) - sizeof(OriginalPayloadSize) */
#define SMB_COMPRESS_PAYLOAD_HDR_LEN 8
-#define SMB_COMPRESS_MIN_LEN PAGE_SIZE
+#define SMB_COMPRESS_MIN_LEN SZ_64K
+#define SMB_DECOMPRESS_MAX_LEN(_srv) \
+ (256 + SMB_COMPRESS_HDR_LEN + max3((_srv)->maxBuf, (_srv)->max_read, (_srv)->max_write))
+
+static __always_inline u32 decompressed_size(const void *buf)
+{
+ const struct smb2_compression_hdr *hdr = buf;
+
+ if (!buf || !IS_ENABLED(CONFIG_CIFS_COMPRESSION))
+ return 0;
+
+ return le32_to_cpu(hdr->Offset) +
+ le32_to_cpu(hdr->OriginalCompressedSegmentSize);
+}
+
+static __always_inline bool is_compress_hdr(const void *buf)
+{
+ const struct smb2_compression_hdr *hdr = buf;
+
+ if (!buf)
+ return false;
+
+ return (hdr->ProtocolId == SMB2_COMPRESSION_TRANSFORM_ID);
+}
#ifdef CONFIG_CIFS_COMPRESSION
+struct TCP_Server_Info;
+struct cifs_tcon;
+struct smb_rqst;
+
typedef int (*compress_send_fn)(struct TCP_Server_Info *, int, struct smb_rqst *);
int smb_compress(struct TCP_Server_Info *server, struct smb_rqst *rq, compress_send_fn send_fn);
+int smb_decompress(const void *src, u32 slen, void *dst, u32 *dlen);
/**
* should_compress() - Determines if a request (write) or the response to a
@@ -47,6 +76,7 @@ int smb_compress(struct TCP_Server_Info *server, struct smb_rqst *rq, compress_s
* Return false otherwise.
*/
bool should_compress(const struct cifs_tcon *tcon, const struct smb_rqst *rq);
+bool should_decompress(struct TCP_Server_Info *server, const void *buf);
/**
* smb_compress_alg_valid() - Validate a compression algorithm.
@@ -77,11 +107,21 @@ static inline int smb_compress(void *unused1, void *unused2, void *unused3)
return -EOPNOTSUPP;
}
+static inline int smb_decompress(const void *unused1, u32 unused2, void *unused3, u32 unused4)
+{
+ return -EOPNOTSUPP;
+}
+
static inline bool should_compress(void *unused1, void *unused2)
{
return false;
}
+static inline bool should_decompress(void *unused1, void *unused2)
+{
+ return false;
+}
+
static inline int smb_compress_alg_valid(__le16 unused1, bool unused2)
{
return -EOPNOTSUPP;