Skip to content

Commit 24337b6

Browse files
ematsumiyaSteve French
authored andcommitted
smb: common: simplify compression headers
Unify compression headers (chained and unchained) into a single struct so we can use it for the initial compression transform header interchangeably. Also make the OriginalPayloadSize field to be always visible in the compression payload header, and have callers subtract its size when not needed. Rename the related structs to match the naming convetion used in the other SMB2 structs. Signed-off-by: Enzo Matsumiya <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent f49af46 commit 24337b6

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

fs/smb/common/smb2pdu.h

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -208,36 +208,43 @@ struct smb2_transform_hdr {
208208
__le64 SessionId;
209209
} __packed;
210210

211+
/*
212+
* These are simplified versions from the spec, as we don't need a fully fledged
213+
* form of both unchained and chained structs.
214+
*
215+
* Moreover, even in chained compressed payloads, the initial compression header
216+
* has the form of the unchained one -- i.e. it never has the
217+
* OriginalPayloadSize field and ::Offset field always represent an offset
218+
* (instead of a length, as it is in the chained header).
219+
*
220+
* See MS-SMB2 2.2.42 for more details.
221+
*/
222+
#define SMB2_COMPRESSION_FLAG_NONE 0x0000
223+
#define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
211224

212-
/* See MS-SMB2 2.2.42 */
213-
struct smb2_compression_transform_hdr_unchained {
214-
__le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
225+
struct smb2_compression_hdr {
226+
__le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
215227
__le32 OriginalCompressedSegmentSize;
216228
__le16 CompressionAlgorithm;
217229
__le16 Flags;
218-
__le16 Length; /* if chained it is length, else offset */
230+
__le16 Offset; /* this is the size of the uncompressed SMB2 header below */
231+
/* uncompressed SMB2 header (READ or WRITE) goes here */
232+
/* compressed data goes here */
219233
} __packed;
220234

221-
/* See MS-SMB2 2.2.42.1 */
222-
#define SMB2_COMPRESSION_FLAG_NONE 0x0000
223-
#define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
224-
225-
struct compression_payload_header {
235+
/*
236+
* ... OTOH, set compression payload header to always have OriginalPayloadSize
237+
* as it's easier to pass the struct size minus sizeof(OriginalPayloadSize)
238+
* than to juggle around the header/data memory.
239+
*/
240+
struct smb2_compression_payload_hdr {
226241
__le16 CompressionAlgorithm;
227242
__le16 Flags;
228243
__le32 Length; /* length of compressed playload including field below if present */
229-
/* __le32 OriginalPayloadSize; */ /* optional, present when LZNT1, LZ77, LZ77+Huffman */
230-
} __packed;
231-
232-
/* See MS-SMB2 2.2.42.2 */
233-
struct smb2_compression_transform_hdr_chained {
234-
__le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
235-
__le32 OriginalCompressedSegmentSize;
236-
/* struct compression_payload_header[] */
244+
__le32 OriginalPayloadSize; /* accounted when LZNT1, LZ77, LZ77+Huffman */
237245
} __packed;
238246

239-
/* See MS-SMB2 2.2.42.2.2 */
240-
struct compression_pattern_payload_v1 {
247+
struct smb2_compression_pattern_v1 {
241248
__u8 Pattern;
242249
__u8 Reserved1;
243250
__le16 Reserved2;

0 commit comments

Comments
 (0)