Skip to content

Cannot pass std::fs::File created handle #658

@nicokoch

Description

@nicokoch

Hi,
I have a problem that I cannot solve on my own.
Basically, my program looks something like this:

fn is_block_cloning_supported(p: &Path) -> std::io::Result<bool> {
    let file = std::fs::File::open(p)?;
    let flags = 0u32;
    let res = unsafe {
        GetVolumeInformationByHandleW(file.as_raw_handle() as _, ..., &mut flags as *mut _, ...)
    };
    if res != 0 {
        Err(io::Error::last_os_error())
    } else {
        if flags & FILE_SUPPORTS_BLOCK_REFCOUNTING > 0 { Ok (true) } else { Ok(false) }
    }
}

The problem is, res is always 1 and get_last_error() reports that the handle is invalid.
Now, I notice the *mut c_void type is defined differently in winapi and std, so maybe that is the problem. How can I interop here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions