Skip to content

Commit dd90b6e

Browse files
authored
Merge branch 'main' into parallel-ports
Signed-off-by: Melvin Wang <melvin.mc.wang@gmail.com>
2 parents 6c984fe + 8696928 commit dd90b6e

10 files changed

Lines changed: 135 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ clap-cargo = "0.14.1"
4747
itertools = "0.13.0"
4848
paste = "1.0.15"
4949
pretty_assertions = "1.4.1"
50-
proc-macro2 = "1.0.86"
50+
proc-macro2 = "1.0.93"
5151
quote = "1.0.38"
5252
rustversion = "1.0.19"
5353
serde = "1.0"

crates/wdk-build/src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ pub enum ApiSubset {
205205
ParallelPorts,
206206
/// API subset for SPB (Serial Peripheral Bus) drivers: <https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/_spb/>
207207
Spb,
208+
/// API subset for Storage drivers: <https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/_storage/>
209+
Storage,
208210
}
209211

210212
impl Default for Config {
@@ -706,6 +708,37 @@ impl Config {
706708

707709
spb_headers
708710
}
711+
ApiSubset::Storage => {
712+
let mut storage_headers = vec![
713+
"ehstorioctl.h",
714+
"ntddcdrm.h",
715+
"ntddcdvd.h",
716+
"ntdddisk.h",
717+
"ntddmmc.h",
718+
"ntddscsi.h",
719+
"ntddstor.h",
720+
"ntddtape.h",
721+
"ntddvol.h",
722+
"ufs.h",
723+
];
724+
725+
if let DriverConfig::Wdm | DriverConfig::Kmdf(_) = self.driver_config {
726+
storage_headers.extend([
727+
"mountdev.h",
728+
"mountmgr.h",
729+
"ntddchgr.h",
730+
"ntdddump.h",
731+
"storduid.h",
732+
"storport.h",
733+
]);
734+
}
735+
736+
if let DriverConfig::Kmdf(_) = self.driver_config {
737+
storage_headers.extend(["ehstorbandmgmt.h"]);
738+
}
739+
740+
storage_headers
741+
}
709742
}
710743
.into_iter()
711744
.map(std::string::ToString::to_string)

crates/wdk-sys/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ default = []
3737

3838
gpio = []
3939
hid = []
40-
spb = []
4140
parallel-ports = ["gpio"]
41+
spb = []
42+
storage = []
4243

4344
nightly = ["wdk-macros/nightly"]
4445
test-stubs = []

crates/wdk-sys/build.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const BINDGEN_FILE_GENERATORS_TUPLES: &[(&str, GenerateFn)] = &[
135135
("hid.rs", generate_hid),
136136
("parallel_ports.rs", generate_parallel_ports),
137137
("spb.rs", generate_spb),
138+
("storage.rs", generate_storage),
138139
];
139140

140141
fn initialize_tracing() -> Result<(), ParseError> {
@@ -205,6 +206,8 @@ fn generate_constants(out_path: &Path, config: &Config) -> Result<(), ConfigErro
205206
ApiSubset::Spb,
206207
#[cfg(feature = "parallel-ports")]
207208
ApiSubset::ParallelPorts,
209+
#[cfg(feature = "storage")]
210+
ApiSubset::Storage,
208211
]);
209212
trace!(header_contents = ?header_contents);
210213

@@ -233,6 +236,8 @@ fn generate_types(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
233236
ApiSubset::Spb,
234237
#[cfg(feature = "parallel-ports")]
235238
ApiSubset::ParallelPorts,
239+
#[cfg(feature = "storage")]
240+
ApiSubset::Storage,
236241
]);
237242
trace!(header_contents = ?header_contents);
238243

@@ -445,6 +450,45 @@ fn generate_spb(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
445450
}
446451
}
447452

