options/posix: Implement fchdir()
This commit is contained in:
parent
5b12c94167
commit
9b0ac5214f
|
@ -102,6 +102,7 @@ int sys_close(int fd);
|
|||
[[gnu::weak]] int sys_signalfd_create(sigset_t, int flags, int *fd);
|
||||
[[gnu::weak]] int sys_getcwd(char *buffer, size_t size);
|
||||
[[gnu::weak]] int sys_chdir(const char *path);
|
||||
[[gnu::weak]] int sys_fchdir(int fd);
|
||||
[[gnu::weak]] int sys_chroot(const char *path);
|
||||
[[gnu::weak]] int sys_mkdir(const char *path);
|
||||
[[gnu::weak]] int sys_symlink(const char *target_path, const char *link_path);
|
||||
|
|
|
@ -29,6 +29,19 @@ int chdir(const char *path) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int fchdir(int fd) {
|
||||
if(!mlibc::sys_fchdir) {
|
||||
MLIBC_MISSING_SYSDEP();
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
if(int e = mlibc::sys_fchdir(fd); e) {
|
||||
errno = e;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chown(const char *path, uid_t uid, gid_t gid) {
|
||||
mlibc::infoLogger() << "\e[31mmlibc: chown() is not implemented correctly\e[39m"
|
||||
<< frg::endlog;
|
||||
|
@ -143,10 +156,6 @@ int faccessat(int, const char *, int, int) {
|
|||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
int fchdir(int fd) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
int fchown(int fd, uid_t uid, gid_t gid) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
|
|
|
@ -94,6 +94,43 @@ int sys_chdir(const char *path) {
|
|||
}
|
||||
}
|
||||
|
||||
int sys_fchdir(int fd) {
|
||||
SignalGuard sguard;
|
||||
HelAction actions[3];
|
||||
globalQueue.trim();
|
||||
|
||||
managarm::posix::CntRequest<MemoryAllocator> req(getSysdepsAllocator());
|
||||
req.set_request_type(managarm::posix::CntReqType::FCHDIR);
|
||||
req.set_fd(fd);
|
||||
|
||||
frigg::String<MemoryAllocator> ser(getSysdepsAllocator());
|
||||
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(getPosixLane(), 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::posix::SvrResponse<MemoryAllocator> resp(getSysdepsAllocator());
|
||||
resp.ParseFromArray(recv_resp->data, recv_resp->length);
|
||||
__ensure(resp.error() == managarm::posix::Errors::SUCCESS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_chroot(const char *path) {
|
||||
SignalGuard sguard;
|
||||
HelAction actions[3];
|
||||
|
|
Loading…
Reference in a new issue