Skip to content

Commit d8d9de5

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: Move more definitions into the shared area
Move SMB2_SessionSetup, SMB2_Close, SMB2_Read, SMB2_Write and SMB2_ChangeNotify commands into smbfs_common/smb2pdu.h Signed-off-by: Ronnie Sahlberg <[email protected]> Reviewed-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent fc0b384 commit d8d9de5

File tree

3 files changed

+276
-226
lines changed

3 files changed

+276
-226
lines changed

fs/cifs/smb2pdu.c

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data)
12601260
* if reconnect, we need to send previous sess id
12611261
* otherwise it is 0
12621262
*/
1263-
req->PreviousSessionId = sess_data->previous_session;
1263+
req->PreviousSessionId = cpu_to_le64(sess_data->previous_session);
12641264
req->Flags = 0; /* MBZ */
12651265
}
12661266

@@ -3234,8 +3234,8 @@ SMB2_close_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
32343234
if (rc)
32353235
return rc;
32363236

3237-
req->PersistentFileId = persistent_fid;
3238-
req->VolatileFileId = volatile_fid;
3237+
req->PersistentFileId = cpu_to_le64(persistent_fid);
3238+
req->VolatileFileId = cpu_to_le64(volatile_fid);
32393239
if (query_attrs)
32403240
req->Flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB;
32413241
else
@@ -3598,8 +3598,8 @@ SMB2_notify_init(const unsigned int xid, struct smb_rqst *rqst,
35983598
if (rc)
35993599
return rc;
36003600

3601-
req->PersistentFileId = persistent_fid;
3602-
req->VolatileFileId = volatile_fid;
3601+
req->PersistentFileId = cpu_to_le64(persistent_fid);
3602+
req->VolatileFileId = cpu_to_le64(volatile_fid);
36033603
/* See note 354 of MS-SMB2, 64K max */
36043604
req->OutputBufferLength =
36053605
cpu_to_le32(SMB2_MAX_BUFFER_SIZE - MAX_SMB2_HDR_SIZE);
@@ -3821,8 +3821,8 @@ SMB2_flush_init(const unsigned int xid, struct smb_rqst *rqst,
38213821
if (rc)
38223822
return rc;
38233823

3824-
req->PersistentFileId = persistent_fid;
3825-
req->VolatileFileId = volatile_fid;
3824+
req->PersistentFileId = cpu_to_le64(persistent_fid);
3825+
req->VolatileFileId = cpu_to_le64(volatile_fid);
38263826

38273827
iov[0].iov_base = (char *)req;
38283828
iov[0].iov_len = total_len;
@@ -3888,7 +3888,7 @@ smb2_new_read_req(void **buf, unsigned int *total_len,
38883888
unsigned int remaining_bytes, int request_type)
38893889
{
38903890
int rc = -EACCES;
3891-
struct smb2_read_plain_req *req = NULL;
3891+
struct smb2_read_req *req = NULL;
38923892
struct smb2_hdr *shdr;
38933893
struct TCP_Server_Info *server = io_parms->server;
38943894

@@ -3903,8 +3903,8 @@ smb2_new_read_req(void **buf, unsigned int *total_len,
39033903
shdr = &req->hdr;
39043904
shdr->Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid);
39053905

3906-
req->PersistentFileId = io_parms->persistent_fid;
3907-
req->VolatileFileId = io_parms->volatile_fid;
3906+
req->PersistentFileId = cpu_to_le64(io_parms->persistent_fid);
3907+
req->VolatileFileId = cpu_to_le64(io_parms->volatile_fid);
39083908
req->ReadChannelInfoOffset = 0; /* reserved */
39093909
req->ReadChannelInfoLength = 0; /* reserved */
39103910
req->Channel = 0; /* reserved */
@@ -3938,7 +3938,7 @@ smb2_new_read_req(void **buf, unsigned int *total_len,
39383938
if (need_invalidate)
39393939
req->Channel = SMB2_CHANNEL_RDMA_V1;
39403940
req->ReadChannelInfoOffset =
3941-
cpu_to_le16(offsetof(struct smb2_read_plain_req, Buffer));
3941+
cpu_to_le16(offsetof(struct smb2_read_req, Buffer));
39423942
req->ReadChannelInfoLength =
39433943
cpu_to_le16(sizeof(struct smbd_buffer_descriptor_v1));
39443944
v1 = (struct smbd_buffer_descriptor_v1 *) &req->Buffer[0];
@@ -3964,8 +3964,8 @@ smb2_new_read_req(void **buf, unsigned int *total_len,
39643964
*/
39653965
shdr->SessionId = cpu_to_le64(0xFFFFFFFFFFFFFFFF);
39663966
shdr->Id.SyncId.TreeId = cpu_to_le32(0xFFFFFFFF);
3967-
req->PersistentFileId = 0xFFFFFFFFFFFFFFFF;
3968-
req->VolatileFileId = 0xFFFFFFFFFFFFFFFF;
3967+
req->PersistentFileId = cpu_to_le64(0xFFFFFFFFFFFFFFFF);
3968+
req->VolatileFileId = cpu_to_le64(0xFFFFFFFFFFFFFFFF);
39693969
}
39703970
}
39713971
if (remaining_bytes > io_parms->length)
@@ -4142,7 +4142,7 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
41424142
{
41434143
struct smb_rqst rqst;
41444144
int resp_buftype, rc;
4145-
struct smb2_read_plain_req *req = NULL;
4145+
struct smb2_read_req *req = NULL;
41464146
struct smb2_read_rsp *rsp = NULL;
41474147
struct kvec iov[1];
41484148
struct kvec rsp_iov;
@@ -4176,19 +4176,22 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
41764176
if (rc != -ENODATA) {
41774177
cifs_stats_fail_inc(io_parms->tcon, SMB2_READ_HE);
41784178
cifs_dbg(VFS, "Send error in read = %d\n", rc);
4179-
trace_smb3_read_err(xid, req->PersistentFileId,
4179+
trace_smb3_read_err(xid,
4180+
le64_to_cpu(req->PersistentFileId),
41804181
io_parms->tcon->tid, ses->Suid,
41814182
io_parms->offset, io_parms->length,
41824183
rc);
41834184
} else
4184-
trace_smb3_read_done(xid, req->PersistentFileId,
4185-
io_parms->tcon->tid, ses->Suid,
4186-
io_parms->offset, 0);
4185+
trace_smb3_read_done(xid,
4186+
le64_to_cpu(req->PersistentFileId),
4187+
io_parms->tcon->tid, ses->Suid,
4188+
io_parms->offset, 0);
41874189
free_rsp_buf(resp_buftype, rsp_iov.iov_base);
41884190
cifs_small_buf_release(req);
41894191
return rc == -ENODATA ? 0 : rc;
41904192
} else
4191-
trace_smb3_read_done(xid, req->PersistentFileId,
4193+
trace_smb3_read_done(xid,
4194+
le64_to_cpu(req->PersistentFileId),
41924195
io_parms->tcon->tid, ses->Suid,
41934196
io_parms->offset, io_parms->length);
41944197

@@ -4330,8 +4333,8 @@ smb2_async_writev(struct cifs_writedata *wdata,
43304333
shdr = (struct smb2_hdr *)req;
43314334
shdr->Id.SyncId.ProcessId = cpu_to_le32(wdata->cfile->pid);
43324335

4333-
req->PersistentFileId = wdata->cfile->fid.persistent_fid;
4334-
req->VolatileFileId = wdata->cfile->fid.volatile_fid;
4336+
req->PersistentFileId = cpu_to_le64(wdata->cfile->fid.persistent_fid);
4337+
req->VolatileFileId = cpu_to_le64(wdata->cfile->fid.volatile_fid);
43354338
req->WriteChannelInfoOffset = 0;
43364339
req->WriteChannelInfoLength = 0;
43374340
req->Channel = 0;
@@ -4428,7 +4431,8 @@ smb2_async_writev(struct cifs_writedata *wdata,
44284431
wdata, flags, &wdata->credits);
44294432

44304433
if (rc) {
4431-
trace_smb3_write_err(0 /* no xid */, req->PersistentFileId,
4434+
trace_smb3_write_err(0 /* no xid */,
4435+
le64_to_cpu(req->PersistentFileId),
44324436
tcon->tid, tcon->ses->Suid, wdata->offset,
44334437
wdata->bytes, rc);
44344438
kref_put(&wdata->refcount, release);
@@ -4481,8 +4485,8 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
44814485

44824486
req->hdr.Id.SyncId.ProcessId = cpu_to_le32(io_parms->pid);
44834487

4484-
req->PersistentFileId = io_parms->persistent_fid;
4485-
req->VolatileFileId = io_parms->volatile_fid;
4488+
req->PersistentFileId = cpu_to_le64(io_parms->persistent_fid);
4489+
req->VolatileFileId = cpu_to_le64(io_parms->volatile_fid);
44864490
req->WriteChannelInfoOffset = 0;
44874491
req->WriteChannelInfoLength = 0;
44884492
req->Channel = 0;
@@ -4510,18 +4514,20 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
45104514
rsp = (struct smb2_write_rsp *)rsp_iov.iov_base;
45114515

45124516
if (rc) {
4513-
trace_smb3_write_err(xid, req->PersistentFileId,
4517+
trace_smb3_write_err(xid,
4518+
le64_to_cpu(req->PersistentFileId),
45144519
io_parms->tcon->tid,
45154520
io_parms->tcon->ses->Suid,
45164521
io_parms->offset, io_parms->length, rc);
45174522
cifs_stats_fail_inc(io_parms->tcon, SMB2_WRITE_HE);
45184523
cifs_dbg(VFS, "Send error in write = %d\n", rc);
45194524
} else {
45204525
*nbytes = le32_to_cpu(rsp->DataLength);
4521-
trace_smb3_write_done(xid, req->PersistentFileId,
4522-
io_parms->tcon->tid,
4523-
io_parms->tcon->ses->Suid,
4524-
io_parms->offset, *nbytes);
4526+
trace_smb3_write_done(xid,
4527+
le64_to_cpu(req->PersistentFileId),
4528+
io_parms->tcon->tid,
4529+
io_parms->tcon->ses->Suid,
4530+
io_parms->offset, *nbytes);
45254531
}
45264532

45274533
cifs_small_buf_release(req);

fs/cifs/smb2pdu.h

Lines changed: 0 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -115,48 +115,6 @@ struct share_redirect_error_context_rsp {
115115
/* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
116116
} __packed;
117117

118-
/* Flags */
119-
#define SMB2_SESSION_REQ_FLAG_BINDING 0x01
120-
#define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
121-
122-
struct smb2_sess_setup_req {
123-
struct smb2_hdr hdr;
124-
__le16 StructureSize; /* Must be 25 */
125-
__u8 Flags;
126-
__u8 SecurityMode;
127-
__le32 Capabilities;
128-
__le32 Channel;
129-
__le16 SecurityBufferOffset;
130-
__le16 SecurityBufferLength;
131-
__u64 PreviousSessionId;
132-
__u8 Buffer[1]; /* variable length GSS security buffer */
133-
} __packed;
134-
135-
/* Currently defined SessionFlags */
136-
#define SMB2_SESSION_FLAG_IS_GUEST 0x0001
137-
#define SMB2_SESSION_FLAG_IS_NULL 0x0002
138-
#define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
139-
struct smb2_sess_setup_rsp {
140-
struct smb2_hdr hdr;
141-
__le16 StructureSize; /* Must be 9 */
142-
__le16 SessionFlags;
143-
__le16 SecurityBufferOffset;
144-
__le16 SecurityBufferLength;
145-
__u8 Buffer[1]; /* variable length GSS security buffer */
146-
} __packed;
147-
148-
struct smb2_logoff_req {
149-
struct smb2_hdr hdr;
150-
__le16 StructureSize; /* Must be 4 */
151-
__le16 Reserved;
152-
} __packed;
153-
154-
struct smb2_logoff_rsp {
155-
struct smb2_hdr hdr;
156-
__le16 StructureSize; /* Must be 4 */
157-
__le16 Reserved;
158-
} __packed;
159-
160118
/* File Attrubutes */
161119
#define FILE_ATTRIBUTE_READONLY 0x00000001
162120
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
@@ -720,161 +678,6 @@ struct smb2_ioctl_rsp {
720678
/* char * buffer[] */
721679
} __packed;
722680

723-
/* Currently defined values for close flags */
724-
#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
725-
struct smb2_close_req {
726-
struct smb2_hdr hdr;
727-
__le16 StructureSize; /* Must be 24 */
728-
__le16 Flags;
729-
__le32 Reserved;
730-
__u64 PersistentFileId; /* opaque endianness */
731-
__u64 VolatileFileId; /* opaque endianness */
732-
} __packed;
733-
734-
/*
735-
* Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
736-
*/
737-
#define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
738-
739-
struct smb2_close_rsp {
740-
struct smb2_hdr hdr;
741-
__le16 StructureSize; /* 60 */
742-
__le16 Flags;
743-
__le32 Reserved;
744-
__le64 CreationTime;
745-
__le64 LastAccessTime;
746-
__le64 LastWriteTime;
747-
__le64 ChangeTime;
748-
__le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
749-
__le64 EndOfFile;
750-
__le32 Attributes;
751-
} __packed;
752-
753-
struct smb2_flush_req {
754-
struct smb2_hdr hdr;
755-
__le16 StructureSize; /* Must be 24 */
756-
__le16 Reserved1;
757-
__le32 Reserved2;
758-
__u64 PersistentFileId; /* opaque endianness */
759-
__u64 VolatileFileId; /* opaque endianness */
760-
} __packed;
761-
762-
struct smb2_flush_rsp {
763-
struct smb2_hdr hdr;
764-
__le16 StructureSize;
765-
__le16 Reserved;
766-
} __packed;
767-
768-
/* For read request Flags field below, following flag is defined for SMB3.02 */
769-
#define SMB2_READFLAG_READ_UNBUFFERED 0x01
770-
#define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
771-
772-
/* Channel field for read and write: exactly one of following flags can be set*/
773-
#define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
774-
#define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */
775-
#define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
776-
#define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003) /* >= SMB3.02, only used on write */
777-
778-
/* SMB2 read request without RFC1001 length at the beginning */
779-
struct smb2_read_plain_req {
780-
struct smb2_hdr hdr;
781-
__le16 StructureSize; /* Must be 49 */
782-
__u8 Padding; /* offset from start of SMB2 header to place read */
783-
__u8 Flags; /* MBZ unless SMB3.02 or later */
784-
__le32 Length;
785-
__le64 Offset;
786-
__u64 PersistentFileId; /* opaque endianness */
787-
__u64 VolatileFileId; /* opaque endianness */
788-
__le32 MinimumCount;
789-
__le32 Channel; /* MBZ except for SMB3 or later */
790-
__le32 RemainingBytes;
791-
__le16 ReadChannelInfoOffset;
792-
__le16 ReadChannelInfoLength;
793-
__u8 Buffer[1];
794-
} __packed;
795-
796-
/* Read flags */
797-
#define SMB2_READFLAG_RESPONSE_NONE 0x00000000
798-
#define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM 0x00000001
799-
800-
struct smb2_read_rsp {
801-
struct smb2_hdr hdr;
802-
__le16 StructureSize; /* Must be 17 */
803-
__u8 DataOffset;
804-
__u8 Reserved;
805-
__le32 DataLength;
806-
__le32 DataRemaining;
807-
__u32 Flags;
808-
__u8 Buffer[1];
809-
} __packed;
810-
811-
/* For write request Flags field below the following flags are defined: */
812-
#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
813-
#define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
814-
815-
struct smb2_write_req {
816-
struct smb2_hdr hdr;
817-
__le16 StructureSize; /* Must be 49 */
818-
__le16 DataOffset; /* offset from start of SMB2 header to write data */
819-
__le32 Length;
820-
__le64 Offset;
821-
__u64 PersistentFileId; /* opaque endianness */
822-
__u64 VolatileFileId; /* opaque endianness */
823-
__le32 Channel; /* MBZ unless SMB3.02 or later */
824-
__le32 RemainingBytes;
825-
__le16 WriteChannelInfoOffset;
826-
__le16 WriteChannelInfoLength;
827-
__le32 Flags;
828-
__u8 Buffer[1];
829-
} __packed;
830-
831-
struct smb2_write_rsp {
832-
struct smb2_hdr hdr;
833-
__le16 StructureSize; /* Must be 17 */
834-
__u8 DataOffset;
835-
__u8 Reserved;
836-
__le32 DataLength;
837-
__le32 DataRemaining;
838-
__u32 Reserved2;
839-
__u8 Buffer[1];
840-
} __packed;
841-
842-
/* notify flags */
843-
#define SMB2_WATCH_TREE 0x0001
844-
845-
/* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
846-
#define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
847-
#define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
848-
#define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
849-
#define FILE_NOTIFY_CHANGE_SIZE 0x00000008
850-
#define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
851-
#define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
852-
#define FILE_NOTIFY_CHANGE_CREATION 0x00000040
853-
#define FILE_NOTIFY_CHANGE_EA 0x00000080
854-
#define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
855-
#define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
856-
#define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
857-
#define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
858-
859-
struct smb2_change_notify_req {
860-
struct smb2_hdr hdr;
861-
__le16 StructureSize;
862-
__le16 Flags;
863-
__le32 OutputBufferLength;
864-
__u64 PersistentFileId; /* opaque endianness */
865-
__u64 VolatileFileId; /* opaque endianness */
866-
__le32 CompletionFilter;
867-
__u32 Reserved;
868-
} __packed;
869-
870-
struct smb2_change_notify_rsp {
871-
struct smb2_hdr hdr;
872-
__le16 StructureSize; /* Must be 9 */
873-
__le16 OutputBufferOffset;
874-
__le32 OutputBufferLength;
875-
__u8 Buffer[1]; /* array of file notify structs */
876-
} __packed;
877-
878681
#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
879682
#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
880683
#define SMB2_LOCKFLAG_UNLOCK 0x0004

0 commit comments

Comments
 (0)