Guest User

Untitled

a guest
Jun 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. pub fn get_physical_ts(&self, h: RawHandle) -> u64
  2. {
  3. use winapi::um::winnt::LARGE_INTEGER;
  4. use winapi::um::winioctl::*;
  5. use winapi::shared::minwindef::{DWORD, LPVOID};
  6. use winapi::um::ioapiset::DeviceIoControl;
  7. use winapi::shared::ntdef::NULL;
  8. use std::mem;
  9. use std::ptr::null_mut;
  10.  
  11.  
  12. unsafe {
  13. let mut p: PARTITION_INFORMATION = PARTITION_INFORMATION {
  14. StartingOffset: std::mem::zeroed(), // can't initialize this
  15. PartitionLength: std::mem::zeroed(), // and this, both are LARGE_INTEGER
  16. HiddenSectors: 0,
  17. PartitionNumber: 0,
  18. PartitionType: 0,
  19. BootIndicator: 0,
  20. RecognizedPartition: 0,
  21. RewritePartition: 0,
  22. };
  23. }
  24.  
  25. let pptr: *mut PARTITION_INFORMATION = &mut p;
  26.  
  27. let mut br: DWORD = 0;
  28. let mut ts: u64 = 0;
  29. let mut r: i32 = 0;
  30.  
  31. unsafe {
  32. r = DeviceIoControl(h, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0, pptr as LPVOID, mem::size_of::<PARTITION_INFORMATION>() as u32, &mut br, null_mut());
  33. ts = *(p.PartitionLength.QuadPart()) as u64;
  34. }
  35.  
  36. if r == 0 { panic!("Cannot get partition total sectors"); }
  37. (ts / (BYTES_PER_SECTOR as u64)) - 1
  38. }
  39.  
  40. pub fn main()
  41. let f = File::open("\\\\.\\d:");
  42. let ts = get_physical_ts(f.as_raw_handle());
  43. println!("{}", ts);
Add Comment
Please, Sign In to add comment