Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/uring/uring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ module Uring = struct
external submit_openat2 : t -> id -> Unix.file_descr -> Open_how.t -> bool = "ocaml_uring_submit_openat2" [@@noalloc]
external submit_linkat : t -> id -> Unix.file_descr -> Sketch.ptr -> Unix.file_descr -> Sketch.ptr -> int -> bool = "ocaml_uring_submit_linkat_byte" "ocaml_uring_submit_linkat_native" [@@noalloc]
external submit_unlinkat : t -> id -> Unix.file_descr -> Sketch.ptr -> bool -> bool = "ocaml_uring_submit_unlinkat" [@@noalloc]
external submit_mkdirat : t -> id -> Unix.file_descr -> Sketch.ptr -> int -> bool = "ocaml_uring_submit_mkdirat" [@@noalloc]
external submit_send_msg : t -> id -> Unix.file_descr -> Msghdr.t -> Sketch.ptr -> bool = "ocaml_uring_submit_send_msg" [@@noalloc]
external submit_recv_msg : t -> id -> Unix.file_descr -> Msghdr.t -> Sketch.ptr -> bool = "ocaml_uring_submit_recv_msg" [@@noalloc]
external submit_fsync : t -> id -> Unix.file_descr -> int64 -> int -> bool = "ocaml_uring_submit_fsync" [@@noalloc]
Expand Down Expand Up @@ -487,6 +488,12 @@ let unlink t ~dir ?(fd=at_fdcwd) path user_data =
Uring.submit_unlinkat t.uring id fd buf dir
) user_data

let mkdirat t ~mode ?(fd=at_fdcwd) path user_data =
with_id t (fun id ->
let buf = Sketch.String.alloc t.sketch path in
Uring.submit_mkdirat t.uring id fd buf mode
) user_data

let read t ~file_offset fd (buf : Cstruct.t) user_data =
with_id_full t (fun id -> Uring.submit_read t.uring fd id buf file_offset) user_data ~extra_data:buf

Expand Down
5 changes: 5 additions & 0 deletions lib/uring/uring.mli
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ val unlink : 'a t -> dir:bool -> ?fd:Unix.file_descr -> string -> 'a -> 'a job o
@param dir If [true], this acts like [rmdir] (only removing empty directories).
If [false], it acts like [unlink] (only removing non-directories). *)

val mkdirat : 'a t -> mode:Unix.file_perm -> ?fd:Unix.file_descr -> string -> 'a -> 'a job option
(** [mkdirat t ~mode ~fd path] makes a directory [path], which is resolved relative to [fd].
If [fd] is not given, then the current working directory is used.
@param mode The mode used to create the directory. *)

module Poll_mask : sig
include FLAGS

Expand Down
11 changes: 11 additions & 0 deletions lib/uring/uring_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,17 @@ ocaml_uring_submit_unlinkat(value v_uring, value v_id, value v_fd, value v_sketc
return (Val_true);
}

value /* noalloc */
ocaml_uring_submit_mkdirat(value v_uring, value v_id, value v_fd, value v_sketch_ptr, value v_mode) {
struct io_uring *ring = Ring_val(v_uring);
struct io_uring_sqe *sqe = io_uring_get_sqe(ring);
char *path = Sketch_ptr_val(v_sketch_ptr);
if (!sqe) return (Val_false);
io_uring_prep_mkdirat(sqe, Int_val(v_fd), path, Int_val(v_mode));
io_uring_sqe_set_data(sqe, (void *)Long_val(v_id));
return (Val_true);
}

value /* noalloc */
ocaml_uring_submit_fsync(value v_uring, value v_id, value v_fd, value v_off, value v_len)
{
Expand Down
25 changes: 25 additions & 0 deletions tests/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,31 @@ This currently doesn't work due to https://github.com/axboe/liburing/issues/955:
- : unit = ()
```

## Mkdirat

```ocaml
# let t : [ `Mkdir of int ] Uring.t = Uring.create ~queue_depth:1 ();;
val t : [ `Mkdir of int ] Uring.t = <abstr>
# Uring.mkdirat t ~mode:0o755 "mkdir" (`Mkdir 0);;
- : [ `Mkdir of int ] Uring.job option = Some <abstr>
# Uring.submit t;;
- : int = 1
# Uring.wait t;;
- : [ `Mkdir of int ] Uring.completion_option =
Uring.Some {Uring.result = 0; data = `Mkdir 0}
# (Unix.stat "mkdir").st_perm;;
- : int = 448
# let v = Uring.mkdirat t ~mode:0o755 "mkdir" (`Mkdir 1);;
val v : [ `Mkdir of int ] Uring.job option = Some <abstr>
# Uring.submit t;;
- : int = 1
# Uring.wait t;;
- : [ `Mkdir of int ] Uring.completion_option =
Uring.Some {Uring.result = -17; data = `Mkdir 1}
# Uring.exit t;;
- : unit = ()
```

## Timeout

Timeout should return (-ETIME). This is defined in https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/errno.h#L45
Expand Down