From mboxrd@z Thu Jan 1 00:00:00 1970 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: 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 | 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-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..cea5fec66aec 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,32 @@ 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. + */ + if (sizeof(__kernel_long_t) != 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" +/* + * 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