options/posix: Implement posix_fallocate()
This commit is contained in:
parent
99dcd1d581
commit
a047553581
|
@ -28,6 +28,7 @@ int sys_isatty(int fd, int *ptr);
|
|||
int sys_stat(const char *pathname, struct stat *statbuf);
|
||||
int sys_fstat(int fd, struct stat *statbuf);
|
||||
int sys_readlink(const char *path, void *buffer, size_t max_size, ssize_t *length);
|
||||
int sys_fallocate(int fd, off_t offset, size_t size);
|
||||
int sys_unlink(const char *path);
|
||||
int sys_socket(int family, int type, int protocol, int *fd);
|
||||
gid_t sys_getgid();
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
#include <cstdarg>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <bits/ensure.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <mlibc/sysdeps.hpp>
|
||||
|
||||
|
@ -28,9 +27,24 @@ int posix_fadvise(int, off_t, off_t, int) {
|
|||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
int posix_fallocate(int, off_t, off_t) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
int posix_fallocate(int fd, off_t offset, off_t size) {
|
||||
struct error_guard {
|
||||
error_guard()
|
||||
: _s{errno} { }
|
||||
|
||||
~error_guard() {
|
||||
errno = _s;
|
||||
}
|
||||
|
||||
private:
|
||||
int _s;
|
||||
};
|
||||
|
||||
error_guard guard;
|
||||
|
||||
if(mlibc::sys_fallocate(fd, offset, size))
|
||||
return errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This is a linux extension
|
||||
|
|
|
@ -1938,6 +1938,46 @@ int sys_readlink(const char *path, void *data, size_t max_size, ssize_t *length)
|
|||
}
|
||||
}
|
||||
|
||||
int sys_fallocate(int fd, off_t offset, size_t size) {
|
||||
HelAction actions[3];
|
||||
globalQueue.trim();
|
||||
|
||||
auto handle = cacheFileTable()[fd];
|
||||
__ensure(handle);
|
||||
|
||||
managarm::fs::CntRequest<MemoryAllocator> req(getAllocator());
|
||||
req.set_req_type(managarm::fs::CntReqType::PT_FALLOCATE);
|
||||
req.set_rel_offset(offset);
|
||||
req.set_size(size);
|
||||
|
||||
frigg::String<MemoryAllocator> ser(getAllocator());
|
||||
req.SerializeToString(&ser);
|
||||
actions[0].type = kHelActionOffer;
|
||||
actions[0].flags = kHelItemAncillary;
|
||||
actions[1].type = kHelActionSendFromBuffer;
|
||||
actions[1].flags = kHelItemChain;
|
||||
actions[1].buffer = ser.data();
|
||||
actions[1].length = ser.size();
|
||||
actions[2].type = kHelActionRecvInline;
|
||||
actions[2].flags = 0;
|
||||
HEL_CHECK(helSubmitAsync(handle, actions, 3,
|
||||
globalQueue.getQueue(), 0, 0));
|
||||
|
||||
auto element = globalQueue.dequeueSingle();
|
||||
auto offer = parseSimple(element);
|
||||
auto send_req = parseSimple(element);
|
||||
auto recv_resp = parseInline(element);
|
||||
|
||||
HEL_CHECK(offer->error);
|
||||
HEL_CHECK(send_req->error);
|
||||
HEL_CHECK(recv_resp->error);
|
||||
|
||||
managarm::fs::SvrResponse<MemoryAllocator> resp(getAllocator());
|
||||
resp.ParseFromArray(recv_resp->data, recv_resp->length);
|
||||
__ensure(resp.error() == managarm::fs::Errors::SUCCESS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_unlink(const char *path) {
|
||||
HelAction actions[3];
|
||||
|
||||
|
|
Loading…
Reference in a new issue