2013-06-18 17:21:38 +02:00
|
|
|
/**
|
2013-06-22 05:11:53 +02:00
|
|
|
* POSIX implementation of basic IO operations.
|
2013-06-18 17:21:38 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013, INRIA.
|
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2013-06-18 17:21:38 +02:00
|
|
|
*
|
2013-11-28 13:25:33 +01:00
|
|
|
* @ingroup sys_posix
|
2013-06-18 17:21:38 +02:00
|
|
|
* @{
|
2015-05-22 07:34:41 +02:00
|
|
|
* @file
|
2013-06-22 05:11:53 +02:00
|
|
|
* @brief Implementation of basic POSIX IO functionality.
|
2013-06-18 17:21:38 +02:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "thread.h"
|
|
|
|
#include "msg.h"
|
2010-09-24 16:28:34 +02:00
|
|
|
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "posix_io.h"
|
2010-09-24 16:28:34 +02:00
|
|
|
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
static int _posix_fileop(kernel_pid_t pid, int op, int flags)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2011-03-08 10:54:40 +01:00
|
|
|
msg_t m;
|
2010-09-24 16:28:34 +02:00
|
|
|
m.type = op;
|
|
|
|
m.content.value = flags;
|
|
|
|
msg_send_receive(&m, &m, pid);
|
|
|
|
return m.content.value;
|
|
|
|
}
|
|
|
|
|
2014-07-06 22:57:56 +02:00
|
|
|
static int _posix_fileop_data(kernel_pid_t pid, int op, char *buffer, int nbytes)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2011-03-08 11:43:21 +01:00
|
|
|
struct posix_iop_t r;
|
2010-09-24 16:28:34 +02:00
|
|
|
r.nbytes = nbytes;
|
|
|
|
r.buffer = buffer;
|
|
|
|
|
2011-03-08 10:54:40 +01:00
|
|
|
msg_t m;
|
2010-09-24 16:28:34 +02:00
|
|
|
m.type = op;
|
2013-06-22 05:11:53 +02:00
|
|
|
m.content.ptr = (char *) &r;
|
2010-09-24 16:28:34 +02:00
|
|
|
|
|
|
|
msg_send_receive(&m, &m, pid);
|
|
|
|
|
|
|
|
return r.nbytes;
|
|
|
|
}
|
|
|
|
|
2014-08-11 13:10:12 +02:00
|
|
|
int posix_open(int pid, int flags)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2015-07-15 13:52:25 +02:00
|
|
|
if (pid == KERNEL_PID_UNDEF) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-08-11 13:10:12 +02:00
|
|
|
return _posix_fileop((kernel_pid_t) pid, OPEN, flags);
|
2010-09-24 16:28:34 +02:00
|
|
|
}
|
|
|
|
|
2014-08-11 13:10:12 +02:00
|
|
|
int posix_close(int pid)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2014-08-11 13:10:12 +02:00
|
|
|
return _posix_fileop((kernel_pid_t) pid, CLOSE, 0);
|
2010-09-24 16:28:34 +02:00
|
|
|
}
|
|
|
|
|
2014-08-11 13:10:12 +02:00
|
|
|
int posix_read(int pid, char *buffer, int bufsize)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2014-08-11 13:10:12 +02:00
|
|
|
return _posix_fileop_data((kernel_pid_t) pid, READ, buffer, bufsize);
|
2010-09-24 16:28:34 +02:00
|
|
|
}
|
|
|
|
|
2014-08-11 13:10:12 +02:00
|
|
|
int posix_write(int pid, char *buffer, int bufsize)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2014-08-11 13:10:12 +02:00
|
|
|
return _posix_fileop_data((kernel_pid_t) pid, WRITE, buffer, bufsize);
|
2010-09-24 16:28:34 +02:00
|
|
|
}
|