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.

90 lines
2.8 KiB

  1. // genoid.c
  2. #include "oidtst.h"
  3. int
  4. FsTestGenOid(
  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_CREATE_OR_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( "\nExtended info is %s\n", ObjectIdBuffer->ExtendedInfo );
  25. }
  26. return FsTestDecipherStatus( Status );
  27. }
  28. VOID
  29. _cdecl
  30. main(
  31. int argc,
  32. char *argv[]
  33. )
  34. {
  35. HANDLE File;
  36. FILE_OBJECTID_BUFFER ObjectIdBuffer;
  37. IO_STATUS_BLOCK IoStatusBlock;
  38. char mybuffer[100];
  39. NTSTATUS GetNameStatus;
  40. //
  41. // Get parameters
  42. //
  43. if (argc < 2) {
  44. printf("This program finds the object id of a file and generates one if necessary (ntfs only).\n\n");
  45. printf("usage: %s filename\n", argv[0]);
  46. return;
  47. }
  48. File = CreateFile( argv[1],
  49. 0,
  50. FILE_SHARE_READ | FILE_SHARE_WRITE,
  51. NULL,
  52. OPEN_EXISTING,
  53. 0,
  54. NULL );
  55. if ( File == INVALID_HANDLE_VALUE ) {
  56. printf( "Error opening file %s %x\n", argv[1], GetLastError() );
  57. return;
  58. }
  59. GetNameStatus = NtQueryInformationFile( File,
  60. &IoStatusBlock,
  61. mybuffer,
  62. sizeof(mybuffer),
  63. FileNameInformation );
  64. printf( "\nGetNameStatus %x, Filename is:", GetNameStatus );
  65. printf( "%S", (mybuffer + 4) );
  66. RtlZeroBytes( &ObjectIdBuffer, sizeof( ObjectIdBuffer ) );
  67. printf( "\nUsing file:%s", argv[1] );
  68. FsTestGenOid( File, &ObjectIdBuffer );
  69. CloseHandle( File );
  70. }