vfs: code review fixes

- fix typo in readme
- remove unneeded extern declaration
- fix header guard macro
- tabs->spaces in syscalls.c
- spaces->tabs in tasks.c
This commit is contained in:
Ivan Grokhotkov 2016-10-27 11:47:41 +08:00
parent da56e76255
commit 6f1d3ce4a7
6 changed files with 34 additions and 30 deletions

View File

@ -60,7 +60,6 @@ static bool app_cpu_started = false;
static void do_global_ctors(void);
static void main_task(void* args);
extern void ets_setup_syscalls(void);
extern void app_main(void);
extern int _bss_start;

View File

@ -963,8 +963,8 @@ UBaseType_t x;
#if ( configUSE_NEWLIB_REENTRANT == 1 )
{
/* Initialise this task's Newlib reent structure. */
esp_reent_init(&pxNewTCB->xNewLib_reent);
/* Initialise this task's Newlib reent structure. */
esp_reent_init(&pxNewTCB->xNewLib_reent);
}
#endif

View File

@ -38,26 +38,26 @@ void* IRAM_ATTR _malloc_r(struct _reent *r, size_t size)
void IRAM_ATTR _free_r(struct _reent *r, void* ptr)
{
return vPortFree(ptr);
vPortFree(ptr);
}
void* IRAM_ATTR _realloc_r(struct _reent *r, void* ptr, size_t size)
{
void* new_chunk;
if (size == 0) {
if (ptr) {
vPortFree(ptr);
}
return NULL;
}
void* new_chunk;
if (size == 0) {
if (ptr) {
vPortFree(ptr);
}
return NULL;
}
new_chunk = pvPortMalloc(size);
if (new_chunk && ptr) {
memcpy(new_chunk, ptr, size);
vPortFree(ptr);
}
// realloc behaviour: don't free original chunk if alloc failed
return new_chunk;
new_chunk = pvPortMalloc(size);
if (new_chunk && ptr) {
memcpy(new_chunk, ptr, size);
vPortFree(ptr);
}
// realloc behaviour: don't free original chunk if alloc failed
return new_chunk;
}
void* IRAM_ATTR _calloc_r(struct _reent *r, size_t count, size_t size)
@ -65,7 +65,7 @@ void* IRAM_ATTR _calloc_r(struct _reent *r, size_t count, size_t size)
void* result = pvPortMalloc(count * size);
if (result)
{
memset(result, 0, count * size);
memset(result, 0, count * size);
}
return result;
}

View File

@ -31,5 +31,5 @@ clock_t _times_r(struct _reent *r, struct tms *ptms)
int _gettimeofday_r(struct _reent *r, struct timeval *tv, void *tz)
{
__errno_r(r) = ENOSYS;
return (clock_t) -1;
return -1;
}

View File

@ -8,7 +8,7 @@ Virtual filesystem (VFS) component provides a unified interface for drivers whic
This component allows C library functions, such as fopen and fprintf, to work with FS drivers. At high level, each FS driver is associated with some path prefix. When one of C library functions needs to open a file, VFS component searches for the FS driver associated with the file's path, and forwards the call to that driver. VFS also forwards read, write, and other calls for the given file to the same FS driver.
For example, one can register a FAT filesystem driver with ``/fat`` prefix, and call ``fopen("/fat/file.txt", "w")``. VFS component will the call ``open`` function of FAT driver and pass ``/file.txt`` argument to it (and appropriate mode flags). All subsequent calls to C library functions for the returned ``FILE*`` stream will also be forwarded to the FAT driver.
For example, one can register a FAT filesystem driver with ``/fat`` prefix, and call ``fopen("/fat/file.txt", "w")``. VFS component will then call ``open`` function of FAT driver and pass ``/file.txt`` argument to it (and appropriate mode flags). All subsequent calls to C library functions for the returned ``FILE*`` stream will also be forwarded to the FAT driver.
FS registration
---------------
@ -32,7 +32,7 @@ To register an FS driver, application needs to define in instance of esp_vfs_t s
ESP_ERROR_CHECK(esp_vfs_register("/data", &myfs, NULL));
Depending on the way FS driver declares it's APIs, either ``read``, ``write``, etc., or ``read_p``, ``write_p``, etc. should be used.
Depending on the way FS driver declares its APIs, either ``read``, ``write``, etc., or ``read_p``, ``write_p``, etc. should be used.
Case 1: API functions are declared without an extra context pointer (FS driver is a singleton)::
@ -41,7 +41,7 @@ Case 1: API functions are declared without an extra context pointer (FS driver i
// In definition of esp_vfs_t:
.flags = ESP_VFS_FLAG_DEFAULT,
.write = &myfs_write,
// ... other member initialized
// ... other members initialized
// When registering FS, context pointer (third argument) is NULL:
ESP_ERROR_CHECK(esp_vfs_register("/data", &myfs, NULL));
@ -53,15 +53,15 @@ Case 2: API functions are declared with an extra context pointer (FS driver supp
// In definition of esp_vfs_t:
.flags = ESP_VFS_FLAG_CONTEXT_PTR,
.write_p = &myfs_write,
// ... other member initialized
// ... other members initialized
// When registering FS, pass the FS context pointer into the third argument
// (hypothetical myfs_mount function is used for illustrative purposes)
myfs_t* myfs_inst1 = myfs_mount(partition1->offset, parition1->size);
myfs_t* myfs_inst1 = myfs_mount(partition1->offset, partition1->size);
ESP_ERROR_CHECK(esp_vfs_register("/data1", &myfs, myfs_inst1));
// Can register another instance:
myfs_t* myfs_inst2 = myfs_mount(partition2->offset, parition2->size);
myfs_t* myfs_inst2 = myfs_mount(partition2->offset, partition2->size);
ESP_ERROR_CHECK(esp_vfs_register("/data2", &myfs, myfs_inst2));
Paths
@ -79,7 +79,12 @@ This **will not work** as expected:
- FS 1 on /data
- FS 2 on /data/fs2
When opening files, FS driver will only be given relative path to files. If the ``myfs`` driver is registered with ``/data`` as prefix, and application calls ``fopen("/data/config.json", ...)``, VFS component will call ``myfs_open("/config.json", ...)``.
When opening files, FS driver will only be given relative path to files. For example:
- ``myfs`` driver is registered with ``/data`` as path prefix
- and application calls ``fopen("/data/config.json", ...)``
- then VFS component will call ``myfs_open("/config.json", ...)``.
- ``myfs`` driver will open ``/config.json`` file
VFS doesn't impose a limit on total file path length, but it does limit FS path prefix to ``ESP_VFS_PATH_MAX`` characters. Individual FS drivers may have their own filename length limitations.

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __ESP_VFS_H__
#define __ESP_VFS_H__
#ifndef __ESP_VFS_DEV_H__
#define __ESP_VFS_DEV_H__
#include "esp_vfs.h"
@ -25,4 +25,4 @@
void esp_vfs_dev_uart_register();
#endif //__ESP_VFS_H__
#endif //__ESP_VFS_DEV_H__