]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: F_GETPIPE_SZ/F_SETPIPE_SZ pipe capacity control via fcntl
authorTulio A M Mendes <[email protected]>
Sun, 15 Feb 2026 00:45:30 +0000 (21:45 -0300)
committerTulio A M Mendes <[email protected]>
Sun, 15 Feb 2026 00:45:30 +0000 (21:45 -0300)
- F_GETPIPE_SZ returns current pipe buffer capacity
- F_SETPIPE_SZ resizes pipe buffer (min 512, max 65536)
- Linearizes ring buffer data during resize
- Returns EBUSY if new size < current data count
- Added EBUSY errno (16)
- 35/35 smoke tests pass, cppcheck clean

include/errno.h
src/kernel/syscall.c
user/ulibc/include/fcntl.h

index 78105c910e82861a312a02fd3f20f9c9b3f95467..ec682f445537b4794b058f6f79d643f61ccdb97c 100644 (file)
@@ -36,6 +36,7 @@
 #define ECONNRESET 54
 #define ETIMEDOUT 60
 #define ENOLCK 37
+#define EBUSY 16
 #define EWOULDBLOCK EAGAIN
 
 #endif
index 46c7aa0e6790bd6289dda6e139d1983db2e36042..3cd4bf4259ea73492edfa684c8e2ea496dcf0c2c 100644 (file)
@@ -174,6 +174,8 @@ enum {
     FCNTL_F_SETLK = 6,
     FCNTL_F_SETLKW = 7,
     FCNTL_F_DUPFD_CLOEXEC = 1030,
+    FCNTL_F_GETPIPE_SZ = 1032,
+    FCNTL_F_SETPIPE_SZ = 1033,
 };
 
 enum {
@@ -1251,6 +1253,36 @@ static int syscall_fcntl_impl(int fd, int cmd, uint32_t arg) {
         return rlock_setlk(ino, current_process->pid, kfl.l_type,
                            start, end, cmd == FCNTL_F_SETLKW);
     }
+    if (cmd == FCNTL_F_GETPIPE_SZ) {
+        if (!f->node) return -EBADF;
+        if (f->node->f_ops != &pipe_read_fops && f->node->f_ops != &pipe_write_fops)
+            return -ENOTTY;
+        struct pipe_node* pn = (struct pipe_node*)f->node;
+        return (int)pn->ps->cap;
+    }
+    if (cmd == FCNTL_F_SETPIPE_SZ) {
+        if (!f->node) return -EBADF;
+        if (f->node->f_ops != &pipe_read_fops && f->node->f_ops != &pipe_write_fops)
+            return -ENOTTY;
+        struct pipe_node* pn = (struct pipe_node*)f->node;
+        struct pipe_state* ps = pn->ps;
+        uint32_t new_cap = arg;
+        if (new_cap < 512) new_cap = 512;
+        if (new_cap > 65536) new_cap = 65536;
+        if (new_cap == ps->cap) return (int)ps->cap;
+        if (new_cap < ps->count) return -EBUSY;
+        uint8_t* new_buf = (uint8_t*)kmalloc(new_cap);
+        if (!new_buf) return -ENOMEM;
+        for (uint32_t i = 0; i < ps->count; i++) {
+            new_buf[i] = ps->buf[(ps->rpos + i) % ps->cap];
+        }
+        kfree(ps->buf);
+        ps->buf = new_buf;
+        ps->rpos = 0;
+        ps->wpos = ps->count;
+        ps->cap = new_cap;
+        return (int)ps->cap;
+    }
     if (cmd == FCNTL_F_DUPFD_CLOEXEC) {
         if (!current_process) return -EINVAL;
         int new_fd = -1;
index f0db0741a03389f216b093de5c56bcc3bfb5e28c..25446460b86b8f1f8f4687b0ceb726462af65755 100644 (file)
@@ -21,6 +21,8 @@
 #define F_SETLK     6
 #define F_SETLKW    7
 #define F_DUPFD_CLOEXEC 1030
+#define F_GETPIPE_SZ    1032
+#define F_SETPIPE_SZ    1033
 
 #define FD_CLOEXEC  1