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.

89 lines
2.6 KiB

  1. // dismount.c
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <nt.h>
  5. #include <ntrtl.h>
  6. #include <nturtl.h>
  7. #include <windows.h>
  8. #include <ntioapi.h>
  9. VOID
  10. _cdecl
  11. main(
  12. int argc,
  13. char *argv[]
  14. )
  15. {
  16. HANDLE Volume;
  17. IO_STATUS_BLOCK IoStatusBlock;
  18. NTSTATUS Status;
  19. OBJECT_ATTRIBUTES ObjAttr;
  20. ANSI_STRING AnsiName;
  21. UNICODE_STRING UnicodeName;
  22. char DriveNameBuffer[32];
  23. //
  24. // Get parameter
  25. //
  26. if (argc < 2) {
  27. printf("This program dismounts a volume.\n\n");
  28. printf("usage: %s <driveletter>:\n", argv[0]);
  29. return;
  30. }
  31. strcpy( DriveNameBuffer, "\\DosDevices\\" );
  32. strcat( DriveNameBuffer, argv[1] );
  33. RtlInitAnsiString( &AnsiName, DriveNameBuffer );
  34. Status = RtlAnsiStringToUnicodeString( &UnicodeName, &AnsiName, TRUE );
  35. if (!NT_SUCCESS(Status)) {
  36. printf( "Error initalizing strings" );
  37. return;
  38. }
  39. RtlZeroMemory( &ObjAttr, sizeof(OBJECT_ATTRIBUTES) );
  40. ObjAttr.Length = sizeof(OBJECT_ATTRIBUTES);
  41. ObjAttr.ObjectName = &UnicodeName;
  42. ObjAttr.Attributes = OBJ_CASE_INSENSITIVE;
  43. Status = NtOpenFile( &Volume,
  44. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA,
  45. &ObjAttr,
  46. &IoStatusBlock,
  47. FILE_SHARE_READ | FILE_SHARE_WRITE,
  48. FILE_SYNCHRONOUS_IO_ALERT );
  49. if (Volume == INVALID_HANDLE_VALUE) {
  50. printf( "Error opening file %s %x\n", argv[1], GetLastError() );
  51. return;
  52. }
  53. Status = NtFsControlFile( Volume, // file handle
  54. NULL, // event
  55. NULL, // apc routine
  56. NULL, // apc context
  57. &IoStatusBlock, // iosb
  58. FSCTL_DISMOUNT_VOLUME, // FsControlCode
  59. NULL, // input buffer
  60. 0, // input buffer length
  61. NULL, // OutputBuffer for data from the FS
  62. 0); // OutputBuffer Length
  63. if (Status == STATUS_SUCCESS) {
  64. printf( "\nDismount succeeded." );
  65. } else {
  66. printf( "\nDismount failed with status %x", Status );
  67. }
  68. CloseHandle( Volume );
  69. }