Pure Erlang implementation of 9p2000 protocol
filesystem
fs
9p2000
erlang
9p
1% SPDX-FileCopyrightText: 2025 Łukasz Niemier <~@hauleth.dev>
2%
3% SPDX-License-Identifier: Apache-2.0
4
5-module(e9p).
6
7-export([make_qid/3, is_type/2]).
8
9-export_type([qid/0, fid/0]).
10
11-export_type([u8/0, u16/0, u32/0, u64/0]).
12
13-include("e9p_internal.hrl").
14
15-type u8() :: 16#00..16#FF.
16-type u16() :: 16#0000..16#FFFF.
17-type u32() :: 16#00000000..16#FFFFFFFF.
18-type u64() :: 16#0000000000000000..16#FFFFFFFFFFFFFFFF.
19
20-opaque qid() :: #qid{type :: u8(), version :: u32(), path :: u64()}.
21
22-type fid() :: 16#00000000..16#FFFFFFFF.
23
24%-spec make_qid()
25make_qid(Type, Version, Path) ->
26 #qid{type = to_qtype(Type), version = Version, path = Path}.
27
28is_type(#qid{type = QType}, Type) ->
29 (to_qtype(Type) band QType) =/= 0.
30
31to_qtype(directory) -> 16#80;
32to_qtype(append) -> 16#40;
33to_qtype(excl) -> 16#20;
34to_qtype(device) -> 16#10;
35to_qtype(auth) -> 16#08;
36to_qtype(tmp) -> 16#04;
37to_qtype(symlink) -> 16#02;
38to_qtype(regular) -> 16#00.