Skip to contentSkip to conversation

fallocate: allow O_CREATE if mode is FALLOC_FL_WRITE_ZEROES

PATCH Applied Lukas Herbolt 2 participants 2 messages Oct 1, 2025 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fallocate: allow O_CREATE if mode is FALLOC_FL_WRITE_ZEROES

With the new flag we can create the ZEROED allcoated files directly and not in the two steps. Removing FALLOC_FL_WRITE_ZEROES from the flags of not using O_CREATE on open().

---
 sys-utils/fallocate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sys-utils/fallocate.c +1 -1
index f06009483..686e4925e 100644
@@ -408,7 +408,7 @@ int main(int argc, char **argv)
 
 	/* O_CREAT makes sense only for the default fallocate(2) behavior
 	 * when mode is no specified and new space is allocated */
-	fd = open(filename, O_RDWR | (!dig && !mode ? O_CREAT : 0),
+	fd = open(filename, O_RDWR | (!dig && !(mode & ~FALLOC_FL_WRITE_ZEROES) ? O_CREAT : 0),
 		  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
 	if (fd < 0)
 		err(EXIT_FAILURE, _("cannot open %s"), filename);
Signature · 1 line
2.51.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Lukas Herbolt

With the new flag we can create the ZEROED allcoated files directly and not in the two steps. Removing FALLOC_FL_WRITE_ZEROES from the flags of not using O_CREATE on open().

---
 sys-utils/fallocate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com