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.

84 lines
2.3 KiB

  1. // getvid.c
  2. #include "oidtst.h"
  3. VOID
  4. _cdecl
  5. main(
  6. int argc,
  7. char *argv[]
  8. )
  9. {
  10. HANDLE Volume;
  11. IO_STATUS_BLOCK IoStatusBlock;
  12. NTSTATUS Status;
  13. OBJECT_ATTRIBUTES ObjAttr;
  14. ANSI_STRING AnsiName;
  15. UNICODE_STRING UnicodeName;
  16. char DriveNameBuffer[32];
  17. FILE_OBJECTID_BUFFER ObjectIdBuffer;
  18. //
  19. // Get parameters
  20. //
  21. if (argc < 2) {
  22. printf("This program finds the object id of a volume (ntfs only).\n\n");
  23. printf("usage: %s <drive letter>:\n", argv[0]);
  24. return;
  25. }
  26. strcpy( DriveNameBuffer, "\\DosDevices\\" );
  27. strcat( DriveNameBuffer, argv[1] );
  28. RtlInitAnsiString( &AnsiName, DriveNameBuffer );
  29. Status = RtlAnsiStringToUnicodeString( &UnicodeName, &AnsiName, TRUE );
  30. if (!NT_SUCCESS(Status)) {
  31. printf( "Error initalizing strings" );
  32. return;
  33. }
  34. RtlZeroMemory( &ObjAttr, sizeof(OBJECT_ATTRIBUTES) );
  35. ObjAttr.Length = sizeof(OBJECT_ATTRIBUTES);
  36. ObjAttr.ObjectName = &UnicodeName;
  37. ObjAttr.Attributes = OBJ_CASE_INSENSITIVE;
  38. Status = NtOpenFile( &Volume,
  39. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  40. &ObjAttr,
  41. &IoStatusBlock,
  42. FILE_SHARE_READ | FILE_SHARE_WRITE,
  43. FILE_SYNCHRONOUS_IO_ALERT );
  44. if (Volume == INVALID_HANDLE_VALUE) {
  45. printf( "Error opening file %s %x\n", argv[1], GetLastError() );
  46. return;
  47. }
  48. // RtlZeroBytes( &ObjectIdBuffer, sizeof( ObjectIdBuffer ) );
  49. Status = NtQueryVolumeInformationFile( Volume,
  50. &IoStatusBlock,
  51. &ObjectIdBuffer,
  52. sizeof(ObjectIdBuffer),
  53. FileFsObjectIdInformation );
  54. if (Status == STATUS_SUCCESS) {
  55. printf( "\nVolume Object Id is: " );
  56. FsTestHexDump( (UCHAR *)&ObjectIdBuffer.ObjectId, 16 );
  57. printf( "\nExtended info: " );
  58. FsTestHexDump( (UCHAR *)&ObjectIdBuffer.ExtendedInfo, 48 );
  59. } else {
  60. FsTestDecipherStatus( Status );
  61. }
  62. CloseHandle( Volume );
  63. }