1*38c8a9a5SSteve French /* SPDX-License-Identifier: GPL-2.0-or-later */ 2*38c8a9a5SSteve French /* 3*38c8a9a5SSteve French * Copyright (C) 2018 Samsung Electronics Co., Ltd. 4*38c8a9a5SSteve French */ 5*38c8a9a5SSteve French 6*38c8a9a5SSteve French #ifndef __SMB_COMMON_H__ 7*38c8a9a5SSteve French #define __SMB_COMMON_H__ 8*38c8a9a5SSteve French 9*38c8a9a5SSteve French #include <linux/kernel.h> 10*38c8a9a5SSteve French 11*38c8a9a5SSteve French #include "glob.h" 12*38c8a9a5SSteve French #include "nterr.h" 13*38c8a9a5SSteve French #include "../common/smb2pdu.h" 14*38c8a9a5SSteve French #include "smb2pdu.h" 15*38c8a9a5SSteve French 16*38c8a9a5SSteve French /* ksmbd's Specific ERRNO */ 17*38c8a9a5SSteve French #define ESHARE 50000 18*38c8a9a5SSteve French 19*38c8a9a5SSteve French #define SMB1_PROT 0 20*38c8a9a5SSteve French #define SMB2_PROT 1 21*38c8a9a5SSteve French #define SMB21_PROT 2 22*38c8a9a5SSteve French /* multi-protocol negotiate request */ 23*38c8a9a5SSteve French #define SMB2X_PROT 3 24*38c8a9a5SSteve French #define SMB30_PROT 4 25*38c8a9a5SSteve French #define SMB302_PROT 5 26*38c8a9a5SSteve French #define SMB311_PROT 6 27*38c8a9a5SSteve French #define BAD_PROT 0xFFFF 28*38c8a9a5SSteve French 29*38c8a9a5SSteve French #define SMB1_VERSION_STRING "1.0" 30*38c8a9a5SSteve French #define SMB20_VERSION_STRING "2.0" 31*38c8a9a5SSteve French #define SMB21_VERSION_STRING "2.1" 32*38c8a9a5SSteve French #define SMB30_VERSION_STRING "3.0" 33*38c8a9a5SSteve French #define SMB302_VERSION_STRING "3.02" 34*38c8a9a5SSteve French #define SMB311_VERSION_STRING "3.1.1" 35*38c8a9a5SSteve French 36*38c8a9a5SSteve French #define SMB_ECHO_INTERVAL (60 * HZ) 37*38c8a9a5SSteve French 38*38c8a9a5SSteve French #define CIFS_DEFAULT_IOSIZE (64 * 1024) 39*38c8a9a5SSteve French #define MAX_CIFS_SMALL_BUFFER_SIZE 448 /* big enough for most */ 40*38c8a9a5SSteve French 41*38c8a9a5SSteve French #define MAX_STREAM_PROT_LEN 0x00FFFFFF 42*38c8a9a5SSteve French 43*38c8a9a5SSteve French /* Responses when opening a file. */ 44*38c8a9a5SSteve French #define F_SUPERSEDED 0 45*38c8a9a5SSteve French #define F_OPENED 1 46*38c8a9a5SSteve French #define F_CREATED 2 47*38c8a9a5SSteve French #define F_OVERWRITTEN 3 48*38c8a9a5SSteve French 49*38c8a9a5SSteve French /* 50*38c8a9a5SSteve French * File Attribute flags 51*38c8a9a5SSteve French */ 52*38c8a9a5SSteve French #define ATTR_POSIX_SEMANTICS 0x01000000 53*38c8a9a5SSteve French #define ATTR_BACKUP_SEMANTICS 0x02000000 54*38c8a9a5SSteve French #define ATTR_DELETE_ON_CLOSE 0x04000000 55*38c8a9a5SSteve French #define ATTR_SEQUENTIAL_SCAN 0x08000000 56*38c8a9a5SSteve French #define ATTR_RANDOM_ACCESS 0x10000000 57*38c8a9a5SSteve French #define ATTR_NO_BUFFERING 0x20000000 58*38c8a9a5SSteve French #define ATTR_WRITE_THROUGH 0x80000000 59*38c8a9a5SSteve French 60*38c8a9a5SSteve French /* List of FileSystemAttributes - see 2.5.1 of MS-FSCC */ 61*38c8a9a5SSteve French #define FILE_SUPPORTS_SPARSE_VDL 0x10000000 /* faster nonsparse extend */ 62*38c8a9a5SSteve French #define FILE_SUPPORTS_BLOCK_REFCOUNTING 0x08000000 /* allow ioctl dup extents */ 63*38c8a9a5SSteve French #define FILE_SUPPORT_INTEGRITY_STREAMS 0x04000000 64*38c8a9a5SSteve French #define FILE_SUPPORTS_USN_JOURNAL 0x02000000 65*38c8a9a5SSteve French #define FILE_SUPPORTS_OPEN_BY_FILE_ID 0x01000000 66*38c8a9a5SSteve French #define FILE_SUPPORTS_EXTENDED_ATTRIBUTES 0x00800000 67*38c8a9a5SSteve French #define FILE_SUPPORTS_HARD_LINKS 0x00400000 68*38c8a9a5SSteve French #define FILE_SUPPORTS_TRANSACTIONS 0x00200000 69*38c8a9a5SSteve French #define FILE_SEQUENTIAL_WRITE_ONCE 0x00100000 70*38c8a9a5SSteve French #define FILE_READ_ONLY_VOLUME 0x00080000 71*38c8a9a5SSteve French #define FILE_NAMED_STREAMS 0x00040000 72*38c8a9a5SSteve French #define FILE_SUPPORTS_ENCRYPTION 0x00020000 73*38c8a9a5SSteve French #define FILE_SUPPORTS_OBJECT_IDS 0x00010000 74*38c8a9a5SSteve French #define FILE_VOLUME_IS_COMPRESSED 0x00008000 75*38c8a9a5SSteve French #define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100 76*38c8a9a5SSteve French #define FILE_SUPPORTS_REPARSE_POINTS 0x00000080 77*38c8a9a5SSteve French #define FILE_SUPPORTS_SPARSE_FILES 0x00000040 78*38c8a9a5SSteve French #define FILE_VOLUME_QUOTAS 0x00000020 79*38c8a9a5SSteve French #define FILE_FILE_COMPRESSION 0x00000010 80*38c8a9a5SSteve French #define FILE_PERSISTENT_ACLS 0x00000008 81*38c8a9a5SSteve French #define FILE_UNICODE_ON_DISK 0x00000004 82*38c8a9a5SSteve French #define FILE_CASE_PRESERVED_NAMES 0x00000002 83*38c8a9a5SSteve French #define FILE_CASE_SENSITIVE_SEARCH 0x00000001 84*38c8a9a5SSteve French 85*38c8a9a5SSteve French #define FILE_READ_DATA 0x00000001 /* Data can be read from the file */ 86*38c8a9a5SSteve French #define FILE_WRITE_DATA 0x00000002 /* Data can be written to the file */ 87*38c8a9a5SSteve French #define FILE_APPEND_DATA 0x00000004 /* Data can be appended to the file */ 88*38c8a9a5SSteve French #define FILE_READ_EA 0x00000008 /* Extended attributes associated */ 89*38c8a9a5SSteve French /* with the file can be read */ 90*38c8a9a5SSteve French #define FILE_WRITE_EA 0x00000010 /* Extended attributes associated */ 91*38c8a9a5SSteve French /* with the file can be written */ 92*38c8a9a5SSteve French #define FILE_EXECUTE 0x00000020 /*Data can be read into memory from */ 93*38c8a9a5SSteve French /* the file using system paging I/O */ 94*38c8a9a5SSteve French #define FILE_DELETE_CHILD 0x00000040 95*38c8a9a5SSteve French #define FILE_READ_ATTRIBUTES 0x00000080 /* Attributes associated with the */ 96*38c8a9a5SSteve French /* file can be read */ 97*38c8a9a5SSteve French #define FILE_WRITE_ATTRIBUTES 0x00000100 /* Attributes associated with the */ 98*38c8a9a5SSteve French /* file can be written */ 99*38c8a9a5SSteve French #define DELETE 0x00010000 /* The file can be deleted */ 100*38c8a9a5SSteve French #define READ_CONTROL 0x00020000 /* The access control list and */ 101*38c8a9a5SSteve French /* ownership associated with the */ 102*38c8a9a5SSteve French /* file can be read */ 103*38c8a9a5SSteve French #define WRITE_DAC 0x00040000 /* The access control list and */ 104*38c8a9a5SSteve French /* ownership associated with the */ 105*38c8a9a5SSteve French /* file can be written. */ 106*38c8a9a5SSteve French #define WRITE_OWNER 0x00080000 /* Ownership information associated */ 107*38c8a9a5SSteve French /* with the file can be written */ 108*38c8a9a5SSteve French #define SYNCHRONIZE 0x00100000 /* The file handle can waited on to */ 109*38c8a9a5SSteve French /* synchronize with the completion */ 110*38c8a9a5SSteve French /* of an input/output request */ 111*38c8a9a5SSteve French #define GENERIC_ALL 0x10000000 112*38c8a9a5SSteve French #define GENERIC_EXECUTE 0x20000000 113*38c8a9a5SSteve French #define GENERIC_WRITE 0x40000000 114*38c8a9a5SSteve French #define GENERIC_READ 0x80000000 115*38c8a9a5SSteve French /* In summary - Relevant file */ 116*38c8a9a5SSteve French /* access flags from CIFS are */ 117*38c8a9a5SSteve French /* file_read_data, file_write_data */ 118*38c8a9a5SSteve French /* file_execute, file_read_attributes*/ 119*38c8a9a5SSteve French /* write_dac, and delete. */ 120*38c8a9a5SSteve French 121*38c8a9a5SSteve French #define SET_FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \ 122*38c8a9a5SSteve French | FILE_READ_ATTRIBUTES \ 123*38c8a9a5SSteve French | DELETE | READ_CONTROL | WRITE_DAC \ 124*38c8a9a5SSteve French | WRITE_OWNER | SYNCHRONIZE) 125*38c8a9a5SSteve French #define SET_FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \ 126*38c8a9a5SSteve French | FILE_WRITE_EA \ 127*38c8a9a5SSteve French | FILE_DELETE_CHILD \ 128*38c8a9a5SSteve French | FILE_WRITE_ATTRIBUTES \ 129*38c8a9a5SSteve French | DELETE | READ_CONTROL | WRITE_DAC \ 130*38c8a9a5SSteve French | WRITE_OWNER | SYNCHRONIZE) 131*38c8a9a5SSteve French #define SET_FILE_EXEC_RIGHTS (FILE_READ_EA | FILE_WRITE_EA | FILE_EXECUTE \ 132*38c8a9a5SSteve French | FILE_READ_ATTRIBUTES \ 133*38c8a9a5SSteve French | FILE_WRITE_ATTRIBUTES \ 134*38c8a9a5SSteve French | DELETE | READ_CONTROL | WRITE_DAC \ 135*38c8a9a5SSteve French | WRITE_OWNER | SYNCHRONIZE) 136*38c8a9a5SSteve French 137*38c8a9a5SSteve French #define SET_MINIMUM_RIGHTS (FILE_READ_EA | FILE_READ_ATTRIBUTES \ 138*38c8a9a5SSteve French | READ_CONTROL | SYNCHRONIZE) 139*38c8a9a5SSteve French 140*38c8a9a5SSteve French /* generic flags for file open */ 141*38c8a9a5SSteve French #define GENERIC_READ_FLAGS (READ_CONTROL | FILE_READ_DATA | \ 142*38c8a9a5SSteve French FILE_READ_ATTRIBUTES | \ 143*38c8a9a5SSteve French FILE_READ_EA | SYNCHRONIZE) 144*38c8a9a5SSteve French 145*38c8a9a5SSteve French #define GENERIC_WRITE_FLAGS (READ_CONTROL | FILE_WRITE_DATA | \ 146*38c8a9a5SSteve French FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | \ 147*38c8a9a5SSteve French FILE_APPEND_DATA | SYNCHRONIZE) 148*38c8a9a5SSteve French 149*38c8a9a5SSteve French #define GENERIC_EXECUTE_FLAGS (READ_CONTROL | FILE_EXECUTE | \ 150*38c8a9a5SSteve French FILE_READ_ATTRIBUTES | SYNCHRONIZE) 151*38c8a9a5SSteve French 152*38c8a9a5SSteve French #define GENERIC_ALL_FLAGS (DELETE | READ_CONTROL | WRITE_DAC | \ 153*38c8a9a5SSteve French WRITE_OWNER | SYNCHRONIZE | FILE_READ_DATA | \ 154*38c8a9a5SSteve French FILE_WRITE_DATA | FILE_APPEND_DATA | \ 155*38c8a9a5SSteve French FILE_READ_EA | FILE_WRITE_EA | \ 156*38c8a9a5SSteve French FILE_EXECUTE | FILE_DELETE_CHILD | \ 157*38c8a9a5SSteve French FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES) 158*38c8a9a5SSteve French 159*38c8a9a5SSteve French #define SMB1_PROTO_NUMBER cpu_to_le32(0x424d53ff) 160*38c8a9a5SSteve French #define SMB_COM_NEGOTIATE 0x72 161*38c8a9a5SSteve French #define SMB1_CLIENT_GUID_SIZE (16) 162*38c8a9a5SSteve French 163*38c8a9a5SSteve French #define SMBFLG_RESPONSE 0x80 /* this PDU is a response from server */ 164*38c8a9a5SSteve French 165*38c8a9a5SSteve French #define SMBFLG2_IS_LONG_NAME cpu_to_le16(0x40) 166*38c8a9a5SSteve French #define SMBFLG2_EXT_SEC cpu_to_le16(0x800) 167*38c8a9a5SSteve French #define SMBFLG2_ERR_STATUS cpu_to_le16(0x4000) 168*38c8a9a5SSteve French #define SMBFLG2_UNICODE cpu_to_le16(0x8000) 169*38c8a9a5SSteve French 170*38c8a9a5SSteve French struct smb_hdr { 171*38c8a9a5SSteve French __be32 smb_buf_length; 172*38c8a9a5SSteve French __u8 Protocol[4]; 173*38c8a9a5SSteve French __u8 Command; 174*38c8a9a5SSteve French union { 175*38c8a9a5SSteve French struct { 176*38c8a9a5SSteve French __u8 ErrorClass; 177*38c8a9a5SSteve French __u8 Reserved; 178*38c8a9a5SSteve French __le16 Error; 179*38c8a9a5SSteve French } __packed DosError; 180*38c8a9a5SSteve French __le32 CifsError; 181*38c8a9a5SSteve French } __packed Status; 182*38c8a9a5SSteve French __u8 Flags; 183*38c8a9a5SSteve French __le16 Flags2; /* note: le */ 184*38c8a9a5SSteve French __le16 PidHigh; 185*38c8a9a5SSteve French union { 186*38c8a9a5SSteve French struct { 187*38c8a9a5SSteve French __le32 SequenceNumber; /* le */ 188*38c8a9a5SSteve French __u32 Reserved; /* zero */ 189*38c8a9a5SSteve French } __packed Sequence; 190*38c8a9a5SSteve French __u8 SecuritySignature[8]; /* le */ 191*38c8a9a5SSteve French } __packed Signature; 192*38c8a9a5SSteve French __u8 pad[2]; 193*38c8a9a5SSteve French __le16 Tid; 194*38c8a9a5SSteve French __le16 Pid; 195*38c8a9a5SSteve French __le16 Uid; 196*38c8a9a5SSteve French __le16 Mid; 197*38c8a9a5SSteve French __u8 WordCount; 198*38c8a9a5SSteve French } __packed; 199*38c8a9a5SSteve French 200*38c8a9a5SSteve French struct smb_negotiate_req { 201*38c8a9a5SSteve French struct smb_hdr hdr; /* wct = 0 */ 202*38c8a9a5SSteve French __le16 ByteCount; 203*38c8a9a5SSteve French unsigned char DialectsArray[1]; 204*38c8a9a5SSteve French } __packed; 205*38c8a9a5SSteve French 206*38c8a9a5SSteve French struct smb_negotiate_rsp { 207*38c8a9a5SSteve French struct smb_hdr hdr; /* wct = 17 */ 208*38c8a9a5SSteve French __le16 DialectIndex; /* 0xFFFF = no dialect acceptable */ 209*38c8a9a5SSteve French __le16 ByteCount; 210*38c8a9a5SSteve French } __packed; 211*38c8a9a5SSteve French 212*38c8a9a5SSteve French struct filesystem_attribute_info { 213*38c8a9a5SSteve French __le32 Attributes; 214*38c8a9a5SSteve French __le32 MaxPathNameComponentLength; 215*38c8a9a5SSteve French __le32 FileSystemNameLen; 216*38c8a9a5SSteve French __le16 FileSystemName[1]; /* do not have to save this - get subset? */ 217*38c8a9a5SSteve French } __packed; 218*38c8a9a5SSteve French 219*38c8a9a5SSteve French struct filesystem_device_info { 220*38c8a9a5SSteve French __le32 DeviceType; 221*38c8a9a5SSteve French __le32 DeviceCharacteristics; 222*38c8a9a5SSteve French } __packed; /* device info level 0x104 */ 223*38c8a9a5SSteve French 224*38c8a9a5SSteve French struct filesystem_vol_info { 225*38c8a9a5SSteve French __le64 VolumeCreationTime; 226*38c8a9a5SSteve French __le32 SerialNumber; 227*38c8a9a5SSteve French __le32 VolumeLabelSize; 228*38c8a9a5SSteve French __le16 Reserved; 229*38c8a9a5SSteve French __le16 VolumeLabel[1]; 230*38c8a9a5SSteve French } __packed; 231*38c8a9a5SSteve French 232*38c8a9a5SSteve French struct filesystem_info { 233*38c8a9a5SSteve French __le64 TotalAllocationUnits; 234*38c8a9a5SSteve French __le64 FreeAllocationUnits; 235*38c8a9a5SSteve French __le32 SectorsPerAllocationUnit; 236*38c8a9a5SSteve French __le32 BytesPerSector; 237*38c8a9a5SSteve French } __packed; /* size info, level 0x103 */ 238*38c8a9a5SSteve French 239*38c8a9a5SSteve French #define EXTENDED_INFO_MAGIC 0x43667364 /* Cfsd */ 240*38c8a9a5SSteve French #define STRING_LENGTH 28 241*38c8a9a5SSteve French 242*38c8a9a5SSteve French struct fs_extended_info { 243*38c8a9a5SSteve French __le32 magic; 244*38c8a9a5SSteve French __le32 version; 245*38c8a9a5SSteve French __le32 release; 246*38c8a9a5SSteve French __u64 rel_date; 247*38c8a9a5SSteve French char version_string[STRING_LENGTH]; 248*38c8a9a5SSteve French } __packed; 249*38c8a9a5SSteve French 250*38c8a9a5SSteve French struct object_id_info { 251*38c8a9a5SSteve French char objid[16]; 252*38c8a9a5SSteve French struct fs_extended_info extended_info; 253*38c8a9a5SSteve French } __packed; 254*38c8a9a5SSteve French 255*38c8a9a5SSteve French struct file_directory_info { 256*38c8a9a5SSteve French __le32 NextEntryOffset; 257*38c8a9a5SSteve French __u32 FileIndex; 258*38c8a9a5SSteve French __le64 CreationTime; 259*38c8a9a5SSteve French __le64 LastAccessTime; 260*38c8a9a5SSteve French __le64 LastWriteTime; 261*38c8a9a5SSteve French __le64 ChangeTime; 262*38c8a9a5SSteve French __le64 EndOfFile; 263*38c8a9a5SSteve French __le64 AllocationSize; 264*38c8a9a5SSteve French __le32 ExtFileAttributes; 265*38c8a9a5SSteve French __le32 FileNameLength; 266*38c8a9a5SSteve French char FileName[]; 267*38c8a9a5SSteve French } __packed; /* level 0x101 FF resp data */ 268*38c8a9a5SSteve French 269*38c8a9a5SSteve French struct file_names_info { 270*38c8a9a5SSteve French __le32 NextEntryOffset; 271*38c8a9a5SSteve French __u32 FileIndex; 272*38c8a9a5SSteve French __le32 FileNameLength; 273*38c8a9a5SSteve French char FileName[]; 274*38c8a9a5SSteve French } __packed; /* level 0xc FF resp data */ 275*38c8a9a5SSteve French 276*38c8a9a5SSteve French struct file_full_directory_info { 277*38c8a9a5SSteve French __le32 NextEntryOffset; 278*38c8a9a5SSteve French __u32 FileIndex; 279*38c8a9a5SSteve French __le64 CreationTime; 280*38c8a9a5SSteve French __le64 LastAccessTime; 281*38c8a9a5SSteve French __le64 LastWriteTime; 282*38c8a9a5SSteve French __le64 ChangeTime; 283*38c8a9a5SSteve French __le64 EndOfFile; 284*38c8a9a5SSteve French __le64 AllocationSize; 285*38c8a9a5SSteve French __le32 ExtFileAttributes; 286*38c8a9a5SSteve French __le32 FileNameLength; 287*38c8a9a5SSteve French __le32 EaSize; 288*38c8a9a5SSteve French char FileName[]; 289*38c8a9a5SSteve French } __packed; /* level 0x102 FF resp */ 290*38c8a9a5SSteve French 291*38c8a9a5SSteve French struct file_both_directory_info { 292*38c8a9a5SSteve French __le32 NextEntryOffset; 293*38c8a9a5SSteve French __u32 FileIndex; 294*38c8a9a5SSteve French __le64 CreationTime; 295*38c8a9a5SSteve French __le64 LastAccessTime; 296*38c8a9a5SSteve French __le64 LastWriteTime; 297*38c8a9a5SSteve French __le64 ChangeTime; 298*38c8a9a5SSteve French __le64 EndOfFile; 299*38c8a9a5SSteve French __le64 AllocationSize; 300*38c8a9a5SSteve French __le32 ExtFileAttributes; 301*38c8a9a5SSteve French __le32 FileNameLength; 302*38c8a9a5SSteve French __le32 EaSize; /* length of the xattrs */ 303*38c8a9a5SSteve French __u8 ShortNameLength; 304*38c8a9a5SSteve French __u8 Reserved; 305*38c8a9a5SSteve French __u8 ShortName[24]; 306*38c8a9a5SSteve French char FileName[]; 307*38c8a9a5SSteve French } __packed; /* level 0x104 FFrsp data */ 308*38c8a9a5SSteve French 309*38c8a9a5SSteve French struct file_id_both_directory_info { 310*38c8a9a5SSteve French __le32 NextEntryOffset; 311*38c8a9a5SSteve French __u32 FileIndex; 312*38c8a9a5SSteve French __le64 CreationTime; 313*38c8a9a5SSteve French __le64 LastAccessTime; 314*38c8a9a5SSteve French __le64 LastWriteTime; 315*38c8a9a5SSteve French __le64 ChangeTime; 316*38c8a9a5SSteve French __le64 EndOfFile; 317*38c8a9a5SSteve French __le64 AllocationSize; 318*38c8a9a5SSteve French __le32 ExtFileAttributes; 319*38c8a9a5SSteve French __le32 FileNameLength; 320*38c8a9a5SSteve French __le32 EaSize; /* length of the xattrs */ 321*38c8a9a5SSteve French __u8 ShortNameLength; 322*38c8a9a5SSteve French __u8 Reserved; 323*38c8a9a5SSteve French __u8 ShortName[24]; 324*38c8a9a5SSteve French __le16 Reserved2; 325*38c8a9a5SSteve French __le64 UniqueId; 326*38c8a9a5SSteve French char FileName[]; 327*38c8a9a5SSteve French } __packed; 328*38c8a9a5SSteve French 329*38c8a9a5SSteve French struct file_id_full_dir_info { 330*38c8a9a5SSteve French __le32 NextEntryOffset; 331*38c8a9a5SSteve French __u32 FileIndex; 332*38c8a9a5SSteve French __le64 CreationTime; 333*38c8a9a5SSteve French __le64 LastAccessTime; 334*38c8a9a5SSteve French __le64 LastWriteTime; 335*38c8a9a5SSteve French __le64 ChangeTime; 336*38c8a9a5SSteve French __le64 EndOfFile; 337*38c8a9a5SSteve French __le64 AllocationSize; 338*38c8a9a5SSteve French __le32 ExtFileAttributes; 339*38c8a9a5SSteve French __le32 FileNameLength; 340*38c8a9a5SSteve French __le32 EaSize; /* EA size */ 341*38c8a9a5SSteve French __le32 Reserved; 342*38c8a9a5SSteve French __le64 UniqueId; /* inode num - le since Samba puts ino in low 32 bit*/ 343*38c8a9a5SSteve French char FileName[]; 344*38c8a9a5SSteve French } __packed; /* level 0x105 FF rsp data */ 345*38c8a9a5SSteve French 346*38c8a9a5SSteve French struct smb_version_values { 347*38c8a9a5SSteve French char *version_string; 348*38c8a9a5SSteve French __u16 protocol_id; 349*38c8a9a5SSteve French __le16 lock_cmd; 350*38c8a9a5SSteve French __u32 capabilities; 351*38c8a9a5SSteve French __u32 max_read_size; 352*38c8a9a5SSteve French __u32 max_write_size; 353*38c8a9a5SSteve French __u32 max_trans_size; 354*38c8a9a5SSteve French __u32 max_credits; 355*38c8a9a5SSteve French __u32 large_lock_type; 356*38c8a9a5SSteve French __u32 exclusive_lock_type; 357*38c8a9a5SSteve French __u32 shared_lock_type; 358*38c8a9a5SSteve French __u32 unlock_lock_type; 359*38c8a9a5SSteve French size_t header_size; 360*38c8a9a5SSteve French size_t max_header_size; 361*38c8a9a5SSteve French size_t read_rsp_size; 362*38c8a9a5SSteve French unsigned int cap_unix; 363*38c8a9a5SSteve French unsigned int cap_nt_find; 364*38c8a9a5SSteve French unsigned int cap_large_files; 365*38c8a9a5SSteve French __u16 signing_enabled; 366*38c8a9a5SSteve French __u16 signing_required; 367*38c8a9a5SSteve French size_t create_lease_size; 368*38c8a9a5SSteve French size_t create_durable_size; 369*38c8a9a5SSteve French size_t create_durable_v2_size; 370*38c8a9a5SSteve French size_t create_mxac_size; 371*38c8a9a5SSteve French size_t create_disk_id_size; 372*38c8a9a5SSteve French size_t create_posix_size; 373*38c8a9a5SSteve French }; 374*38c8a9a5SSteve French 375*38c8a9a5SSteve French struct filesystem_posix_info { 376*38c8a9a5SSteve French /* For undefined recommended transfer size return -1 in that field */ 377*38c8a9a5SSteve French __le32 OptimalTransferSize; /* bsize on some os, iosize on other os */ 378*38c8a9a5SSteve French __le32 BlockSize; 379*38c8a9a5SSteve French /* The next three fields are in terms of the block size. 380*38c8a9a5SSteve French * (above). If block size is unknown, 4096 would be a 381*38c8a9a5SSteve French * reasonable block size for a server to report. 382*38c8a9a5SSteve French * Note that returning the blocks/blocksavail removes need 383*38c8a9a5SSteve French * to make a second call (to QFSInfo level 0x103 to get this info. 384*38c8a9a5SSteve French * UserBlockAvail is typically less than or equal to BlocksAvail, 385*38c8a9a5SSteve French * if no distinction is made return the same value in each 386*38c8a9a5SSteve French */ 387*38c8a9a5SSteve French __le64 TotalBlocks; 388*38c8a9a5SSteve French __le64 BlocksAvail; /* bfree */ 389*38c8a9a5SSteve French __le64 UserBlocksAvail; /* bavail */ 390*38c8a9a5SSteve French /* For undefined Node fields or FSID return -1 */ 391*38c8a9a5SSteve French __le64 TotalFileNodes; 392*38c8a9a5SSteve French __le64 FreeFileNodes; 393*38c8a9a5SSteve French __le64 FileSysIdentifier; /* fsid */ 394*38c8a9a5SSteve French /* NB Namelen comes from FILE_SYSTEM_ATTRIBUTE_INFO call */ 395*38c8a9a5SSteve French /* NB flags can come from FILE_SYSTEM_DEVICE_INFO call */ 396*38c8a9a5SSteve French } __packed; 397*38c8a9a5SSteve French 398*38c8a9a5SSteve French struct smb_version_ops { 399*38c8a9a5SSteve French u16 (*get_cmd_val)(struct ksmbd_work *swork); 400*38c8a9a5SSteve French int (*init_rsp_hdr)(struct ksmbd_work *swork); 401*38c8a9a5SSteve French void (*set_rsp_status)(struct ksmbd_work *swork, __le32 err); 402*38c8a9a5SSteve French int (*allocate_rsp_buf)(struct ksmbd_work *work); 403*38c8a9a5SSteve French int (*set_rsp_credits)(struct ksmbd_work *work); 404*38c8a9a5SSteve French int (*check_user_session)(struct ksmbd_work *work); 405*38c8a9a5SSteve French int (*get_ksmbd_tcon)(struct ksmbd_work *work); 406*38c8a9a5SSteve French bool (*is_sign_req)(struct ksmbd_work *work, unsigned int command); 407*38c8a9a5SSteve French int (*check_sign_req)(struct ksmbd_work *work); 408*38c8a9a5SSteve French void (*set_sign_rsp)(struct ksmbd_work *work); 409*38c8a9a5SSteve French int (*generate_signingkey)(struct ksmbd_session *sess, struct ksmbd_conn *conn); 410*38c8a9a5SSteve French int (*generate_encryptionkey)(struct ksmbd_conn *conn, struct ksmbd_session *sess); 411*38c8a9a5SSteve French bool (*is_transform_hdr)(void *buf); 412*38c8a9a5SSteve French int (*decrypt_req)(struct ksmbd_work *work); 413*38c8a9a5SSteve French int (*encrypt_resp)(struct ksmbd_work *work); 414*38c8a9a5SSteve French }; 415*38c8a9a5SSteve French 416*38c8a9a5SSteve French struct smb_version_cmds { 417*38c8a9a5SSteve French int (*proc)(struct ksmbd_work *swork); 418*38c8a9a5SSteve French }; 419*38c8a9a5SSteve French 420*38c8a9a5SSteve French int ksmbd_min_protocol(void); 421*38c8a9a5SSteve French int ksmbd_max_protocol(void); 422*38c8a9a5SSteve French 423*38c8a9a5SSteve French int ksmbd_lookup_protocol_idx(char *str); 424*38c8a9a5SSteve French 425*38c8a9a5SSteve French int ksmbd_verify_smb_message(struct ksmbd_work *work); 426*38c8a9a5SSteve French bool ksmbd_smb_request(struct ksmbd_conn *conn); 427*38c8a9a5SSteve French 428*38c8a9a5SSteve French int ksmbd_lookup_dialect_by_id(__le16 *cli_dialects, __le16 dialects_count); 429*38c8a9a5SSteve French 430*38c8a9a5SSteve French void ksmbd_init_smb_server(struct ksmbd_work *work); 431*38c8a9a5SSteve French 432*38c8a9a5SSteve French struct ksmbd_kstat; 433*38c8a9a5SSteve French int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, 434*38c8a9a5SSteve French int info_level, 435*38c8a9a5SSteve French struct ksmbd_file *dir, 436*38c8a9a5SSteve French struct ksmbd_dir_info *d_info, 437*38c8a9a5SSteve French char *search_pattern, 438*38c8a9a5SSteve French int (*fn)(struct ksmbd_conn *, 439*38c8a9a5SSteve French int, 440*38c8a9a5SSteve French struct ksmbd_dir_info *, 441*38c8a9a5SSteve French struct ksmbd_kstat *)); 442*38c8a9a5SSteve French 443*38c8a9a5SSteve French int ksmbd_extract_shortname(struct ksmbd_conn *conn, 444*38c8a9a5SSteve French const char *longname, 445*38c8a9a5SSteve French char *shortname); 446*38c8a9a5SSteve French 447*38c8a9a5SSteve French int ksmbd_smb_negotiate_common(struct ksmbd_work *work, unsigned int command); 448*38c8a9a5SSteve French 449*38c8a9a5SSteve French int ksmbd_smb_check_shared_mode(struct file *filp, struct ksmbd_file *curr_fp); 450*38c8a9a5SSteve French int ksmbd_override_fsids(struct ksmbd_work *work); 451*38c8a9a5SSteve French void ksmbd_revert_fsids(struct ksmbd_work *work); 452*38c8a9a5SSteve French 453*38c8a9a5SSteve French unsigned int ksmbd_server_side_copy_max_chunk_count(void); 454*38c8a9a5SSteve French unsigned int ksmbd_server_side_copy_max_chunk_size(void); 455*38c8a9a5SSteve French unsigned int ksmbd_server_side_copy_max_total_size(void); 456*38c8a9a5SSteve French bool is_asterisk(char *p); 457*38c8a9a5SSteve French __le32 smb_map_generic_desired_access(__le32 daccess); 458*38c8a9a5SSteve French 459*38c8a9a5SSteve French static inline unsigned int get_rfc1002_len(void *buf) 460*38c8a9a5SSteve French { 461*38c8a9a5SSteve French return be32_to_cpu(*((__be32 *)buf)) & 0xffffff; 462*38c8a9a5SSteve French } 463*38c8a9a5SSteve French 464*38c8a9a5SSteve French static inline void inc_rfc1001_len(void *buf, int count) 465*38c8a9a5SSteve French { 466*38c8a9a5SSteve French be32_add_cpu((__be32 *)buf, count); 467*38c8a9a5SSteve French } 468*38c8a9a5SSteve French #endif /* __SMB_COMMON_H__ */ 469