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.

109 lines
3.6 KiB

  1. // getoid.c
  2. #include "oidtst.h"
  3. int
  4. FsTestGetOid(
  5. IN HANDLE hFile,
  6. IN FILE_OBJECTID_BUFFER *ObjectIdBuffer
  7. )
  8. {
  9. IO_STATUS_BLOCK IoStatusBlock;
  10. NTSTATUS Status;
  11. Status = NtFsControlFile( hFile, // file handle
  12. NULL, // event
  13. NULL, // apc routine
  14. NULL, // apc context
  15. &IoStatusBlock, // iosb
  16. FSCTL_GET_OBJECT_ID, // FsControlCode
  17. &hFile, // input buffer
  18. sizeof(HANDLE), // input buffer length
  19. ObjectIdBuffer, // OutputBuffer for data from the FS
  20. sizeof(FILE_OBJECTID_BUFFER) ); // OutputBuffer Length
  21. if (Status == STATUS_SUCCESS) {
  22. printf( "\nOid for this file is %s", ObjectIdBuffer->ObjectId );
  23. FsTestHexDump( ObjectIdBuffer->ObjectId, 16 );
  24. printf( "\nObjectId:%08x %08x %08x %08x\n",
  25. *((PULONG)&ObjectIdBuffer->ObjectId[12]),
  26. *((PULONG)&ObjectIdBuffer->ObjectId[8]),
  27. *((PULONG)&ObjectIdBuffer->ObjectId[4]),
  28. *((PULONG)&ObjectIdBuffer->ObjectId[0]) );
  29. printf( "\nExtended info is %s\n", ObjectIdBuffer->ExtendedInfo );
  30. FsTestHexDump( ObjectIdBuffer->ExtendedInfo, 48 );
  31. }
  32. return FsTestDecipherStatus( Status );
  33. }
  34. VOID
  35. _cdecl
  36. main(
  37. int argc,
  38. char *argv[]
  39. )
  40. {
  41. HANDLE File;
  42. FILE_OBJECTID_BUFFER ObjectIdBuffer;
  43. IO_STATUS_BLOCK IoStatusBlock;
  44. char mybuffer[100];
  45. NTSTATUS GetNameStatus;
  46. NTSTATUS GetFrsStatus;
  47. FILE_INTERNAL_INFORMATION InternalInfo;
  48. //
  49. // Get parameters
  50. //
  51. if (argc < 2) {
  52. printf("This program finds the object id of a file (ntfs only).\n\n");
  53. printf("usage: %s filename\n", argv[0]);
  54. return;
  55. }
  56. File = CreateFile( argv[1],
  57. 0,
  58. FILE_SHARE_READ | FILE_SHARE_WRITE,
  59. NULL,
  60. OPEN_EXISTING,
  61. 0,
  62. NULL );
  63. if ( File == INVALID_HANDLE_VALUE ) {
  64. printf( "Error opening file %s %x\n", argv[1], GetLastError() );
  65. return;
  66. }
  67. GetNameStatus = NtQueryInformationFile( File,
  68. &IoStatusBlock,
  69. mybuffer,
  70. sizeof(mybuffer),
  71. FileNameInformation );
  72. printf( "\nGetNameStatus %x, Filename is:", GetNameStatus );
  73. printf( "%S", (mybuffer + 4) );
  74. GetFrsStatus = NtQueryInformationFile( File,
  75. &IoStatusBlock,
  76. &InternalInfo,
  77. sizeof(InternalInfo),
  78. FileInternalInformation );
  79. printf( "\nGetFrsStatus %x, FRS is: (highpart lowpart )", GetFrsStatus );
  80. printf( "\n %08x %08x", InternalInfo.IndexNumber.HighPart, InternalInfo.IndexNumber.LowPart );
  81. RtlZeroBytes( &ObjectIdBuffer, sizeof( ObjectIdBuffer ) );
  82. printf( "\nGetting object id for file:%s\n", argv[1] );
  83. FsTestGetOid( File, &ObjectIdBuffer );
  84. CloseHandle( File );
  85. }