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 non-allocating direct statx API

Co-authored-by: Thomas Leonard <talex5@gmail.com>

authored by

Patrick Ferris
Thomas Leonard
and committed by
Thomas Leonard
9e6e911b 1c9529b6

+305 -120
+45 -9
vendor/opam/uring/lib/uring/include/discover.ml
··· 109 109 | _ -> assert false 110 110 ) 111 111 in 112 - let at_flags, mask_flags = 112 + let at_flags, mask_flags, attr_flags = 113 + let new_flags = 114 + C.C_define.Type.[ 115 + (* Masks *) 116 + "STATX_MNT_ID", Int; 117 + "STATX_DIOALIGN", Int; 118 + (* File Attributes *) 119 + "STATX_ATTR_VERITY", Int; 120 + "STATX_ATTR_DAX", Int; 121 + ] 122 + in 123 + let new_flag_prelude = 124 + let def_flag = function 125 + | name, C.C_define.Type.Int -> 126 + Printf.sprintf "#ifndef %s\n#define %s 0\n#endif\n" name name; 127 + | _ -> assert false 128 + in 129 + String.concat "" (List.map def_flag new_flags) 130 + in 113 131 C.C_define.import c ~c_flags:["-D_GNU_SOURCE"; "-I"; Filename.concat (Sys.getcwd ()) "include"] 114 - ~prelude:{|#include <sys/stat.h> 132 + ~prelude:({|#include <sys/stat.h> 115 133 #ifndef STATX_TYPE 116 134 #include <linux/stat.h> 117 - #endif|} 135 + #endif 136 + |} ^ new_flag_prelude) 118 137 ~includes:["fcntl.h" ] 119 - C.C_define.Type.[ 138 + (C.C_define.Type.[ 120 139 "AT_EMPTY_PATH", Int; 121 140 "AT_NO_AUTOMOUNT", Int; 122 141 "AT_SYMLINK_NOFOLLOW", Int; ··· 137 156 "STATX_BLOCKS", Int; 138 157 "STATX_BASIC_STATS", Int; 139 158 "STATX_BTIME", Int; 140 - ] 141 - |> List.fold_left (fun (ats, stats) (v, k) -> match String.split_on_char '_' v, k with 159 + 160 + "STATX_ATTR_COMPRESSED", Int; 161 + "STATX_ATTR_IMMUTABLE", Int; 162 + "STATX_ATTR_APPEND", Int; 163 + "STATX_ATTR_NODUMP", Int ; 164 + "STATX_ATTR_ENCRYPTED", Int; 165 + ] @ new_flags) 166 + |> List.fold_left (fun (ats, stats, attrs) (v, k) -> match String.split_on_char '_' v, k with 142 167 | "AT" :: name, C.C_define.Value.Int v -> 143 168 let ocaml_name = String.lowercase_ascii (String.concat "_" name) in 144 - ((ocaml_name, v) :: ats, stats) 169 + ((ocaml_name, v) :: ats, stats, attrs) 170 + | "STATX" :: "ATTR" :: name, C.C_define.Value.Int v -> 171 + let name = String.concat "_" name |> String.lowercase_ascii in 172 + let ocaml_name = match name with 173 + | "type" -> "type'" 174 + | v -> v 175 + in 176 + (ats, stats, (ocaml_name, v) :: attrs) 145 177 | "STATX" :: name, C.C_define.Value.Int v -> 146 178 let name = String.concat "_" name |> String.lowercase_ascii in 147 179 let ocaml_name = match name with 148 180 | "type" -> "type'" 149 181 | v -> v 150 182 in 151 - (ats, (ocaml_name, v) :: stats) 183 + (ats, (ocaml_name, v) :: stats, attrs) 152 184 | _ -> assert false 153 - ) ([], []) 185 + ) ([], [], []) 154 186 in 155 187 let op_sig = List.map (fun (name, _) -> Printf.sprintf " val %s : t" name) ops in 156 188 let op_struct = List.map (fun (name, v) -> Printf.sprintf " let %s = 0x%x" name v) ops in 157 189 let at_struct = List.map (fun (name, v) -> Printf.sprintf " let %s = 0x%x" name v) at_flags in 158 190 let mask_struct = List.map (fun (name, v) -> Printf.sprintf " let %s = 0x%x" name v) mask_flags in 191 + let attr_struct = List.map (fun (name, v) -> Printf.sprintf " let %s = 0x%x" name v) attr_flags in 159 192 C.Flags.write_lines "config.ml" 160 193 (defs @ 161 194 ["module Op : sig"; ··· 172 205 " end"; 173 206 " module Mask = struct"; 174 207 ] @ mask_struct @ [ 208 + " end"; 209 + " module Attr = struct"; 210 + ] @ attr_struct @ [ 175 211 " end"; 176 212 "end" 177 213 ])
+39 -26
vendor/opam/uring/lib/uring/uring.ml
··· 87 87 end 88 88 89 89 module Statx = struct 90 - type internal 90 + type t 91 91 92 92 type kind = [ 93 93 | `Unknown ··· 100 100 | `Socket 101 101 ] 102 102 103 - type t = { 104 - blksize : Int64.t; 105 - attributes : Int64.t; 106 - nlink : Int64.t; 107 - uid : Int64.t; 108 - gid : Int64.t; 109 - mode : int; 110 - ino : Int64.t; 111 - size : Optint.Int63.t; 112 - blocks : Int64.t; 113 - attributes_mask : Int64.t; 114 - atime : float; 115 - btime : float; 116 - ctime : float; 117 - mtime : float; 118 - rdev : Int64.t; 119 - dev : Int64.t; 120 - perm : int; 121 - kind : kind; 122 - mask : Int64.t; 123 - } 124 - 125 - external create : unit -> internal = "ocaml_uring_make_statx" 126 - external internal_to_t : internal -> t = "ocaml_uring_statx_internal_to_t" 103 + external create : unit -> t = "ocaml_uring_make_statx" 127 104 128 105 module Flags = struct 129 106 include Flags 130 107 include Config.Statx.Flags 131 108 end 132 109 110 + module Attr = struct 111 + include Flags 112 + include Config.Statx.Attr 113 + 114 + let check ?mask attr t = 115 + let i = Int64.of_int t in 116 + (match mask with Some m -> if Int64.equal (Int64.logand m i) i then invalid_arg "Attribute not supported" | _ -> ()); 117 + Int64.equal (Int64.logand attr i) i 118 + end 119 + 133 120 module Mask = struct 134 121 include Flags 135 122 include Config.Statx.Mask ··· 138 125 let i = Int64.of_int t in 139 126 Int64.equal (Int64.logand mask i) i 140 127 end 128 + 129 + external blksize : t -> (int64 [@unboxed]) = "ocaml_uring_statx_blksize_bytes" "ocaml_uring_statx_blksize_native" [@@noalloc] 130 + external attributes : t -> (int64 [@unboxed]) = "ocaml_uring_statx_attributes_bytes" "ocaml_uring_statx_attributes_native" [@@noalloc] 131 + external nlink : t -> (int64 [@unboxed]) = "ocaml_uring_statx_nlink_bytes" "ocaml_uring_statx_nlink_native" [@@noalloc] 132 + external uid : t -> (int64 [@unboxed]) = "ocaml_uring_statx_uid_bytes" "ocaml_uring_statx_uid_native" [@@noalloc] 133 + external gid : t -> (int64 [@unboxed]) = "ocaml_uring_statx_gid_bytes" "ocaml_uring_statx_gid_native" [@@noalloc] 134 + external ino : t -> (int64 [@unboxed]) = "ocaml_uring_statx_ino_bytes" "ocaml_uring_statx_ino_native" [@@noalloc] 135 + external blocks : t -> (int64 [@unboxed]) = "ocaml_uring_statx_blocks_bytes" "ocaml_uring_statx_blocks_native" [@@noalloc] 136 + external attributes_mask : t -> (int64 [@unboxed]) = "ocaml_uring_statx_attributes_mask_bytes" "ocaml_uring_statx_attributes_mask_native" [@@noalloc] 137 + external rdev : t -> (int64 [@unboxed]) = "ocaml_uring_statx_rdev_bytes" "ocaml_uring_statx_rdev_native" [@@noalloc] 138 + external dev : t -> (int64 [@unboxed]) = "ocaml_uring_statx_dev_bytes" "ocaml_uring_statx_dev_native" [@@noalloc] 139 + external mask : t -> (int64 [@unboxed]) = "ocaml_uring_statx_mask_bytes" "ocaml_uring_statx_mask_native" [@@noalloc] 140 + external mnt_id : t -> (int64 [@unboxed]) = "ocaml_uring_statx_mnt_id_bytes" "ocaml_uring_statx_mnt_id_native" [@@noalloc] 141 + external dio_mem_align : t -> (int64 [@unboxed]) = "ocaml_uring_statx_dio_mem_align_bytes" "ocaml_uring_statx_dio_mem_align_native" [@@noalloc] 142 + external dio_offset_align : t -> (int64 [@unboxed]) = "ocaml_uring_statx_dio_offset_align_bytes" "ocaml_uring_statx_dio_offset_align_native" [@@noalloc] 143 + 144 + external atime : t -> (float [@unboxed]) = "ocaml_uring_statx_atime_bytes" "ocaml_uring_statx_atime_native" [@@noalloc] 145 + external btime : t -> (float [@unboxed]) = "ocaml_uring_statx_btime_bytes" "ocaml_uring_statx_btime_native" [@@noalloc] 146 + external ctime : t -> (float [@unboxed]) = "ocaml_uring_statx_ctime_bytes" "ocaml_uring_statx_ctime_native" [@@noalloc] 147 + external mtime : t -> (float [@unboxed]) = "ocaml_uring_statx_mtime_bytes" "ocaml_uring_statx_mtime_native" [@@noalloc] 148 + 149 + external mode : t -> (int [@untagged]) = "ocaml_uring_statx_mode_bytes" "ocaml_uring_statx_mode_native" [@@noalloc] 150 + external perm : t -> (int [@untagged]) = "ocaml_uring_statx_perm_bytes" "ocaml_uring_statx_perm_native" [@@noalloc] 151 + 152 + external kind : t -> kind = "ocaml_uring_statx_kind" 153 + external size : t -> Optint.Int63.t = "ocaml_uring_statx_size" 141 154 end 142 155 143 156 module Sockaddr = struct ··· 293 306 external submit_readv_fixed : t -> Unix.file_descr -> id -> Cstruct.buffer -> int -> int -> offset -> bool = "ocaml_uring_submit_readv_fixed_byte" "ocaml_uring_submit_readv_fixed_native" [@@noalloc] 294 307 external submit_writev_fixed : t -> Unix.file_descr -> id -> Cstruct.buffer -> int -> int -> offset -> bool = "ocaml_uring_submit_writev_fixed_byte" "ocaml_uring_submit_writev_fixed_native" [@@noalloc] 295 308 external submit_close : t -> Unix.file_descr -> id -> bool = "ocaml_uring_submit_close" [@@noalloc] 296 - external submit_statx : t -> id -> Unix.file_descr -> Statx.internal -> Sketch.ptr -> int -> int -> bool = "ocaml_uring_submit_statx_byte" "ocaml_uring_submit_statx_native" [@@noalloc] 309 + external submit_statx : t -> id -> Unix.file_descr -> Statx.t -> Sketch.ptr -> int -> int -> bool = "ocaml_uring_submit_statx_byte" "ocaml_uring_submit_statx_native" [@@noalloc] 297 310 external submit_splice : t -> id -> Unix.file_descr -> Unix.file_descr -> int -> bool = "ocaml_uring_submit_splice" [@@noalloc] 298 311 external submit_connect : t -> id -> Unix.file_descr -> Sockaddr.t -> bool = "ocaml_uring_submit_connect" [@@noalloc] 299 312 external submit_accept : t -> id -> Unix.file_descr -> Sockaddr.t -> bool = "ocaml_uring_submit_accept" [@@noalloc]
+67 -35
vendor/opam/uring/lib/uring/uring.mli
··· 226 226 The result is [EINVAL] if the file descriptors don't support splicing. *) 227 227 228 228 module Statx : sig 229 - type internal 230 - (** An internal type used to pass into {! statx}. *) 229 + type t 230 + (** A statx struct. *) 231 231 232 232 type kind = [ 233 233 | `Unknown ··· 240 240 | `Socket 241 241 ] 242 242 243 - type t = { 244 - blksize : Int64.t; 245 - attributes : Int64.t; 246 - nlink : Int64.t; 247 - uid : Int64.t; 248 - gid : Int64.t; 249 - mode : int; 250 - ino : Int64.t; 251 - size : Optint.Int63.t; 252 - blocks : Int64.t; 253 - attributes_mask : Int64.t; 254 - atime : float; 255 - btime : float; 256 - ctime : float; 257 - mtime : float; 258 - rdev : Int64.t; 259 - dev : Int64.t; 260 - perm : int; 261 - kind : kind; 262 - mask : Int64.t; 263 - } (** See statx(2). *) 264 - 265 - val create : unit -> internal 266 - (** Use [create] to make an {! internal} statx struct to pass to {! statx}. *) 267 - 268 - val internal_to_t : internal -> t 269 - (** Convert an internal statx struct to an OCaml value. This should only be called 270 - after a successful completition of a {! statx} call. *) 243 + val create : unit -> t 244 + (** Use [create] to make a statx result buffer to pass to {! statx}. *) 271 245 272 246 module Flags : sig 273 247 include FLAGS ··· 281 255 val statx_dont_sync : t 282 256 end 283 257 258 + module Attr : sig 259 + include FLAGS 260 + 261 + val compressed : t 262 + val immutable : t 263 + val append : t 264 + val nodump : t 265 + val encrypted : t 266 + val verity : t 267 + 268 + val dax : t 269 + (** Since Linux 5.8 *) 270 + 271 + val check : ?mask:Int64.t -> Int64.t -> t -> bool 272 + (** [check ?mask attr t] will check if [t] is set in [attr]. 273 + 274 + If [mask] is not [None] then it will first check the mask to see 275 + if the file attribute is supported and if not raise [Invalid_argument]. *) 276 + end 277 + 284 278 module Mask : sig 285 279 include FLAGS 286 280 ··· 299 293 300 294 val btime : t 301 295 296 + val mnt_id : t 297 + (** As of Linux 5.8 *) 298 + 299 + val dioalign : t 300 + (** As of Linux 6.1 *) 301 + 302 302 val check : Int64.t -> t -> bool 303 303 (** [check mask t] checks if [t] is set in [mask]. *) 304 304 end 305 + 306 + (** You may wish to use {! Mask.check} to verify the field has actually 307 + been returned with a sensible value first. *) 308 + 309 + val blksize : t -> Int64.t 310 + val attributes : t -> Int64.t 311 + val nlink : t -> Int64.t 312 + val uid : t -> Int64.t 313 + val gid : t -> Int64.t 314 + val ino : t -> Int64.t 315 + val blocks : t -> Int64.t 316 + val attributes_mask : t -> Int64.t 317 + val rdev : t -> Int64.t 318 + val dev : t -> Int64.t 319 + val mask : t -> Int64.t 320 + 321 + val mnt_id : t -> Int64.t 322 + (** See {! Mask.mnt_id}. *) 323 + 324 + val dio_mem_align : t -> Int64.t 325 + (** See {! Mask.dioalign}. *) 326 + 327 + val dio_offset_align : t -> Int64.t 328 + (** See {! Mask.dioalign}. *) 329 + 330 + val atime : t -> float 331 + val btime : t -> float 332 + val ctime : t -> float 333 + val mtime : t -> float 334 + 335 + val mode : t -> int 336 + val perm : t -> int 337 + 338 + val size : t -> Optint.Int63.t 339 + val kind : t -> kind 305 340 end 306 341 307 - val statx : 'a t -> ?fd:Unix.file_descr -> mask:Statx.Mask.t -> string -> Statx.internal -> Statx.Flags.t -> 'a -> 'a job option 342 + val statx : 'a t -> ?fd:Unix.file_descr -> mask:Statx.Mask.t -> string -> Statx.t -> Statx.Flags.t -> 'a -> 'a job option 308 343 (** [statx t ?fd ~mask path stat flags] stats [path], which is resolved relative to [fd] 309 - (or the current directory if [fd] is not given). 310 - 311 - Create a {! Statx.internal} using {! Statx.create} and after successful completion 312 - of the job, convert it to {! Statx.t} using {! Statx.internal_to_t}. *) 344 + (or the current directory if [fd] is not given). *) 313 345 314 346 val connect : 'a t -> Unix.file_descr -> Unix.sockaddr -> 'a -> 'a job option 315 347 (** [connect t fd addr d] will submit a request to connect [fd] to [addr]. *)
+147 -44
vendor/opam/uring/lib/uring/uring_stubs.c
··· 454 454 455 455 static value get_file_type_variant(struct statx *sb) { 456 456 int filetype = sb->stx_mode & S_IFMT; 457 - if (filetype == S_IFREG) { 458 - return caml_hash_variant("Regular_file"); 459 - } else if (filetype == S_IFSOCK) { 460 - return caml_hash_variant("Socket"); 461 - } else if (filetype == S_IFLNK) { 462 - return caml_hash_variant("Symbolic_link"); 463 - } else if (filetype == S_IFBLK) { 464 - return caml_hash_variant("Block_device"); 465 - } else if (filetype == S_IFDIR) { 466 - return caml_hash_variant("Directory"); 467 - } else if (filetype == S_IFCHR) { 468 - return caml_hash_variant("Character_special"); 469 - } else if (filetype == S_IFIFO) { 470 - return caml_hash_variant("Fifo"); 471 - } else { 472 - return caml_hash_variant("Unknown"); 457 + switch (filetype) { 458 + case S_IFREG: 459 + return caml_hash_variant("Regular_file"); 460 + case S_IFSOCK: 461 + return caml_hash_variant("Socket"); 462 + case S_IFLNK: 463 + return caml_hash_variant("Symbolic_link"); 464 + case S_IFBLK: 465 + return caml_hash_variant("Block_device"); 466 + case S_IFDIR: 467 + return caml_hash_variant("Directory"); 468 + case S_IFCHR: 469 + return caml_hash_variant("Character_special"); 470 + case S_IFIFO: 471 + return caml_hash_variant("Fifo"); 472 + default: 473 + return caml_hash_variant("Unknown"); 473 474 } 474 475 } 475 476 476 477 value 477 - ocaml_uring_statx_internal_to_t(value v_statx) { 478 - CAMLparam1(v_statx); 479 - CAMLlocal1(v); 480 - v = caml_alloc(19, 0); 481 - struct statx *s = Statx_val(v_statx); 482 - Store_field(v, 0, caml_copy_int64(s->stx_blksize)); 483 - Store_field(v, 1, caml_copy_int64(s->stx_attributes)); 484 - Store_field(v, 2, caml_copy_int64(s->stx_nlink)); 485 - Store_field(v, 3, caml_copy_int64(s->stx_uid)); 486 - Store_field(v, 4, caml_copy_int64(s->stx_gid)); 487 - Store_field(v, 5, Val_int(s->stx_mode)); 488 - Store_field(v, 6, caml_copy_int64(s->stx_ino)); 489 - Store_field(v, 7, caml_copy_int63(s->stx_size)); 490 - Store_field(v, 8, caml_copy_int64(s->stx_blocks)); 491 - Store_field(v, 9, caml_copy_int64(s->stx_attributes_mask)); 492 - Store_field(v, 10, caml_copy_double(double_of_timespec(&s->stx_atime))); 493 - Store_field(v, 11, caml_copy_double(double_of_timespec(&s->stx_btime))); 494 - Store_field(v, 12, caml_copy_double(double_of_timespec(&s->stx_ctime))); 495 - Store_field(v, 13, caml_copy_double(double_of_timespec(&s->stx_mtime))); 496 - Store_field(v, 14, caml_copy_int64(makedev(s->stx_rdev_major,s->stx_rdev_minor))); 497 - Store_field(v, 15, caml_copy_int64(makedev(s->stx_dev_major,s->stx_dev_minor))); 498 - Store_field(v, 16, Val_int(s->stx_mode & ~S_IFMT)); 499 - Store_field(v, 17, get_file_type_variant(s)); 500 - Store_field(v, 18, caml_copy_int64(s->stx_mask)); 501 - CAMLreturn(v); 502 - } 503 - 504 - value 505 478 ocaml_uring_submit_statx_native(value v_uring, value v_id, value v_fd, value v_statx, value v_sketch_ptr, value v_flags, value v_mask) { 506 479 struct io_uring *ring = Ring_val(v_uring); 507 480 struct io_uring_sqe *sqe = io_uring_get_sqe(ring); ··· 522 495 values[4], 523 496 values[5], 524 497 values[6]); 498 + } 499 + 500 + // Non-allocating (for native mode) accessors for statx 501 + #define STATX_GETTER(field, return_type, ocaml_value_maker) \ 502 + return_type ocaml_uring_statx_##field##_native(value v_statx) { \ 503 + struct statx *s = Statx_val(v_statx); \ 504 + return s->stx_##field; \ 505 + } \ 506 + value ocaml_uring_statx_ ## field ## _bytes(value v_statx) { \ 507 + return ocaml_value_maker(ocaml_uring_statx_##field##_native(v_statx)); \ 508 + } 509 + 510 + // Int64 511 + STATX_GETTER(blksize, int64_t, caml_copy_int64); 512 + STATX_GETTER(attributes, int64_t, caml_copy_int64); 513 + STATX_GETTER(nlink, int64_t, caml_copy_int64); 514 + STATX_GETTER(uid, int64_t, caml_copy_int64); 515 + STATX_GETTER(gid, int64_t, caml_copy_int64); 516 + STATX_GETTER(ino, int64_t, caml_copy_int64); 517 + STATX_GETTER(blocks, int64_t, caml_copy_int64); 518 + STATX_GETTER(attributes_mask, int64_t, caml_copy_int64); 519 + STATX_GETTER(mask, int64_t, caml_copy_int64); 520 + 521 + int64_t 522 + ocaml_uring_statx_rdev_native(value v_statx) { 523 + struct statx *s = Statx_val(v_statx); 524 + return makedev(s->stx_rdev_major,s->stx_rdev_minor); 525 + } 526 + 527 + value 528 + ocaml_uring_statx_rdev_bytes(value v_statx) { 529 + return caml_copy_int64(ocaml_uring_statx_rdev_native(v_statx)); 530 + } 531 + 532 + int64_t 533 + ocaml_uring_statx_dev_native(value v_statx) { 534 + struct statx *s = Statx_val(v_statx); 535 + return makedev(s->stx_dev_major,s->stx_dev_minor); 536 + } 537 + 538 + value 539 + ocaml_uring_statx_dev_bytes(value v_statx) { 540 + return caml_copy_int64(ocaml_uring_statx_dev_native(v_statx)); 541 + } 542 + 543 + int64_t 544 + ocaml_uring_statx_mnt_id_native(value v_statx) { 545 + #ifdef STATX_MNT_ID // Linux 5.8 and above 546 + struct statx *s = Statx_val(v_statx); 547 + return s->stx_mnt_id; 548 + #else 549 + return 0; 550 + #endif 551 + } 552 + 553 + value 554 + ocaml_uring_statx_mnt_id_bytes(value v_statx) { 555 + return caml_copy_int64(ocaml_uring_statx_mnt_id_native(v_statx)); 556 + } 557 + 558 + int64_t 559 + ocaml_uring_statx_dio_mem_align_native(value v_statx) { 560 + #ifdef STATX_DIOALIGN // Linux 6.1 and above 561 + struct statx *s = Statx_val(v_statx); 562 + return s->stx_dio_mem_align; 563 + #else 564 + return 0; 565 + #endif 566 + } 567 + 568 + value 569 + ocaml_uring_statx_dio_mem_align_bytes(value v_statx) { 570 + return caml_copy_int64(ocaml_uring_statx_dio_mem_align_native(v_statx)); 571 + } 572 + 573 + int64_t 574 + ocaml_uring_statx_dio_offset_align_native(value v_statx) { 575 + #ifdef STATX_DIOALIGN // Linux 6.1 and above 576 + struct statx *s = Statx_val(v_statx); 577 + return s->stx_dio_mem_align; 578 + #else 579 + return 0; 580 + #endif 581 + } 582 + 583 + value 584 + ocaml_uring_statx_dio_offset_align_bytes(value v_statx) { 585 + return caml_copy_int64(ocaml_uring_statx_dio_offset_align_native(v_statx)); 586 + } 587 + 588 + #define STATX_TIME_GETTER(field, return_type, ocaml_value_maker) \ 589 + return_type ocaml_uring_statx_##field##_native(value v_statx) { \ 590 + struct statx *s = Statx_val(v_statx); \ 591 + return double_of_timespec(&s->stx_##field); \ 592 + } \ 593 + value ocaml_uring_statx_ ## field ## _bytes(value v_statx) { \ 594 + return ocaml_value_maker(ocaml_uring_statx_##field##_native(v_statx)); \ 595 + } 596 + 597 + // Float 598 + STATX_TIME_GETTER(atime, double, caml_copy_double); 599 + STATX_TIME_GETTER(btime, double, caml_copy_double); 600 + STATX_TIME_GETTER(ctime, double, caml_copy_double); 601 + STATX_TIME_GETTER(mtime, double, caml_copy_double); 602 + 603 + // Int 604 + STATX_GETTER(mode, intnat, Val_int); 605 + 606 + intnat 607 + ocaml_uring_statx_perm_native(value v_statx) { 608 + struct statx *s = Statx_val(v_statx); 609 + return (s->stx_mode & ~S_IFMT); 610 + } 611 + 612 + value 613 + ocaml_uring_statx_perm_bytes(value v_statx) { 614 + return Val_int(ocaml_uring_statx_perm_native(v_statx)); 615 + } 616 + 617 + // Allocating 618 + value 619 + ocaml_uring_statx_kind(value v_statx) { 620 + struct statx *s = Statx_val(v_statx); 621 + return get_file_type_variant(s); 622 + } 623 + 624 + value 625 + ocaml_uring_statx_size(value v_statx) { 626 + struct statx *s = Statx_val(v_statx); 627 + return caml_copy_int63(s->stx_size); 525 628 } 526 629 527 630 struct sock_addr_data {
+7 -6
vendor/opam/uring/tests/main.md
··· 198 198 val t : [ `Open_path | `Statx ] Uring.t = <abstr> 199 199 200 200 # let statx = Uring.Statx.create ();; 201 - val statx : Uring.Statx.internal = <abstr> 201 + val statx : Uring.Statx.t = <abstr> 202 202 # Uring.statx t 203 203 ~mask:Uring.Statx.Mask.basic_stats 204 204 "test-openat" ··· 214 214 val token : [ `Open_path | `Statx ] = `Statx 215 215 val retval : int = 0 216 216 217 - # let x = Uring.Statx.internal_to_t statx in 218 - x.kind, Printf.sprintf "0o%o" x.perm, Int63.to_int x.size;; 217 + # Uring.Statx.kind statx, Printf.sprintf "0o%o" (Uring.Statx.perm statx), Int63.to_int (Uring.Statx.size statx);; 219 218 - : Uring.Statx.kind * string * int = (`Regular_file, "0o600", 9) 219 + 220 + # if not (Uring.Statx.(Mask.check (mask statx) Mask.dioalign)) then assert (Uring.Statx.dio_mem_align statx = 0L);; 221 + - : unit = () 220 222 ``` 221 223 222 224 Now using `~fd`: ··· 242 244 val fd : Unix.file_descr = <abstr> 243 245 244 246 # let statx = Uring.Statx.create ();; 245 - val statx : Uring.Statx.internal = <abstr> 247 + val statx : Uring.Statx.t = <abstr> 246 248 # Uring.statx t 247 249 ~fd 248 250 ~mask:Uring.Statx.Mask.(type' + mode + size) ··· 259 261 val token : [ `Open_path | `Statx ] = `Statx 260 262 val retval : int = 0 261 263 262 - # let x = Uring.Statx.internal_to_t statx in 263 - x.kind, Printf.sprintf "0o%o" x.perm, Int63.to_int x.size;; 264 + # Uring.Statx.kind statx, Printf.sprintf "0o%o" (Uring.Statx.perm statx), Int63.to_int (Uring.Statx.size statx);; 264 265 - : Uring.Statx.kind * string * int = (`Regular_file, "0o600", 9) 265 266 266 267 # let fd : unit = Unix.close fd;;