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.

229 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1989-1997 Microsoft Corporation
  3. Module Name:
  4. proptest.c
  5. Abstract:
  6. This module contains tests for Ntfs Property support.
  7. --*/
  8. extern "C" {
  9. #include <nt.h>
  10. #include <ntioapi.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. }
  14. #include <windows.h>
  15. #include <stdio.h>
  16. #include <ddeml.h> // for CP_WINUNICODE
  17. #include <objidl.h>
  18. extern "C"
  19. {
  20. #include <propapi.h>
  21. }
  22. #include <stgprop.h>
  23. #include <stgvar.hxx>
  24. #include <propstm.hxx>
  25. #include <align.hxx>
  26. #include <sstream.hxx>
  27. #include <propvar.h>
  28. //
  29. // Simple wrapper for NtCreateFile
  30. //
  31. NTSTATUS
  32. OpenObject (
  33. WCHAR const *pwszFile,
  34. ULONG CreateOptions,
  35. ULONG DesiredAccess,
  36. ULONG ShareAccess,
  37. ULONG CreateDisposition,
  38. HANDLE *ph)
  39. {
  40. NTSTATUS Status;
  41. OBJECT_ATTRIBUTES oa;
  42. UNICODE_STRING str;
  43. IO_STATUS_BLOCK isb;
  44. RtlDosPathNameToNtPathName_U(pwszFile, &str, NULL, NULL);
  45. InitializeObjectAttributes(
  46. &oa,
  47. &str,
  48. OBJ_CASE_INSENSITIVE,
  49. NULL,
  50. NULL);
  51. Status = NtCreateFile(
  52. ph,
  53. DesiredAccess | SYNCHRONIZE,
  54. &oa,
  55. &isb,
  56. NULL, // pallocationsize (none!)
  57. FILE_ATTRIBUTE_NORMAL,
  58. ShareAccess,
  59. CreateDisposition,
  60. CreateOptions,
  61. NULL, // EA buffer (none!)
  62. 0);
  63. RtlFreeHeap(RtlProcessHeap(), 0, str.Buffer);
  64. return(Status);
  65. }
  66. void
  67. SzToWsz (
  68. OUT WCHAR *Unicode,
  69. IN char *Ansi
  70. )
  71. {
  72. while (*Unicode++ = *Ansi++)
  73. ;
  74. }
  75. void
  76. OpenTest (
  77. char *FileName
  78. )
  79. {
  80. NTSTATUS Status;
  81. HANDLE Handle;
  82. WCHAR WFileName[MAX_PATH];
  83. char InputBuffer[10];
  84. char OutputBuffer[200];
  85. IO_STATUS_BLOCK Iosb;
  86. //
  87. // OPENTEST file count
  88. //
  89. //
  90. // Create the new file
  91. //
  92. SzToWsz( WFileName, FileName );
  93. Status = OpenObject( WFileName,
  94. FILE_SYNCHRONOUS_IO_NONALERT,
  95. FILE_READ_DATA | FILE_WRITE_DATA,
  96. FALSE,
  97. FILE_CREATE,
  98. &Handle );
  99. if (!NT_SUCCESS( Status )) {
  100. printf( "Unable to open %s - %x\n", FileName, Status );
  101. }
  102. //
  103. // Write a small amount of data
  104. //
  105. Status = NtWriteFile( Handle, NULL, NULL, NULL, &Iosb, InputBuffer, 10, NULL, NULL );
  106. if (!NT_SUCCESS( Status )) {
  107. printf( "Unable to write %s - %x\n", FileName, Status );
  108. }
  109. //
  110. // Close the file
  111. //
  112. Status = NtClose( Handle );
  113. if (!NT_SUCCESS( Status )) {
  114. printf( "Unable to close %s - %x\n", FileName, Status );
  115. }
  116. //
  117. // Overwrite the file
  118. //
  119. Status = OpenObject( WFileName,
  120. FILE_SYNCHRONOUS_IO_NONALERT,
  121. FILE_READ_DATA | FILE_WRITE_DATA,
  122. FALSE,
  123. FILE_OVERWRITE,
  124. &Handle );
  125. if (!NT_SUCCESS( Status )) {
  126. printf( "Unable to overwrite %s - %x\n", FileName, Status );
  127. }
  128. //
  129. // Write a small amount of data
  130. //
  131. Status = NtWriteFile( Handle, NULL, NULL, NULL, &Iosb, InputBuffer, 10, NULL, NULL );
  132. if (!NT_SUCCESS( Status )) {
  133. printf( "Unable to write %s - %x\n", FileName, Status );
  134. }
  135. //
  136. // Close the file
  137. //
  138. Status = NtClose( Handle );
  139. if (!NT_SUCCESS( Status )) {
  140. printf( "Unable to close %s - %x\n", FileName, Status );
  141. }
  142. //
  143. // Delete the file
  144. //
  145. {
  146. OBJECT_ATTRIBUTES oa;
  147. UNICODE_STRING str;
  148. RtlDosPathNameToNtPathName_U( WFileName, &str, NULL, NULL );
  149. InitializeObjectAttributes(
  150. &oa,
  151. &str,
  152. OBJ_CASE_INSENSITIVE,
  153. NULL,
  154. NULL);
  155. Status = NtDeleteFile( &oa );
  156. RtlFreeHeap(RtlProcessHeap(), 0, str.Buffer);
  157. if (!NT_SUCCESS( Status )) {
  158. printf( "Unable to delete %s - %x\n", FileName, Status );
  159. }
  160. }
  161. }
  162. int __cdecl
  163. main (
  164. int argc,
  165. char **argv)
  166. {
  167. DbgPrint( "--------------------------------------------\n" );
  168. while (--argc != 0) {
  169. OpenTest( *++argv );
  170. }
  171. DbgPrint( "--------------------------------------------\n" );
  172. return 0;
  173. }