git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15152 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-11-29 13:29:30 +00:00
parent 271f5841ce
commit 80ff5d0766
3 changed files with 37 additions and 27 deletions

View File

@ -142,8 +142,6 @@ static const struct vfs_fatfs_file_node_vmt file_node_vmt = {
static vfs_fatfs_dir_node_t drv_dir_nodes[DRV_DIR_NODES_NUM];
static vfs_fatfs_file_node_t drv_file_nodes[DRV_FILE_NODES_NUM];
static vfs_fatfs_driver_t drv_fatfs;
/*===========================================================================*/
/* Module local functions. */
/*===========================================================================*/
@ -200,7 +198,7 @@ static msg_t drv_open_dir(void *instance,
vfs_fatfs_dir_node_t *ffdnp;
FRESULT res;
ffdnp = chPoolAlloc(&drv_fatfs.dir_nodes_pool);
ffdnp = chPoolAlloc(&drvp->dir_nodes_pool);
if (ffdnp != NULL) {
/* Node object initialization.*/
@ -215,7 +213,7 @@ static msg_t drv_open_dir(void *instance,
break;
}
chPoolFree(&drv_fatfs.dir_nodes_pool, (void *)ffdnp);
chPoolFree(&drvp->dir_nodes_pool, (void *)ffdnp);
}
err = translate_error(res);
@ -236,7 +234,7 @@ static msg_t drv_open_file(void *instance,
vfs_fatfs_file_node_t *fffnp;
FRESULT res;
fffnp = chPoolAlloc(&drv_fatfs.file_nodes_pool);
fffnp = chPoolAlloc(&drvp->file_nodes_pool);
if (fffnp != NULL) {
/* Node object initialization.*/
@ -251,7 +249,7 @@ static msg_t drv_open_file(void *instance,
break;
}
chPoolFree(&drv_fatfs.file_nodes_pool, (void *)fffnp);
chPoolFree(&drvp->file_nodes_pool, (void *)fffnp);
}
err = translate_error(res);
@ -292,10 +290,11 @@ static msg_t node_dir_next(void *instance, vfs_node_info_t *nip) {
do {
vfs_fatfs_dir_node_t *ffdnp = (vfs_fatfs_dir_node_t *)instance;
vfs_fatfs_driver_t *drvp = (vfs_fatfs_driver_t *)ffdnp->driver;
FRESULT res;
FILINFO *fip;
fip = (FILINFO *)chPoolAlloc(&drv_fatfs.info_nodes_pool);
fip = (FILINFO *)chPoolAlloc(&drvp->info_nodes_pool);
if (fip != NULL) {
res = f_readdir(&ffdnp->dir, fip);
@ -315,7 +314,7 @@ static msg_t node_dir_next(void *instance, vfs_node_info_t *nip) {
err = translate_error(res);
}
chPoolFree(&drv_fatfs.info_nodes_pool, (void *)fip);
chPoolFree(&drvp->info_nodes_pool, (void *)fip);
}
}
while (false);
@ -377,31 +376,41 @@ static vfs_offset_t node_file_getsize(void *instance) {
/* Module exported functions. */
/*===========================================================================*/
vfs_driver_t *drvFatfsInit(const char *rootname) {
/**
* @brief VFS FatFS object initialization.
*
* @param[out] vodp pointer to a @p vfs_fatfs_driver_t structure
* @param[in] rootname name to be attributed to this object
* @return A pointer to this initialized object.
*
* @api
*/
vfs_driver_t *drvFatfsObjectInit(vfs_fatfs_driver_t *ffdp,
const char *rootname) {
drv_fatfs.vmt = &driver_vmt;
drv_fatfs.rootname = rootname;
ffdp->vmt = &driver_vmt;
ffdp->rootname = rootname;
/* Initializing pools.*/
chPoolObjectInit(&drv_fatfs.dir_nodes_pool,
chPoolObjectInit(&ffdp->dir_nodes_pool,
sizeof (vfs_fatfs_dir_node_t),
chCoreAllocAligned);
chPoolObjectInit(&drv_fatfs.file_nodes_pool,
chPoolObjectInit(&ffdp->file_nodes_pool,
sizeof (vfs_fatfs_file_node_t),
chCoreAllocAligned);
chPoolObjectInit(&drv_fatfs.info_nodes_pool,
chPoolObjectInit(&ffdp->info_nodes_pool,
sizeof (FILINFO),
chCoreAllocAligned);
/* Preloading pools.*/
chPoolLoadArray(&drv_fatfs.dir_nodes_pool,
chPoolLoadArray(&ffdp->dir_nodes_pool,
drv_dir_nodes,
DRV_DIR_NODES_NUM);
chPoolLoadArray(&drv_fatfs.file_nodes_pool,
chPoolLoadArray(&ffdp->file_nodes_pool,
drv_file_nodes,
DRV_FILE_NODES_NUM);
return (vfs_driver_t *)&drv_fatfs;
return (vfs_driver_t *)ffdp;
}
/** @} */

View File

@ -170,7 +170,8 @@ typedef struct vfs_drv_streams {
#ifdef __cplusplus
extern "C" {
#endif
vfs_driver_t *drvFatFSInit(const char *rootname);
vfs_driver_t *drvFatfsObjectInit(vfs_fatfs_driver_t *ffdp,
const char *rootname);
#ifdef __cplusplus
}
#endif

View File

@ -103,7 +103,7 @@ static msg_t match_driver(vfs_overlay_driver_t *odp,
static msg_t drv_open_dir(void *instance,
const char *path,
vfs_directory_node_t **vdnpp) {
vfs_overlay_driver_t *odp = (vfs_overlay_driver_t *)instance;
vfs_overlay_driver_t *drvp = (vfs_overlay_driver_t *)instance;
msg_t err;
do {
@ -113,7 +113,7 @@ static msg_t drv_open_dir(void *instance,
if (*path == '\0') {
/* Creating a root directory node.*/
vfs_overlay_dir_node_t *onp = chPoolAlloc(&odp->dir_nodes_pool);
vfs_overlay_dir_node_t *onp = chPoolAlloc(&drvp->dir_nodes_pool);
if (onp != NULL) {
/* Node object initialization.*/
@ -130,7 +130,7 @@ static msg_t drv_open_dir(void *instance,
vfs_driver_t *dp;
/* Delegating node creation to a registered driver.*/
err = match_driver(odp, &path, &dp);
err = match_driver(drvp, &path, &dp);
VFS_BREAK_ON_ERROR(err);
err = dp->vmt->open_dir((void *)dp, path, vdnpp);
@ -145,7 +145,7 @@ static msg_t drv_open_file(void *instance,
const char *path,
unsigned mode,
vfs_file_node_t **vfnpp) {
vfs_overlay_driver_t *odp = (vfs_overlay_driver_t *)instance;
vfs_overlay_driver_t *drvp = (vfs_overlay_driver_t *)instance;
msg_t err;
do {
@ -162,7 +162,7 @@ static msg_t drv_open_file(void *instance,
vfs_driver_t *dp;
/* Delegating node creation to a registered driver.*/
err = match_driver(odp, &path, &dp);
err = match_driver(drvp, &path, &dp);
VFS_BREAK_ON_ERROR(err);
err = dp->vmt->open_file((void *)dp, path, mode, vfnpp);
@ -175,11 +175,11 @@ static msg_t drv_open_file(void *instance,
static void node_dir_release(void *instance) {
vfs_overlay_dir_node_t *odnp = (vfs_overlay_dir_node_t *)instance;
vfs_overlay_driver_t *drvp = (vfs_overlay_driver_t *)odnp->driver;
if (--odnp->refs == 0U) {
chPoolFree(&((vfs_overlay_driver_t *)odnp->driver)->dir_nodes_pool,
(void *)odnp);
chPoolFree(&drvp->dir_nodes_pool, (void *)odnp);
}
}
@ -193,12 +193,12 @@ static msg_t node_dir_first(void *instance, vfs_node_info_t *nip) {
static msg_t node_dir_next(void *instance, vfs_node_info_t *nip) {
vfs_overlay_dir_node_t *odnp = (vfs_overlay_dir_node_t *)instance;
vfs_overlay_driver_t *drvp = (vfs_overlay_driver_t *)odnp->driver;
if (odnp->index < DRV_CFG_OVERLAY_DRV_MAX) {
nip->attr = VFS_NODE_ATTR_ISDIR | VFS_NODE_ATTR_READONLY;
nip->size = (vfs_offset_t)0;
strcpy(nip->name,
((vfs_overlay_driver_t *)odnp->driver)->drivers[odnp->index]->rootname);
strcpy(nip->name, drvp->drivers[odnp->index]->rootname);
odnp->index++;