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.

108 lines
3.2 KiB

  1. // setoid.c
  2. #include "oidtst.h"
  3. int
  4. FsTestSetOid(
  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_SET_OBJECT_ID, // FsControlCode
  17. &ObjectIdBuffer, // input buffer
  18. sizeof(ObjectIdBuffer), // input buffer length
  19. NULL, // OutputBuffer for data from the FS
  20. 0 // OutputBuffer Length
  21. );
  22. return FsTestDecipherStatus( Status );
  23. }
  24. VOID
  25. _cdecl
  26. main(
  27. int argc,
  28. char *argv[]
  29. )
  30. {
  31. HANDLE File;
  32. FILE_OBJECTID_BUFFER ObjectIdBuffer;
  33. IO_STATUS_BLOCK IoStatusBlock;
  34. NTSTATUS Status;
  35. OBJECT_ATTRIBUTES ObjAttr;
  36. ANSI_STRING AnsiName;
  37. UNICODE_STRING UnicodeName;
  38. char DriveNameBuffer[32];
  39. //
  40. // Get parameters.
  41. //
  42. if (argc < 4) {
  43. printf("This program sets an object id for a file (ntfs only).\n\n");
  44. printf("usage: %s filename ObjectId ExtendedInfo\n", argv[0]);
  45. return;
  46. }
  47. strcpy( DriveNameBuffer, "\\DosDevices\\" );
  48. strcat( DriveNameBuffer, argv[1] );
  49. RtlInitAnsiString( &AnsiName, DriveNameBuffer );
  50. Status = RtlAnsiStringToUnicodeString( &UnicodeName, &AnsiName, TRUE );
  51. if (!NT_SUCCESS(Status)) {
  52. printf( "Error initalizing strings" );
  53. return;
  54. }
  55. RtlZeroMemory( &ObjAttr, sizeof(OBJECT_ATTRIBUTES) );
  56. ObjAttr.Length = sizeof(OBJECT_ATTRIBUTES);
  57. ObjAttr.ObjectName = &UnicodeName;
  58. ObjAttr.Attributes = OBJ_CASE_INSENSITIVE;
  59. Status = NtCreateFile( &File,
  60. GENERIC_WRITE | GENERIC_ALL | STANDARD_RIGHTS_ALL,
  61. &ObjAttr,
  62. &IoStatusBlock,
  63. NULL,
  64. FILE_ATTRIBUTE_NORMAL,
  65. FILE_SHARE_READ | FILE_SHARE_WRITE,
  66. FILE_OPEN,
  67. FILE_OPEN_FOR_BACKUP_INTENT,
  68. NULL,
  69. 0 );
  70. if (!NT_SUCCESS(Status)) {
  71. printf( "Error opening file %s %x\n", argv[1], Status );
  72. return;
  73. }
  74. RtlZeroBytes( &ObjectIdBuffer, sizeof( ObjectIdBuffer ) );
  75. sscanf( argv[2], "%s", &ObjectIdBuffer.ObjectId );
  76. sscanf( argv[3], "%s", &ObjectIdBuffer.ExtendedInfo );
  77. printf( "\nUsing file:%s, ObjectId:%s, ExtendedInfo:%s",
  78. argv[1],
  79. ObjectIdBuffer.ObjectId,
  80. ObjectIdBuffer.ExtendedInfo );
  81. FsTestSetOid( File, ObjectIdBuffer );
  82. CloseHandle( File );
  83. return;
  84. }