453+
fn generate_storage(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
454+
cfg_if::cfg_if! {
455+
if #[cfg(feature = "storage")] {
456+
info!("Generating bindings to WDK: storage.rs");
457+
458+
let header_contents = config.bindgen_header_contents([
459+
ApiSubset::Base,
460+
ApiSubset::Wdf,
461+
ApiSubset::Storage,
462+
]);
463+
trace!(header_contents = ?header_contents);
464+
465+
let bindgen_builder = {
466+
let mut builder = bindgen::Builder::wdk_default(config)?
467+
.with_codegen_config((CodegenConfig::TYPES | CodegenConfig::VARS).complement())
468+
.header_contents("storage-input.h", &header_contents);
469+
470+
// Only allowlist files in the storage-specific files to avoid
471+
// duplicate definitions
472+
for header_file in config.headers(ApiSubset::Storage) {
473+
builder = builder.allowlist_file(format!("(?i).*{header_file}.*"));
474+
}
475+
builder
476+
};
477+
trace!(bindgen_builder = ?bindgen_builder);
478+
479+
Ok(bindgen_builder
480+
.generate()
481+
.expect("Bindings should succeed to generate")
482+
.write_to_file(out_path.join("storage.rs"))?)
483+
} else {
484+
let _ = (out_path, config); // Silence unused variable warnings when storage feature is not enabled
485+
486+
info!("Skipping storage.rs generation since storage feature is not enabled");
487+
Ok(())
488+
}
489+
}
490+
}
491+
448492
/// Generates a `wdf_function_count.rs` file in `OUT_DIR` which contains the
449493
/// definition of the function `get_wdf_function_count()`. This is required to
450494
/// be generated here since the size of the table is derived from either a

crates/wdk-sys/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ pub mod parallel_ports;
6969
))]
7070
pub mod spb;
7171

72+
#[cfg(all(
73+
any(
74+
driver_model__driver_type = "WDM",
75+
driver_model__driver_type = "KMDF",
76+
driver_model__driver_type = "UMDF"
77+
),
78+
feature = "storage"
79+
))]
80+
pub mod storage;
81+
7282
#[cfg(feature = "test-stubs")]
7383
pub mod test_stubs;
7484

crates/wdk-sys/src/storage.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation
2+
// License: MIT OR Apache-2.0
3+
4+
//! Direct FFI bindings to Storage APIs from the Windows Driver Kit (WDK)
5+
//!
6+
//! This module contains all bindings to functions, constants, methods,
7+
//! constructors and destructors for Storage headers. Types are not included in
8+
//! this module, but are available in the top-level `wdk_sys` module.
9+
10+
#[allow(
11+
missing_docs,
12+
reason = "most items in the WDK headers have no inline documentation, so bindgen is unable to \
13+
generate documentation for their bindings"
14+
)]
15+
mod bindings {
16+
#[allow(
17+
clippy::wildcard_imports,
18+
reason = "the underlying c code relies on all type definitions being in scope, which \
19+
results in the bindgen generated code relying on the generated types being in \
20+
scope as well"
21+
)]
22+
#[allow(
23+
unused_imports,
24+
reason = "in certain configurations of the WDK (ex. UMDF), there are no functions related \
25+
to Storage that can be generated by bindgen, so these types are unused"
26+
)]
27+
use crate::types::*;
28+
29+
include!(concat!(env!("OUT_DIR"), "/storage.rs"));
30+
}
31+
#[allow(
32+
unused_imports,
33+
reason = "in certain configurations of the WDK (ex. UMDF), there are no functions related to \
34+
Storage that can be generated by bindgen, so the `bindings` module is empty"
35+
)]
36+
pub use bindings::*;

examples/sample-kmdf-driver/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ default = []
3434

3535
gpio = ["wdk-sys/gpio"]
3636
hid = ["wdk-sys/hid"]
37-
spb = ["wdk-sys/spb"]
3837
parallel-ports = ["wdk-sys/parallel-ports"]
38+
spb = ["wdk-sys/spb"]
39+
storage = ["wdk-sys/storage"]
3940

4041
nightly = ["wdk/nightly", "wdk-sys/nightly"]
4142

examples/sample-umdf-driver/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ default = []
3232

3333
gpio = ["wdk-sys/gpio"]
3434
hid = ["wdk-sys/hid"]
35-
spb = ["wdk-sys/spb"]
3635
parallel-ports = ["wdk-sys/parallel-ports"]
36+
spb = ["wdk-sys/spb"]
37+
storage = ["wdk-sys/storage"]
3738

3839
nightly = ["wdk/nightly", "wdk-sys/nightly"]
3940

examples/sample-wdm-driver/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ wdk = { path = "../../crates/wdk", version = "0.3.0" }
2727
wdk-panic = { path = "../../crates/wdk-panic", version = "0.3.0" }
2828
wdk-sys = { path = "../../crates/wdk-sys", version = "0.3.0" }
2929

30-
3130
[features]
3231
default = []
3332

3433
gpio = ["wdk-sys/gpio"]
3534
hid = ["wdk-sys/hid"]
3635
spb = ["wdk-sys/spb"]
3736
parallel-ports = ["wdk-sys/parallel-ports"]
37+
storage = ["wdk-sys/storage"]
3838

3939
nightly = ["wdk/nightly", "wdk-sys/nightly"]
4040

0 commit comments

Comments
 (0)