From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 9882138F23A for ; Fri, 17 Apr 2026 11:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776425196; cv=none; b=trTKQcAZGgzW+hecJFXyWIDURwnA26ws+aGJA9guEf4FFcqtA51ZxPuj/4qfznBQvaxn4Xb+pR7BWy6faX7sJyecnLpuIoZFPT1iRvuj40j8BU+eh2kJaQHOGHiQ9RIh+G71p0Ts8pCtpIJuY4r+aaAoYPHH1LUj3fuosUV0qBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776425196; c=relaxed/simple; bh=pip/hk2yvLKdGfeGANiXPHHeth7OM6uNiuH2AvXqSMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PK94zCaT/DtL5oA+T2atbHQKq6hQwWR6MwavJe3Y/HOM+G55ed8id22uaeswrN1NECaNG+Jt7WZ0fNQb7Xd2SM3R5rbwJevROfx8JrnIQHcnQz1voj7mrOJd/ZvSWEB/20jjdHhcahcjG2yz7/H/6r2RbnOfV3MI4NB86xJV0mk= 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=HbNybBu5; arc=none smtp.client-ip=209.85.216.46 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="HbNybBu5" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-36143b0dbdbso212577a91.2 for ; Fri, 17 Apr 2026 04:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thingy.jp; s=google; t=1776425194; x=1777029994; 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=kyAwC7S7/jOi7XNSEXsqrfiZtwsiSBzqI812noxwDq4=; b=HbNybBu51dC21Q6IzYxBByWT7NhMsKz0MJHrxvNE4d8jveHk1fZhMxcLLxOPd0XJy9 pfsxZOzoDfyI6/RLCbAGsD47nhIkhZTkBbbAT8GT2IUYe+wtzmE2koLJqEUQkhthgNIN 4moJbtlO2YeOZmRTLr2oZBPVPkuKOlcxy1tf4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776425194; x=1777029994; 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=kyAwC7S7/jOi7XNSEXsqrfiZtwsiSBzqI812noxwDq4=; b=pyyMVKpM1ctVM/GToyAVD0Wb0Ec2lQelcm6iOlplX4sk6eAx9tMpXo/i8bSk7uX7SO KPRUzie7jbrh7gtrBG6nsMCu1sbjOXmIU2KjSz2ygC30cc/m/1CvjOXN+dzrycxoGS60 PbdD6vuuxGsqtyOTklVYmgS6kf8bHprfF5f25ccCFCfGGZHAMt/OfxXGQkrLbi6xk4JA DcPyHFOlbnkEllcbtpSaUcR9AN2bgXdKSpFUZGeSmYztWEt50ZRpm2v1arzOipXFKXV8 vIt/G3afQQTwKgEmPr9TG+uxXmbSyLlW4eF1JXXgaRXTfwIIo5nJjUenoWgnBZ1YIUHd n60Q== X-Gm-Message-State: AOJu0YxPgcmvNua8MSDDjQlWNBgDt6rwzqqPDOhdO5SqDwuCJyO6DSV9 5UYmHwpRLy7CD8ZMga97ce/suveAOwm6VT4Leno10lNZrsUoFMRhKq14+dQKmpTJsjk= X-Gm-Gg: AeBDieutnHWzPs2HH4ITHSn+lf7Q7C0gt06Pg30NJUnnvzd8znGQm5VwZ7Pn00eLquE ub0y+7Z/HtS59QQHLlt4oZAk6zVNJGHsYNZ7KOl0e3vK7KMWA1cIjAxEyNusiJTE8rgGAODPcio n4hHk69FEnh4H5/3wEe9yA6rp9DLo0FtuaUQnfSvy9yaErVMkGJKc6CqUeb7jANtrWOr4VV+o4Q S8xT2+4zJvUFHog2HizFlhTWDCLc/UZcA1I2RsOEgiVh0f9mAX+kdVhaNEmTMdJefDt6gdYmNIp rJufoWKCQcrdFfA3wRb465MbScc+IBuePBkiF4kdFRxDvsXyCwc50S/gScgSB0tviVZueoHROmG N13wDgyJ8+8i7IfRl2HNHKZC42IKbAnZFx6VG+YlAIVx0AohnpR7cQfILY5sAzfpL9/8mb8iqd5 tPB4JEIeBANHgvC4IzIPXGqECM/K4shyvQnAYH6pqugNqGz55yi/csk0LTSTz0sfoOga+I9sEl+ sd+rBQ6gzt5rA1UVY/3APRT9hFiSge0UeM= X-Received: by 2002:a17:90a:f94f:b0:35e:576e:5bc with SMTP id 98e67ed59e1d1-361404990eamr2454382a91.25.1776425193913; Fri, 17 Apr 2026 04:26:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 04:26:33 -0700 (PDT) From: Daniel Palmer To: w@1wt.eu, linux@weissschuh.net Cc: linux-kernel@vger.kernel.org, Daniel Palmer Subject: [PATCH v2 2/2] selftests/nolibc: Add a very basic test for fallocate() Date: Fri, 17 Apr 2026 20:26:22 +0900 Message-ID: <20260417112622.1182216-3-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 1: Create a tmp file, fallocate() to make it a bit bigger, check the size is what was expected. 2: Try to fallocate() (1 << 28), 3: Try to fallocate() (1 << 60), this causes a EFBIG Signed-off-by: Daniel Palmer --- tools/testing/selftests/nolibc/nolibc-test.c | 58 ++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index d3c4facb54c0..6dcc2f631c3e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -896,6 +896,63 @@ int test_getpagesize(void) return !c; } +int test_fallocate(void) +{ + struct stat st; + int fd, r; + + /* Create a new tmp file */ + fd = open("/tmp", O_TMPFILE | O_RDWR, 0644); + if (fd == -1) + return -1; + + /* Expand it to 42 bytes */ + r = fallocate(fd, 0, 0, 42); + if (r) + goto close_tmpfile; + + /* Get the new stat */ + r = fstat(fd, &st); + if (r) + goto close_tmpfile; + + /* It should be 42 bytes long */ + if (st.st_size != 42) { + r = -1; + goto close_tmpfile; + } + + /* Now try to allocate 256MiB, this shouldn't fail + */ + r = fallocate(fd, 0, 0, (1ll << 28)); + if (r) + goto close_tmpfile; + + /* Check that a massive size that happens to be the + * opposite endian version of the above. This should + * returns an error and errno = EFBIG indicating the + * value was passed correctly but the kernel rejected + * it. + */ + r = fallocate(fd, 0, 0, (1ll << (28 + 32))); + if (r != -1) { + r = -1; + goto close_tmpfile; + } + if (errno != EFBIG) { + r = -1; + goto close_tmpfile; + } + + /* Test passed */ + r = 0; + +close_tmpfile: + close(fd); + + return r; +} + int test_file_stream(void) { FILE *f; @@ -1442,6 +1499,7 @@ int run_syscall(int min, int max) CASE_TEST(dup3_0); tmp = dup3(0, 100, 0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; CASE_TEST(dup3_m1); tmp = dup3(-1, 100, 0); EXPECT_SYSER(1, tmp, -1, EBADF); if (tmp != -1) close(tmp); break; CASE_TEST(execve_root); EXPECT_SYSER(1, execve("/", (char*[]){ [0] = "/", [1] = NULL }, NULL), -1, EACCES); break; + CASE_TEST(fallocate); EXPECT_SYSZR(1, 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); break; CASE_TEST(file_stream); EXPECT_SYSZR(1, test_file_stream()); break; -- 2.51.0