Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. smbmacro.h
  5. Abstract:
  6. This module defines macros related to SMB processing.
  7. Author:
  8. Chuck Lenzmeier (chuckl) 1-Dec-1989
  9. David Treadwell (davidtr)
  10. Revision History:
  11. --*/
  12. #ifndef _SMBMACRO_
  13. #define _SMBMACRO_
  14. //#include <nt.h>
  15. //
  16. // PVOID
  17. // ALIGN_SMB_WSTR(
  18. // IN PVOID Pointer
  19. // )
  20. //
  21. // Routine description:
  22. //
  23. // This macro aligns the input pointer to the next 2-byte boundary.
  24. // Used to align Unicode strings in SMBs.
  25. //
  26. // Arguments:
  27. //
  28. // Pointer - A pointer
  29. //
  30. // Return Value:
  31. //
  32. // PVOID - Pointer aligned to next 2-byte boundary.
  33. //
  34. #define ALIGN_SMB_WSTR( Pointer ) \
  35. (PVOID)( ((ULONG_PTR)Pointer + 1) & ~1 )
  36. //
  37. // Macro to find the size of an SMB parameter block. This macro takes
  38. // as input the type of a parameter block and a byte count. It finds
  39. // the offset of the Buffer field, which appears at the end of all
  40. // parameter blocks, and adds the byte count to find the total size.
  41. // The type of the returned offset is USHORT.
  42. //
  43. // Note that this macro does NOT pad to a word or longword boundary.
  44. //
  45. #define SIZEOF_SMB_PARAMS(type,byteCount) \
  46. (USHORT)( (ULONG_PTR)&((type *)0)->Buffer[0] + (byteCount) )
  47. //
  48. // Macro to find the next location after an SMB parameter block. This
  49. // macro takes as input the address of the current parameter block, its
  50. // type, and a byte count. It finds the address of the Buffer field,
  51. // which appears at the end of all parameter blocks, and adds the byte
  52. // count to find the next available location. The type of the returned
  53. // pointer is PVOID.
  54. //
  55. // The byte count is passed in even though it is available through
  56. // base->ByteCount. The reason for this is that this number will be a
  57. // compile-time constant in most cases, so the resulting code will be
  58. // simpler and faster.
  59. //
  60. // !!! This macro does not round to a longword boundary when packing
  61. // is turned off. Pre-LM 2.0 DOS redirectors cannot handle having
  62. // too much data sent to them; the exact amount must be sent.
  63. // We may want to make this macro such that the first location
  64. // AFTER the returned value (WordCount field of the SMB) is aligned,
  65. // since most of the fields are misaligned USHORTs. This would
  66. // result in a minor performance win on the 386 and other CISC
  67. // machines.
  68. //
  69. #ifndef NO_PACKING
  70. #define NEXT_LOCATION(base,type,byteCount) \
  71. (PVOID)( (ULONG_PTR)( (PUCHAR)( &((type *)(base))->Buffer[0] ) ) + \
  72. (byteCount) )
  73. #else
  74. #define NEXT_LOCATION(base,type,byteCount) \
  75. (PVOID)(( (ULONG_PTR)( (PUCHAR)( &((type *)(base))->Buffer[0] ) ) + \
  76. (byteCount) + 3) & ~3)
  77. #endif
  78. //
  79. // Macro to find the offset of a followon command to an and X command.
  80. // This offset is the number of bytes from the start of the SMB header
  81. // to where the followon command's parameters should start.
  82. //
  83. #define GET_ANDX_OFFSET(header,params,type,byteCount) \
  84. (USHORT)( (PCHAR)(params) - (PCHAR)(header) + \
  85. SIZEOF_SMB_PARAMS( type,(byteCount) ) )
  86. //
  87. // The following are macros to assist in converting OS/2 1.2 EAs to
  88. // NT style and vice-versa.
  89. //
  90. //++
  91. //
  92. // ULONG
  93. // SmbGetNtSizeOfFea (
  94. // IN PFEA Fea
  95. // )
  96. //
  97. // Routine Description:
  98. //
  99. // This macro gets the size that would be required to hold the FEA
  100. // in NT format. The length is padded to account for the fact that
  101. // each FILE_FULL_EA_INFORMATION structure must start on a
  102. // longword boundary.
  103. //
  104. // Arguments:
  105. //
  106. // Fea - a pointer to the OS/2 1.2 FEA structure to evaluate.
  107. //
  108. // Return Value:
  109. //
  110. // ULONG - number of bytes the FEA would require in NT format.
  111. //
  112. //--
  113. //
  114. // The +1 is for the zero terminator on the name, the +3 is for padding.
  115. //
  116. #define SmbGetNtSizeOfFea( Fea ) \
  117. (ULONG)(( FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0]) + \
  118. (Fea)->cbName + 1 + SmbGetUshort( &(Fea)->cbValue ) + \
  119. 3 ) & ~3 )
  120. //++
  121. //
  122. // ULONG
  123. // SmbGetNtSizeOfGea (
  124. // IN PFEA Gea
  125. // )
  126. //
  127. // Routine Description:
  128. //
  129. // This macro gets the size that would be required to hold the GEA
  130. // in NT format. The length is padded to account for the fact that
  131. // each FILE_FULL_EA_INFORMATION structure must start on a
  132. // longword boundary.
  133. //
  134. // Arguments:
  135. //
  136. // Gea - a pointer to the OS/2 1.2 GEA structure to evaluate.
  137. //
  138. // Return Value:
  139. //
  140. // ULONG - number of bytes the GEA would require in NT format.
  141. //
  142. //--
  143. //
  144. // The +1 is for the zero terminator on the name, the +3 is for padding.
  145. //
  146. #define SmbGetNtSizeOfGea( Gea ) \
  147. (ULONG)(( FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0]) + \
  148. (Gea)->cbName + 1 + 3 ) & ~3 )
  149. //++
  150. //
  151. // ULONG
  152. // SmbGetOs2SizeOfNtFullEa (
  153. // IN PFILE_FULL_EA_INFORMATION NtFullEa;
  154. // )
  155. //
  156. // Routine Description:
  157. //
  158. // This macro gets the size a FILE_FULL_EA_INFORMATION structure would
  159. // require to be represented in a OS/2 1.2 style FEA.
  160. //
  161. // Arguments:
  162. //
  163. // NtFullEa - a pointer to the NT FILE_FULL_EA_INFORMATION structure
  164. // to evaluate.
  165. //
  166. // Return Value:
  167. //
  168. // ULONG - number of bytes requires for the FEA.
  169. //
  170. //--
  171. #define SmbGetOs2SizeOfNtFullEa( NtFullEa ) \
  172. (ULONG)( sizeof(FEA) + (NtFullEa)->EaNameLength + 1 + \
  173. (NtFullEa)->EaValueLength )
  174. //++
  175. //
  176. // ULONG
  177. // SmbGetOs2SizeOfNtGetEa (
  178. // IN PFILE_GET_EA_INFORMATION NtGetEa;
  179. // )
  180. //
  181. // Routine Description:
  182. //
  183. // This macro gets the size a FILE_GET_EA_INFORMATION structure would
  184. // require to be represented in a OS/2 1.2 style GEA.
  185. //
  186. // Arguments:
  187. //
  188. // NtGetEa - a pointer to the NT FILE_GET_EA_INFORMATION structure
  189. // to evaluate.
  190. //
  191. // Return Value:
  192. //
  193. // ULONG - number of bytes requires for the GEA.
  194. //
  195. //--
  196. //
  197. // The zero terminator on the name is accounted for by the szName[0]
  198. // field in the GEA definition.
  199. //
  200. #define SmbGetOs2SizeOfNtGetEa( NtGetEa ) \
  201. (ULONG)( sizeof(GEA) + (NtGetEa)->EaNameLength )
  202. #endif // def _SMBMACRO_