From d33aa0a18965dc82dd00c0a51deba490ed4a4304 Mon Sep 17 00:00:00 2001
From: Terraneo Federico <fede.tft@hotmail.it>
Date: Fri, 30 Aug 2013 23:40:10 +0000
Subject: [PATCH] Moved console out of DevFs

---
 miosix/Makefile                               |   2 +-
 miosix/_doc/textdoc/Changelog.txt             |   2 +
 miosix/_tools/testsuite/testsuite.cpp         |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../stm32f103ve_mp3v2/interfaces-impl/bsp.cpp |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../interfaces-impl/bsp.cpp                   |   2 +-
 .../{devfs => console}/console_device.cpp     |  49 +++++++-
 .../{devfs => console}/console_device.h       |  46 ++++++--
 miosix/filesystem/devfs/base_files.cpp        |   2 -
 miosix/filesystem/devfs/base_files.h          |  11 +-
 miosix/filesystem/devfs/devfs.cpp             |   3 -
 miosix/filesystem/file_access.cpp             |   8 +-
 miosix/filesystem/file_access.h               |   5 +-
 miosix/kernel/logging.h                       |   2 +-
 miosix_np_2/nbproject/configurations.xml      | 110 +++++++++---------
 .../nbproject/private/configurations.xml      |   6 +-
 25 files changed, 164 insertions(+), 108 deletions(-)
 rename miosix/filesystem/{devfs => console}/console_device.cpp (86%)
 rename miosix/filesystem/{devfs => console}/console_device.h (86%)

diff --git a/miosix/Makefile b/miosix/Makefile
index a7b95f7d..c9a5b8ad 100644
--- a/miosix/Makefile
+++ b/miosix/Makefile
@@ -23,10 +23,10 @@ filesystem/filesystem.cpp                                                  \
 filesystem/file_access.cpp                                                 \
 filesystem/file.cpp                                                        \
 filesystem/stringpart.cpp                                                  \
+filesystem/console/console_device.cpp                                      \
 filesystem/mountpointfs/mountpointfs.cpp                                   \
 filesystem/devfs/devfs.cpp                                                 \
 filesystem/devfs/base_files.cpp                                            \
-filesystem/devfs/console_device.cpp                                        \
 filesystem/fat32/ff.c                                                      \
 filesystem/fat32/diskio.cpp                                                \
 stdlib_integration/libc_integration.cpp                                    \
diff --git a/miosix/_doc/textdoc/Changelog.txt b/miosix/_doc/textdoc/Changelog.txt
index 4349c713..ba515e2f 100644
--- a/miosix/_doc/textdoc/Changelog.txt
+++ b/miosix/_doc/textdoc/Changelog.txt
@@ -1,5 +1,7 @@
 Changelog for Miosix np embedded OS
 
+- File abstraction layer: Moved console support out of DevFs, will allow
+  better code size reduction if DevFs is not needed
 - File abstraction layer: Addded support for stateless and stateful
   device files, added DeviceFileGenerator to support stateful devices.
 - File abstraction layer: TerminalDevice is now instantiated in the FDT
diff --git a/miosix/_tools/testsuite/testsuite.cpp b/miosix/_tools/testsuite/testsuite.cpp
index 8f93c2e4..72b8411d 100644
--- a/miosix/_tools/testsuite/testsuite.cpp
+++ b/miosix/_tools/testsuite/testsuite.cpp
@@ -52,7 +52,7 @@
 #include "interfaces/endianness.h"
 #include "miosix/e20/e20.h"
 #include "kernel/intrusive.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 #include "util/crc16.h"
 
 using namespace std::tr1;
diff --git a/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/bsp.cpp b/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/bsp.cpp
index f646efb8..ed587db5 100644
--- a/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/bsp.cpp
+++ b/miosix/arch/arm7_lpc2000/lpc2138_miosix_board/interfaces-impl/bsp.cpp
@@ -45,7 +45,7 @@
 #include "config/miosix_settings.h"
 #include "kernel/logging.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 /**
 \internal
