mte/src/fat.ml
2026-07-03 19:53:23 +02:00

46 lines
937 B
OCaml

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
module Fat = Mfat.Make (struct
include Mkernel.Block
let read = atomic_read
let write = atomic_write
end)
include Fat
type entry = Mfat.entry = {
name: string;
is_dir: bool;
size: int32;
}
let create blk =
match Fat.create blk with
| Error (`Msg e) -> Fmt.failwith "FAT file system failure: %s." e
| Ok fs -> fs
type t = Mkernel.Block.t Mfat.t
module type FS = sig
val t : t
end