~cypheon/ocaml-apfs

7635de99d5788a8865442cf8e945cb584cf76846 — Johann Rudloff 1 year, 7 months ago d9efb5b master
Implement stat returning file size and a/m/c-time.
1 files changed, 16 insertions(+), 5 deletions(-)

M lib/apfs.ml
M lib/apfs.ml => lib/apfs.ml +16 -5
@@ 497,15 497,22 @@ module FileSystem = struct
        | Ok inode -> Lwt.return inode
        | _ -> failwith "unable to find root"

    let inode_size inode =
      let is_dstream f = (match f with (InodeXfield.XFDstream d) -> Some d | _ -> None) in
      let xf_dstream = List.nth_opt (List.filter_map is_dstream inode.FsBtree_val.InodeVal.xfields) 0 in
      Option.map (fun x -> x.InodeXfield.size) xf_dstream |>
      Option.value ~default:0L

    let stat fs inode =
      let lookup_key = ((inode, FsObject.type_inode), FsObject.Inode inode) in
      let* lookup_result = FS.find fs.fs_root lookup_key in
      match lookup_result with
        | Some (_, (Inode v)) -> Format.printf "other: %a\n" FsBtree_val.pp (Inode v);Lwt_result.return {
            st_size = 0L;
            st_atime = 0L;
            st_mtime = 0L;
            st_ctime = 0L;
        | Some (_, (Inode v)) ->
          Lwt_result.return {
            st_size = inode_size v;
            st_atime = v.access_time;
            st_mtime = v.mod_time;
            st_ctime = v.create_time;
            st_mode = 0l;
            st_uid = 0l;
            st_gid = 0l;


@@ 544,6 551,10 @@ let lwt_main () =
  Format.printf "root_inode: %a / dir_inode: %a\n" LoFS.pp_vnode root_inode LoFS.pp_vnode dir_inode;
  let* dir_stat = LoFS.stat fs dir_inode >|= get_ok in
  Format.printf "stat:\n%a\n" LoFS.pp_stat dir_stat;
  let* file_inode = LoFS.lookup fs dir_inode "README" >|= get_ok in
  Format.printf "file_inode: %a\n" LoFS.pp_vnode file_inode;
  let* file_stat = LoFS.stat fs file_inode >|= get_ok in
  Format.printf "file_stat:\n%a\n" LoFS.pp_stat file_stat;
  Lwt.return ()

let test_name_hash hashstr reference = Printf.printf