diff --git a/miosix/arch/cortexM3_stm32/stm32f100rb_stm32vldiscovery/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32/stm32f100rb_stm32vldiscovery/interfaces-impl/bsp.cpp
index a2111dd8..45191c87 100644
--- a/miosix/arch/cortexM3_stm32/stm32f100rb_stm32vldiscovery/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32/stm32f100rb_stm32vldiscovery/interfaces-impl/bsp.cpp
@@ -45,7 +45,7 @@
 #include "kernel/logging.h"
 #include "drivers/serial.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM3_stm32/stm32f103ve_mp3v2/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32/stm32f103ve_mp3v2/interfaces-impl/bsp.cpp
index a42f7d2a..f2075020 100644
--- a/miosix/arch/cortexM3_stm32/stm32f103ve_mp3v2/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32/stm32f103ve_mp3v2/interfaces-impl/bsp.cpp
@@ -45,7 +45,7 @@
 #include "kernel/logging.h"
 #include "drivers/serial.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM3_stm32/stm32f103ve_strive_mini/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32/stm32f103ve_strive_mini/interfaces-impl/bsp.cpp
index 474631a8..6d27b088 100644
--- a/miosix/arch/cortexM3_stm32/stm32f103ve_strive_mini/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32/stm32f103ve_strive_mini/interfaces-impl/bsp.cpp
@@ -45,7 +45,7 @@
 #include "kernel/logging.h"
 #include "drivers/serial.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM3_stm32/stm32f103ze_redbull_v2/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32/stm32f103ze_redbull_v2/interfaces-impl/bsp.cpp
index 8b0fae92..6cd31897 100644
--- a/miosix/arch/cortexM3_stm32/stm32f103ze_redbull_v2/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32/stm32f103ze_redbull_v2/interfaces-impl/bsp.cpp
@@ -45,7 +45,7 @@
 #include "kernel/logging.h"
 #include "drivers/serial.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM3_stm32/stm32f103ze_stm3210e-eval/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32/stm32f103ze_stm3210e-eval/interfaces-impl/bsp.cpp
index 549c7a29..16af6cb4 100644
--- a/miosix/arch/cortexM3_stm32/stm32f103ze_stm3210e-eval/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32/stm32f103ze_stm3210e-eval/interfaces-impl/bsp.cpp
@@ -45,7 +45,7 @@
 #include "kernel/logging.h"
 #include "drivers/serial.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/interfaces-impl/bsp.cpp
index 26c8ef85..30263294 100644
--- a/miosix/arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32f2/stm32f207ig_stm3220g-eval/interfaces-impl/bsp.cpp
@@ -46,7 +46,7 @@
 #include "kernel/logging.h"
 #include "console-impl.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM3_stm32f2/stm32f207ze_als_camboard/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32f2/stm32f207ze_als_camboard/interfaces-impl/bsp.cpp
index 489a40b5..715dcaa4 100644
--- a/miosix/arch/cortexM3_stm32f2/stm32f207ze_als_camboard/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32f2/stm32f207ze_als_camboard/interfaces-impl/bsp.cpp
@@ -44,7 +44,7 @@
 #include "kernel/logging.h"
 #include "console-impl.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM3_stm32f2/stm32f207zg_EthBoardV2/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32f2/stm32f207zg_EthBoardV2/interfaces-impl/bsp.cpp
index e08d60e6..c316415e 100644
--- a/miosix/arch/cortexM3_stm32f2/stm32f207zg_EthBoardV2/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32f2/stm32f207zg_EthBoardV2/interfaces-impl/bsp.cpp
@@ -47,7 +47,7 @@
 #include "kernel/logging.h"
 #include "console-impl.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM3_stm32l1/stm32l151c8_als_mainboard/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32l1/stm32l151c8_als_mainboard/interfaces-impl/bsp.cpp
