How to check if a file of a given length can be created?

I want to create an unsharp file with a given length (i.e. 2 GB), but I want to check if this is possible before writing material to disk.

In other words, I want that during recording there was no access to ENOSPC (there is no space left on the device). I would prefer not to create a “test file” of 2 GB or the like in order to check if there is enough space left.

Is it possible?

+4
source share
2 answers

You can use the function statvfsto determine the number of free bytes (and inodes) of a given file system.

, , , (, , , ) - ( ) . .

fallocate posix_fallocate ( ) . , . ( , , .)

+3

posix_fallocate(3).

:

posix_fallocate() , fd len . posix_fallocate(), -

+5

Source: https://habr.com/ru/post/1568645/


All Articles