Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn get_physical_ts(&self, h: RawHandle) -> u64
- {
- use winapi::um::winnt::LARGE_INTEGER;
- use winapi::um::winioctl::*;
- use winapi::shared::minwindef::{DWORD, LPVOID};
- use winapi::um::ioapiset::DeviceIoControl;
- use winapi::shared::ntdef::NULL;
- use std::mem;
- use std::ptr::null_mut;
- unsafe {
- let mut p: PARTITION_INFORMATION = PARTITION_INFORMATION {
- StartingOffset: std::mem::zeroed(), // can't initialize this
- PartitionLength: std::mem::zeroed(), // and this, both are LARGE_INTEGER
- HiddenSectors: 0,
- PartitionNumber: 0,
- PartitionType: 0,
- BootIndicator: 0,
- RecognizedPartition: 0,
- RewritePartition: 0,
- };
- }
- let pptr: *mut PARTITION_INFORMATION = &mut p;
- let mut br: DWORD = 0;
- let mut ts: u64 = 0;
- let mut r: i32 = 0;
- unsafe {
- r = DeviceIoControl(h, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0, pptr as LPVOID, mem::size_of::<PARTITION_INFORMATION>() as u32, &mut br, null_mut());
- ts = *(p.PartitionLength.QuadPart()) as u64;
- }
- if r == 0 { panic!("Cannot get partition total sectors"); }
- (ts / (BYTES_PER_SECTOR as u64)) - 1
- }
- pub fn main()
- let f = File::open("\\\\.\\d:");
- let ts = get_physical_ts(f.as_raw_handle());
- println!("{}", ts);
Add Comment
Please, Sign In to add comment