From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 313F638D6A3 for ; Fri, 17 Apr 2026 11:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776425194; cv=none; b=kFyK0C/+2lYObl0YvAm8+i9GquDcr0fVnt/X/zqZ7lx9oaB2O7Z/R+QbY2eHSBmDpVB0gkY/2n32Jav5Vz60XG+emgNjNt612nBdcXDgi/0JauVqCQMbrx3sAII5/xKbZM/0O6rZXeoDqpDYeUov2G80DQs82iagwbe+RTJiJUs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776425194; c=relaxed/simple; bh=XWxbxly3C05WxnzOggJ3XL4kQdJP1qReZkFpEQ5thDU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A8e1Z6an5iyN+/xmQ3DDVu2ucgMk2T3UH5n8c0zG43X58zpHEBtrXCko6diN9p5krXnRTOBkYd+836rIJ1tGCJHReE9ZIjZRupaYwBZLwCK0PYpX17d0aUAatDB+reENaNDQLAs8q/GADiQmTbgaJjLz1bppwjbj0Aq/ou6PWaY= 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=g5mMZ+S7; arc=none smtp.client-ip=209.85.214.176 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="g5mMZ+S7" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2b2429f98d0so3032275ad.2 for ; Fri, 17 Apr 2026 04:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1776425192; x=1777029992; 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=3F+FS0a+dkWq0VvcunVsHxcOiTsK17K0BF2llo9C6Xg=; b=g5mMZ+S723bqWnfUL0PhNplXdpZ1F3K9lxWnmahO+nLe2TClP6RmxX8b44of6l+DWN uRynbMO10CSFnZuPo1AtQttNXzRJGm3Vl5MUq5GiFcyOuHd/CIwvY+ukdsoQC93JQZXl PRGXwN+Bxvyhl7QOis6BWb5BleypFWwmgBx68= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776425192; x=1777029992; 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=3F+FS0a+dkWq0VvcunVsHxcOiTsK17K0BF2llo9C6Xg=; b=kBCKoN5AfS10hD9Je3lZrHS2MOPTqer64kIeg2bc//osU/Zzqxxabh59I+Pup8OESt G4iAmYscRTTSYxHw4rBVDIoqaIcVFpox2/Gfci0ybKO+5tYNRq+/cIjzfiE8n4ORM0Kb JIVKvdGABlZwTNd9pGVAlGFh2C2PseGVlOibcKa5OPlyrdjSLhSx7RuSNfjnQQlb9tZU Av8UsOi/3AfWZ2YHHMb4thMdUfA+Qh9yK23bdQQwe22lbsHBCop9/m6i4pbOZn7KBlpq z39KarNJskjf8GZwT4UeALYLYKT2sekhqH5FThDoswBux84hdHpH9tHvH9JtdfVzF+m9 KFtQ== X-Gm-Message-State: AOJu0YxSgh4uzTTQhbtvbdxq5/KmqYg8utd0zSIWzi1arMOp4kDmU46Y OUR1E9bZcGZrrLCqLJkpyGztpSvgRHo0GLWAO8oOno7p0s9hMsrnSK9u7wOyVmwWY3g= X-Gm-Gg: AeBDieu3RD2bRUZ1sOjFy5+lJYDzBPmLbwMg1iBjEMLxzCyks2/fr0pCfPfEBd98fG/ pvEiQ+rH79rKEbpH3yB81jE5R0DPXknaUTJToXpf04RmoF59ao8N88Q8Pqij0i8V10fz/IGC8Nt 8iEmVWSLejN8u6SX9Mv6yGUnQtmFr/ep4c3o08cCID73WksjPUovTmhc2Ui4ODR8FSWY2LcpMey M2mlJ9yepj/Knl2hEY2Y/UvP7DFfB66sUfhnNfMX1HjDDEtmk0HMJaTpEJluiX9QoCDy0DVedxZ a8wWT2YC47ar8jZS3uE9rbzI6+zd34SAclkHTZzV6SVaMdEjJCAxcZ9o6FO/Z5ZJULkSPll7qi1 pV6hCzmYR06xNrb9GGfzH0Ey84QgNPp/K9uilSWPtutFkORNhbimYZOJzMa/RgNcj7miRAtrQdI FlAPJVOsLhDacnGhBowkfZYZKzDr8xeL977Om+zJL3w8YqHcEezeWts+pWXAA/2D5L0Uty5iw4i 85C7CSHG64zZRgL6db0HX8k X-Received: by 2002:a17:902:b697:b0:2b0:9a61:9e9 with SMTP id d9443c01a7336-2b5f9f61d3amr19886395ad.32.1776425192438; Fri, 17 Apr 2026 04:26:32 -0700 (PDT) Received: from kinako.work.home.arpa (p1329195-ipxg00a01sizuokaden.shizuoka.ocn.ne.jp. [114.145.5.195]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2b5faa2e5cesm21407035ad.25.2026.04.17.04.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 04:26:32 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v2 1/2] tools/nolibc: fcntl: Add fallocate() Date: Fri, 17 Apr 2026 20:26:21 +0900 Message-ID: <20260417112622.1182216-2-daniel@thingy.jp> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260417112622.1182216-1-daniel@thingy.jp> References: <20260417112622.1182216-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: 8bit 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 --- tools/include/nolibc/arch-mips.h | 11 +++++++++++ tools/include/nolibc/fcntl.h | 32 ++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 51 insertions(+) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index bb9d580ea1b1..2c5cda632911 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -6,6 +6,7 @@ #ifndef _NOLIBC_ARCH_MIPS_H #define _NOLIBC_ARCH_MIPS_H +#include #include "compiler.h" #include "crt.h" @@ -252,6 +253,16 @@ _arg4 ? -_num : _num; \ }) +/* 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 */ #ifndef NOLIBC_NO_RUNTIME diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h index ed2f5553c65a..e65be2f84cbd 100644 --- a/tools/include/nolibc/fcntl.h +++ b/tools/include/nolibc/fcntl.h @@ -14,6 +14,9 @@ #include "types.h" #include "sys.h" +/* For fallocate() modes */ +#include + /* * int openat(int dirfd, const char *path, int flags[, mode_t mode]); */ @@ -66,4 +69,33 @@ int open(const char *path, int flags, ...) return __sysret(_sys_open(path, flags, mode)); } +/* + * 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 it for 64 machines we can use the values as-is + */ + const bool offsetsz_two_args = sizeof(__kernel_long_t) != sizeof(off_t); + + if (offsetsz_two_args) + 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 6335fd51f07f..4f4491af9426 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -29,6 +29,14 @@ #include "stdarg.h" #include "types.h" +/* + * Helper for 32bit machines where a 64bit syscall arg needs to be split into + * two 32bit parts while making sure the order of the low/high parts are correct + * for the endian: + * __NOLIBC_LLARGPART(x, 0), __NOLIBC_LLARGPART(x, 1) + */ +#define __NOLIBC_LLARGPART(_arg, _part) \ + (((union { long long ll; long l[2]; }) { .ll = _arg }).l[_part]) /* Syscall return helper: takes the syscall value in argument and checks for an * error in it. This may only be used with signed returns (int or long), but -- 2.51.0