From nobody Sat Jun 13 13:03:07 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C219359A6B for ; Thu, 7 May 2026 09:04:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778144658; cv=none; b=nXHwN+Z25SYyNxokoRHkraHPjxIywTDMrksgizPFRoD2jlk5kNFxWOK9dOFF3qc8JefKhVoZ4T8FsLD39khHtpddZ3yZVhr0o1pfOsyILqQuXTTjmRy4KzkoXK7ra+dIYpPTeF7juflIaBBMwG619ZLRYu/UvT/n/Pmn04gKjKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778144658; c=relaxed/simple; bh=pUMqjLcMLZlZUbd8R8Usq4iQ1A+UwzDBJHW1ax7OSa4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KVbEI8NRcohZ9/FSHXVBPcwv5dte5Mtzc2giaNSIVzFYq0xs1W4sVLWn50JfoghDXCCttYkQ7rs5lsZz8FMXMbLTT80cuXJ6lL88hx31TJIfITCO2iP8KosMO5SZRcY/y2Q/g4g3YTfLvMxH5GSyi7hGas9obfm2Fc7pWkR5Hjs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=jVGg4xe9; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="jVGg4xe9" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2ba6485d219so4003155ad.3 for ; Thu, 07 May 2026 02:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1778144648; x=1778749448; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/Q3iF41b1ecSQ2/0R94h0am6le7T8jhnSGIzF13noeo=; b=jVGg4xe9lx7CSoIwPGy4z+pbt3PdxxIbMUYWOkC1KK17DPzGuqulllx/xg7GGdSy+P 81Lus6/+/ZRuBr+z0teBs6KyQbkQlIxUS75FWAmyx7EgBkRdkgH8yRwrAnk39y6DzNj0 VejlnfJQ3diX27Llh7yBC242GyPJMWsKEgi3M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778144648; x=1778749448; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/Q3iF41b1ecSQ2/0R94h0am6le7T8jhnSGIzF13noeo=; b=FxISxq5uqSgar5n+5d5t+r1fPCevEGJGIRADgaNUtwo+TICfR97GTuTjm9lXld+S/9 eP8U90FwPlq7Iz4tkz/dAtBYH/xjvk+R2nI9Dffeufsisr3657RL3g2f+uLkz8Xqv+jK 1CY1jFqGTBeDbDu+rgFfKQ3fZ+t0fhaLlMyy17YZn1v2U/5dZNgfueOh9ZQaEYD36eF9 eJuVcyzUKTArt57fO2i5jbtQWsxX0Ia1Z6QXFUwjLp3F1GvWq51XpSxGDMtZ/E16Vup4 qTskIVo/Kwrqy8Kc0fOohizncrbp5AlecM3qHw2PpxKDe85J8rdlAVMCab3QoQoPJrTa YABQ== X-Forwarded-Encrypted: i=1; AFNElJ+6jdqlKWeo9G1qkqEVj31LyKKM/l3/e+h2BG19/9mQIeOFUcVJGA9f1tUplJglfJVtKxKOcZsaLwWD8EA=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/eGQszGwjaN0AUF6VEojJm1mcx1yCimITvXFZvXB2R8bqPGS9 DVtzGIwc7fjgAhd1NSResh5qWRwKKEM7R9u8iztKwhgH6MuEj4sE42B45CMsFzdxBTw= X-Gm-Gg: AeBDiev50XFZISyjeD6jiFLtyKcbU6z/TF2aGZxMG5iSZmi7/YOUUf6IMjKssk6Bbqs 325Vr2j3FXAvUxLR4EhDHRLxXakty5e8Z5AwQo68WIZ9G5v488uhVrEe5MyP9zttLFm87p8HNDn WLKi1QyEGWt7ADR87E5ZAtn1PUdWpMaGrhw/r3FOyuPfg4ePrRf+ZsxdJ3MhX1VyHMKSA0vt+Ph bONhQv4jdKTWDr0e+GWX9T30WQvzkZ2bKVuZxHVoHqP4dRvcITl/6UNzzHM7/J0etxpaio+om2t K9swdIw0VaKMCMHpSkiSCGuFrg09HDk6uR+HZRkeHWJvRAZZAHmsweOTtnVq8446EELoH89h+Xd ikyJuiqX9AsCUgpNtzS/ePG2mlhiZf1SO51matdQuF2FQ4XFv1caueYh/DGMY2UCI3zxuoQqqyh 965PUCJ65davOgWiMerTCgmByp8xkA3HuccrFCx2S45vSX8x/ypOhXE9F6fjyKtLOw6bz3EcplO 25pEJC0nQ3VqNZM1ORPnFeDgLk= X-Received: by 2002:a17:903:8c5:b0:2ba:60a:3105 with SMTP id d9443c01a7336-2ba78f7812fmr76006105ad.9.1778144648470; Thu, 07 May 2026 02:04:08 -0700 (PDT) Received: from kinako.work.home.arpa (p1387170-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [153.221.239.170]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2babaac34a4sm20061215ad.16.2026.05.07.02.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 02:04:08 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: david.laight.linux@gmail.com, linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v4 1/3] tools/nolibc: fcntl: Add fallocate() Date: Thu, 7 May 2026 18:03:51 +0900 Message-ID: <20260507090353.356764-2-daniel@thingy.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260507090353.356764-1-daniel@thingy.jp> References: <20260507090353.356764-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add fallocate(). Some special care is needed to put the offset and size into the syscall parameters for 32bit machines, x32, and mipsn32. For x32 we can just check if the kernel long size is the same as off_t and use the same path as x86_64. For mipsn32 we override the generic version and provide one that does the right thing. Signed-off-by: Daniel Palmer Acked-by: Willy Tarreau --- tools/include/nolibc/arch-mips.h | 11 +++++++++++ tools/include/nolibc/fcntl.h | 31 +++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 50 insertions(+) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index 1400653c76c1..e4e42f2bcaf4 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -6,6 +6,7 @@ =20 #ifndef _NOLIBC_ARCH_MIPS_H #define _NOLIBC_ARCH_MIPS_H +#include =20 #include "compiler.h" #include "crt.h" @@ -256,6 +257,16 @@ _arg4 ? -_num : _num; \ }) =20 +/* The generic version of this will split offset and size for _ABIN32, + * override it and do the right thing here. + */ +static __attribute__((unused)) +int _sys_fallocate(int fd, int mode, off_t offset, off_t size) +{ + return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); +} +#define _sys_fallocate _sys_fallocate + #endif /* _ABIO32 */ =20 #ifndef NOLIBC_NO_RUNTIME diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h index 014910a8e928..cea5fec66aec 100644 --- a/tools/include/nolibc/fcntl.h +++ b/tools/include/nolibc/fcntl.h @@ -14,6 +14,9 @@ #include "types.h" #include "sys.h" =20 +/* For fallocate() modes */ +#include + /* * int openat(int dirfd, const char *path, int flags[, mode_t mode]); */ @@ -80,4 +83,32 @@ int creat(const char *path, mode_t mode) return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode); } =20 +/* + * int fallocate(int fd, int mode, off_t offset, off_t size); + */ + +#if !defined(_sys_fallocate) +static __attribute__((unused)) +int _sys_fallocate(int fd, int mode, off_t offset, off_t size) +{ + /* + * For 32 bit machines __kernel_long_t will be 4, off_t will be 8 + * and we need to split offset and size, for 64 machines we can use + * the values as-is. + */ + if (sizeof(__kernel_long_t) !=3D 8) + return __nolibc_syscall6(__NR_fallocate, fd, mode, + __NOLIBC_LLARGPART(offset, 0), __NOLIBC_LLARGPART(offset, 1), + __NOLIBC_LLARGPART(size, 0), __NOLIBC_LLARGPART(size, 1)); + else + return __nolibc_syscall4(__NR_fallocate, fd, mode, offset, size); +} +#endif + +static __attribute__((unused)) +int fallocate(int fd, int mode, off_t offset, off_t size) +{ + return __sysret(_sys_fallocate(fd, mode, offset, size)); +} + #endif /* _NOLIBC_FCNTL_H */ diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 33f9c970ae57..b7136a3a7d6a 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -29,6 +29,14 @@ #include "stdarg.h" #include "types.h" =20 +/* + * Helper for 32bit machines where a 64bit syscall arg needs to be split i= nto + * two 32bit parts while making sure the order of the low/high parts are c= orrect + * for the endian: + * __NOLIBC_LLARGPART(x, 0), __NOLIBC_LLARGPART(x, 1) + */ +#define __NOLIBC_LLARGPART(_arg, _part) \ + (((union { long long ll; long l[2]; }) { .ll =3D _arg }).l[_part]) =20 /* Syscall return helper: takes the syscall value in argument and checks f= or an * error in it. This may only be used with signed returns (int or long), b= ut --=20 2.53.0 From nobody Sat Jun 13 13:03:07 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7D2039936F for ; Thu, 7 May 2026 09:04:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778144660; cv=none; b=arUntws8Jgr8C6IwaiGm6APB29UGR0O1XWsDl2YmkvVrYa1imbZMpINKZgx0n43Y8y9NXWeg5/A8tvMgMw7//QY+8Mb5kZvvpPALwlVjswml+jLLXj6o1HpgGQiyyobk30IbyD7pGIiZp5Se69VQInBMZMLsoPHud0tjrhyQMVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778144660; c=relaxed/simple; bh=M5yvFofCO1qUwRq5bzr1fKlvLrGSOVFir3TJ+NpHObQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PylvA4Qo1Ix6m4w4mdHa16K9LumtQ8lh95be1tH/C5ivfWR1NjJ+Ry7oog/BsCpWZ/v7N7dhm3WynLVFaPm3M7IDrX+mEFDZ2HhYiNN2kKJiPHWbKwGUq3sckNZzGrFWBPGYKOwfpGUP9nd12GNcNYlOROPpIFq2XXZ5fS+GYFM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=JgKhwaWQ; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="JgKhwaWQ" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-365312a27abso626216a91.3 for ; Thu, 07 May 2026 02:04:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1778144650; x=1778749450; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uK+GPzkOujW5xDT5KKGwstDaPPTKsXO9ffI7RkE7Sv8=; b=JgKhwaWQ1k7D/qgW1ng002DzUtynT5xC2hH2YkCaEQzAsf9RYrF3mYZucJYCbf6k0b NKAYfMIz2Q+fjuAzlhSMaPoRScUx1nJg/WmU5dixF7OGFO/TE26SsSHuyk2c1t+GtcIr YT1vcqYlGb1ZEbDqr8hN+Z6Gr1RRSIeyP/WMM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778144650; x=1778749450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uK+GPzkOujW5xDT5KKGwstDaPPTKsXO9ffI7RkE7Sv8=; b=Awi1A1FolxhT6YyKDog7UO11AgEncrcf/n38Bg+a0m1NrgWcywj3SbEEvMvBECU+fs OYKLTmLNuEtxg4iEhAJMhZGSjM3tG/cC4GgSZL0PW4fVEZSGK0XUX/NjnZHLQ8A/MRpp V59YRUM3uPaHa65pBjjWh68BOtv0DO+DyjiGJFkssfVvZdjCpOlYtMfl/zusPFImxTyU hf2yxM8SavYnnH8BHUWA65hyvxLYiAtAKq9zYAEX+wjnAce48P1f9+zpvlb+jrYJ59Sl B/lvnweSxvyKmzn0Hr6jQMd3jOAEZlRhz6IEO8Rvc3M3UC/lK4jSecAR5+ymWl//G2EF TPVA== X-Forwarded-Encrypted: i=1; AFNElJ8PBYW8iPETJxD5zVYmHbzCqiNIyZ2sO2WHpIEPjg+GsnxWdxGVBtqCxF8hADpS0PgLLOs5u1t7np0O1oc=@vger.kernel.org X-Gm-Message-State: AOJu0YzLbZk3giNDQA2E0nuVGijxk3sUw+FmkUN/ixh393ZqxWdRyf90 S8vkIMQlI48kNxuU5rGjV0AI/vIjoHN/Nm4DCu6y0or1zRcthL/Vr+Cxa6RYVbzVUlvEye/NKi9 jtFB+ X-Gm-Gg: AeBDietkzj8cFPJ5R6qW/TG39S70CwEMBUQ/J8VulpoiCmH1cqEspdbZGAcIO1T9Fb+ z4/oxE72FoK0H/Ndy2W/IOyRXIpmms0oq5N1pU/r5T3ZjfHrtcoFjBBVqg3dBkLa+WV2DIvTy/q a0MT4539/fp1hlGA5o0sRuSt5QWKUyJTJHF8decNBSJAelVr5vkl2mdcxF7kYybfnEd/1iESCCc CCoh9W+5aPOUtN1ZJRODOfBiFLsTpoBGA2ExXvSuKTEBoiHYrwvinzbCaDUpjc80PDrS6ved3HQ DObjabl7AHEtFGESgSXr7IAkjARt4suBXNUNi7TLMyJZGCOjiSrPsrctSFM4o2C+WkGUuUjBior R/AnHHCSFdjYufPbp1T5tM0OgYRKLAKgfb8IAQj3inlvSBLd9dwIdn0vAg0ZMTgt+WQ5sKy8Tbi psq/nkz86lmc+jfiZ8OZ3hRrzTZEW+DeZA5rmiiCcXnt2yM/obivYGUndpGwqDCq27/NOpPx5Xo nZp3quZr7y/WeBNoyDfrs1qU8E= X-Received: by 2002:a17:903:44cb:b0:2b9:5d1b:73da with SMTP id d9443c01a7336-2ba798aac9cmr54034565ad.30.1778144650010; Thu, 07 May 2026 02:04:10 -0700 (PDT) Received: from kinako.work.home.arpa (p1387170-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [153.221.239.170]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2babaac34a4sm20061215ad.16.2026.05.07.02.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 02:04:09 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: david.laight.linux@gmail.com, linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v4 2/3] tools/nolibc: Add statfs() Date: Thu, 7 May 2026 18:03:52 +0900 Message-ID: <20260507090353.356764-3-daniel@thingy.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260507090353.356764-1-daniel@thingy.jp> References: <20260507090353.356764-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add statfs(). Signed-off-by: Daniel Palmer Acked-by: Willy Tarreau --- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/sys/statfs.h | 50 +++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tools/include/nolibc/sys/statfs.h diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile index 00fd2e566d75..e6281f58e6e2 100644 --- a/tools/include/nolibc/Makefile +++ b/tools/include/nolibc/Makefile @@ -60,6 +60,7 @@ all_files :=3D \ sys/resource.h \ sys/select.h \ sys/stat.h \ + sys/statfs.h \ sys/syscall.h \ sys/sysmacros.h \ sys/time.h \ diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index faa94f247281..425cf87befdc 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -107,6 +107,7 @@ #include "sys/resource.h" #include "sys/select.h" #include "sys/stat.h" +#include "sys/statfs.h" #include "sys/syscall.h" #include "sys/sysmacros.h" #include "sys/time.h" diff --git a/tools/include/nolibc/sys/statfs.h b/tools/include/nolibc/sys/s= tatfs.h new file mode 100644 index 000000000000..26976ac2e94a --- /dev/null +++ b/tools/include/nolibc/sys/statfs.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * statfs for NOLIBC + * Copyright (C) 2026 Daniel Palmer + */ + +/* make sure to include all global symbols */ +#include "../nolibc.h" + +#ifndef _NOLIBC_SYS_STATFS_H +#define _NOLIBC_SYS_STATFS_H + +#include "../sys.h" + +/* Some preprocessor hackery to get struct statfs to + * always be the 64bit one. + */ +#define statfs __nolibc_kernel_statfs +#define statfs64 __nolibc_kernel_statfs64 +#include +#undef statfs +#undef statfs64 + +#ifdef __NR_statfs64 +#define statfs __nolibc_kernel_statfs64 +#else +#define statfs __nolibc_kernel_statfs +#endif + +/* + * statfs(const char *path, struct statfs *buf); + */ + +static __attribute__((unused)) +int _sys_statfs(const char *path, struct statfs *buf) +{ +#ifdef __NR_statfs64 + return __nolibc_syscall3(__NR_statfs64, path, sizeof(*buf), buf); +#else + return __nolibc_syscall2(__NR_statfs, path, buf); +#endif +} + +static __attribute__((unused)) +int statfs(const char *path, struct statfs *buf) +{ + return __sysret(_sys_statfs(path, buf)); +} + +#endif /* _NOLIBC_SYS_STATFS_H */ --=20 2.53.0 From nobody Sat Jun 13 13:03:07 2026 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C28D38F248 for ; Thu, 7 May 2026 09:04:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778144660; cv=none; b=Jw9uy7Fn7HU+GuLAXX1aAq1I3rtS1YRh4chTui8PFRnYXjmHCNE+/G1eim8MMLLmXYL6j7OTMQ+yLM/oVQOoHCwL3wxdjevRgIjcENpSs/w8RmZUJQOFXIZ794ThXATwHXcEW385PbA3F4EGloNgSMDETwMKzPsyapdNCqU4i/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778144660; c=relaxed/simple; bh=aNoEqGApD+eAjWkTOz/lXdtBlXoEuUexshsIqjlwc/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L83UXVAx35TM3JInkvLoChVDtjEmwd8/w+tCqgTLINLNcP/wvfcseRSy1HMX5Uh3c5Frj0MsKmOdJO0OOL9siUd6wWWPQ/u+elmzo/TkBBNpJkdcmrHcnvQjMh/WtzAH1mOXmx8KJc4zdZTkEDT5LMbZ0DvDKIITADMW7tO7MUI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp; spf=pass smtp.mailfrom=0x0f.com; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b=pA7eiE7D; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=thingy.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=0x0f.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=thingy.jp header.i=@thingy.jp header.b="pA7eiE7D" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-365312a27abso626237a91.3 for ; Thu, 07 May 2026 02:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1778144651; x=1778749451; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RE2b5bv8drxMPZvWvisFxWNHfnllHA18/fcjXacN4ZQ=; b=pA7eiE7DU3GLuJ9RiaWolhsiK6cdHa9otI7IGWoqcJUpKNKaKIz+LXoIm3iigxww+m uZ3SRMUDyUBFT1D79JJnMSbbqt8yS4Yv3jo+g8E0X9YABxDTDKxi+pypPA2p5xfOBvKY uGNYNWn0lBxUw/IuZ89Vt7qmhJK8wajRZ2IoE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778144651; x=1778749451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RE2b5bv8drxMPZvWvisFxWNHfnllHA18/fcjXacN4ZQ=; b=T8iOygpX4hMRSdT4cJZADOZm6bjlBG1UyhozIVL/HKiNGdeMmRQU2swsu3T7AcoPNW RW1JcRPDJvhPeVVENwEYzYS+9Io16D/djj/r4yHOcP2//WtWUtAkr1+sWLkMbQqF6zPC cyGi66C0LYJmxVicVZU+b8Ym9v4c3v0/zPiCObb+vZtAlzW3BoJ7bDdsqt+G6FeqQE4W IWHkzvdb9bG/n9e0CAR4+zmwV92DQttDqU2nUC8oXGIegiigG4bH4FJKhpol0IuNtNmU FWnxdtGZgdx4ivUSmg/CfOj2Z2XOygQB9a07Y3U4ASQnmXG6ID0dDZrnfwMg2eXLfxEJ S/bQ== X-Forwarded-Encrypted: i=1; AFNElJ+MJKXGOO0CYvrHFM4Bd/r46Wn6guXz0krpHDGuf5ncRYjEqwEjhDtWUUTK8lMq46XQVPcp1XLPWWFzsT4=@vger.kernel.org X-Gm-Message-State: AOJu0YwZxiAXX9qVrzsyXqtSF8wY3G/SgXEYk+NkpJxQBXwJSe3lx+H+ 1x4sk8z3c5oH/3mbbXeVEgcpqYJevdgmi4B/iFoyW9tzxpr8m3iOuC1d3AqFlaLvTw0= X-Gm-Gg: AeBDiet8j8Eug775/kjUvzNt5vQfe9QN3OwFJPgA2qwa/Hw1wrhohklUG2dUxHeInE7 vxRHPP1bwFQ+QZrCVg5TQfQCw9ZSv/sqC+JOqJ2hZ/zdStImKcxzg2/ilUH2x2JrxE/+MhAI6LC /yA3KEi7wUrgJRDNKWULsDMJpxCgXasT4/uG336gcqGDEcwTHmLJ6t8zDdev0SU15GlUoGmU2sf AuU9f9ThwwzBE7kUMTSbEazd4avzH8Upbvs6S6ozt9ZNeM4eGakThkJ9SHY4/iqtxSr3RPReyqC E6wU3INarjGh/jZVClcCjE8IhC0tgTRt14O+kY3TRNnkw/yWWrN6/3NtCKGzfmhdWE4xee2Ih8S BF8+vzsmWeek4eTwgKHNrB6TwIurmiDzrBBBEdoaMJgO+XNs8s6jAw7UIlzCXSKgqSGH/zArk5J I5fmyqLv1jOpvZXgbFZ6Mmyw7PLpZ2suOJebM55AaXOx33SBqnvwQDBxlSA+DmcJnCF/7UMOCwc PkdM3hLJWN0ncSgofdo5mDulOk= X-Received: by 2002:a17:902:fc8b:b0:2b2:4eec:9806 with SMTP id d9443c01a7336-2ba78b48751mr45472395ad.8.1778144651429; Thu, 07 May 2026 02:04:11 -0700 (PDT) Received: from kinako.work.home.arpa (p1387170-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [153.221.239.170]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2babaac34a4sm20061215ad.16.2026.05.07.02.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 02:04:11 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: david.laight.linux@gmail.com, linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v4 3/3] selftests/nolibc: Add a very basic test for fallocate() Date: Thu, 7 May 2026 18:03:53 +0900 Message-ID: <20260507090353.356764-4-daniel@thingy.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260507090353.356764-1-daniel@thingy.jp> References: <20260507090353.356764-1-daniel@thingy.jp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 1: Create a tmp file, fallocate() to make it a bit bigger, check the size is what was expected. 2: Try to fallocate() (1 << 20), this should work. 3: Try to fallocate() (1 << 52), this should cause ENOSPC or EFBIG. 2 and 3 are basically to make sure if the offset or size are split into a pair of registers for the syscall that we are passing them the correct way around. This test requires /tmp to be a tmpfs and not ramfs or something else so before running the tests check what /tmp is and if its not tmpfs skip the test. Signed-off-by: Daniel Palmer Acked-by: Willy Tarreau --- tools/testing/selftests/nolibc/nolibc-test.c | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index 1db6e8d55c16..2a3b855214bc 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -48,6 +48,9 @@ #include #include =20 +/* For TMPFS_MAGIC */ +#include + #pragma GCC diagnostic ignored "-Wmissing-prototypes" =20 #include "nolibc-test-linkage.h" @@ -903,6 +906,66 @@ int test_getpagesize(void) return !c; } =20 +int test_fallocate(void) +{ + struct stat st; + int fd, r; + + /* Create a new tmp file */ + fd =3D open("/tmp", O_TMPFILE | O_RDWR, 0644); + if (fd =3D=3D -1) + return -1; + + /* Expand it to 42 bytes */ + r =3D fallocate(fd, 0, 0, 42); + if (r) + goto close_tmpfile; + + /* Get the new stat */ + r =3D fstat(fd, &st); + if (r) + goto close_tmpfile; + + /* It should be 42 bytes long */ + if (st.st_size !=3D 42) { + r =3D -1; + goto close_tmpfile; + } + + /* Now try to allocate 1MiB. This puts a single bit + * into one of the registers if the size is split into + * two registers. This shouldn't fail if the bit is in + * the correct register. + */ + r =3D fallocate(fd, 0, 0, (1ll << 20)); + if (r) + goto close_tmpfile; + + /* Check a massive size that puts a single bit into + * the other register if splitting. + * This should return an error and errno =3D ENOSPC or + * EFBIG indicating the value was passed correctly but it + * was rejected. + */ + r =3D fallocate(fd, 0, 0, (1ll << (20 + 32))); + if (r !=3D -1) { + r =3D -1; + goto close_tmpfile; + } + if (errno !=3D ENOSPC && errno !=3D EFBIG) { + r =3D -1; + goto close_tmpfile; + } + + /* Test passed */ + r =3D 0; + +close_tmpfile: + close(fd); + + return r; +} + int test_file_stream(void) { FILE *f; @@ -1455,6 +1518,8 @@ int run_syscall(int min, int max) void *p1, *p2; int has_gettid =3D 1; int has_brk; + int tmp_is_tmpfs =3D 0; + struct statfs tmp_statfs_buf; =20 /* indicates whether or not /proc is mounted */ proc =3D stat("/proc", &stat_buf) =3D=3D 0; @@ -1470,6 +1535,10 @@ int run_syscall(int min, int max) /* on musl setting brk()/sbrk() always fails */ has_brk =3D brk(0) =3D=3D 0; =20 + /* Check if /tmp is tmpfs */ + if (statfs("/tmp", &tmp_statfs_buf) =3D=3D 0 && tmp_statfs_buf.f_type =3D= =3D TMPFS_MAGIC) + tmp_is_tmpfs =3D 1; + for (test =3D min; test >=3D 0 && test <=3D max; test++) { int llen =3D 0; /* line length */ =20 @@ -1512,6 +1581,7 @@ int run_syscall(int min, int max) CASE_TEST(dup3_0); tmp =3D dup3(0, 100, 0); EXPECT_SYSNE(1, = tmp, -1); close(tmp); break; CASE_TEST(dup3_m1); tmp =3D dup3(-1, 100, 0); EXPECT_SYSER(1, = tmp, -1, EBADF); if (tmp !=3D -1) close(tmp); break; CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0]= =3D "/", [1] =3D NULL }, NULL), -1, EACCES); break; + CASE_TEST(fallocate); EXPECT_SYSZR(tmp_is_tmpfs, test_fallocate(= )); break; CASE_TEST(fchdir_stdin); EXPECT_SYSER(1, fchdir(STDIN_FILENO), -1, = ENOTDIR); break; CASE_TEST(fchdir_badfd); EXPECT_SYSER(1, fchdir(-1), -1, EBADF); br= eak; CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break; --=20 2.53.0