From nobody Sun May 24 19:36:18 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45D853DF00F for ; Thu, 21 May 2026 17:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779384721; cv=none; b=qnO8m9AaLaNNuER8/8nKbfYvkFzOlwD8CNagd77ZBXeZqVGuuUjFkZq1fft/7yolB10rK2d71VUb1AZWy9iKU/6H0blWAW4yaMtGfY6tV9p98B8NkmdZdyARZ9jhd8SI44OtarpiB/8sk59NvA9R+NuW7QLAebpVxLRydjkxfAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779384721; c=relaxed/simple; bh=6D+1eMfZ00vXijyRgOHBJCzIFj/TACnFkGYaVvki2oc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qEcSHVfpZcb3zFms90wk2HqDFyoaCJGTzoLvkub2oe2MPv+NQ6jdCZeXJ+C99TvfBQrkfEdGsv4U1wY3zSGahFJMBXPH3hII9EP+rT+Rxd0VKSU3017W/4dTaX5jcvq6RbLg4P2KGkQw6sWewR7N1CBxW5eDRIlKHOhR2A1hHjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=iU1leeVu; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="iU1leeVu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1779384717; bh=6D+1eMfZ00vXijyRgOHBJCzIFj/TACnFkGYaVvki2oc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iU1leeVuYqs3rDkBj46hTEsfORqvIstc35SIRXwXjNdh7gP5IAWiF0cKv/wf8Odl+ p1BqDWQmAQ5O1QQ9qo/xJXwIXguBtIgIPXQwmDD8rc2LnaxSwxKgloxzZtOoUziIOa 1q05g8CQV4ivub0GH/qhqQsiRw31t6Rhsz8hGtb0= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 21 May 2026 19:31:02 +0200 Subject: [PATCH 1/3] selftests/nolibc: enable CONFIG_TMPFS for sparc32 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-nolibc-ftruncate-v1-1-5384a83b2402@weissschuh.net> References: <20260521-nolibc-ftruncate-v1-0-5384a83b2402@weissschuh.net> In-Reply-To: <20260521-nolibc-ftruncate-v1-0-5384a83b2402@weissschuh.net> To: Willy Tarreau Cc: David Laight , linux-kernel@vger.kernel.org, Daniel Palmer , Jordan Richards , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779384716; l=963; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=6D+1eMfZ00vXijyRgOHBJCzIFj/TACnFkGYaVvki2oc=; b=SAnyyggAPq+f+2Qk7r4mn/NJdeUGhvK5jDcf2InQiuVg50TfoIAS60eJMLNrMGRmdeYMJfvCX e47e48lPWhnBl26KZIeznatCMnF0e3uVu3Vwni/vtMGTp4kbDns4nbP X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= An upcoming selftest will use memfd_create() which require tmpfs. Enable that. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by is for maintainers to use on changes within their subsystems. Acked-by: Daniel Palmer Acked-by: Willy Tarreau Reviewed-by: Daniel Palmer --- tools/testing/selftests/nolibc/Makefile.nolibc | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing= /selftests/nolibc/Makefile.nolibc index c6dcd54078f2..06f881e2e90c 100644 --- a/tools/testing/selftests/nolibc/Makefile.nolibc +++ b/tools/testing/selftests/nolibc/Makefile.nolibc @@ -109,6 +109,7 @@ DEFCONFIG =3D $(or $(DEFCONFIG_$(XARCH)),def= config) EXTRACONFIG_x32 =3D -e CONFIG_X86_X32_ABI EXTRACONFIG_arm =3D -e CONFIG_NAMESPACES EXTRACONFIG_armthumb =3D -e CONFIG_NAMESPACES +EXTRACONFIG_sparc32 =3D -e CONFIG_TMPFS EXTRACONFIG_m68k =3D -e CONFIG_BLK_DEV_INITRD EXTRACONFIG_sh4 =3D -e CONFIG_BLK_DEV_INITRD -e CONFIG_CMDLINE_FROM_= BOOTLOADER EXTRACONFIG =3D $(EXTRACONFIG_$(XARCH)) --=20 2.54.0 From nobody Sun May 24 19:36:18 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA4E36F8F0 for ; Thu, 21 May 2026 17:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779384721; cv=none; b=UEidKjjew7+fB8JHEAH5za0nJstqwcEGud6ooyYwcZDZVMpIGaPZ9nrHngfgb88QR3NYFzAqw9vGIopIF8cUFMEpp1ehTCuyZOWW0xL6U2RqMSG5QDS7/Y19uyld6dZbIUNqjq2S/qNYMFDibBRHImJ5/vKKOuIsTmK1TrKUIhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779384721; c=relaxed/simple; bh=4eowNUAjAOv4nDeJN6K31yxlmOO0Pd3LAOnFD+TdqXY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r9juF/1jnsKvK0Bwg0S+K70valhH5xv8rwAeALZ5GHiAieQpIyGA2vDnVnE/GWnw2/MzA+B4pvkp+aFVVOi51X3N6YCUsOG5liQEPiBdOIEeThHUzh51nzKQ4MlscLOCsP34g+0pT1qPrXMQxFTm69n1N/y2Ne7CLrIgicv12R4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=qxuSZYBV; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="qxuSZYBV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1779384717; bh=4eowNUAjAOv4nDeJN6K31yxlmOO0Pd3LAOnFD+TdqXY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qxuSZYBVVhncUB6GchHhHmFqTKhc6xGbrEkHAysjy5yzsJliFIefxeSWHcLMqY9Ug 7sm8cugPMWHwoQsB6k83MfwY4Df3B+AgrDWmTumZMthzxpRlkgNUWbabjJeCndGWLX mXO6fzQLBp/PVVew3Pw2KXEujOriPw8xOd66+2IY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 21 May 2026 19:31:03 +0200 Subject: [PATCH 2/3] tools/nolibc: add a helper to split a 64-bit argument into 32-bit halves Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-nolibc-ftruncate-v1-2-5384a83b2402@weissschuh.net> References: <20260521-nolibc-ftruncate-v1-0-5384a83b2402@weissschuh.net> In-Reply-To: <20260521-nolibc-ftruncate-v1-0-5384a83b2402@weissschuh.net> To: Willy Tarreau Cc: David Laight , linux-kernel@vger.kernel.org, Daniel Palmer , Jordan Richards , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779384716; l=1394; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=GshsGi9N3eKl+7P/GY9UBh/bvqAEs2eB5NQqcs8EDk0=; b=VhXazlcaNKhXe0Av/mNvloXGgIxcv4MOYkt0100e5ujlCOYdvvdpRc/zLQjjlerxsvH/zIk3y 18w3iGvDE7sDimXh18ewSp84WtstjkhmJd2OFL0OQFw9ZIsnDYG3klJ X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= From: Daniel Palmer On 32-bit architectures some system calls require a single 64-bit argument to be passed as two 32-bit halves. Add a helper to easily split such arguments. This works on little and bit endian. Signed-off-by: Daniel Palmer Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by is for maintainers to use on changes within their subsystems. Acked-by: Daniel Palmer Acked-by: Willy Tarreau Reviewed-by: Daniel Palmer --- Lifted from https://lore.kernel.org/lkml/20260507090353.356764-2-daniel@thi= ngy.jp/ --- tools/include/nolibc/sys.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 33f9c970ae57..548f94d96ed2 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -70,6 +70,17 @@ static __inline__ int __nolibc_enosys(const char *syscal= l, ...) } #endif =20 + +/* + * Helper for 32-bit machines where a 64-bit syscall arg needs to be split= into + * two 32-bit parts while making sure the order of the low/high parts are = correct + * for the endianness: + * __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]) + + /* Functions in this file only describe syscalls. They're declared static = so * that the compiler usually decides to inline them while still being allo= wed * to pass a pointer to one of their instances. Each syscall exists in two --=20 2.54.0 From nobody Sun May 24 19:36:18 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45B9E385D77 for ; Thu, 21 May 2026 17:31:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779384721; cv=none; b=bYpkRS7GesR8kIC+Hs9CmCh6GHSZqEFhvwDGq8997HD8WuttCvmTVCInAN/LLs0B0fPelU0bhrSjdPHcqxaaMVVPUdnqGDb+CKcKuGeTxtFd/kYdj+rbOkZc60jJJTZ3Eq8RAy5LWq8rHLql8Ruknl50MQqsoZlQlucBNGGOATY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779384721; c=relaxed/simple; bh=FI2BGPlCHLTnjO3Ms+SnbzHrzw1V0G5357tnJJqn3Lw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j6/245M5Z0x+A6ypuwGKt8zp5VMvI53x2MTshwEtbkLQ/vvTsvLzsC9VJPevYupoYM3ZPReGLYPTvkrVbQwdo/bjZdIXTyxcM4FyjdYw1JtsVIAQO6sPakgl6VshcJBdoRQJlxcxvZZ4huFRJEdXY93T2Q/bJSYExL02plUDn04= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=jhnu3RZI; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="jhnu3RZI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1779384717; bh=FI2BGPlCHLTnjO3Ms+SnbzHrzw1V0G5357tnJJqn3Lw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jhnu3RZIXI7U7Nouoh4Z3hezfVkR6QMT3J9GJb2PqBCvJF4UHYei4OIXWZ3q8pZ4B MfFQVJ4iw/RrXW+L6QZRpv51MvUFrtO4wpQ3572Weau76B38cn8Ee0rYzHosHcrCwl Mt0F6GGxKHq/lx6OBftWcKqHl4uvMNnjgrzab85I= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 21 May 2026 19:31:04 +0200 Subject: [PATCH 3/3] tools/nolibc: add ftruncate() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260521-nolibc-ftruncate-v1-3-5384a83b2402@weissschuh.net> References: <20260521-nolibc-ftruncate-v1-0-5384a83b2402@weissschuh.net> In-Reply-To: <20260521-nolibc-ftruncate-v1-0-5384a83b2402@weissschuh.net> To: Willy Tarreau Cc: David Laight , linux-kernel@vger.kernel.org, Daniel Palmer , Jordan Richards , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779384716; l=6933; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=FI2BGPlCHLTnjO3Ms+SnbzHrzw1V0G5357tnJJqn3Lw=; b=8jSCPPOlDuLTEsJkxahzrErlFgJS+CZWRYOviyHlho+AenvcxMpB/3T79t4/MlqmHSvQaMMaB 2KDbMdJics6AAhP6ck0N7v7zJX+DtVYQpIeAY6skog8haoHM7B7J2DQ X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= On architectures with 32-bit longs, call the compat syscall __NR_ftruncate64. As off_t is 64-bit it must be split into 2 registers. Unlike llseek() which passes the high and low parts in explicitly named arguments, the order here is endian independent. Some architectures (arm, mips, ppc) require this pair of registers to be aligned to an even register, so add custom _sys_ftruncate64() wrappers for those. A test case for ftruncate is added which validates negative length or invalid fd return the appropriate error, and checks the length is correct on success. Co-developed-by: Jordan Richards Signed-off-by: Jordan Richards Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by is for maintainers to use on changes within their subsystems. Acked-by: Daniel Palmer Acked-by: Willy Tarreau Reviewed-by: Daniel Palmer --- Lifted from https://lore.kernel.org/lkml/20260303010039.2969125-1-jordanric= hards@google.com/ --- tools/include/nolibc/arch-arm.h | 10 ++++++ tools/include/nolibc/arch-mips.h | 12 +++++++ tools/include/nolibc/arch-powerpc.h | 12 +++++++ tools/include/nolibc/unistd.h | 24 +++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 52 ++++++++++++++++++++++++= ++++ 5 files changed, 110 insertions(+) diff --git a/tools/include/nolibc/arch-arm.h b/tools/include/nolibc/arch-ar= m.h index 72a2b28170e2..8681922e05ca 100644 --- a/tools/include/nolibc/arch-arm.h +++ b/tools/include/nolibc/arch-arm.h @@ -7,8 +7,11 @@ #ifndef _NOLIBC_ARCH_ARM_H #define _NOLIBC_ARCH_ARM_H =20 +#include + #include "compiler.h" #include "crt.h" +#include "std.h" =20 /* Syscalls for ARM in ARM or Thumb modes : * - registers are 32-bit @@ -196,4 +199,11 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoi= nt __nolibc_no_stack_prote } #endif /* NOLIBC_NO_RUNTIME */ =20 +static __attribute__((unused)) +int _sys_ftruncate64(int fd, uint32_t length0, uint32_t length1) +{ + return __nolibc_syscall4(__NR_ftruncate64, fd, 0, length0, length1); +} +#define _sys_ftruncate64 _sys_ftruncate64 + #endif /* _NOLIBC_ARCH_ARM_H */ diff --git a/tools/include/nolibc/arch-mips.h b/tools/include/nolibc/arch-m= ips.h index 1400653c76c1..26ad413cec62 100644 --- a/tools/include/nolibc/arch-mips.h +++ b/tools/include/nolibc/arch-mips.h @@ -7,8 +7,11 @@ #ifndef _NOLIBC_ARCH_MIPS_H #define _NOLIBC_ARCH_MIPS_H =20 +#include + #include "compiler.h" #include "crt.h" +#include "std.h" =20 #if !defined(_ABIO32) && !defined(_ABIN32) && !defined(_ABI64) #error Unsupported MIPS ABI @@ -282,4 +285,13 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoi= nt __nolibc_no_stack_prote } #endif /* NOLIBC_NO_RUNTIME */ =20 +#if defined(_ABIO32) +static __attribute__((unused)) +int _sys_ftruncate64(int fd, uint32_t length0, uint32_t length1) +{ + return __nolibc_syscall4(__NR_ftruncate64, fd, 0, length0, length1); +} +#define _sys_ftruncate64 _sys_ftruncate64 +#endif + #endif /* _NOLIBC_ARCH_MIPS_H */ diff --git a/tools/include/nolibc/arch-powerpc.h b/tools/include/nolibc/arc= h-powerpc.h index 111cda70f2cc..a1ab91d55384 100644 --- a/tools/include/nolibc/arch-powerpc.h +++ b/tools/include/nolibc/arch-powerpc.h @@ -7,8 +7,11 @@ #ifndef _NOLIBC_ARCH_POWERPC_H #define _NOLIBC_ARCH_POWERPC_H =20 +#include + #include "compiler.h" #include "crt.h" +#include "std.h" =20 /* Syscalls for PowerPC : * - stack is 16-byte aligned @@ -218,4 +221,13 @@ void __attribute__((weak, noreturn)) __nolibc_entrypoi= nt __nolibc_no_stack_prote } #endif /* NOLIBC_NO_RUNTIME */ =20 +#if !defined(__powerpc64__) +static __attribute__((unused)) +int _sys_ftruncate64(int fd, uint32_t length0, uint32_t length1) +{ + return __nolibc_syscall4(__NR_ftruncate64, fd, 0, length0, length1); +} +#define _sys_ftruncate64 _sys_ftruncate64 +#endif + #endif /* _NOLIBC_ARCH_POWERPC_H */ diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h index 5882a6862066..79599ceef45d 100644 --- a/tools/include/nolibc/unistd.h +++ b/tools/include/nolibc/unistd.h @@ -48,6 +48,30 @@ int access(const char *path, int amode) return faccessat(AT_FDCWD, path, amode, 0); } =20 +#if !defined(_sys_ftruncate64) && defined(__NR_ftruncate64) +static __attribute__((unused)) +int _sys_ftruncate64(int fd, uint32_t length0, uint32_t length1) +{ + return __nolibc_syscall3(__NR_ftruncate64, fd, length0, length1); +} +#define _sys_ftruncate64 _sys_ftruncate64 +#endif + +static __attribute__((unused)) +int _sys_ftruncate(int fd, off_t length) +{ +#if defined(_sys_ftruncate64) + return _sys_ftruncate64(fd, __NOLIBC_LLARGPART(length, 0), __NOLIBC_LLARG= PART(length, 1)); +#else + return __nolibc_syscall2(__NR_ftruncate, fd, length); +#endif +} + +static __attribute__((unused)) +int ftruncate(int fd, off_t length) +{ + return __sysret(_sys_ftruncate(fd, length)); +} =20 static __attribute__((unused)) int msleep(unsigned int msecs) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/s= elftests/nolibc/nolibc-test.c index c3867cc570c6..7c3b711c125c 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1017,6 +1017,57 @@ int test_fork(enum fork_type type) } } =20 +int test_ftruncate(void) +{ + struct stat stat_buf; + int ret, fd; + + ret =3D ftruncate(-1, 0); + if (ret !=3D -1 || errno !=3D EBADF) { + errno =3D EINVAL; + return __LINE__; + } + + fd =3D memfd_create(__func__, 0); + if (fd =3D=3D -1) + return __LINE__; + + /* + * This also tests that the high 32-bit half is passed through correctly. + * If it gets lost, the kernel will see a positive number and not fail. + */ + ret =3D ftruncate(fd, -1); + if (!(ret =3D=3D -1 && errno =3D=3D EINVAL)) { + if (ret =3D=3D 0) + errno =3D EINVAL; + ret =3D __LINE__; + goto end; + } + + ret =3D ftruncate(fd, 42); + if (ret !=3D 0) { + ret =3D __LINE__; + goto end; + } + + ret =3D fstat(fd, &stat_buf); + if (ret !=3D 0) { + ret =3D __LINE__; + goto end; + } + + if (stat_buf.st_size !=3D 42) { + errno =3D EINVAL; + ret =3D __LINE__; + goto end; + } + +end: + close(fd); + + return ret; +} + int test_stat_timestamps(void) { struct stat st; @@ -1539,6 +1590,7 @@ int run_syscall(int min, int max) CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break; CASE_TEST(file_stream_wsr); EXPECT_SYSZR(1, test_file_stream_wsr()); b= reak; CASE_TEST(fork); EXPECT_SYSZR(1, test_fork(FORK_STANDARD));= break; + CASE_TEST(ftruncate); EXPECT_SYSZR(1, test_ftruncate()); break; CASE_TEST(getdents64_root); EXPECT_SYSNE(1, test_getdents64("/"), -1);= break; CASE_TEST(getdents64_null); EXPECT_SYSER(1, test_getdents64("/dev/null= "), -1, ENOTDIR); break; CASE_TEST(directories); EXPECT_SYSZR(is_nolibc && proc, test_diren= t()); break; --=20 2.54.0