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.

315 lines
8.3 KiB

  1. /*
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. forks.h
  5. Abstract:
  6. This module contains the data structures to handle open forks.
  7. Author:
  8. Jameel Hyder (microsoft!jameelh)
  9. Revision History:
  10. 25 Apr 1992 Initial Version
  11. Notes: Tab stop: 4
  12. --*/
  13. #ifndef _FORKS_
  14. #define _FORKS_
  15. // Afp Open modes
  16. #define FORK_OPEN_NONE 0x00
  17. #define FORK_OPEN_READ 0x01
  18. #define FORK_OPEN_WRITE 0x02
  19. #define FORK_OPEN_READWRITE 0x03
  20. #define FORK_OPEN_MASK 0x03
  21. // The Deny mode values are shifted left 2 bits and or'd with the open modes
  22. // in AfpOpenFork() API.
  23. #define FORK_DENY_SHIFT 4
  24. #define FORK_DENY_NONE 0x00
  25. #define FORK_DENY_READ 0x01
  26. #define FORK_DENY_WRITE 0x02
  27. #define FORK_DENY_ALL 0x03
  28. #define FORK_DENY_MASK 0x03
  29. // AfpOpenFork SubFunction values
  30. #define FORK_DATA 0
  31. #define FORK_RSRC 0x80
  32. #define AFP_UNLOCK_FLAG 1
  33. #define AFP_END_FLAG 0x80
  34. /*
  35. * A ForkLock describes a lock on the fork. The locks are anchored at the
  36. * OpenForkDesc structure. The list describes all locks for this fork by
  37. * all sessions and all OForkRefNums. flo_key and flo_OForkRefNum identifies
  38. * the lock uniquely.
  39. */
  40. #if DBG
  41. #define FORKLOCK_SIGNATURE *(DWORD *)"FLO"
  42. #define VALID_FORKLOCK (((pForkLock) != NULL) && \
  43. ((pForkLock)->Signature == FORKLOCK_SIGNATURE))
  44. #else
  45. #define VALID_FORKLOCK ((pForkLock) != NULL)
  46. #endif
  47. // Forward reference for the ForkLock structure
  48. struct _OpenForkEntry;
  49. typedef struct _ForkLock
  50. {
  51. #if DBG
  52. DWORD Signature;
  53. DWORD QuadAlign1;
  54. #endif
  55. struct _ForkLock * flo_Next; // ForkDesc links
  56. struct _OpenForkEntry * flo_pOpenForkEntry;
  57. DWORD QuadAlign2;
  58. // The owning OFE for this lock
  59. LONG flo_Offset; // Beginning of lock
  60. LONG flo_Size; // Size of lock
  61. DWORD flo_Key; // Key for this lock, essentially the
  62. // SessionId from the SDA
  63. } FORKLOCK, *PFORKLOCK;
  64. /*
  65. * An OpenForkDesc represents an open-fork. The list is anchored at the volume
  66. * Descriptor. There is exactly one entry per file/fork. Multiple instances of
  67. * open just ups the reference count. The list of locks originating here is for
  68. * all instances. A back link to the Volume descriptor exists for comfort.
  69. */
  70. #if DBG
  71. #define OPENFORKDESC_SIGNATURE *(DWORD *)"OFD"
  72. #define VALID_OPENFORKDESC(pOpenForkDesc) (((pOpenForkDesc) != NULL) && \
  73. ((pOpenForkDesc)->Signature == OPENFORKDESC_SIGNATURE))
  74. #else
  75. #define VALID_OPENFORKDESC(pOpenForkDesc) ((pOpenForkDesc) != NULL)
  76. #endif
  77. typedef struct _OpenForkDesc
  78. {
  79. #if DBG
  80. DWORD Signature;
  81. DWORD QuadAlign1;
  82. #endif
  83. struct _OpenForkDesc * ofd_Next; // Volume links
  84. struct _OpenForkDesc ** ofd_Prev; // Volume links
  85. struct _VolDesc * ofd_pVolDesc; // Pointer to the volume descriptor
  86. PFORKLOCK ofd_pForkLock; // List of file locks
  87. DWORD ofd_FileNumber; // File number of the open file
  88. LONG ofd_UseCount; // Number of OpenForkEntry refs.
  89. USHORT ofd_cOpenR; // # of instances of open for read
  90. USHORT ofd_cOpenW; // # of instances of open for write
  91. USHORT ofd_cDenyR; // # of instances of deny read
  92. USHORT ofd_cDenyW; // # of instances of deny write
  93. USHORT ofd_NumLocks; // Number of file locks
  94. USHORT ofd_Flags; // OPEN_FORK_xxx bits
  95. AFP_SPIN_LOCK ofd_Lock; // Lock for this descriptor
  96. UNICODE_STRING ofd_FileName; // Name of the file (w/o the stream)
  97. UNICODE_STRING ofd_FilePath; // Volume relative path to the file
  98. } OPENFORKDESC, *POPENFORKDESC;
  99. #define OPEN_FORK_RESOURCE True
  100. #define OPEN_FORK_DATA False
  101. #define OPEN_FORK_CLOSING 0x8000
  102. // To determine whether FlushFork of resource should really take the current
  103. // ChangeTime to be the LastWriteTime
  104. #define OPEN_FORK_WRITTEN 0x0100
  105. /*
  106. * An OpenForkEntry represents an OForkRefNum. Every instance of an open
  107. * fork has an entry here. This list is anchored in the SDA. A global open
  108. * fork list used by the admin APIs is also linked to this.
  109. */
  110. #if DBG
  111. #define OPENFORKENTRY_SIGNATURE *(DWORD *)"OFE"
  112. #define VALID_OPENFORKENTRY(pOpenForkEntry) \
  113. (((pOpenForkEntry) != NULL) && \
  114. ((pOpenForkEntry)->Signature == OPENFORKENTRY_SIGNATURE))
  115. #else
  116. #define VALID_OPENFORKENTRY(pOpenForkEntry) ((pOpenForkEntry) != NULL)
  117. #endif
  118. typedef struct _OpenForkEntry
  119. {
  120. #if DBG
  121. DWORD Signature;
  122. #endif
  123. struct _OpenForkEntry * ofe_Next; // Global links
  124. struct _OpenForkEntry **ofe_Prev; // Global links
  125. struct _OpenForkDesc * ofe_pOpenForkDesc; // Pointer to the descriptor
  126. struct _SessDataArea * ofe_pSda; // Identifies the owning session
  127. struct _ConnDesc * ofe_pConnDesc; // Identifies the owning connection
  128. FILESYSHANDLE ofe_FileSysHandle; // The file system handles
  129. #define ofe_ForkHandle ofe_FileSysHandle.fsh_FileHandle
  130. #define ofe_pFileObject ofe_FileSysHandle.fsh_FileObject
  131. #define ofe_pDeviceObject ofe_FileSysHandle.fsh_DeviceObject
  132. DWORD ofe_OForkRefNum; // Open Fork reference number
  133. DWORD ofe_ForkId; // Unique file id used by admin.
  134. // Not re-cycled
  135. BYTE ofe_OpenMode; // Open modes - AFP
  136. BYTE ofe_DenyMode; // Deny modes - AFP
  137. USHORT ofe_Flags; // Flag bits defined above
  138. LONG ofe_RefCount; // Count of references to this entry
  139. LONG ofe_cLocks; // Number of locks on this fork
  140. AFP_SPIN_LOCK ofe_Lock; // Lock for manipulating locks etc.
  141. } OPENFORKENTRY, *POPENFORKENTRY;
  142. #define RESCFORK(pOpenForkEntry) \
  143. (((pOpenForkEntry)->ofe_Flags & OPEN_FORK_RESOURCE) ? True : False)
  144. #define DATAFORK(pOpenForkEntry) (!RESCFORK(pOpenForkEntry))
  145. #define FORK_OPEN_CHUNKS 7
  146. typedef struct _OpenForkSession
  147. {
  148. POPENFORKENTRY ofs_pOpenForkEntry[FORK_OPEN_CHUNKS];
  149. // Pointer to actual entry
  150. struct _OpenForkSession *ofs_Link; // Link to next cluster
  151. } OPENFORKSESS, *POPENFORKSESS;
  152. // Used by AfpForkLockOperation call.
  153. typedef enum
  154. {
  155. LOCK = 1,
  156. UNLOCK,
  157. IOCHECK,
  158. } LOCKOP;
  159. GLOBAL POPENFORKENTRY AfpOpenForksList EQU NULL; // List of open forks
  160. GLOBAL DWORD AfpNumOpenForks EQU 0; // Total # of open forks
  161. GLOBAL AFP_SPIN_LOCK AfpForksLock EQU { 0 }; // Lock for AfpOpenForksList,
  162. // and AfpNumOpenForks
  163. extern
  164. NTSTATUS
  165. AfpForksInit(
  166. VOID
  167. );
  168. extern
  169. POPENFORKENTRY FASTCALL
  170. AfpForkReferenceByRefNum(
  171. IN struct _SessDataArea * pSda,
  172. IN DWORD OForkRefNum
  173. );
  174. extern
  175. POPENFORKENTRY FASTCALL
  176. AfpForkReferenceByPointer(
  177. IN POPENFORKENTRY pOpenForkEntry
  178. );
  179. extern
  180. POPENFORKENTRY FASTCALL
  181. AfpForkReferenceById(
  182. IN DWORD ForkId
  183. );
  184. extern
  185. VOID FASTCALL
  186. AfpForkDereference(
  187. IN POPENFORKENTRY pOpenForkEntry
  188. );
  189. extern
  190. AFPSTATUS
  191. AfpForkOpen(
  192. IN struct _SessDataArea * pSda,
  193. IN struct _ConnDesc * pConnDesc,
  194. IN struct _PathMapEntity * pPME,
  195. IN struct _FileDirParms * pFDParm,
  196. IN DWORD AccessMode,
  197. IN BOOLEAN Resource,
  198. OUT POPENFORKENTRY * ppOpenForkEntry,
  199. OUT PBOOLEAN pCleanupExchgLock
  200. );
  201. extern
  202. VOID
  203. AfpForkClose(
  204. IN POPENFORKENTRY pOpenForkEntry
  205. );
  206. extern
  207. AFPSTATUS
  208. AfpCheckDenyConflict(
  209. IN struct _VolDesc * pVolDesc,
  210. IN DWORD AfpId,
  211. IN BOOLEAN Resource,
  212. IN BYTE OpenMode,
  213. IN BYTE DenyMode,
  214. IN POPENFORKDESC * ppOpenForkDesc OPTIONAL
  215. );
  216. extern
  217. AFPSTATUS
  218. AfpForkLockOperation(
  219. IN struct _SessDataArea * pSda,
  220. IN POPENFORKENTRY pOpenForkEntry,
  221. IN OUT PFORKOFFST pOffset,
  222. IN OUT PFORKSIZE pSize,
  223. IN LOCKOP Operation, // LOCK, UNLOCK or IOCHECK
  224. IN BOOLEAN EndFlag // If True range is from end, else start
  225. );
  226. extern
  227. VOID
  228. AfpForkLockUnlink(
  229. IN PFORKLOCK pForkLock
  230. );
  231. extern
  232. AFPSTATUS
  233. AfpAdmWForkClose(
  234. IN OUT PVOID InBuf OPTIONAL,
  235. IN LONG OutBufLen OPTIONAL,
  236. OUT PVOID OutBuf OPTIONAL
  237. );
  238. extern
  239. VOID
  240. AfpExchangeForkAfpIds(
  241. IN struct _VolDesc * pVolDesc,
  242. IN DWORD AfpId1,
  243. IN DWORD AfpId2
  244. );
  245. #ifdef FORK_LOCALS
  246. LOCAL DWORD afpNextForkId = 1; // Id to be assigned to an open fork
  247. LOCAL BOOLEAN
  248. afpForkGetNewForkRefNumAndLinkInSda(
  249. IN struct _SessDataArea * pSda,
  250. IN POPENFORKENTRY pOpenForkEntry
  251. );
  252. LOCAL
  253. AFPSTATUS
  254. afpForkConvertToAbsOffSize(
  255. IN POPENFORKENTRY pOpenForkEntry,
  256. IN LONG Offset,
  257. IN OUT PLONG pSize,
  258. OUT PFORKOFFST pAbsOffset
  259. );
  260. #endif // FORK_LOCALS
  261. #endif // _FORKS_