Pure Erlang implementation of 9p2000 protocol
filesystem fs 9p2000 erlang 9p

Pass user name when generating root QID

hauleth.dev e8ab7c8c d863e1f6

verified
+7 -7
+3 -3
src/e9p_fs.erl
··· 48 48 %% If implementation provides multiple trees then the `AName' will be set to the 49 49 %% tree defined by the client. It is left to the implementation to ensure the 50 50 %% constraints of the file root (aka `walk(Root, "..", State0) =:= {Root, State1}'. 51 - -callback root(AName :: unicode:chardata(), state()) -> {ok, e9p:qid(), state()}. 51 + -callback root(UName :: unicode:chardata(), AName :: unicode:chardata(), state()) -> {ok, e9p:qid(), state()}. 52 52 53 53 -callback flush(state()) -> {ok, state()} | {error, term(), state()}. 54 54 ··· 105 105 Error -> Error 106 106 end. 107 107 108 - root({Mod, State}, AName) -> 109 - case Mod:root(AName, State) of 108 + root({Mod, State}, UName, AName) -> 109 + case Mod:root(UName, AName, State) of 110 110 {ok, QID, NewState} -> 111 111 {ok, QID, {Mod, NewState}} 112 112 end.
+2 -2
src/e9p_server.erl
··· 64 64 % nothing 65 65 {ok, #rflush{}, FIDs, Handler}; 66 66 67 - handle_message(#tattach{fid = FID, uname = _UName, aname = AName}, FIDs, Handler0) -> 67 + handle_message(#tattach{fid = FID, uname = UName, aname = AName}, FIDs, Handler0) -> 68 68 maybe 69 - {ok, QID, Handler} ?= e9p_fs:root(Handler0, AName), 69 + {ok, QID, Handler} ?= e9p_fs:root(Handler0, UName, AName), 70 70 NFIDs = FIDs#{FID => QID}, 71 71 {ok, #rattach{qid = QID}, NFIDs, Handler} 72 72 end;
+2 -2
src/e9p_unfs.erl
··· 9 9 % -include_lib("kernel/include/logger.hrl"). 10 10 -include_lib("kernel/include/file.hrl"). 11 11 12 - -export([init/1, root/2, walk/3, stat/2, open/3, read/4, clunk/2]). 12 + -export([init/1, root/3, walk/3, stat/2, open/3, read/4, clunk/2]). 13 13 14 14 qid(Path) -> 15 15 case file:read_file_info(Path, [{time, posix}]) of ··· 31 31 init(#{path := Path}) -> 32 32 {ok, #{root => Path}}. 33 33 34 - root(_AName, #{root := Root} = State) -> 34 + root(_UName, _AName, #{root := Root} = State) -> 35 35 maybe 36 36 {ok, Qid} ?= qid(Root), 37 37 {ok, Qid, State}