From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 D59304779BC for ; Thu, 30 Apr 2026 16:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777567302; cv=none; b=Qhx6V3pznOawCBpZqW6sjXZqPnPN8wiNnJ0L6tRYCQtdBr8KkyZhHJw51N99m71yV6pftP/Qw37LjyRwpS1ojUXdmfACf6aJfzpWqm/r9KXdOLzUlcKO9e8KCeDxU0Eu2KG+omirOmLiY7XUO9n7Rga6BcJ+aDvqg3sXMC4RIew= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777567302; c=relaxed/simple; bh=Urv1NMxqy7fqRmjv6fW3AacM+kfhc4l6HlvpHKM8Hyc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=azxwDYo/IC507TiIJtyAMfXNg/LcYp0OoWXcsDos6L5z4oi13IQKUu3UaZXOYlVvd/Jra4M2rhGDz60gpPGOb/lxtnHi4OboaJeWby/uBpck8+Jf/UADYZRj0tq6+vLGjl+dfwqiGYdBKqpNbZZR4hBgEpX06/ALCuagn1c9TaU= 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=Z3pccUkL; arc=none smtp.client-ip=209.85.215.182 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="Z3pccUkL" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-b6ce6d1d3dcso441815a12.3 for ; Thu, 30 Apr 2026 09:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1777567299; x=1778172099; 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=WYsW7L8CITDm1iPPurBgxm3JHO8q1VbtP3QHlmc070s=; b=Z3pccUkL+n10B1Zi18oJ1TPkesXoDjZ4/JbVYTgoFeAReoAglOgThco+xqmZMSf0F/ c5W1vPknOvjb4umoNch7PhlfwY7WssZ1DP4/nXwYLKE7cE+ZU6EphBo7+U5RHrxHZEZt UwiwNK7/Ew88kJhPRRmE8aTd6wg3icyXUfB/w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777567299; x=1778172099; 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=WYsW7L8CITDm1iPPurBgxm3JHO8q1VbtP3QHlmc070s=; b=LxXf0GvrDAYlpxo/06+M7qpbEQEgR+zAkPAO8KFiIOKrHEEOgjaPwHXVOYBDqnbwrs hayFFn+MWxe48ndUDunN989DFNei7QLD/qR21mr7pYHF7igmPGLA6c82FXpqXaUnuwbB W9mNao+BlLP9U4NctcCkYu4Hcyq+hNyAlrQJ50X7FYPFhDZruGWtd82TcQgWUg2zhuqN A2S8GfDf90bFpgSL60LZwRs6tmo48ZDIq7ZOvOrOcrz1IQnLf00LZ2D7q7laZq7AP36Y E7aEhCIqM2tU72pJKO7CmVBAXpWuyqJUCD7lBqnYposplAUxnnyPE/FwbAzw+Dop1uSG opsQ== X-Gm-Message-State: AOJu0YwTF2QD1J3M2pywyXfJPmoThrKy2lZ7+d3+a0HrslefwJd0Zeyb 4xDBxscGU0pLxPRPshmFchwa1ul023pOcDrv/8tPl0PY8ypgZ7VobzE3tEdmlY+llErgfjbYJ2Q dsoGY X-Gm-Gg: AeBDiev/kLiZRqkgVga2PHtFU78/eTAnXawZV/opZghoRxe88zWVNxB2+pR4gYZhxJg Andh0rcc5ZjFMSpEQ8eNw6K95QYB+sysy6sIZqVy6+f46NtCWT8dw2G8QVR6CO/7mpISyn2pDIK CnBRVGqZGAKPD8m5Zxcx4C29btP5wCqNlWG1/qQoDmC2rx8MSM5MUyEjTeCuAFrx3E1iRbnJTXJ XRIxzNPrg0G43DqzGugCt3KkZuUc/sC+QK/NRULg2qeT4h9Fhdquv2zdcBdbXvbwg1E/hPgB1OZ 0WGtlRVBuKW1qMsLeqqCLnntFW5dc04+0qa8ZaxnPR625RwZGBUSJIdoLX4hoz8Fdg3RUfg0r8E zvz8hcvmrXPgbsLGHNas5h4tMirEeH1HlgUmb8+EDb2JJ2FvR4R1ke52Gz1BLW6OwX6Z1RqHb5I HCSXILBEqumVDb5sXqdI4019Qqy56No4iwtBJOYHCROszsBdBf430UvMnF6FiMOQvLMqGdg5jPu g7SsnDf4q9SnguisDTWQf+H5uOl8YMT9OHdaA== X-Received: by 2002:a05:6a20:734e:b0:39f:82bd:298 with SMTP id adf61e73a8af0-3a3cf112d5bmr4427139637.0.1777567298834; Thu, 30 Apr 2026 09:41:38 -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 d2e1a72fcca58-83515b543b0sm130519b3a.53.2026.04.30.09.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2026 09:41:38 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v3 1/2] tools/nolibc: fcntl: Add fallocate() Date: Fri, 1 May 2026 01:41:24 +0900 Message-ID: <20260430164125.1106350-2-daniel@thingy.jp> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260430164125.1106350-1-daniel@thingy.jp> References: <20260430164125.1106350-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 | 33 ++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 8 ++++++++ 3 files changed, 52 insertions(+) diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-mips.h index 1400653c76c1..e4e42f2bcaf4 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" @@ -256,6 +257,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 014910a8e928..dbc99188a49e 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]); */ @@ -80,4 +83,34 @@ int creat(const char *path, mode_t mode) return open(path, O_CREAT | O_WRONLY | O_TRUNC, 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 offset and size, 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 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" +/* + * 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.53.0