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.

272 lines
9.5 KiB

  1. /*
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. pathmap.c
  5. Abstract:
  6. This module contains definitions relating to manipulation of AFP paths.
  7. Author:
  8. Sue Adams (microsoft!suea)
  9. Revision History:
  10. 04 Jun 1992 Initial Version
  11. Notes: Tab stop: 4
  12. --*/
  13. #ifndef _PATHMAP_
  14. #define _PATHMAP_
  15. #define UNICODE_HOST_PATHSEPZ L"\\" // a null terminated wide string
  16. #define ANSI_HOST_PATHSEP '\\'
  17. #define AFP_PATHSEP 0
  18. #define UNICODE_AFP_PATHSEP UNICODE_NULL
  19. #define AVERAGE_NODE_DEPTH 16
  20. // describes the entity found by pathmapping routines
  21. typedef struct _PathMapEntity
  22. {
  23. // Handle is returned for LOOKUPS ONLY!
  24. FILESYSHANDLE pme_Handle; // Handle to DATA Stream, returned for lookups
  25. // Full, UTail and ParentPath are returned whenever the following bitmap
  26. //
  27. // FD_INTERNAL_BITMAP_RETURN_PMEPATHS
  28. // is specified in the AfpMapAfpPath call. These are mostly for Create and
  29. // for lookups ONLY for apis that MAKE DISK CHANGES which will produce a
  30. // change notification to come in. Caller must free the FullPath.Buffer.
  31. // All other strings point into this buffer and do not need to be freed.
  32. // Also used by Open to get the path of the file being opened.
  33. UNICODE_STRING pme_FullPath; // Fully qualified relative to volume root
  34. UNICODE_STRING pme_UTail; // Points to last component of Full
  35. UNICODE_STRING pme_ParentPath; // Points to Full w/ length of UTail deleted
  36. // pme_pDfeParent is used for Create and points to the parent directory.
  37. // pme_pDfEntry is used for lookup (mainly for delete case) and points to the entity.
  38. union
  39. {
  40. PDFENTRY pme_pDfeParent; // DFE of parent dir in which to create
  41. PDFENTRY pme_pDfEntry; // DFE of of the entity for Lookup
  42. };
  43. } PATHMAPENTITY, *PPATHMAPENTITY;
  44. #define AfpInitializePME(pPME, FullPathLen, FullPathBuffer) \
  45. (pPME)->pme_FullPath.Buffer = FullPathBuffer; \
  46. (pPME)->pme_FullPath.MaximumLength = FullPathLen; \
  47. (pPME)->pme_Handle.fsh_FileHandle = NULL
  48. //
  49. // Values for path mapping DFFlag parameter;
  50. // DFE_DIR/FILE/ANY tell the pathmapping code what type of entity we are
  51. // trying to lookup/create
  52. //
  53. #define DFE_DIR 0x0001 // Specified if the object should be a dir
  54. #define DFE_FILE 0x0002 // Specified if the object should be a file
  55. #define DFE_ANY 0x0004 // Specified if the object can be either
  56. //
  57. // Values for reason of pathmap: Lookup, SoftCreate or HardCreate
  58. //
  59. typedef enum _PATHMAP_TYPE
  60. {
  61. Lookup,
  62. SoftCreate,
  63. HardCreate,
  64. LookupForEnumerate // Same as Lookup but file children will be cached
  65. // in during pathmap of the directory itself.
  66. } PATHMAP_TYPE;
  67. extern
  68. AFPSTATUS
  69. AfpMapAfpPath(
  70. IN PCONNDESC pConnDesc,
  71. IN DWORD DirId,
  72. IN PANSI_STRING Path,
  73. IN BYTE PathType,
  74. IN PATHMAP_TYPE MapReason,
  75. IN DWORD DFFlag,
  76. IN DWORD Bitmap,
  77. OUT PPATHMAPENTITY pPME,
  78. OUT PFILEDIRPARM pFDParm OPTIONAL // for lookups only
  79. );
  80. extern
  81. AFPSTATUS
  82. AfpMapAfpPathForLookup(
  83. IN PCONNDESC pConnDesc,
  84. IN DWORD DirId,
  85. IN PANSI_STRING Path,
  86. IN BYTE PathType,
  87. IN DWORD DFFlag,
  88. IN DWORD Bitmap,
  89. OUT PPATHMAPENTITY pPME OPTIONAL,
  90. OUT PFILEDIRPARM pFDParm OPTIONAL
  91. );
  92. extern
  93. AFPSTATUS
  94. AfpMapAfpIdForLookup(
  95. IN PCONNDESC pConnDesc,
  96. IN DWORD AfpId,
  97. IN DWORD DFFlag,
  98. IN DWORD Bitmap,
  99. OUT PPATHMAPENTITY pPME OPTIONAL,
  100. OUT PFILEDIRPARM pFDParm OPTIONAL
  101. );
  102. extern
  103. AFPSTATUS
  104. AfpHostPathFromDFEntry(
  105. IN PDFENTRY pDFE,
  106. IN DWORD taillen,
  107. OUT PUNICODE_STRING pPath
  108. );
  109. extern
  110. AFPSTATUS
  111. AfpCheckParentPermissions(
  112. IN PCONNDESC pConnDesc,
  113. IN DWORD ParentDirId,
  114. IN PUNICODE_STRING pParentPath,
  115. IN DWORD RequiredPerms,
  116. OUT PFILESYSHANDLE pHandle OPTIONAL,
  117. OUT PBYTE pUserRights OPTIONAL
  118. );
  119. #ifdef _PATHMAP_LOCALS
  120. // An AFP path to an entity consists of a Dirid and pathname. A MAPPEDPATH
  121. // structure resolves the AFP path into a PDFENTRY for the entity on lookups,
  122. // or to a PDFENTRY of the parent directory plus the UNICODE file/dir name
  123. // of the entity on creates.
  124. typedef struct _MappedPath
  125. {
  126. PDFENTRY mp_pdfe;
  127. UNICODE_STRING mp_Tail; // valid for Create only
  128. WCHAR mp_Tailbuf[AFP_FILENAME_LEN+1]; // for mp_tail.Buffer
  129. // mp_Tail is also used as an interim buffer during pathmap for looking up
  130. // by name in the idindex database.
  131. } MAPPEDPATH, *PMAPPEDPATH;
  132. /* private function prototypes */
  133. LOCAL
  134. AFPSTATUS
  135. afpGetMappedForLookupFDInfo(
  136. IN PCONNDESC pConnDesc,
  137. IN PDFENTRY pDfEntry,
  138. IN DWORD Bitmap,
  139. OUT PPATHMAPENTITY pPME OPTIONAL,
  140. OUT PFILEDIRPARM pFDParm OPTIONAL
  141. );
  142. /*** afpGetNextComponent
  143. *
  144. * Takes an AFP path with leading and trailing nulls removed,
  145. * and parses out the next path component.
  146. *
  147. * pComponent must point to a buffer of at least AFP_LONGNAME_LEN+1
  148. * characters in length if pathtype is AFP_LONGNAME or AFP_SHORTNAME_LEN+1
  149. * if pathtype is AFP_SHORTNAME.
  150. *
  151. * Returns the number of bytes (Mac ANSI characters) parsed off of
  152. * pPath, else -1 for error.
  153. LOCAL VOID
  154. afpGetNextComponent(
  155. IN PCHAR pPath,
  156. IN int Length,
  157. IN BYTE PathType,
  158. OUT PCHAR Component,
  159. OUT PINT pIndex
  160. )
  161. */
  162. #define afpGetNextComponent(_pPath, _Length, _PathType, _Component, _pIndex) \
  163. do \
  164. { \
  165. int Length = _Length; \
  166. PCHAR pPath = _pPath; \
  167. int maxlen; \
  168. CHAR ch; \
  169. \
  170. maxlen = (_PathType == AFP_LONGNAME) ? \
  171. AFP_LONGNAME_LEN : \
  172. AFP_SHORTNAME_LEN; \
  173. *(_pIndex) = 0; \
  174. \
  175. while ((Length > 0) && ((ch = *pPath) != '\0')) \
  176. { \
  177. if ((*(_pIndex) == maxlen) || (ch == ':')) \
  178. { \
  179. /* component too long or invalid char */ \
  180. *(_pIndex) = -1; \
  181. break; \
  182. } \
  183. \
  184. (_Component)[(*(_pIndex))++] = ch; \
  185. \
  186. pPath++; \
  187. Length--; \
  188. } \
  189. \
  190. if (*(_pIndex) == -1) \
  191. break; \
  192. \
  193. /* null terminate the component */ \
  194. (_Component)[*(_pIndex)] = (CHAR)0; \
  195. \
  196. if ((PathType == AFP_SHORTNAME) && ((_Component)[0] != AFP_PATHSEP)) \
  197. { \
  198. ANSI_STRING as; \
  199. \
  200. AfpInitUnicodeStringWithNonNullTerm(&as, *(_pIndex), _Component); \
  201. if (!AfpIsLegalShortname(&as)) \
  202. { \
  203. *(_pIndex) = -1; \
  204. break; \
  205. } \
  206. } \
  207. \
  208. /* if we stopped due to null, move past it */ \
  209. if (Length > 0) \
  210. { \
  211. (*(_pIndex))++; \
  212. } \
  213. } while (FALSE);
  214. LOCAL
  215. AFPSTATUS
  216. afpMapAfpPathToMappedPath(
  217. IN PVOLDESC pVolDesc,
  218. IN DWORD DirId,
  219. IN PANSI_STRING Path,
  220. IN BYTE PathType,
  221. IN PATHMAP_TYPE MapReason,
  222. IN DWORD DFflag,
  223. IN BOOLEAN LockedForWrite,
  224. OUT PMAPPEDPATH pMappedPath
  225. );
  226. LOCAL
  227. AFPSTATUS
  228. afpOpenUserHandle(
  229. IN PCONNDESC pConnDesc,
  230. IN struct _DirFileEntry * pDfEntry,
  231. IN PUNICODE_STRING pPath OPTIONAL,
  232. IN DWORD Bitmap,
  233. OUT PFILESYSHANDLE pfshData // Handle of data stream of object
  234. );
  235. #endif // _PATHMAP_LOCALS
  236. #endif // _PATHMAP_
  237.