Skip to contentSkip to conversation

IORING_OP_GETDENTS: add opcode, prep function, test, man page section

PATCH In review Lennert Buytenhek 1 participant 2 messages Feb 18, 2021 – Mar 30, 2021 io_uring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IORING_OP_GETDENTS: add opcode, prep function, test, man page section

---
 man/io_uring_enter.2            |  26 +++++
 src/include/liburing.h          |   7 ++
 src/include/liburing/io_uring.h |   1 +
 test/Makefile                   |   1 +
 test/getdents.c                 | 180 ++++++++++++++++++++++++++++++++
 5 files changed, 215 insertions(+)
 create mode 100644 test/getdents.c
man/io_uring_enter.2 +26 -0
index 086207d..e0bd638 100644
@@ -759,6 +759,32 @@ being passed in to
 .BR unlinkat(2).
 Available since 5.11.
 
+.TP
+.B IORING_OP_GETDENTS
+Issue the equivalent of an
+.BR lseek(2)
+system call plus a
+.BR getdents64(2)
+system call.
+.I fd
+should be set to the fd of the directory being operated on,
+.I off
+should be set to the offset in the directory to start reading from,
+.I addr
+should be set to the
+.I dirp,
+and
+.I len
+should be set to the
+.I count.
+
+.B IORING_OP_GETDENTS
+may or may not change the specified directory's file offset, and the
+file offset should not be relied upon having any particular value during
+or after an
+.B IORING_OP_GETDENTS
+operation.
+
 .PP
 The
 .I flags
src/include/liburing.h +7 -0
index 5b96e02..1769cda 100644
@@ -535,6 +535,13 @@ static inline void io_uring_prep_sync_file_range(struct io_uring_sqe *sqe,
 	sqe->sync_range_flags = flags;
 }
 
+static inline void io_uring_prep_getdents(struct io_uring_sqe *sqe, int fd,
+					  void *buf, unsigned int count,
+					  uint64_t off)
+{
+	io_uring_prep_rw(IORING_OP_GETDENTS, sqe, fd, buf, count, off);
+}
+
 /*
  * Returns number of unconsumed (if SQPOLL) or unsubmitted entries exist in
  * the SQ ring
src/include/liburing/io_uring.h +1 -0
index 1d47389..8abc0af 100644
@@ -142,6 +142,7 @@ enum {
 	IORING_OP_RENAMEAT,
 	IORING_OP_UNLINKAT,
 	IORING_OP_MKDIRAT,
+	IORING_OP_GETDENTS,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
test/Makefile +1 -0
index 7751eff..c76987a 100644
@@ -55,6 +55,7 @@ test_targets += \
 	files-exit-hang-timeout \
 	fixed-link \
 	fsync \
+	getdents \
 	io-cancel \
 	io_uring_enter \
 	io_uring_register \
test/getdents.c new file +180 -0

180 lines not on this page · raw message

Signature · 1 line
2.29.2
#1 lore raw
Quoted 2 lines · Lennert Buytenhek

---

I'll shortly send a v2 of this that will:

- update the man page to specify that the file offset is updated unconditionally by IORING_OP_GETDENTS;

- update the man pages to indicate that IORING_FEAT_RW_CUR_POS also applies to IORING_OP_GETDENTS;

- update the getdents test to verify that offset == -1 reads from the current directory offset.