The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a `urstat` equivalent to stat(1) that uses uring

authored by

Anil Madhavapeddy and committed by
Thomas Leonard
9f571b10 9e6e911b

+69
+12
vendor/opam/uring/lib/uring/uring.ml
··· 100 100 | `Socket 101 101 ] 102 102 103 + let pp_kind f k = 104 + Fmt.pf f "%s" 105 + (match k with 106 + |`Unknown -> "unknown" 107 + |`Fifo -> "fifo" 108 + |`Character_special -> "character special file" 109 + |`Directory -> "directory" 110 + |`Block_device -> "block device" 111 + |`Regular_file -> "regular file" 112 + |`Symbolic_link -> "symbolic link" 113 + |`Socket -> "socket") 114 + 103 115 external create : unit -> t = "ocaml_uring_make_statx" 104 116 105 117 module Flags = struct
+2
vendor/opam/uring/lib/uring/uring.mli
··· 240 240 | `Socket 241 241 ] 242 242 243 + val pp_kind : kind Fmt.t 244 + 243 245 val create : unit -> t 244 246 (** Use [create] to make a statx result buffer to pass to {! statx}. *) 245 247
+5
vendor/opam/uring/tests/dune
··· 30 30 (libraries cmdliner logs.cli logs.fmt fmt.tty fmt.cli lwtcp_lib)) 31 31 32 32 (executable 33 + (name urstat) 34 + (modules urstat) 35 + (libraries uring fmt)) 36 + 37 + (executable 33 38 (name poll_add) 34 39 (modules poll_add) 35 40 (libraries unix uring logs logs.fmt))
+50
vendor/opam/uring/tests/urstat.ml
··· 1 + (* stat(1) built with liburing. *) 2 + 3 + module S = Uring.Statx 4 + 5 + (* TODO move into Uring.Statx? *) 6 + let pp_time f t = 7 + let nsec, sec = modf t in 8 + let tm = Unix.localtime sec in 9 + Format.fprintf f "%04d-%02d-%02d %02d:%02d:%02d.%9.0f +0000" 10 + (tm.Unix.tm_year + 1900) (tm.Unix.tm_mon + 1) tm.Unix.tm_mday 11 + tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec 12 + (nsec *. 1e9) 13 + 14 + let get_completion_and_print uring = 15 + let (fname, buf), _ = 16 + match Uring.wait uring with 17 + | Some { data; result } -> (data, result) 18 + | None -> failwith "retry" 19 + in 20 + let kind = S.kind buf in 21 + let opt_symlink = match kind with 22 + `Symbolic_link -> Printf.sprintf " -> %s" (Unix.readlink fname) (* TODO no readlink in io_uring? *) 23 + | _ -> "" in 24 + Format.printf " File: %s%s\n Size: %Lu\t\tBlocks: %Lu\tIO Block: %Lu\t %a\nDevice: %Lu\tInode: %Lu\tLinks: %Lu\nAccess: (%04o/TODO)\tUid: (%Lu/TODO)\tGid: (%Lu/TODO)\nAccess: %a\nModify: %a\nChange: %a\n Birth: %a\n%!" 25 + fname opt_symlink 26 + (Optint.Int63.to_int64 (S.size buf)) 27 + (S.blocks buf) 28 + (S.blksize buf) 29 + S.pp_kind (S.kind buf) 30 + (S.dev buf) (* TODO expose makedev/major/minor *) (S.ino buf) (S.nlink buf) 31 + (S.perm buf) (S.uid buf) (S.gid buf) 32 + pp_time (S.atime buf) 33 + pp_time (S.mtime buf) 34 + pp_time (S.ctime buf) 35 + pp_time (S.btime buf) 36 + 37 + let submit_stat_request fname buf uring = 38 + let mask = S.Mask.(basic_stats + btime) in 39 + let flags = S.Flags.(symlink_nofollow + statx_dont_sync) in 40 + let _ = Uring.statx uring ~mask fname buf flags (fname,buf) in 41 + let numreq = Uring.submit uring in 42 + assert(numreq=1); 43 + () 44 + 45 + let () = 46 + let fname = Sys.argv.(1) in 47 + let buf = S.create () in 48 + let uring = Uring.create ~queue_depth:1 () in 49 + submit_stat_request fname buf uring; 50 + get_completion_and_print uring