vfs: file system abstraction#5616
Conversation
|
Nice! Thank you for tackling this. Looks very nice already! Some thoughts that came up while skimming the diff:
|
My thoughts were that some of these structs should be constant and static, e.g. the file system driver, and should not consume valuable RAM, while other parts are variable. Right now I think all of it is kept in RAM, but the goal is to keep the static parts in flash instead and using pointers from the RAM parts to the flash parts.
No particular reason, I started using them in one place to get a pointer to the same type of struct, and then it just kind of kept on. I'll see if it still compiles if I modify it to use the typedefs instead. |
| off += filp->pos; | ||
| break; | ||
| case SEEK_END: | ||
| off += fp->size; |
|
updated todo-list with some more ideas. |
|
This looks very nice. I was working on the same topic, but my work is much less advanced than yours. I'm trying to get SPIFFS working and we worked on a low level flash interface as well. I'll push some work soon and will try to rebase my SPIFFS port on top of your vfs. Thanks for that work |
|
@vincent-d Nice! I have had plans to add SPIFFS but I did not feel that I knew where to begin, so I started with this instead, it's good to see that others are working towards the same goal. |
|
squashed, WIP commit list was getting out of hand. |
518d49b to
7549a62
Compare
|
How do we deal with directories? |
|
Updated with more work on DevFS, including:
|
|
@kaspar030 not sure. CFS and SPIFFS both implement specific |
sys/vfs/vfs.c
Outdated
| return -ENOENT; | ||
| } | ||
| /* Increment open files counter for this mount */ | ||
| atomic_inc(&_vfs_mounts[md].open_files); |
There was a problem hiding this comment.
This should not be done here but only in vfs_open, otherwise the unlink also increments the counter and umount fails afterwards.
There was a problem hiding this comment.
Actually, this is on purpose as a kind of semaphore to avoid races between umount and open/unlink. There were a few missing decrements of open_files in vfs_unlink though that I have fixed now.
|
I'll do an update tomorrow morning with opendir, readdir, closedir support for devfs and constfs (and the VFS support code of course) |
|
Updated with the directory interface. No unit tests yet or ConstFS, DevFS support for directories. |
|
I know FAT is not the most ideal FS for our purposes with all its layers of backwards compatibility, but we also should consider porting the FatFS library as a package using this interface. After all: FAT is still the file system type most SD cards are shipped with. I saw this library used on systems that are way more constraint than the ones RIOT targets (the CCC's r0ket badge e.g.), so space shouldn't be an issue. |
This line gave a -Wunused-value in gcc-4.6 before the stdatomic.h header for msp430 was modified as a workaround.
Enable adding more C++ specifics inside the same ifdef block (e.g. sys/include/vfs.h)
…unctions and constants
The VFS layer provides file system abstractions to allow using a unified interface to access files from mounted file systems.
|
Does this need a re-ACK? |
|
@miri64 Needs at least someone to approve the workaround for the mips board in the beginning of fcntl.h and statvfs.h |
|
@vincent-d Does your ACK hold? |
|
Yes! ACK |
|
qemu error on Jarvis seems unrelated and Murdock (1) is still the imperative CI, so merge at will. |
|
Yay! :D |
|
Congratz \o/ |
|
Great!! |
|
Congrats and a lot of thanks to @gebart! Good job! |
|
great!! |
|
Super! Thanks @gebart ! |
This PR provides a basic virtual file system (VFS) layer for RIOT. The intention is to provide a much simpler layer than what was proposed in #2474 and #1265.
The overall design goals are:
enumof all file system drivers that has to be kept up to date with external packages etc.<errno.h>numbers as negative return codes for errors, avoid the globalerrnovariable.The file systems for resource constrained systems that I have been looking at (so far) are Contiki CFS and SPIFFS.
I have also been looking at Linux kernel headers and books/articles on writing Linux device drivers for more ideas for the design.
The API should be easy to understand for users who are familiar with the POSIX file functions (open, close, read, write, fstat, lseek).
The VFS layer keeps track of mounted file systems and open files, the
vfs_openfunction searches the array of mounted file systems and dispatches the call to the file system instance with the longest matching mount point prefix.Subsequent calls to
vfs_read,vfs_write, etc will do a look up in the table of open files and dispatch the call to the correct file system driver for handling.vfs_mounttakes a string containing the mount point, a file system driver specification (struct file_system), and an opaque pointer that only the FS driver knows how to use, which can be used to keep driver parameters in order to allow dynamic handling of multiple devices.Also included is a simple file system implementation of a
static constfile system called ConstFS. This was created as a tool to assist in unit testing of the VFS layer, and as an exercise in implementing file system drivers, and to provide an example for developers who wish to write their own file system driver to hook into the VFS layer.TODO:
private_datamembers when implementing a file system driverauto_initstuff?vfs df)vfs_file_ops_tin flash.fcntl- change flags on already open FDs- not needed since kernel is rebuilt every time, easy to use device driver directlyioctl- communicate with special devicesstat(may wrapopen+fstat+closesequence as a fall back)statvfs,fstatvfs- information about a mounted file systemvfs_openvfs_closevfs_readvfs_writevfs_lseekvfs_fstatvfs_fcntlvfs_mountvfs_umountvfs_renamevfs_unlinkvfs_mkdirvfs_rmdirvfs_bindvfs_opendirvfs_closedirvfs_readdirvfs_normalize_pathvfs_iterate_mountsvfs_statvfs_statvfsvfs_fstatvfsauto_initfor mounting/dev/uartXUART devices/dev/nvramXNVRAM devices - basic implementation done/dev/flashXFlash devices (requires: Flash API, see mtd flash: add a generic low level flash interface [RFC] #5624, Flash interface #2239)/dev/randomperiph/randomxxd-like dumper from other branch as shell commandopendirreaddirclosedirvfs_renameNot implemented:
How to try it
Right now the only place to run the code is through a newly added embunit unit test batch:
(also successfully tested on BOARD=mulle)
Open questions
mode_torint? (newlib uses int, POSIX usesmode_twhich isunsigned longon 32 bit platforms)Should mounted file systems be changed into a linked list? (originally was statically allocated array with fixed maximum mount point length)- implemented