Expand description
Create swap files and devices in pure Rust.
This library will construct this header, copied from the Linux kernel:
// Note that this code snippet is licensed GPL-2.0, matching include/linux/swap.h in the Linux Kernel.
union swap_header {
struct {
char reserved[PAGE_SIZE - 10];
char magic[10]; /* SWAP-SPACE or SWAPSPACE2 */
} magic;
struct {
char bootbits[1024]; /* Space for disklabel etc. */
__u32 version;
__u32 last_page;
__u32 nr_badpages;
unsigned char sws_uuid[16];
unsigned char sws_volume[16];
__u32 padding[117];
__u32 badpages[1];
} info;
};
use std::io::Cursor;
use mkswap::SwapWriter;
let mut buffer: Cursor<Vec<u8>> = Cursor::new(vec![0; 40 * 1024]);
let size = SwapWriter::new()
.label("🔀".into())
.unwrap()
.write(&mut buffer)
.unwrap();
§Notes
This library will seek around the file, including back to position 0. If this isn’t desirable, consider use fscommon::StreamSlice or sending a pull request.
Structs§
- Swap
Writer - A builder to construct a swap space.
Enums§
- Error
- General errors that can occur while configuring and writing a swap space.
Traits§
- Write
Seek - A general wrapper to merge std::io::Write and std::io::Seek.