-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
…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:
enum
of 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 globalerrno
variable.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_open
function 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_mount
takes 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 const
file 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_data
members when implementing a file system driverauto_init
stuff?vfs df
)vfs_file_ops_t
in 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
+close
sequence as a fall back)statvfs
,fstatvfs
- information about a mounted file systemvfs_open
vfs_close
vfs_read
vfs_write
vfs_lseek
vfs_fstat
vfs_fcntl
vfs_mount
vfs_umount
vfs_rename
vfs_unlink
vfs_mkdir
vfs_rmdir
vfs_bind
vfs_opendir
vfs_closedir
vfs_readdir
vfs_normalize_path
vfs_iterate_mounts
vfs_stat
vfs_statvfs
vfs_fstatvfs
auto_init
for mounting/dev/uartX
UART devices/dev/nvramX
NVRAM devices - basic implementation done/dev/flashX
Flash devices (requires: Flash API, see mtd flash: add a generic low level flash interface [RFC] #5624, Flash interface #2239)/dev/random
periph/randomxxd
-like dumper from other branch as shell commandopendir
readdir
closedir
vfs_rename
Not 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_t
orint
? (newlib uses int, POSIX usesmode_t
which isunsigned long
on 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