From 7d178cd7c1dd63932d50d9518722894a09396a67 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 15 Aug 2020 15:20:52 +0900 Subject: [PATCH] sys/io: Add sys_write() implementation --- sys/io/write.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 sys/io/write.c diff --git a/sys/io/write.c b/sys/io/write.c new file mode 100644 index 0000000..ca7962e --- /dev/null +++ b/sys/io/write.c @@ -0,0 +1,66 @@ +/* + * This file is part of the Corax operating system. + * Copyright (C) 2020 Matthias Kruk + * + * Corax is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Corax is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Corax. If not, see . + */ + +#include +#include +#include +#include +#include +#include "proc.h" +#include "filedesc.h" + +ssize_t sys_write(const pid_t pid, struct cxio_write *msg) +{ + struct proc *proc; + struct filedesc *filedesc; + struct cxmsg resp; + struct cxio_response *ioresp; + ssize_t ret_val; + + ret_val = proc_lookup(pid, &proc); + + ioresp = (struct cxio_response*)resp.cm_data; + + memset(&resp, 0, sizeof(resp)); + + if(!ret_val) { + ret_val = proc_get_fd(proc, msg->fd, &filedesc); + + if(!ret_val) { + ret_val = fd_write(filedesc, msg->data, msg->datalen); + + if(ret_val >= 0) { + ioresp->retval = ret_val; + ioresp->error = 0; + } + } + } + + if(ret_val < 0) { + ioresp->retval = -1; + ioresp->error = -ret_val; + } + + ioresp->fd = msg->fd; + resp.cm_type = CXIO_RESPONSE; + resp.cm_len = sizeof(*ioresp); + + ret_val = cxsend(pid, &resp); + + return(ret_val); +} -- 2.47.3