Files
fuse-tar/bin/main.ml
2025-11-26 23:36:52 +03:00

50 lines
1.6 KiB
OCaml

module Octal = Octal
module Tar = Tar
let (root, tar_ch) = Tar.parse_tar "asd.tar"
let () = Tar.print_tree "" root
let getattr path =
match Tar.find path root with
| None -> raise (Unix.Unix_error (Unix.ENOENT, "hi1", "hi1"))
| Some (File (_, md)) -> md
| Some (Directory (_, md)) -> md
| Some (InferredDirectory (_, md)) -> md
let readdir path _ =
match Tar.find path root with
| None -> raise (Unix.Unix_error (Unix.ENOENT, "234", "234"))
| Some (File (_, _)) -> raise (Unix.Unix_error (Unix.ENOENT, "345", "345"))
| Some (InferredDirectory (children, _))
| Some (Directory (children, _)) ->
["."; ".."] @ (List.map (fun (name, _) -> name) (Tar.NameMap.to_list children))
(* There seems to be a bug here - the amount argument given to this function
is NOT the correct requested amount. The buffer size is correct though
so I'm taking that as the source of truth.
*)
let read path buf offset _amount =
(*
let () = Printf.printf "PARAMS %d %d %d\n" (Int64.to_int offset) amount (Bigarray.Array1.dim buf) in
let () = Out_channel.flush_all () in*)
match Tar.find path root with
| None -> raise (Unix.Unix_error (Unix.ENOENT, "read", path))
| Some (File (fo, md)) ->
(let (file_buf,read) = (Tar.read_file (File (fo, md)) tar_ch offset (Bigarray.Array1.dim buf)) in
Bytes.iteri (fun i c -> Bigarray.Array1.set buf i c) file_buf;
read)
| _ -> raise (Unix.Unix_error (Unix.EISDIR, "read", path))
let _ =
Fuse.main Sys.argv
{
Fuse.default_operations with
getattr = getattr;
readdir = readdir;
read = read;
}