1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) Mike Grier.
//! The `GetFileInformationByHandle` entry.
//!
//! Entry 6 of the audited catalogue: the **non-`Ex`** call, returning a
//! `BY_HANDLE_FILE_INFORMATION`.
//!
//! # Why this is not a class of the `Ex` entry
//!
//! It is a distinct Win32 call with its own signature, its own out-parameter,
//! and no class argument at all -- so the one-entry-per-Win32-call rule makes
//! it its own entry. The two overlap in what they report and are not
//! interchangeable: this call yields the link count and a 64-bit file index in
//! one shot, where the `Ex` form's `FileIdInfo` gives a 128-bit id and no link
//! count. The watcher uses this one where the `Ex` form would not do.
//!
//! # A pure read
//!
//! Measured: this call does **not** disturb a directory enumeration in
//! progress, on the handle or on a duplicate of it. It composes freely with
//! [`crate::query`]'s enumeration classes.
use MaybeUninit;
use ;
use crate;
use crate;
/// An owned, marshalable parameter set for `GetFileInformationByHandle`.
///
/// # Example
///
/// ```
/// use std::fs;
/// use std::os::windows::io::AsHandle;
///
/// use windows_namespace_request_sys::file_info::QueryFileInformationByHandle;
/// use windows_namespace_request_sys::CapturedHandle;
///
/// let path = std::env::temp_dir().join(format!("wnrs-fi-{}.tmp", std::process::id()));
/// fs::write(&path, b"example")?;
/// let file = fs::File::open(&path)?;
///
/// let information = QueryFileInformationByHandle::new(
/// CapturedHandle::capture(file.as_handle())?,
/// )
/// .perform()?;
///
/// // The 64-bit file index this call reports in one shot, which the Ex form's
/// // FileIdInfo does not give in this shape.
/// let index = (u64::from(information.nFileIndexHigh) << 32)
/// | u64::from(information.nFileIndexLow);
/// assert_ne!(index, 0);
/// assert_eq!(information.nFileSizeLow, b"example".len() as u32);
/// # drop(file);
/// # fs::remove_file(&path)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```