mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
posix: remove fd subsystem
Fixes #637. This only provides a subset of vfs while being incompatible with it. Since POSIX sockets don't use this module anymore it can be removed.
This commit is contained in:
parent
ac7671762d
commit
1caa024038
@ -46,6 +46,7 @@ PSEUDOMODULES += netstats_rpl
|
||||
PSEUDOMODULES += newlib
|
||||
PSEUDOMODULES += newlib_nano
|
||||
PSEUDOMODULES += pktqueue
|
||||
PSEUDOMODULES += posix
|
||||
PSEUDOMODULES += printf_float
|
||||
PSEUDOMODULES += saul_adc
|
||||
PSEUDOMODULES += saul_default
|
||||
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 INRIA.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup posix
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Unifies diverse identifiers of RIOT to POSIX like file descriptors.
|
||||
*
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
||||
*/
|
||||
#ifndef FD_H
|
||||
#define FD_H
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include "kernel_types.h"
|
||||
#include "cpu.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* File descriptor table.
|
||||
*/
|
||||
typedef struct {
|
||||
/** private status of this fd_t */
|
||||
int internal_active;
|
||||
|
||||
/** Stores the RIOT internal value for the file descriptor (not POSIX). */
|
||||
int internal_fd;
|
||||
|
||||
/**
|
||||
* Read *n* bytes into *buf* from *fd*. Return the
|
||||
* number read, -1 for errors or 0 for EOF.
|
||||
*/
|
||||
ssize_t (*read)(int fd, void *buf, size_t n);
|
||||
|
||||
/** Write *n* bytes of *buf* to *fd*. Return the number written, or -1. */
|
||||
ssize_t (*write)(int fd, const void *buf, size_t n);
|
||||
|
||||
/** Close the file descriptor *fd*. */
|
||||
int (*close)(int fd);
|
||||
} fd_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes file descriptors
|
||||
*
|
||||
* @return maximum number of available file descriptors.
|
||||
*/
|
||||
int fd_init(void);
|
||||
|
||||
/**
|
||||
* @brief Creates a new file descriptor.
|
||||
*
|
||||
* @param[in] internal_fd RIOT-internal identifier for the new FD.
|
||||
* @param[in] internal_read Function to read from new FD.
|
||||
* @param[in] internal_write Function to write into new FD.
|
||||
* @param[in] internal_close Function to close new FD.
|
||||
*
|
||||
* @return 0 on success, -1 otherwise. *errno* is set accordingly.
|
||||
*/
|
||||
int fd_new(int internal_fd, ssize_t (*internal_read)(int, void *, size_t),
|
||||
ssize_t (*internal_write)(int, const void *, size_t),
|
||||
int (*internal_close)(int));
|
||||
|
||||
/**
|
||||
* @brief Gets the file descriptor table entry associated with file
|
||||
* descriptor *fd*.
|
||||
*
|
||||
* @param[in] fd A POSIX-like file descriptor.
|
||||
*
|
||||
* @return The file descriptor table entry associated with file descriptor
|
||||
*fd* or NULL if there is non.
|
||||
*/
|
||||
fd_t *fd_get(int fd);
|
||||
|
||||
/**
|
||||
* @brief Removes file descriptor table entry associated with *fd* from table.
|
||||
*
|
||||
* @param[in] fd A POSIX-like file descriptor.
|
||||
*/
|
||||
void fd_destroy(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FD_H */
|
||||
/** @} */
|
@ -1 +0,0 @@
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Freie Universität Berlin
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup posix
|
||||
* @{
|
||||
* @file
|
||||
* @brief Providing unifying file descriptor wrapper for POSIX-compliant
|
||||
* operations.
|
||||
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "unistd.h"
|
||||
|
||||
#include "fd.h"
|
||||
|
||||
#ifdef CPU_MSP430
|
||||
#define FD_MAX 5
|
||||
#else
|
||||
#define FD_MAX 15
|
||||
#endif
|
||||
|
||||
static fd_t fd_table[FD_MAX];
|
||||
|
||||
int fd_init(void)
|
||||
{
|
||||
memset(fd_table, 0, sizeof(fd_t) * FD_MAX);
|
||||
|
||||
return FD_MAX;
|
||||
}
|
||||
|
||||
static int fd_get_next_free(void)
|
||||
{
|
||||
for (int i = 0; i < FD_MAX; i++) {
|
||||
fd_t *cur = &fd_table[i];
|
||||
|
||||
if (!cur->internal_active) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fd_new(int internal_fd, ssize_t (*internal_read)(int, void *, size_t),
|
||||
ssize_t (*internal_write)(int, const void *, size_t),
|
||||
int (*internal_close)(int))
|
||||
{
|
||||
int fd = fd_get_next_free();
|
||||
|
||||
if (fd >= 0) {
|
||||
fd_t *fd_s = fd_get(fd);
|
||||
fd_s->internal_active = 1;
|
||||
fd_s->internal_fd = internal_fd;
|
||||
fd_s->read = internal_read;
|
||||
fd_s->write = internal_write;
|
||||
fd_s->close = internal_close;
|
||||
}
|
||||
else {
|
||||
errno = ENFILE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
fd_t *fd_get(int fd)
|
||||
{
|
||||
if (fd >= 0 && fd < FD_MAX) {
|
||||
return &fd_table[fd];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void fd_destroy(int fd)
|
||||
{
|
||||
fd_t *cur = fd_get(fd);
|
||||
|
||||
if (!cur) {
|
||||
return;
|
||||
}
|
||||
|
||||
memset(cur, 0, sizeof(fd_t));
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Freie Universität Berlin
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
* @file
|
||||
* @brief Providing implementation for close for fds defined in fd.h.
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "fd.h"
|
||||
|
||||
int close(int fildes)
|
||||
{
|
||||
fd_t *fd_obj = fd_get(fildes);
|
||||
|
||||
if (!fd_obj || (fd_obj->close == NULL)) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fd_obj->close(fd_obj->internal_fd) < 0) {
|
||||
errno = EIO; // EINTR may not occur since RIOT has no signals yet.
|
||||
return -1;
|
||||
}
|
||||
|
||||
fd_destroy(fd_obj->internal_fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user