Re: [hatari-devel] GemDOS_DFree

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Previous uses this method to calculate the various sizes:

(parts from the code in https://sourceforge.net/p/previous/code/1657/tree//branches/branch_filesharing/src/slirp/rpc/nfs.c)

        xdr_write_long(m_out, nfs_blocks(&fsstat, fsstat.f_blocks)); /* total blocks */

        xdr_write_long(m_out, nfs_blocks(&fsstat, fsstat.f_bfree));  /* free blocks */

        xdr_write_long(m_out, nfs_blocks(&fsstat, fsstat.f_bavail)); /* available blocks */



static uint32_t nfs_blocks(const struct statvfs* fsstat, uint64_t fsblocks) {

    /* take minimum as block size, looks like every filesystem uses these fields somewhat different */

    fsblocks *= (uint64_t)min(fsstat->f_frsize, fsstat->f_bsize);

    if (fsblocks > 0x7FFFFFFF) fsblocks = 0x7FFFFFFF; /* limit size to signed 32-bit integer */

    return (uint32_t)(fsblocks / BLOCK_SIZE);

}



Limiting the size is due to internal limitations of the guest system. This might not be necessary for Hatari. And you can of course forget about the xdr stuff. Furthermore you might want to get the size in bytes instead of blocks. The relevant part is in the min-statement.



Am 10.06.2025 um 08:16 schrieb Christian Zietz <czietz@xxxxxxx>:

Eero Tamminen schrieb:

You could clear the struct before getting its values, to avoid getting
bogus values for untouched members.
[...]
3.97 MiB blocksize seems rather unlikely, especially as that would
indicate that your disk has 45 TB free.  On Linux I got 4 KiB for both.

Even if I clear the struct beforehand, I still get on macOS:

f_blocks = 83758080
f_frsize = 4096
f_bfree = 11661429
f_bavail = 11661429
f_bsize = 4161536

df gives:

Filesystem        Size    Used   Avail Capacity iused ifree %iused Mounted on
/dev/disk3s1s1   320Gi   9.6Gi    44Gi    18%    404k  466M    0%   /

Hence, both the total size and the available size must be calculated by multiplying with "f_frsize" (and ignoring "f_bsize").


Hatari uses different units for total and free space: "Total = buf.f_blocks/1024 * buf.f_frsize" and "Free = Free/1024 * buf.f_bsize".
As they are blocks, using block size seems logical.

Then again, why should total size use a different unit ("f_frsize") than free/available space? Sadly, so far I could only find the NetBSD man page that makes this explicit: "The following are in units of f_frsize":

https://man.netbsd.org/statvfs.5


Any idea where the code for statfs() that fills those values is?

Probably from the kernel, which queries the values from the respective file system. I don't think we have access to the source code of every Apple software.

Regards
Christian
--
Christian Zietz  -  CHZ-Soft  -  czietz@xxxxxxx
WWW: https://www.chzsoft.de/
New GnuPG-Key-ID: 0x8708B34C827B159E





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/