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.

92 lines
2.7 KiB

  1. // deloid.c
  2. #include "oidtst.h"
  3. int
  4. FsTestDeleteOid(
  5. IN HANDLE File
  6. )
  7. {
  8. IO_STATUS_BLOCK IoStatusBlock;
  9. NTSTATUS Status;
  10. Status = NtFsControlFile( File, // file handle
  11. NULL, // event
  12. NULL, // apc routine
  13. NULL, // apc context
  14. &IoStatusBlock, // iosb
  15. FSCTL_DELETE_OBJECT_ID, // FsControlCode
  16. NULL, // input buffer
  17. 0, // input buffer length
  18. NULL, // OutputBuffer for data from the FS
  19. 0 // OutputBuffer Length
  20. );
  21. return FsTestDecipherStatus( Status );
  22. }
  23. VOID
  24. _cdecl
  25. main(
  26. int argc,
  27. char *argv[]
  28. )
  29. {
  30. HANDLE File;
  31. IO_STATUS_BLOCK IoStatusBlock;
  32. NTSTATUS Status;
  33. OBJECT_ATTRIBUTES ObjAttr;
  34. ANSI_STRING AnsiName;
  35. UNICODE_STRING UnicodeName;
  36. char DriveNameBuffer[32];
  37. strcpy( DriveNameBuffer, "\\DosDevices\\" );
  38. strcat( DriveNameBuffer, argv[1] );
  39. RtlInitAnsiString( &AnsiName, DriveNameBuffer );
  40. Status = RtlAnsiStringToUnicodeString( &UnicodeName, &AnsiName, TRUE );
  41. if (!NT_SUCCESS(Status)) {
  42. printf( "Error initalizing strings" );
  43. return;
  44. }
  45. if (argc < 2) {
  46. printf("This program deletes the object id (if any) from a file (ntfs only).\n\n");
  47. printf("usage: %s filename\n", argv[0]);
  48. return;
  49. }
  50. RtlZeroMemory( &ObjAttr, sizeof(OBJECT_ATTRIBUTES) );
  51. ObjAttr.Length = sizeof(OBJECT_ATTRIBUTES);
  52. ObjAttr.ObjectName = &UnicodeName;
  53. ObjAttr.Attributes = OBJ_CASE_INSENSITIVE;
  54. Status = NtCreateFile( &File,
  55. GENERIC_WRITE | GENERIC_ALL | STANDARD_RIGHTS_ALL,
  56. &ObjAttr,
  57. &IoStatusBlock,
  58. NULL,
  59. FILE_ATTRIBUTE_NORMAL,
  60. FILE_SHARE_READ | FILE_SHARE_WRITE,
  61. FILE_OPEN,
  62. FILE_OPEN_FOR_BACKUP_INTENT,
  63. NULL,
  64. 0 );
  65. if (!NT_SUCCESS(Status)) {
  66. printf( "Error opening file %s %x\n", argv[1], Status );
  67. return;
  68. }
  69. printf( "\nUsing file:%s", argv[1] );
  70. FsTestDeleteOid( File );
  71. CloseHandle( File );
  72. return;
  73. }