mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-29 16:31:18 +01:00
Merge pull request #8552 from gebart/pr/vfs-reserve-stdio-fileno
sys/vfs: Exclude stdio file numbers from auto allocation
This commit is contained in:
commit
4947e8a8aa
@ -21,6 +21,7 @@
|
||||
#include <sys/stat.h> /* for struct stat */
|
||||
#include <sys/statvfs.h> /* for struct statvfs */
|
||||
#include <fcntl.h> /* for O_ACCMODE, ..., fcntl */
|
||||
#include <unistd.h> /* 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;
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "embUnit/embUnit.h"
|
||||
|
||||
@ -71,6 +72,9 @@ static void test_vfs_bind(void)
|
||||
uint8_t buf[_VFS_TEST_BIND_BUFSIZE];
|
||||
fd = vfs_bind(VFS_ANY_FD, O_RDWR, &_test_bind_ops, &buf[0]);
|
||||
TEST_ASSERT(fd >= 0);
|
||||
TEST_ASSERT(fd != STDIN_FILENO);
|
||||
TEST_ASSERT(fd != STDOUT_FILENO);
|
||||
TEST_ASSERT(fd != STDERR_FILENO);
|
||||
if (fd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user