Source code of Windows XP (NT5)
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.

345 lines
8.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. fsp.h
  5. Abstract:
  6. Private replication file system data structures and functions
  7. Author:
  8. Ahmed Mohamed (ahmedm) 1-Feb-2000
  9. Revision History:
  10. --*/
  11. #ifndef FS_P_H
  12. #define FS_P_H
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #include "crs.h"
  17. typedef ULONGLONG fs_id_t[2];
  18. #define PAGESIZE 4*1024
  19. #define FsTableSize 1024
  20. #define FS_FID_NAME "CRSFID$"
  21. #define FS_FID_NAME_LEN 7
  22. typedef struct {
  23. FILE_FULL_EA_INFORMATION hdr;
  24. CHAR data[FS_FID_NAME_LEN+sizeof(fs_id_t)];
  25. }fs_ea_t;
  26. typedef struct {
  27. FILE_GET_EA_INFORMATION hdr;
  28. CHAR data[FS_FID_NAME_LEN];
  29. }fs_ea_name_t;
  30. #define FsInitEa(x) { \
  31. (x)->hdr.NextEntryOffset = 0; \
  32. (x)->hdr.Flags = 0; \
  33. (x)->hdr.EaNameLength = FS_FID_NAME_LEN; \
  34. strcpy((x)->hdr.EaName, FS_FID_NAME); \
  35. (x)->hdr.EaValueLength = sizeof(fs_id_t); \
  36. }
  37. #define FsInitEaName(x) { \
  38. (x)->hdr.NextEntryOffset = 0; \
  39. (x)->hdr.EaNameLength = FS_FID_NAME_LEN; \
  40. strcpy((x)->hdr.EaName, FS_FID_NAME); \
  41. }
  42. #define FsInitEaFid(x, fid) { \
  43. (fid) = (fs_id_t *) (&((x)->hdr.EaName[FS_FID_NAME_LEN+1])); \
  44. }
  45. #define xFsOpenRA(fd,hvol,name,sz) \
  46. xFsOpen(fd,hvol,name,sz,FILE_READ_EA | (FILE_GENERIC_READ & ~FILE_READ_DATA), \
  47. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0)
  48. #define xFsOpenWA(fd,hvol,name,sz) \
  49. xFsOpen(fd,hvol,name,sz, FILE_WRITE_EA | ((FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~(FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA)), \
  50. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0)
  51. #define xFsOpenRD(fd,hvol,id,sz) \
  52. xFsOpen(fd,hvol,name,sz,FILE_READ_EA | FILE_GENERIC_READ, \
  53. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0)
  54. #define xFsOpenWD(fd,hvol,name,sz) \
  55. xFsOpenById(fd,hvol,name,sz,FILE_WRITE_EA | fFILE_GENERIC_WRITE, \
  56. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0)
  57. #define LockType CRITICAL_SECTION
  58. #define LockInit(x) InitializeCriticalSection(&x)
  59. #define LockEnter(x) EnterCriticalSection(&x)
  60. #define LockTryEnter(x) TryEnterCriticalSection(&x)
  61. #define LockExit(x) LeaveCriticalSection(&x)
  62. typedef struct {
  63. fs_id_t Id;
  64. UINT32 Flags;
  65. HANDLE Fd[FsMaxNodes];
  66. }hdl_t;
  67. // todo: if we want to support more than one tree/user we need to split this
  68. typedef struct _USERINFO_ {
  69. LockType Lock;
  70. // Add a refcnt, we can have multiple connects on an existing session
  71. DWORD RefCnt;
  72. UINT16 Tid;
  73. UINT16 Uid;
  74. struct _VOLINFO_ *VolInfo;
  75. hdl_t Table[FsTableSize];
  76. struct _USERINFO_ *Next;
  77. }UserInfo_t;
  78. #define ARB_STATE_IDLE 0
  79. #define ARB_STATE_BUSY 1
  80. #define ARB_STATE_CANCEL 2
  81. typedef struct {
  82. ULONG State;
  83. ULONG Set;
  84. ULONG Count;
  85. HANDLE Event;
  86. }FspArbitrate_t;
  87. typedef struct _VOLINFO_ {
  88. LockType qLock; // quorum lock, protects alive set
  89. LockType uLock; // update lock, serializes updates and crs recovery
  90. struct _VOLINFO_ *Next;
  91. UINT16 Tid;
  92. PVOID CrsHdl[FsMaxNodes]; // crs log handles
  93. HANDLE Fd[FsMaxNodes]; // root directory handles
  94. HANDLE NotifyFd[FsMaxNodes]; // root directory notification handles
  95. ULONG ReadSet;
  96. ULONG WriteSet;
  97. ULONG AliveSet;
  98. USHORT LockUpdates;
  99. LPWSTR DiskList[FsMaxNodes];
  100. DWORD DiskListSz;
  101. UserInfo_t *UserList;
  102. LPWSTR Label;
  103. PVOID *ObjIdTable;
  104. HANDLE Event; // signal when quorum is lost
  105. FspArbitrate_t Arbitrate;
  106. struct _FSCTX_ *FsCtx;
  107. WCHAR *Root;
  108. }VolInfo_t;
  109. typedef struct _SESSIONINFO_ {
  110. struct _SESSIONINFO_ *Next;
  111. UserInfo_t TreeCtx; // at tree connect time
  112. }SessionInfo_t;
  113. typedef struct _LOGONINFO_ {
  114. struct _LOGONINFO_ *Next;
  115. HANDLE Token;
  116. LUID LogOnId;
  117. }LogonInfo_t;
  118. typedef struct _FSCTX_ {
  119. LockType Lock;
  120. VolInfo_t *VolList;
  121. DWORD VolListSz;
  122. PVOID reshdl;
  123. PVOID ipcHdl;
  124. // list of logged on users that we have obtained valid lsa tokens
  125. // add an entry during session setup, when we assign a user an id
  126. // At tree connect, we validate the user and create a private structure
  127. // to hold state
  128. LogonInfo_t *LogonList;
  129. SessionInfo_t *SessionList;
  130. WCHAR *Root;
  131. }FsCtx_t;
  132. #define FS_SET_USER_HANDLE(u,nid,f,h) ((u)->Table[f].Fd[nid] = h)
  133. #define FS_GET_USER_HANDLE(u,nid,f) ((u)->Table[f].Fd[nid])
  134. #define FS_GET_FID_HANDLE(u,f) (&(u)->Table[f].Id)
  135. #define FS_GET_VOL_HANDLE(v,nid) ((v)->Fd[nid])
  136. #define FS_GET_VOL_NAME(v,nid) ((v)->DiskList[nid])
  137. #define FS_SET_VOL_HANDLE(v,nid,h) ((v)->Fd[nid] = (h))
  138. #define FS_GET_CRS_HANDLE(v,n) ((v)->CrsHdl[nid])
  139. #define FS_GET_CRS_NID_HANDLE(v,nid) ((v)->CrsHdl[(nid)])
  140. #define FS_GET_VOL_NOTIFY_HANDLE(v,nid) ((v)->NotifyFd[nid])
  141. #define FS_BUILD_LOCK_KEY(uid,nid,fid) ((uid << 16) | fid)
  142. #define MemAlloc(x) malloc(x)
  143. #define MemFree(x) free(x)
  144. typedef NTSTATUS (*fs_handler_t)(VolInfo_t *,UserInfo_t *,int,PVOID,ULONG,PVOID,ULONG_PTR *);
  145. #define FS_CREATE 0
  146. #define FS_SETATTR 1
  147. #define FS_WRITE 2
  148. #define FS_MKDIR 3
  149. #define FS_REMOVE 4
  150. #define FS_RENAME 5
  151. //
  152. typedef struct {
  153. crs_id_t xid;
  154. UINT32 flags;
  155. UINT32 attr;
  156. LPWSTR name;
  157. USHORT name_len;
  158. USHORT fnum; // file number
  159. }fs_create_msg_t;
  160. typedef struct {
  161. fs_id_t fid;
  162. USHORT action; // action taken
  163. USHORT access; // access granted
  164. }fs_create_reply_t;
  165. typedef struct {
  166. crs_id_t xid;
  167. fs_id_t *fs_id;
  168. FILE_BASIC_INFORMATION attr;
  169. union {
  170. struct {
  171. USHORT name_len;
  172. LPWSTR name;
  173. };
  174. USHORT fnum; // file number
  175. };
  176. }fs_setattr_msg_t;
  177. typedef struct {
  178. LPWSTR name;
  179. int name_len;
  180. }fs_lookup_msg_t;
  181. typedef struct {
  182. crs_id_t xid;
  183. fs_id_t *fs_id;
  184. union {
  185. UINT32 offset;
  186. UINT32 cookie;
  187. };
  188. UINT32 size;
  189. PVOID buf;
  190. PVOID context;
  191. USHORT fnum; // file number
  192. }fs_io_msg_t;
  193. typedef struct {
  194. crs_id_t xid;
  195. fs_id_t *fs_id;
  196. LPWSTR name;
  197. int name_len;
  198. }fs_remove_msg_t;
  199. typedef struct {
  200. crs_id_t xid;
  201. fs_id_t *fs_id;
  202. LPWSTR sname;
  203. LPWSTR dname;
  204. USHORT sname_len;
  205. USHORT dname_len;
  206. }fs_rename_msg_t;
  207. #define FS_LOCK_WAIT 0x1
  208. #define FS_LOCK_SHARED 0x2
  209. typedef struct {
  210. crs_id_t xid;
  211. USHORT fnum;
  212. ULONG offset;
  213. ULONG length;
  214. ULONG flags;
  215. }fs_lock_msg_t;
  216. #define EventWait(x) WaitForSingleObject(x, INFINITE)
  217. // Forward declaration
  218. void
  219. DecodeCreateParam(UINT32 uflags, UINT32 *flags, UINT32 *disp, UINT32 *share, UINT32 *access);
  220. NTSTATUS
  221. FspCreate(VolInfo_t *vinfo, UserInfo_t *uinfo, int nid, PVOID args, ULONG len, PVOID rbuf,
  222. ULONG_PTR *rlen);
  223. NTSTATUS
  224. FspSetAttr2(VolInfo_t *vinfo, UserInfo_t *uinfo, int nid, PVOID args, ULONG len, PVOID rbuf,
  225. ULONG_PTR *rlen);
  226. NTSTATUS
  227. FspMkDir(VolInfo_t *vinfo, UserInfo_t *uinfo, int nid, PVOID args, ULONG len, PVOID rbuf, ULONG_PTR *rlen);
  228. NTSTATUS
  229. FspRemove(VolInfo_t *vinfo, UserInfo_t *uinfo, int nid, PVOID args, ULONG len, PVOID rbuf, ULONG_PTR *rlen);
  230. NTSTATUS
  231. FspRename(VolInfo_t *vinfo, UserInfo_t *uinfo, int nid, PVOID args, ULONG len, PVOID rbuf, ULONG_PTR *rlen);
  232. NTSTATUS
  233. FspWrite(VolInfo_t *vinfo, UserInfo_t *uinfo, int nid, PVOID args, ULONG len, PVOID rbuf, ULONG_PTR *rlen);
  234. void
  235. FspEvict(VolInfo_t *vinfo, ULONG mask, BOOLEAN flag);
  236. void
  237. FspJoin(VolInfo_t *vinfo, ULONG mask);
  238. //Consistency Replica Set
  239. NTSTATUS
  240. FsUndoXid(VolInfo_t *volinfo, int nid, PVOID arg, int action, int mid);
  241. NTSTATUS
  242. FsReplayXid(VolInfo_t *volinfo, int nid, PVOID arg, int action, int mid);
  243. // this must be 64 bytes
  244. typedef struct {
  245. fs_id_t id; // crs epoch,seq
  246. ULONGLONG crshdr; // crs header
  247. fs_id_t fs_id;
  248. UINT32 command;
  249. UINT32 flags;
  250. union {
  251. char buf[CRS_RECORD_SZ - (sizeof(ULONGLONG) * 5 + sizeof(int) * 2)];
  252. struct {
  253. // create, set attrib
  254. UINT32 attrib;
  255. };
  256. struct {
  257. // write, lock
  258. UINT32 offset;
  259. UINT32 length;
  260. };
  261. };
  262. }fs_log_rec_t;
  263. typedef NTSTATUS (*FsReplayHandler_t)(VolInfo_t *info,
  264. fs_log_rec_t *lrec,
  265. int nid, int mid);
  266. NTSTATUS
  267. WINAPI
  268. FsCrsCallback(PVOID hd, int nid, CrsRecord_t *arg, int action, int mid);
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272. #endif