p9.rs

a compact systems utility

what even is p9?

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.)

quick start

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();
}

why rust?

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.

features

  • async I/O with tokio
  • full 9P2000 protocol support
  • zero-copy message parsing
  • pluggable filesystem backends
  • TLS support (because security)

architecture

  client        p9.rs         backend
  ┌─────┐     ┌──────┐     ┌──────┐
  │ app │────▶│ 9P   │────▶│ fs   │
  │     │◀────│ mux  │◀────│ impl │
  └─────┘     └──────┘     └──────┘
     │            │            │
     ▼            ▼            ▼
  userland    protocol      kernel
                    

perf

~4.2GB/s

local throughput on M2 silicon. not bad for a weekend project.

custom backends

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())
    }
}

the plan 9 philosophy

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).

install

# 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.

contributing

open an issue. send a PR. argue about lifetime annotations in the comments. the usual.