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.

258 lines
6.6 KiB

  1. /*
  2. * C R T F I L E . C P P
  3. *
  4. * Wrapper for CreateFileW() such that path the "\\?\" path extension
  5. * is prefixed onto each path before a call to CreateFileW() is made.
  6. *
  7. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  8. */
  9. #include "_davfs.h"
  10. //$ REVIEW: undefine the following to have DAV not prefix the paths
  11. // passed to the WIN32 file system APIs.
  12. //
  13. #define DAV_PREFIX_PATHS
  14. //
  15. //$ REVIEW: end.
  16. // Dav path prefix -----------------------------------------------------------
  17. //
  18. DEC_CONST WCHAR gc_wszPathPrefix[] = L"\\\\?\\";
  19. DEC_CONST WCHAR gc_wszUncPathPrefix[] = L"UNC";
  20. // Prefixing macro -----------------------------------------------------------
  21. //
  22. // Note that this is a macro so that the stack buffer legitmately remains
  23. // in scope for the duration of the macro's calling function
  24. //
  25. #define DavPrefix(_v) \
  26. CStackBuffer<WCHAR,MAX_PATH> lpPrefixed ## _v; \
  27. { \
  28. /* Trim off the trailing slash if need be... */ \
  29. UINT cch = static_cast<UINT>(wcslen(lp ## _v)); \
  30. if (L'\\' == lp ## _v[cch - 1]) \
  31. { \
  32. /* Allow for "drive roots" */ \
  33. if ((cch < 2) || (L':' != lp ## _v[cch - 2])) \
  34. cch -= 1; \
  35. } \
  36. \
  37. /* Adjust for UNC paths */ \
  38. UINT cchUnc = 0; \
  39. if ((L'\\' == *(lp ## _v) && (L'\\' == lp ## _v[1]))) \
  40. { \
  41. /* Skip past the first of the two slashes */ \
  42. lp ## _v += 1; \
  43. cch -= 1; \
  44. cchUnc = CchConstString(gc_wszUncPathPrefix); \
  45. } \
  46. \
  47. /* Prefix the path */ \
  48. UINT cchT = cch + CchConstString(gc_wszPathPrefix) + cchUnc; \
  49. \
  50. if (NULL == lpPrefixed ## _v.resize(CbSizeWsz(cchT))) \
  51. { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return FALSE; } \
  52. \
  53. memcpy (lpPrefixed ## _v.get(), \
  54. gc_wszPathPrefix, \
  55. sizeof(gc_wszPathPrefix)); \
  56. memcpy (lpPrefixed ## _v.get() + CchConstString(gc_wszPathPrefix), \
  57. gc_wszUncPathPrefix, \
  58. cchUnc * sizeof(WCHAR)); \
  59. memcpy (lpPrefixed ## _v.get() + \
  60. CchConstString(gc_wszPathPrefix) + \
  61. cchUnc, \
  62. lp ## _v, \
  63. CbSizeWsz(cch)); \
  64. \
  65. /* Terminate the path */ \
  66. lpPrefixed ## _v[cchT] = 0; \
  67. } \
  68. // DavCreateFile() -----------------------------------------------------------
  69. //
  70. HANDLE __fastcall DavCreateFile (
  71. /* [in] */ LPCWSTR lpFileName,
  72. /* [in] */ DWORD dwDesiredAccess,
  73. /* [in] */ DWORD dwShareMode,
  74. /* [in] */ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  75. /* [in] */ DWORD dwCreationDisposition,
  76. /* [in] */ DWORD dwFlagsAndAttributes,
  77. /* [in] */ HANDLE hTemplateFile)
  78. {
  79. #ifdef DAV_PREFIX_PATHS
  80. DavPrefix(FileName);
  81. return CreateFileW (lpPrefixedFileName.get(),
  82. dwDesiredAccess,
  83. dwShareMode,
  84. lpSecurityAttributes,
  85. dwCreationDisposition,
  86. dwFlagsAndAttributes,
  87. hTemplateFile);
  88. #else
  89. return CreateFileW (lpFileName,
  90. dwDesiredAccess,
  91. dwShareMode,
  92. lpSecurityAttributes,
  93. dwCreationDisposition,
  94. dwFlagsAndAttributes,
  95. hTemplateFile);
  96. #endif // DAV_PREFIX_PATHS
  97. }
  98. // DavDeleteFile() -----------------------------------------------------------
  99. //
  100. BOOL __fastcall DavDeleteFile (
  101. /* [in] */ LPCWSTR lpFileName)
  102. {
  103. #ifdef DAV_PREFIX_PATHS
  104. DavPrefix(FileName);
  105. return DeleteFileW (lpPrefixedFileName.get());
  106. #else
  107. return DeleteFileW (lpFileName);
  108. #endif // DAV_PREFIX_PATHS
  109. }
  110. // DavCopyFile() -------------------------------------------------------------
  111. //
  112. BOOL __fastcall DavCopyFile (
  113. /* [in] */ LPCWSTR lpExistingFileName,
  114. /* [in] */ LPCWSTR lpNewFileName,
  115. /* [in] */ BOOL bFailIfExists)
  116. {
  117. #ifdef DAV_PREFIX_PATHS
  118. DavPrefix(NewFileName);
  119. DavPrefix(ExistingFileName);
  120. return CopyFileW (lpPrefixedExistingFileName.get(),
  121. lpPrefixedNewFileName.get(),
  122. bFailIfExists);
  123. #else
  124. return CopyFileW (lpExistingFileName,
  125. lpNewFileName,
  126. bFailIfExists);
  127. #endif // DAV_PREFIX_PATHS
  128. }
  129. // DavMoveFile() -------------------------------------------------------------
  130. //
  131. BOOL __fastcall DavMoveFile (
  132. /* [in] */ LPCWSTR lpExistingFileName,
  133. /* [in] */ LPCWSTR lpNewFileName,
  134. /* [in] */ DWORD dwReplace)
  135. {
  136. #ifdef DAV_PREFIX_PATHS
  137. DavPrefix(NewFileName);
  138. DavPrefix(ExistingFileName);
  139. return MoveFileExW (lpPrefixedExistingFileName.get(),
  140. lpPrefixedNewFileName.get(),
  141. dwReplace);
  142. #else
  143. return MoveFileExW (lpExistingFileName,
  144. lpNewFileName,
  145. dwReplace);
  146. #endif // DAV_PREFIX_PATHS
  147. }
  148. // DavCreateDirectory() ------------------------------------------------------
  149. //
  150. BOOL __fastcall DavCreateDirectory (
  151. /* [in] */ LPCWSTR lpFileName,
  152. /* [in] */ LPSECURITY_ATTRIBUTES lpSecurityAttributes)
  153. {
  154. #ifdef DAV_PREFIX_PATHS
  155. DavPrefix(FileName);
  156. return CreateDirectoryW (lpPrefixedFileName.get(),
  157. lpSecurityAttributes);
  158. #else
  159. return CreateDirectoryW (lpFileName,
  160. lpSecurityAttributes);
  161. #endif // DAV_PREFIX_PATHS
  162. }
  163. // DavRemoveDirectory() ------------------------------------------------------
  164. //
  165. BOOL __fastcall DavRemoveDirectory (
  166. /* [in] */ LPCWSTR lpFileName)
  167. {
  168. #ifdef DAV_PREFIX_PATHS
  169. DavPrefix(FileName)
  170. return RemoveDirectoryW (lpPrefixedFileName.get());
  171. #else
  172. return RemoveDirectoryW (lpFileName);
  173. #endif // DAV_PREFIX_PATHS
  174. }
  175. // DavGetFileAttributes() ----------------------------------------------------
  176. //
  177. BOOL __fastcall DavGetFileAttributes (
  178. /* [in] */ LPCWSTR lpFileName,
  179. /* [in] */ GET_FILEEX_INFO_LEVELS fInfoLevelId,
  180. /* [out] */ LPVOID lpFileInformation)
  181. {
  182. #ifdef DAV_PREFIX_PATHS
  183. DavPrefix(FileName);
  184. return GetFileAttributesExW (lpPrefixedFileName.get(),
  185. fInfoLevelId,
  186. lpFileInformation);
  187. #else
  188. return GetFileAttributesExW (lpFileName,
  189. fInfoLevelId,
  190. lpFileInformation);
  191. #endif // DAV_PREFIX_PATHS
  192. }
  193. BOOL __fastcall DavFindFirstFile(
  194. /* [in] */ LPCWSTR lpFileName,
  195. /* [out] */ HANDLE * ph,
  196. /* [out] */ WIN32_FIND_DATAW * pfd)
  197. {
  198. HANDLE h;
  199. Assert(ph);
  200. #ifdef DAV_PREFIX_PATHS
  201. DavPrefix(FileName);
  202. h = FindFirstFileW (lpPrefixedFileName.get(),
  203. pfd);
  204. #else
  205. h = FindFirstFileW (lpFileName,
  206. pfd);
  207. #endif // DAV_PREFIX_PATHS
  208. *ph = h;
  209. return (INVALID_HANDLE_VALUE != h);
  210. }