dirent and directory operations support #3393
Replies: 2 comments 2 replies
|
Neat, thanks for hacking something out! The "right" way is to update Newlib and make a new tuple OS, which is where dirent.h/etc. are implemented. Once you have I'm traveling today so can't really verify, but right now is there a The other thing to be aware of is that the Arduino |
|
My simple dirent.h has a two-field dirent struct with char[256] name and unsigned char type, plus the function prototypes for open/close/read/rewind dir(). To use it I compile with -D_GLIBCXX_HAVE_DIRENT_H and provide an include path that overrides toolchain-rp2040-earlephilhower/arm-none-eabi/include/sys/dirent.h . My current packaging has a "stdfs17" library with Except for the two (custom) files, everything was lifted verbatim from https://github.com/gcc-mirror/gcc/tree/master/libstdc%2B%2B-v3 Everything works using std::filesystem ops - std::path, directories, subdirs, iterators, space() - using VFS with LittleFS and SD mounts. Re the Arduino File/Dir thing: I did find one discrepancy with posix. If you try to create the file /foo/bar, where /foo does not exist, instead of failing, it creates a file named /foo. I suppose it would be possible to check for that case. I think that is an existing problem, not something I created, since it goes through the unmodified _open() method. The mkdir() that I added does not have the issue. I suppose that one way to break down this process would be to first patch the arduino framework, thus enabling posix-style directory ops, then later figure out how best to incorporate the C++ stdfs stuff. |
Uh oh!
There was an error while loading. Please reload this page.
I have VFS directory operations working, including stdfs::directory_iterator and friends, so I can do pretty much everything through std::filesystem. I would like to submit a PR, but I need some guidance about how to structure it. The change to VFS.cpp is pretty straightforward, adding functions like opendir(), readdir(), mkdir(), so that part is easy.
The complicated part is that it needs dirent.h and statvfs.h, as well as fs_dir.cc, fs_ops.cc, and fs_path.cc from the c++ library, which should probably go in the toolchain package in some form. I don't understand the various trees well enough to know where the files should go. In my application I have those extra files in a local directory.
Any suggestions? Or is this something that is a non-starter for one reason or another?
All reactions