Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directory::get_space_left() returns invalid result on Unix #47262

Closed
akien-mga opened this issue Mar 22, 2021 · 3 comments · Fixed by #49222
Closed

Directory::get_space_left() returns invalid result on Unix #47262

akien-mga opened this issue Mar 22, 2021 · 3 comments · Fixed by #49222

Comments

@akien-mga
Copy link
Member

Godot version:
3.x (c0b3ad2)
master (3b380f4)

OS/device including version:
Linux, Mageia Cauldron x86_64
According to @bruvzg, also reproducible on macOS

Issue description:
Running Directory::get_space_left() seems to return garbage data, at least on x86_64.
The data does not correspond to the available disk space reported by df.

For example, with this script:

var dir = Directory.new()
dir.open("/")
print(dir.get_space_left())
dir.open("/home")
print(dir.get_space_left())

And this partition setup:

$ df
[akien@cauldron Over9000]$ df
Filesystem      Size  Used Avail Use% Mounted on
...
/dev/nvme0n1p6   59G   46G   11G  82% /
...
/dev/nvme0n1p7  196G  173G   22G  89% /home

I get, on master and 3.x with x86_64 build:

1208348672
-481312768

Earlier today I had:

1208475648
222502912

I've been compiling the Rust compiler in the meantime which can explain the diff between the values for /home.

With an i686 build, it seems better:

14093234176
25292083200

Steps to reproduce:

  • Compare the output of Directory.get_space_left() on your system to what the system reports

Minimal reproduction project:
OS/user-dependent, but see above for a snippet.

@bruvzg
Copy link
Member

bruvzg commented Mar 22, 2021

On macOS using vfs.f_frsize (fundamental file system block size) instead of vfs.f_bsize (file system block size) works.

Also, it might be better to use vfs.f_bavail (space available to user) instead of vfs.f_bfree (space available to system).
In case of macOS it will be smaller for the system volume, excluding APFS snapshots.

@bruvzg

This comment has been minimized.

@bruvzg
Copy link
Member

bruvzg commented Mar 22, 2021

(uint64_t)vfs.f_bavail * (uint64_t)vfs.f_frsize also works on both 32-bit and 64-bit Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants