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.

212 lines
5.1 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // File: open.cxx
  4. //
  5. // Synopsis: Helper functions for opening all kinds of FILE_STORAGE_TYPEs.
  6. //
  7. // History: 06-May-95 DaveStr created
  8. //
  9. // Notes:
  10. //
  11. //------------------------------------------------------------------------
  12. extern "C"
  13. {
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. }
  18. #include <windows.h>
  19. #include <stgint.h>
  20. #include <stgprop.h>
  21. #define _CAIROSTG_
  22. #include <olecairo.h>
  23. extern BOOL g_fOFS;
  24. HRESULT _Open(
  25. WCHAR *path,
  26. FILE_STORAGE_TYPE type,
  27. BOOL fCreate,
  28. HANDLE *ph)
  29. {
  30. NTSTATUS status;
  31. UNICODE_STRING str;
  32. IO_STATUS_BLOCK iosb;
  33. OBJECT_ATTRIBUTES oa;
  34. HRESULT hr = S_OK;
  35. if ( !RtlDosPathNameToNtPathName_U(path,&str,NULL,NULL) )
  36. {
  37. hr = HRESULT_FROM_NT(STATUS_OBJECT_PATH_INVALID);
  38. }
  39. else
  40. {
  41. InitializeObjectAttributes(
  42. &oa,
  43. &str,
  44. OBJ_CASE_INSENSITIVE,
  45. NULL,
  46. (PSECURITY_DESCRIPTOR) NULL);
  47. status = NtCreateFile(ph,
  48. FILE_GENERIC_READ |
  49. FILE_GENERIC_WRITE |
  50. WRITE_OWNER |
  51. WRITE_DAC |
  52. SYNCHRONIZE |
  53. DELETE,
  54. &oa,
  55. &iosb,
  56. NULL,
  57. 0,
  58. FILE_SHARE_READ,
  59. ( fCreate ) ? FILE_CREATE : 0,
  60. FILE_SYNCHRONOUS_IO_NONALERT |
  61. (g_fOFS ? (FILE_STORAGE_TYPE_SPECIFIED |
  62. (type << FILE_STORAGE_TYPE_SHIFT)) : 0),
  63. NULL,
  64. 0);
  65. if ( !NT_SUCCESS(status) )
  66. {
  67. hr = HRESULT_FROM_NT(status);
  68. }
  69. RtlFreeUnicodeString(&str);
  70. }
  71. return(hr);
  72. }
  73. static DWORD grfmode = (STGM_READWRITE | STGM_SHARE_EXCLUSIVE);
  74. HRESULT OpenDir(
  75. WCHAR *path,
  76. BOOL fCreate,
  77. IStorage **ppistg)
  78. {
  79. if ( fCreate )
  80. {
  81. return(StgCreateStorage(path,
  82. grfmode,
  83. STGFMT_DIRECTORY,
  84. NULL,
  85. ppistg));
  86. }
  87. else
  88. {
  89. return(StgOpenStorage(path,
  90. NULL,
  91. grfmode,
  92. NULL,
  93. 0,
  94. ppistg));
  95. }
  96. }
  97. HRESULT OpenFile(
  98. WCHAR *path,
  99. BOOL fCreate,
  100. IStorage **ppistg)
  101. {
  102. if ( fCreate )
  103. {
  104. return(StgCreateStorage(path,
  105. grfmode,
  106. STGFMT_FILE,
  107. NULL,
  108. ppistg));
  109. }
  110. else
  111. {
  112. return(StgOpenStorage(path,
  113. NULL,
  114. grfmode,
  115. NULL,
  116. 0,
  117. ppistg));
  118. }
  119. }
  120. HRESULT OpenJP(
  121. WCHAR *path,
  122. BOOL fCreate,
  123. IStorage **ppistg)
  124. {
  125. HRESULT hr;
  126. HANDLE h;
  127. hr = _Open(path, StorageTypeJunctionPoint, fCreate, &h);
  128. if ( SUCCEEDED(hr) )
  129. {
  130. if ( fCreate )
  131. {
  132. hr = StgCreateStorageOnHandle(h,
  133. grfmode,
  134. STGFMT_DIRECTORY,
  135. ppistg);
  136. }
  137. else
  138. {
  139. hr = StgOpenStorageOnHandle(h,
  140. grfmode,
  141. ppistg);
  142. }
  143. NtClose(h);
  144. }
  145. return(hr);
  146. }
  147. HRESULT OpenSC(
  148. WCHAR *path,
  149. BOOL fCreate,
  150. IStorage **ppistg)
  151. {
  152. if ( fCreate )
  153. {
  154. return(StgCreateStorage(path,
  155. grfmode,
  156. STGFMT_CATALOG,
  157. NULL,
  158. ppistg));
  159. }
  160. else
  161. {
  162. return(StgOpenStorage(path,
  163. NULL,
  164. grfmode,
  165. NULL,
  166. 0,
  167. ppistg));
  168. }
  169. }
  170. HRESULT OpenStg(
  171. WCHAR *path,
  172. BOOL fCreate,
  173. IStorage **ppistg)
  174. {
  175. if ( fCreate )
  176. {
  177. return(StgCreateStorage(path,
  178. grfmode,
  179. STGFMT_DOCUMENT,
  180. NULL,
  181. ppistg));
  182. }
  183. else
  184. {
  185. return(StgOpenStorage(path,
  186. NULL,
  187. grfmode,
  188. NULL,
  189. 0,
  190. ppistg));
  191. }
  192. }