Minor options preprocessor change for littlefs, "hardened" VFS code. Core build date not changed.

This commit is contained in:
Terje Io
2022-09-11 20:37:47 +02:00
parent 180f9fa9fc
commit 229db6418b
4 changed files with 78 additions and 10 deletions
+24 -2
View File
@@ -1,6 +1,28 @@
## grblHAL changelog
20220905:
20220911:
Core:
* Minor options preprocessor change for littlefs, "hardened" VFS code. Core build date not changed.
Plugins:
* WebUI: Added all grblHAL settings to ESP400 response, file systems handling improvements++. Still WIP, but getting closer to final version!
* Networking: some general enhancements \(for WebUI\).
* SDCard: added VFS wrapper for littlefs. This plugin will be renamed late, likely to _Plugin_storage_.
Drivers:
* iMXRT1062, RP2040 and ESP32: Added [littlefs](https://github.com/littlefs-project/littlefs) support for flash based file storage.
* STM32F7xx: Fixed [typo](https://github.com/grblHAL/core/issues/186#issuecomment-1242943739).
---
20220906:
Core:
@@ -18,7 +40,7 @@ Plugins:
Drivers:
* All: updated for _grbl/limits.h_ name change and HAL version number increase.
* All: updated for grbl/limits.h name change and HAL version number increase.
* iMXRT1062, STM32F4xx, STM32F7xx and ESP32: Added RTC support.
+4
View File
@@ -172,6 +172,10 @@
#define SDCARD_ENABLE 0
#endif
#ifndef LITTLEFS_ENABLE
#define LITTLEFS_ENABLE 0
#endif
#ifndef SPI_ENABLE
#if SDCARD_ENABLE || TRINAMIC_SPI_ENABLE
#define SPI_ENABLE 1
+49 -8
View File
@@ -143,23 +143,48 @@ char *vfs_fixpath (char *path)
return path;
}
static vfs_mount_t *get_mount (const char *filename)
static inline vfs_mount_t *path_is_mount_dir (const char *path)
{
size_t plen = strlen(path);
if(*path == '/' && plen == 1)
return &root;
size_t mlen;
vfs_mount_t *mount = root.next;
if(mount) do {
mlen = strlen(mount->path) - 1;
if(mlen == plen && !strncmp(mount->path, path, mlen))
break;
} while((mount = mount->next));
return mount;
}
static vfs_mount_t *get_mount (const char *path)
{
vfs_errno = 0;
if(*filename == '/') {
if(*path != '/')
return cwdmount;
vfs_mount_t *mount = root.next;
vfs_mount_t *mount;
if((mount = path_is_mount_dir(path)) == NULL) {
mount = root.next;
if(mount) do {
if(!strncmp(mount->path, filename, strlen(mount->path)))
if(!strncmp(mount->path, path, strlen(mount->path)))
break;
} while((mount = mount->next));
return mount ? mount : &root;
if(mount == NULL)
mount = &root;
}
} else
return cwdmount;
return mount;
}
static const char *get_filename (vfs_mount_t *mount, const char *filename)
@@ -245,7 +270,7 @@ int vfs_rename (const char *from, const char *to)
int vfs_unlink (const char *filename)
{
vfs_mount_t *mount = get_mount(filename);
vfs_mount_t *mount = get_mount(filename); // TODO: test for dir?
return mount ? mount->vfs->funlink(get_filename(mount, filename)) : -1;
}
@@ -374,6 +399,9 @@ bool vfs_mount (const char *path, const vfs_t *fs)
else if((vfs = (vfs_mount_t *)malloc(sizeof(vfs_mount_t)))) {
strcpy(vfs->path, path);
if(vfs->path[strlen(path) - 1] != '/')
strcat(vfs->path, "/");
vfs->vfs = fs;
vfs->next = NULL;
@@ -415,6 +443,19 @@ bool vfs_unmount (const char *path)
return true;
}
vfs_drive_t *vfs_get_drive (const char *path)
{
static vfs_drive_t drive;
vfs_mount_t *mount = get_mount(path);
drive.name = mount->vfs->fs_name;
drive.path = (const char *)mount->path;
drive.mode = mount->vfs->mode;
drive.fs = mount->vfs;
return &drive;
}
vfs_drives_t *vfs_drives_open (void)
{
vfs_drives_t *handle;
+1
View File
@@ -201,5 +201,6 @@ vfs_drive_t *vfs_drives_read (vfs_drives_t *handle);
void vfs_drives_close (vfs_drives_t *handle);
vfs_free_t *vfs_drive_getfree (vfs_drive_t *drive);
int vfs_drive_format (vfs_drive_t *drive);
vfs_drive_t *vfs_get_drive (const char *path);
#endif // INCLUDE_VFS_H