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.

231 lines
4.1 KiB

  1. // oidtst.c
  2. #include "oidtst.h"
  3. int
  4. FsTestDecipherStatus(
  5. IN NTSTATUS Status
  6. )
  7. {
  8. int Error;
  9. printf( "Status %x -- ", Status );
  10. switch(Status) {
  11. case STATUS_ACCESS_DENIED:
  12. printf( "STATUS_ACCESS_DENIED\n" );
  13. break;
  14. case STATUS_NOT_IMPLEMENTED:
  15. printf( "STATUS_NOT_IMPLEMENTED\n" );
  16. break;
  17. case STATUS_NOT_LOCKED:
  18. printf( "STATUS_NOT_LOCKED\n" );
  19. break;
  20. case STATUS_OBJECTID_EXISTS:
  21. printf( "STATUS_OBJECTID_EXISTS\n" );
  22. break;
  23. case STATUS_BUFFER_OVERFLOW:
  24. printf( "STATUS_BUFFER_OVERFLOW\n" );
  25. break;
  26. case STATUS_NO_MORE_FILES:
  27. printf( "STATUS_NO_MORE_FILES\n" );
  28. break;
  29. case STATUS_DUPLICATE_NAME:
  30. printf( "STATUS_DUPLICATE_NAME\n" );
  31. break;
  32. case STATUS_OBJECT_NAME_COLLISION:
  33. printf( "STATUS_OBJECT_NAME_COLLISION\n" );
  34. break;
  35. case STATUS_OBJECT_NAME_NOT_FOUND:
  36. printf( "STATUS_OBJECT_NAME_NOT_FOUND\n" );
  37. break;
  38. case STATUS_INVALID_ADDRESS:
  39. printf( "STATUS_INVALID_ADDRESS\n" );
  40. break;
  41. case STATUS_INVALID_PARAMETER:
  42. printf( "STATUS_INVALID_PARAMETER\n" );
  43. break;
  44. case STATUS_OBJECT_PATH_NOT_FOUND:
  45. printf( "STATUS_OBJECT_PATH_NOT_FOUND\n" );
  46. break;
  47. case STATUS_OBJECT_PATH_SYNTAX_BAD:
  48. printf( "STATUS_OBJECT_PATH_SYNTAX_BAD\n" );
  49. break;
  50. case STATUS_SUCCESS:
  51. printf( "STATUS_SUCCESS\n" );
  52. break;
  53. default:
  54. printf( "(unknown status code)\n" );
  55. break;
  56. }
  57. if (Status != STATUS_SUCCESS) {
  58. Error = GetLastError();
  59. printf( "GetLastError returned (dec): %d\n", Error );
  60. return 1;
  61. }
  62. return 0;
  63. }
  64. void
  65. FsTestHexDump (
  66. IN UCHAR *Buffer,
  67. IN ULONG Size
  68. )
  69. {
  70. ULONG idx;
  71. printf( "\n" );
  72. for (idx = 0; idx < Size; idx += 1) {
  73. // printf( "%02x %c ", Buffer[idx], Buffer[idx] );
  74. printf( "%02x ", Buffer[idx] );
  75. }
  76. }
  77. void
  78. FsTestHexDumpLongs (
  79. IN ULONG *Buffer,
  80. IN ULONG SizeInBytes
  81. )
  82. {
  83. ULONG idx;
  84. ULONG Size = SizeInBytes / 4;
  85. printf( "\n" );
  86. for (idx = 0; idx < Size; idx += 1) {
  87. printf( "%08x ", Buffer[idx] );
  88. }
  89. }
  90. #if 0
  91. void
  92. FsTestDumpMenu(
  93. void
  94. )
  95. {
  96. printf( "\n s -- Set object id" );
  97. printf( "\n g -- Get object id" );
  98. printf( "\n d -- Delete object id" );
  99. printf( "\n o -- Open file by object id" );
  100. printf( "\n q -- Quit" );
  101. }
  102. int
  103. FsTestDoCommand(
  104. IN HANDLE hFile,
  105. IN OUT OBJECTID *ObjectId
  106. )
  107. {
  108. char cmd[8];
  109. int retval = 0;
  110. HANDLE OpenedFile;
  111. printf( "\n -->" );
  112. scanf( "%s", cmd);
  113. switch(cmd[0]) {
  114. case 's':
  115. FsTestSetOid( hFile, *ObjectId );
  116. break;
  117. case 'g':
  118. FsTestGetOid( hFile, ObjectId );
  119. break;
  120. case 'd':
  121. FsTestDeleteOid( hFile, *ObjectId );
  122. break;
  123. case 'o':
  124. FsTestOpenByOid( *ObjectId, &OpenedFile );
  125. break;
  126. case 'q':
  127. retval = 1;
  128. break;
  129. default:
  130. printf( "\n Try again" );
  131. }
  132. return retval;
  133. }
  134. VOID
  135. main(
  136. int argc,
  137. char *argv[]
  138. )
  139. {
  140. HANDLE hFile;
  141. OBJECTID ObjectId;
  142. //
  143. // Get parameters
  144. //
  145. if (argc < 3) {
  146. printf("This program tests object ids (ntfs only).\n\n");
  147. printf("usage: %s filename ObjectId\n", argv[0]);
  148. return;
  149. }
  150. hFile = CreateFile( argv[1],
  151. 0,
  152. FILE_SHARE_READ | FILE_SHARE_WRITE,
  153. NULL,
  154. OPEN_EXISTING,
  155. 0,
  156. NULL );
  157. if ( hFile == INVALID_HANDLE_VALUE ) {
  158. printf( "Error opening file %s %x\n", argv[1], GetLastError() );
  159. return;
  160. }
  161. RtlZeroBytes( &ObjectId,
  162. sizeof( ObjectId ) );
  163. sscanf( argv[2], "%d", &ObjectId.Lineage.Data1 );
  164. printf( "\nUsing file:%s, ObjectId:%d", argv[1], ObjectId.Lineage.Data1 );
  165. while (retval == 0) {
  166. FsTestDumpMenu();
  167. retval = FsTestDoCommand( hFile, &ObjectId );
  168. }
  169. CloseHandle( hFile );
  170. return;
  171. }
  172. #endif