]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/posix-pipe: Add pipe stat support
authorAndrei Tatar <andrei@unikraft.io>
Wed, 19 Mar 2025 12:37:23 +0000 (13:37 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Thu, 27 Mar 2025 15:27:28 +0000 (15:27 +0000)
This change implements a real getstat operation for pipes, returning
basic information about an open pipe.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1603

lib/posix-pipe/pipe.c

index 3ee53cf2aa4d8c1e332282a8fc9e0edab6aab0c0..106171d5f6de79697de6278bb22589c72da89749 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <string.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 
 #include <uk/atomic.h>
 #include <uk/alloc.h>
@@ -318,10 +319,21 @@ out_full:
        return -EAGAIN;
 }
 
+static int pipe_getstat(const struct uk_file *f, unsigned mask __unused,
+                       struct uk_statx *arg)
+{
+       /* All data is immediately available, ignore mask */
+       arg->stx_mask = UK_STATX_TYPE | UK_STATX_MODE | UK_STATX_INO;
+       arg->stx_blksize = 1;
+       arg->stx_mode = S_IFIFO | 0600;
+       arg->stx_ino = (uintptr_t)f;
+       return 0;
+}
+
 static const struct uk_file_ops rpipe_ops = {
        .read = pipe_read,
        .write = uk_file_nop_write,
-       .getstat = uk_file_nop_getstat,
+       .getstat = pipe_getstat,
        .setstat = uk_file_nop_setstat,
        .ctl = uk_file_nop_ctl
 };
@@ -329,7 +341,7 @@ static const struct uk_file_ops rpipe_ops = {
 static const struct uk_file_ops wpipe_ops = {
        .read = uk_file_nop_read,
        .write = pipe_write,
-       .getstat = uk_file_nop_getstat,
+       .getstat = pipe_getstat,
        .setstat = uk_file_nop_setstat,
        .ctl = uk_file_nop_ctl
 };