module Path = struct let trim_left s = let s = String.trim s in if String.starts_with ~prefix:"/" s then String.sub s 1 (String.length s - 1) else s let trim_right s = let s = String.trim s in if String.ends_with ~suffix:"/" s then String.sub s 0 (String.length s - 1) else s let add a b = let a = trim_right a in let b = trim_left b in Fmt.str "%s/%s" a b (* let ( / ) = add *) let compare a b = String.compare (trim_right a) (trim_right b) let equal a b = 0 = compare a b end type t = Mkernel.Block.t Mfat.t type entry = Mfat.entry = { name: string; is_dir: bool; size: int32; } module Fat = Mfat.Make (struct include Mkernel.Block let read = atomic_read let write = atomic_write end) include Fat let create blk = match create blk with | Error (`Msg e) -> Fmt.epr "FAT file system initialization failure: %s@." e; exit 1 | Ok fs -> fs let map_err r = Result.map_error (fun (`Msg e) -> `Mfat e) r let ls t p = ls t p |> map_err let read t p = read t p |> map_err let write t p s = write t p s |> map_err let mkdir t p = mkdir t p |> map_err let remove t p = remove t p |> map_err let exists t p = exists t p let stat t p = stat t p |> map_err module type FS = sig val t : t end