From be14d2eacea90f9d4aa378336679ba5b9d9e68b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 13 Feb 2018 18:02:06 +0100 Subject: [PATCH] sys/vfs: Exclude stdio file numbers from auto allocation Fixes #8309 (https://github.com/RIOT-OS/RIOT/issues/8309) --- sys/vfs/vfs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sys/vfs/vfs.c b/sys/vfs/vfs.c index 9eb4c1d309..807a95d0d8 100644 --- a/sys/vfs/vfs.c +++ b/sys/vfs/vfs.c @@ -21,6 +21,7 @@ #include /* for struct stat */ #include /* for struct statvfs */ #include /* for O_ACCMODE, ..., fcntl */ +#include /* for STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO */ #include "vfs.h" #include "mutex.h" @@ -867,6 +868,13 @@ static inline int _allocate_fd(int fd) { if (fd < 0) { for (fd = 0; fd < VFS_MAX_OPEN_FILES; ++fd) { + if ((fd == STDIN_FILENO) || (fd == STDOUT_FILENO) || (fd == STDERR_FILENO)) { + /* Do not auto-allocate the stdio file descriptor numbers to + * avoid conflicts between normal file system users and stdio + * drivers such as uart_stdio, rtt_stdio which need to be able + * to bind to these specific file descriptor numbers. */ + continue; + } if (_vfs_open_files[fd].pid == KERNEL_PID_UNDEF) { break; }