From: Daniel Palmer <daniel@thingy.jp>
To: w@1wt.eu, linux@weissschuh.net
Cc: linux-kernel@vger.kernel.org, Daniel Palmer <daniel@thingy.jp>
Subject: [PATCH 1/2] tools/nolibc: fcntl: Add fallocate()
Date: Wed, 15 Apr 2026 23:32:24 +0900 [thread overview]
Message-ID: <20260415143225.561998-2-daniel@thingy.jp> (raw)
In-Reply-To: <20260415143225.561998-1-daniel@thingy.jp>
Add fallocate(), some special care is needed to
put the offset and size into the syscall parameters
for 32bit machines and for x32.
Signed-off-by: Daniel Palmer <daniel@thingy.jp>
---
tools/include/nolibc/fcntl.h | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/tools/include/nolibc/fcntl.h b/tools/include/nolibc/fcntl.h
index ed2f5553c65a..0ebfdb7bc792 100644
--- a/tools/include/nolibc/fcntl.h
+++ b/tools/include/nolibc/fcntl.h
@@ -66,4 +66,34 @@ 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);
+ */
+
+#define __NOLIBC_LLARGPART(_arg, _part) \
+ (((union { long long ll; long l[2]; }) { .ll = _arg }).l[_part])
+
+static __attribute__((unused))
+int sys_fallocate(int fd, int mode, off_t offset, off_t size)
+{
+#if defined(__x86_64__) && defined(__ILP32__)
+ const bool offsetsz_two_args = false;
+#else
+ const bool offsetsz_two_args = sizeof(long) != sizeof(off_t);
+#endif
+
+ 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);
+}
+
+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 */
--
2.51.0
next prev parent reply other threads:[~2026-04-15 14:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 14:32 [PATCH 0/2] nolibc: Add fallocate() Daniel Palmer
2026-04-15 14:32 ` Daniel Palmer [this message]
2026-04-15 15:56 ` [PATCH 1/2] tools/nolibc: fcntl: " Thomas Weißschuh
2026-04-15 14:32 ` [PATCH 2/2] selftests/nolibc: Add a very basic test for fallocate() Daniel Palmer
2026-04-15 15:59 ` Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260415143225.561998-2-daniel@thingy.jp \
--to=daniel@thingy.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox