[Toybox] [PATCH] Fix df on macOS.

enh enh at google.com
Sat Feb 20 13:26:00 PST 2021


On Linux, struct statvfs' f_bsize and f_frsize seem to be
interchangeable. On macOS, they're wildly different. f_bsize is the
"preferred length of I/O requests for files on this file system"
(corresponding to statfs::f_iosize), and f_frsize is the "size in
bytes of the minimum unit of allocation on this file system"
(corresponding to statfs::f_bsize. POSIX appears to say nothing
about the interpretation of these fields, but man7.org's statvfs(2)
page is quite clear that statvfs::f_blocks, for example, is in units
of f_frsize, not f_bsize.

This is the only place in the tree where we use statvfs::f_bsize
(other than the stat(1) output that's supposed to be f_bsize and
that has a corresponding f_frsize dual anyway.

I've removed the Apple-specific #define f_frsize in portability.h
because that seems to have been from my previous attempt to understand
what was going on here. The output of the relevant stat(1) fields
on macOS are the same before/after this patch.

This makes toybox df's output match the system's df on a MacBook
Pro running macOS 11.2.1.

Tested on a Raspberry Pi 400 running Linux too, where I see no
change in the output before/after this patch.
---
 lib/portability.h | 4 ----
 toys/posix/df.c   | 2 +-
 2 files changed, 1 insertion(+), 5 deletions(-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20210220/442e8631/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-df-on-macOS.patch
Type: application/octet-stream
Size: 2526 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20210220/442e8631/attachment.obj>


More information about the Toybox mailing list