[Toybox] [PATCH] Fix macOS posix_fallocate().

enh enh at google.com
Thu Dec 14 21:07:12 PST 2023


The fallback ftruncate() call was wrong, because posix_fallocate()
will never shrink a file, but ftruncate() will. Also, if that failed,
we didn't turn errno into a return code.

Also the fcntl() was wrong. In my defense, here's the documentation:

     The position modes (fst_posmode) for the F_PREALLOCATE command indicate
     how to use the offset field.  The modes are as follows:

           F_PEOFPOSMODE   Allocate from the physical end of file.  In this
                           case, fst_length indicates the number of newly
                           allocated bytes desired.

           F_VOLPOSMODE    Allocate from the volume offset.

I think the new version is right, though it's obviously a lot more
conservative than the real posix_fallocate(), but I don't think
it's possible to do better?

Also add tests for some of the prior failures.

Fixes #472.
---
 lib/portability.c    | 11 ++++++-----
 tests/fallocate.test |  8 ++++++++
 2 files changed, 14 insertions(+), 5 deletions(-)
 create mode 100755 tests/fallocate.test
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-macOS-posix_fallocate.patch
Type: application/octet-stream
Size: 2690 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20231214/824e445c/attachment.obj>


More information about the Toybox mailing list