index ad82c622..96bdf1b8 100644
--- a/miosix/arch/cortexM3_stm32l1/stm32l151c8_als_mainboard/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM3_stm32l1/stm32l151c8_als_mainboard/interfaces-impl/bsp.cpp
@@ -44,7 +44,7 @@
 #include "kernel/logging.h"
 #include "console-impl.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM4_stm32f4/stm32f407vg_bitsboard/interfaces-impl/bsp.cpp b/miosix/arch/cortexM4_stm32f4/stm32f407vg_bitsboard/interfaces-impl/bsp.cpp
index 721cdac8..d2e2eaa7 100644
--- a/miosix/arch/cortexM4_stm32f4/stm32f407vg_bitsboard/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM4_stm32f4/stm32f407vg_bitsboard/interfaces-impl/bsp.cpp
@@ -46,7 +46,7 @@
 #include "kernel/logging.h"
 #include "console-impl.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/interfaces-impl/bsp.cpp b/miosix/arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/interfaces-impl/bsp.cpp
index ca30fcc2..05fea6ac 100644
--- a/miosix/arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/interfaces-impl/bsp.cpp
+++ b/miosix/arch/cortexM4_stm32f4/stm32f407vg_stm32f4discovery/interfaces-impl/bsp.cpp
@@ -46,7 +46,7 @@
 #include "kernel/logging.h"
 #include "console-impl.h"
 #include "filesystem/file_access.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 
 namespace miosix {
 
diff --git a/miosix/filesystem/devfs/console_device.cpp b/miosix/filesystem/console/console_device.cpp
similarity index 86%
rename from miosix/filesystem/devfs/console_device.cpp
rename to miosix/filesystem/console/console_device.cpp
index 18864b77..edcf3e59 100644
--- a/miosix/filesystem/devfs/console_device.cpp
+++ b/miosix/filesystem/console/console_device.cpp
@@ -27,11 +27,51 @@
 
 #include "console_device.h"
 #include <errno.h>
-#include "base_files.h"
 #include <interfaces/console.h> //FIXME: remove
 
 namespace miosix {
 
+//
+// class ConsoleDevice
+//
+
+ssize_t ConsoleDevice::write(const void *data, size_t len)
+{
+    return len;
+}
+
+ssize_t ConsoleDevice::read(void *data, size_t len)
+{
+    return -EBADF;
+}
+
+off_t ConsoleDevice::lseek(off_t pos, int whence)
+{
+    switch(whence)
+    {
+        case SEEK_SET:
+        case SEEK_CUR:
+        case SEEK_END:
+            return -EBADF;
+        default:
+            return -EINVAL;
+    }
+}
+
+int ConsoleDevice::fstat(struct stat *pstat) const
+{
+    //TODO: st_dev and st_ino
+    memset(pstat,0,sizeof(struct stat));
+    pstat->st_mode=S_IFCHR | 0755;//crwxr-xr-x Character device
+    pstat->st_nlink=1;
+    pstat->st_blksize=0; //If zero means file buffer equals to BUFSIZ
+    return 0;
+}
+
+int ConsoleDevice::isatty() const { return 1; }
+
+void ConsoleDevice::IRQwrite(const char *str) {}
+
 //
 // class ConsoleAdapter
 //
@@ -48,7 +88,6 @@ ssize_t ConsoleAdapter::read(void *data, size_t len)
     for(size_t i=0;i<len;i++) *d++=Console::readChar();
     return len;
 }
-int ConsoleAdapter::isatty() const { return 1; }
 void ConsoleAdapter::IRQwrite(const char* str)
 {
     Console::IRQwrite(str);
@@ -61,8 +100,8 @@ void ConsoleAdapter::IRQwrite(const char* str)
 //
 
 TerminalDevice::TerminalDevice(intrusive_ref_ptr<FileBase> device)
-        : device(device), mutex(), echo(true),
-          binary(false), skipNewline(false) {}
+        : FileBase(intrusive_ref_ptr<FilesystemBase>()), device(device),
+          mutex(), echo(true), binary(false), skipNewline(false) {}
 
 ssize_t TerminalDevice::write(const void *data, size_t len)
 {
@@ -184,7 +223,7 @@ void DefaultConsole::IRQset(intrusive_ref_ptr<ConsoleDevice> console)
     #endif //WITH_FILESYSTEM
 }
 
-DefaultConsole::DefaultConsole() : console(new NullFile)
+DefaultConsole::DefaultConsole() : console(new ConsoleDevice)
 #ifndef WITH_FILESYSTEM
 , terminal(console)
 #endif //WITH_FILESYSTEM      
diff --git a/miosix/filesystem/devfs/console_device.h b/miosix/filesystem/console/console_device.h
similarity index 86%
rename from miosix/filesystem/devfs/console_device.h
rename to miosix/filesystem/console/console_device.h
index b7817678..5624d687 100644
--- a/miosix/filesystem/devfs/console_device.h
+++ b/miosix/filesystem/console/console_device.h
@@ -28,7 +28,8 @@
 #ifndef CONSOLE_DEVICE_H
 #define	CONSOLE_DEVICE_H
 
-#include "devfs.h"
+#include "filesystem/file.h"
+#include "kernel/sync.h"
 
 namespace miosix {
 
@@ -36,24 +37,54 @@ namespace miosix {
  * An extension to the FileBase interface that adds a new member function,
  * which is used by the kernel to write debug information before the kernel is
  * started or in case of serious errors, right before rebooting.
+ * This is not a pure virtual class, and the default implementation of all
+ * member functions does nothing, acting as a null console. To have a working
+ * console, board support packages should subclass it an implement read(),
+ * write() and IRQwrite().
  * Classes of this type are reference counted, must be allocated on the heap
- * and managed through intrusive_ref_ptr<DeviceFile>
+ * and managed through intrusive_ref_ptr<ConsoleDevice>
  */
-class ConsoleDevice : public DeviceFile
+class ConsoleDevice : public FileBase
 {
 public:
     /**
      * Constructor
      */
-    ConsoleDevice() {}
+    ConsoleDevice() : FileBase(intrusive_ref_ptr<FilesystemBase>()) {}
+    
+    /**
+     * This default implementation returns as if the data was written, but
+     * does nothing
+     */
+    virtual ssize_t write(const void *data, size_t len);
+    
+    /**
+     * This default implementation returns an error
+     */
+    virtual ssize_t read(void *data, size_t len);
+    
+    /**
+     * This implementation claims to be a character device
+     */
+    virtual off_t lseek(off_t pos, int whence);
+    
+    /**
+     * This implementation returns an error
+     */
+    virtual int fstat(struct stat *pstat) const;
+    
+    /**
+     * This implementation claims to be a tty
+     */
+    virtual int isatty() const;
     
     /**
      * Write a string to the Console.
      * Can ONLY be called when the kernel is not yet started, paused or within
-     * an interrupt.
+     * an interrupt. This default implementation ignores writes.
      * \param str the string to write. The string must be NUL terminated.
      */
-    virtual void IRQwrite(const char *str)=0;
+    virtual void IRQwrite(const char *str);
 };
 
 /**
@@ -64,7 +95,6 @@ class ConsoleAdapter : public ConsoleDevice
 public:
     virtual ssize_t write(const void *data, size_t len);
     virtual ssize_t read(void *data, size_t len);
-    virtual int isatty() const;
     virtual void IRQwrite(const char *str);
 };
 
@@ -72,7 +102,7 @@ public:
  * Teriminal device, proxy object supporting additional terminal-specific
  * features
  */
-class TerminalDevice : public DeviceFile
+class TerminalDevice : public FileBase
 {
 public:
     /**
diff --git a/miosix/filesystem/devfs/base_files.cpp b/miosix/filesystem/devfs/base_files.cpp
index a9d65924..9345d7c1 100644
--- a/miosix/filesystem/devfs/base_files.cpp
+++ b/miosix/filesystem/devfs/base_files.cpp
@@ -45,8 +45,6 @@ ssize_t NullFile::read(void *data, size_t len)
     return -EBADF;
 }
 
-void NullFile::IRQwrite(const char* str) {}
-
 //
 // class ZeroFile
 //
diff --git a/miosix/filesystem/devfs/base_files.h b/miosix/filesystem/devfs/base_files.h
index 8f82000c..4af5123b 100644
--- a/miosix/filesystem/devfs/base_files.h
+++ b/miosix/filesystem/devfs/base_files.h
@@ -29,14 +29,13 @@
 #define	BASE_FILES_H
 
 #include "devfs.h"
-#include "console_device.h"
 
 namespace miosix {
 
 /**
  * A file where write operations do nothing at all
  */
-class NullFile : public ConsoleDevice
+class NullFile : public DeviceFile
 {
 public:
     /**
@@ -62,14 +61,6 @@ public:
      * of errors
      */
     virtual ssize_t read(void *data, size_t len);
-    
-    /**
-     * Write a string to the Console.
-     * Can ONLY be called when the kernel is not yet started, paused or within
-     * an interrupt.
-     * \param str the string to write. The string must be NUL terminated.
-     */
-    virtual void IRQwrite(const char *str);
 };
 
 /**
diff --git a/miosix/filesystem/devfs/devfs.cpp b/miosix/filesystem/devfs/devfs.cpp
index b652bd61..c4db704a 100644
--- a/miosix/filesystem/devfs/devfs.cpp
+++ b/miosix/filesystem/devfs/devfs.cpp
@@ -29,7 +29,6 @@
 #include <string>
 #include <errno.h>
 #include "base_files.h"
-#include "console_device.h"
 #include "filesystem/stringpart.h"
 
 using namespace std;
@@ -127,8 +126,6 @@ DevFs::DevFs() : inodeCount(1)
     addDeviceFile("/zero",intrusive_ref_ptr<DeviceFileGenerator>(
         new StatelessDeviceFileGenerator(
             intrusive_ref_ptr<DeviceFile>(new ZeroFile))));
-    addDeviceFile("/console",intrusive_ref_ptr<DeviceFileGenerator>(
-        new StatelessDeviceFileGenerator(DefaultConsole::instance().get())));
 }
 
 bool DevFs::addDeviceFile(const char* name,
diff --git a/miosix/filesystem/file_access.cpp b/miosix/filesystem/file_access.cpp
index 134a213a..aec96400 100644
--- a/miosix/filesystem/file_access.cpp
+++ b/miosix/filesystem/file_access.cpp
@@ -2,6 +2,7 @@
 #include "file_access.h"
 #include <vector>
 #include <climits>
+#include "console/console_device.h"
 #include "mountpointfs/mountpointfs.h"
 #include "kernel/logging.h"
 
@@ -77,11 +78,8 @@ FileDescriptorTable::FileDescriptorTable()
     : mutex(FastMutex::RECURSIVE), cwd("/")
 {
     FilesystemManager::instance().addFileDescriptorTable(this);
-    //We need to open stdin, stdout, stderr.
-    //We're relying on open to choose the lowest numbered files slot
-    open("/dev/console",0,0); //FIXME: flags is wrong
-    files[0]=files[1]=files[2]=
-        intrusive_ref_ptr<FileBase>(new TerminalDevice(files[0]));
+    files[0]=files[1]=files[2]=intrusive_ref_ptr<FileBase>(
+        new TerminalDevice(DefaultConsole::instance().get()));
 }
 
 FileDescriptorTable::FileDescriptorTable(const FileDescriptorTable& rhs)
diff --git a/miosix/filesystem/file_access.h b/miosix/filesystem/file_access.h
index 5b3a718e..d7f2d50c 100644
--- a/miosix/filesystem/file_access.h
+++ b/miosix/filesystem/file_access.h
@@ -358,10 +358,7 @@ intrusive_ref_ptr<DevFs> basicFilesystemSetup();
 
 /**
  * \return a pointer to the file descriptor table associated with the
- * current process. Note: make sure you don't call this function before
- * /dev/console exists (which implies that / and /dev are mounted, which is
- * usually done with basicFilesystemSetup()), otherwise stdin/stdout/stderr
- * won't be set up properly
+ * current process.
  */
 FileDescriptorTable& getFileDescriptorTable();
 
diff --git a/miosix/kernel/logging.h b/miosix/kernel/logging.h
index 5ab23a08..eaaa4077 100644
--- a/miosix/kernel/logging.h
+++ b/miosix/kernel/logging.h
@@ -29,7 +29,7 @@
 #define	LOGGING_H
 
 #include "config/miosix_settings.h"
-#include "filesystem/devfs/console_device.h"
+#include "filesystem/console/console_device.h"
 #include <cstring>
 
 namespace miosix {
diff --git a/miosix_np_2/nbproject/configurations.xml b/miosix_np_2/nbproject/configurations.xml
index 36a106b1..fbe87c79 100644
--- a/miosix_np_2/nbproject/configurations.xml
+++ b/miosix_np_2/nbproject/configurations.xml
@@ -304,11 +304,13 @@
           <in>e20.h</in>
         </df>
         <df name="filesystem">
+          <df name="console">
+            <in>console_device.cpp</in>
+            <in>console_device.h</in>
+          </df>
           <df name="devfs">
             <in>base_files.cpp</in>
             <in>base_files.h</in>
-            <in>console_device.cpp</in>
-            <in>console_device.h</in>
             <in>devfs.cpp</in>
             <in>devfs.h</in>
           </df>
@@ -1298,22 +1300,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -2415,22 +2417,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -3534,22 +3536,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -4653,22 +4655,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -5772,22 +5774,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -6891,22 +6893,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -8010,22 +8012,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -9127,22 +9129,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -10244,22 +10246,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -11361,22 +11363,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -12478,22 +12480,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -13595,22 +13597,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
@@ -14712,22 +14714,22 @@
       </item>
       <item path="../miosix/e20/e20.h" ex="false" tool="3" flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.cpp"
+      <item path="../miosix/filesystem/console/console_device.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/base_files.h"
+      <item path="../miosix/filesystem/console/console_device.h"
             ex="false"
             tool="3"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.cpp"
+      <item path="../miosix/filesystem/devfs/base_files.cpp"
             ex="false"
             tool="1"
             flavor2="0">
       </item>
-      <item path="../miosix/filesystem/devfs/console_device.h"
+      <item path="../miosix/filesystem/devfs/base_files.h"
             ex="false"
             tool="3"
             flavor2="0">
diff --git a/miosix_np_2/nbproject/private/configurations.xml b/miosix_np_2/nbproject/private/configurations.xml
index cd0f38a1..76d068c7 100644
--- a/miosix_np_2/nbproject/private/configurations.xml
+++ b/miosix_np_2/nbproject/private/configurations.xml
@@ -308,11 +308,13 @@
           <in>e20.h</in>
         </df>
         <df name="filesystem">
+          <df name="console">
+            <in>console_device.cpp</in>
+            <in>console_device.h</in>
+          </df>
           <df name="devfs">
             <in>base_files.cpp</in>
             <in>base_files.h</in>
-            <in>console_device.cpp</in>
-            <in>console_device.h</in>
             <in>devfs.cpp</in>
             <in>devfs.h</in>
           </df>
-- 
GitLab