Files
fuse-tar/bin/main.ml
2025-11-26 21:12:08 +03:00

47 lines
1.5 KiB
OCaml

module Octal = Octal
module Tar = Tar
let clean_path path =
let clean_split = List.filter (fun x -> (not (String.equal x "")) && (not (String.equal x "."))) in
clean_split (String.split_on_char '/' (String.trim path))
let (root, tar_ch) = Tar.parse_tar "asd.tar"
let () = Tar.print_tree "" root
let getattr path =
match Tar.find_from_split (clean_path path) root with
| None -> raise (Unix.Unix_error (Unix.ENOENT, "hi1", "hi1"))
| Some (File (_, md)) -> md
| Some (Directory (_, md)) -> md
let readdir path _ =
match Tar.find_from_split (clean_path path) root with
| None -> raise (Unix.Unix_error (Unix.ENOENT, "234", "234"))
| Some (File (_, _)) -> raise (Unix.Unix_error (Unix.ENOENT, "345", "345"))
| Some (Directory (children, _)) ->
["."; ".."] @ (List.map (fun (name, _) -> name) (Tar.NameMap.to_list children))
let read path buf offset amount =
match Tar.find_from_split (clean_path 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 amount) in
Bytes.iteri (fun i c -> Bigarray.Array1.set buf i c) file_buf;
read)
| _ -> raise (Unix.Unix_error (Unix.EISDIR, "read", path))
let _ =
let () = Printf.printf "hmmm?\n" in
let () = List.iter (fun x -> Printf.printf "%s\n" x) (readdir "bin" 5) in
let () = Out_channel.flush_all () in
Fuse.main Sys.argv
{
Fuse.default_operations with
getattr = getattr;
readdir = readdir;
read = read;
}