libublk-rs-sys
Low-level FFI bindings for the Linux ublk (userspace block device) kernel interface.
Overview
This crate provides raw, unsafe bindings to the Linux ublk kernel API. These bindings are automatically generated from the kernel headers using bindgen and include serialization support via serde.
libublk-rs-sys is a -sys crate, which means it provides low-level FFI bindings without safe wrappers. If you're looking for a safe, high-level API, consider using the libublk crate instead.
Use Cases
This crate is ideal when you need:
- Custom io_uring management: Handle ublk operations on your own io_uring instance instead of using libublk's thread-local ring
- Direct kernel API access: Work directly with the ublk kernel interface without abstractions
- Custom block device implementations: Build your own high-level wrappers around the ublk API
- Integration with existing io_uring code: Integrate ublk operations into your existing async I/O architecture
Features
- Auto-generated bindings from Linux kernel headers
- Serde serialization support for all structs
- No runtime dependencies except
libcandserde - Support for all ublk features including:
- Zero-copy operations
- Automatic buffer registration
- Zoned block device support
- Unprivileged device creation
- User recovery
Requirements
- Linux kernel 6.0+ with
CONFIG_BLK_DEV_UBLKenabled - Rust 1.80 or later
Example
use *;
use AsRawFd;
// Open the ublk control device
let ctrl_fd = unsafe ;
if ctrl_fd < 0
// Create a control command structure
let mut cmd = ublksrv_ctrl_cmd ;
// Use with your own io_uring instance for async operations...
Safety
⚠️ All functions and types in this crate are unsafe to use. ⚠️
Improper use can lead to:
- Undefined behavior
- Kernel panics
- Data corruption
- System instability
Always refer to the Linux kernel ublk documentation when using these bindings.
Comparison with libublk
| Feature | libublk-rs-sys | libublk |
|---|---|---|
| Safety | Unsafe, raw FFI | Safe Rust API |
| io_uring | Bring your own | Managed thread-local |
| Abstraction | None | High-level builder patterns |
| Use case | Custom integrations | Quick ublk device creation |
Documentation
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please see the main libublk-rs repository for contribution guidelines.