a compact systems utility
it's a compact protocol implementation. think of it as a bridge between your filesystem and the network -- Plan 9's 9P protocol, but in Rust. because everything is better in Rust. (fight me.)
use p9::{Server, FileSystem};
fn main() {
let fs = FileSystem::new("/tmp/p9");
let srv = Server::bind("0.0.0.0:564")
.mount(fs)
.unwrap();
srv.serve_forever();
}
memory safety without garbage collection. zero-cost abstractions. fearless concurrency. also the crab logo is cute.
honestly, the hardest part of systems programming is naming things. p9 was already taken on crates.io so here we are with a whole domain.
client p9.rs backend
┌─────┐ ┌──────┐ ┌──────┐
│ app │────▶│ 9P │────▶│ fs │
│ │◀────│ mux │◀────│ impl │
└─────┘ └──────┘ └──────┘
│ │ │
▼ ▼ ▼
userland protocol kernel
~4.2GB/s
local throughput on M2 silicon. not bad for a weekend project.
impl FileSystem for MyFS {
fn walk(&self, path: &Path)
-> Result<Qid>
{
// your logic here
Ok(Qid::file(path))
}
fn read(&self, fid: Fid, buf: &mut [u8])
-> Result<usize>
{
// zero-copy reads ftw
self.inner.read_exact(buf)?;
Ok(buf.len())
}
}
everything is a file. every interface is a file system. network transparency is not optional. rob pike was right about everything except maybe UTF-8 (actually he was right about that too).
# add to Cargo.toml
[dependencies]
p9 = "0.3.1"
# or grab the binary
cargo install p9-server
works on linux, macos, and technically freebsd but nobody has tested that in production. PRs welcome.
open an issue. send a PR. argue about lifetime annotations in the comments. the usual.