libroot: return EOPNOTSUPP from posix_fallocate

The pre-allocate functionality was added to Haiku in hrev54704. It needs
support at the file system level though, and it is yet to be implemented by
BFS. Some applications (and glibc!) implement a fallback mechanism using
ftruncate(), including the LLVM tools, but they go to this fallback
mechanism when it is clear that the operation is not supported. In particular
they look for EOPNOTSUPP.

The current implementation returns B_UNSUPPORTED from the vfs layer when a
file system does not implement the feature. This error code this not map to
a POSIX error. This change converts it to EOPNOTSUPP.

Change-Id: Ief382b0f4d462dfedf84c731f68f69731de4498c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4492
Reviewed-by: Adrien Destugues <[email protected]>
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Niels Sascha Reedijk
2021-09-21 10:22:10 +00:00
committed by Jérôme Duval
parent cc455ef461
commit 158b8fdab2
+9 -1
View File
@@ -102,5 +102,13 @@ posix_fallocate(int fd, off_t offset, off_t len)
if (len == 0 || offset < 0)
return EINVAL;
return _kern_preallocate(fd, offset, len);
int error = _kern_preallocate(fd, offset, len);
if (error == B_UNSUPPORTED) {
// While the official specification for this function does not
// prescribe which error code to use when the underlying file system
// does not support preallocation, we will convert B_UNSUPPORTED to
// EOPNOTSUPP for better compatibility with existing applications.
return EOPNOTSUPP;
}
return error;
}