From: Tulio A M Mendes Date: Sun, 15 Feb 2026 00:45:30 +0000 (-0300) Subject: feat: F_GETPIPE_SZ/F_SETPIPE_SZ pipe capacity control via fcntl X-Git-Url: https://projects.tadryanom.me/docs/static/gitweb.js?a=commitdiff_plain;h=5da7c84576c45e7a5ecbdd65cdf9f6072edf030d;p=AdrOS.git feat: F_GETPIPE_SZ/F_SETPIPE_SZ pipe capacity control via fcntl - 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 --- diff --git a/include/errno.h b/include/errno.h index 78105c9..ec682f4 100644 --- a/include/errno.h +++ b/include/errno.h @@ -36,6 +36,7 @@ #define ECONNRESET 54 #define ETIMEDOUT 60 #define ENOLCK 37 +#define EBUSY 16 #define EWOULDBLOCK EAGAIN #endif diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index 46c7aa0..3cd4bf4 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -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; diff --git a/user/ulibc/include/fcntl.h b/user/ulibc/include/fcntl.h index f0db074..2544646 100644 --- a/user/ulibc/include/fcntl.h +++ b/user/ulibc/include/fcntl.h @@ -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