Added option to specify tar file, made ocamlfuse use inode numbers no matter what
This commit is contained in:
37
bin/main.ml
37
bin/main.ml
@@ -3,21 +3,32 @@
|
|||||||
module Octal = Octal
|
module Octal = Octal
|
||||||
module Tar = Tar
|
module Tar = Tar
|
||||||
|
|
||||||
|
let tar_path = if Array.length Sys.argv < 2 then
|
||||||
|
failwith "No tar path supplied"
|
||||||
|
else Array.get Sys.argv 1
|
||||||
|
|
||||||
|
let (root, tar_ch) = Tar.parse_tar tar_path
|
||||||
let (root, tar_ch) = Tar.parse_tar "asd.tar"
|
|
||||||
let () = Tar.print_tree "" root
|
let () = Tar.print_tree "" root
|
||||||
|
|
||||||
let getattr path =
|
let rec getattr path =
|
||||||
match Tar.find path root with
|
match Tar.find path root with
|
||||||
| None -> raise (Unix.Unix_error (Unix.ENOENT, "hi1", "hi1"))
|
| None -> raise (Unix.Unix_error (Unix.ENOENT, "hi1", "hi1"))
|
||||||
| Some (File (_, md)) -> md
|
| Some (File (_, md)) -> md
|
||||||
| Some (Directory (_, md)) -> md
|
| Some (Directory (_, md)) -> md
|
||||||
| Some (InferredDirectory (_, md)) -> md
|
| Some (InferredDirectory (_, md)) -> md
|
||||||
|
| Some (Symlink (_, md)) -> md
|
||||||
|
| Some (Hardlink (p)) -> getattr p
|
||||||
|
|
||||||
let readdir path _ =
|
let rec readdir path _i =
|
||||||
match Tar.find path root with
|
match Tar.find path root with
|
||||||
| None -> raise (Unix.Unix_error (Unix.ENOENT, "234", "234"))
|
| None -> raise (Unix.Unix_error (Unix.ENOENT, "234", "234"))
|
||||||
|
| Some (Hardlink linked_path)
|
||||||
|
| Some (Symlink (linked_path, _)) ->
|
||||||
|
if String.equal linked_path path then
|
||||||
|
raise (Unix.Unix_error (Unix.ENOENT, "read", path))
|
||||||
|
else
|
||||||
|
readdir linked_path _i
|
||||||
|
|
||||||
| Some (File (_, _)) -> raise (Unix.Unix_error (Unix.ENOENT, "345", "345"))
|
| Some (File (_, _)) -> raise (Unix.Unix_error (Unix.ENOENT, "345", "345"))
|
||||||
| Some (InferredDirectory (children, _))
|
| Some (InferredDirectory (children, _))
|
||||||
| Some (Directory (children, _)) ->
|
| Some (Directory (children, _)) ->
|
||||||
@@ -27,23 +38,37 @@ let readdir path _ =
|
|||||||
is NOT the correct requested amount. The buffer size is correct though
|
is NOT the correct requested amount. The buffer size is correct though
|
||||||
so I'm taking that as the source of truth.
|
so I'm taking that as the source of truth.
|
||||||
*)
|
*)
|
||||||
let read path buf offset _amount =
|
let rec read path buf offset _amount =
|
||||||
(*
|
(*
|
||||||
let () = Printf.printf "PARAMS %d %d %d\n" (Int64.to_int offset) amount (Bigarray.Array1.dim buf) in
|
let () = Printf.printf "PARAMS %d %d %d\n" (Int64.to_int offset) amount (Bigarray.Array1.dim buf) in
|
||||||
let () = Out_channel.flush_all () in*)
|
let () = Out_channel.flush_all () in*)
|
||||||
match Tar.find path root with
|
match Tar.find path root with
|
||||||
| None -> raise (Unix.Unix_error (Unix.ENOENT, "read", path))
|
| None -> raise (Unix.Unix_error (Unix.ENOENT, "read", path))
|
||||||
|
| Some (Hardlink linked_path)
|
||||||
|
| Some (Symlink (linked_path, _)) ->
|
||||||
|
if String.equal linked_path path then
|
||||||
|
raise (Unix.Unix_error (Unix.ENOENT, "read", path))
|
||||||
|
else
|
||||||
|
read linked_path buf offset _amount
|
||||||
| Some (File (fo, md)) ->
|
| Some (File (fo, md)) ->
|
||||||
(let (file_buf,read) = (Tar.read_file (File (fo, md)) tar_ch offset (Bigarray.Array1.dim buf)) in
|
(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;
|
Bytes.iteri (fun i c -> Bigarray.Array1.set buf i c) file_buf;
|
||||||
read)
|
read)
|
||||||
| _ -> raise (Unix.Unix_error (Unix.EISDIR, "read", path))
|
| _ -> raise (Unix.Unix_error (Unix.EISDIR, "read", path))
|
||||||
|
|
||||||
|
let readlink path =
|
||||||
|
match Tar.find path root with
|
||||||
|
| Some (Symlink (path, _)) ->
|
||||||
|
path
|
||||||
|
| _ -> raise (Unix.Unix_error (Unix.ENOENT, "readlink", path))
|
||||||
|
|
||||||
let _ =
|
let _ =
|
||||||
Fuse.main Sys.argv
|
let args = Array.append (Array.sub Sys.argv 1 ((Array.length Sys.argv) - 1)) [|"-o";"use_ino"|] in
|
||||||
|
Fuse.main args
|
||||||
{
|
{
|
||||||
Fuse.default_operations with
|
Fuse.default_operations with
|
||||||
getattr = getattr;
|
getattr = getattr;
|
||||||
readdir = readdir;
|
readdir = readdir;
|
||||||
read = read;
|
read = read;
|
||||||
|
readlink = readlink;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user