Simplified registration API.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15259 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-12-26 11:17:55 +00:00
parent 57243c7553
commit 6ee9cb3b46
7 changed files with 36 additions and 40 deletions

View File

@ -498,17 +498,14 @@ void __drv_fatfs_init(void) {
/**
* @brief VFS FatFS object initialization.
*
* @param[out] vffdp pointer to a @p vfs_fatfs_driver_c structure
* @param[in] rootname name to be attributed to this object
* @param[out] vffdp Pointer to a @p vfs_fatfs_driver_c structure.
* @return A pointer to this initialized object.
*
* @api
*/
vfs_driver_c *drvFatFSObjectInit(vfs_fatfs_driver_c *vffdp,
const char *rootname) {
vfs_driver_c *drvFatFSObjectInit(vfs_fatfs_driver_c *vffdp) {
__base_object_objinit_impl(vffdp, &driver_vmt);
vffdp->rootname = rootname;
return (vfs_driver_c *)vffdp;
}
@ -516,10 +513,10 @@ vfs_driver_c *drvFatFSObjectInit(vfs_fatfs_driver_c *vffdp,
/**
* @brief Mounts a FatFS volume.
*
* @param[in] name name to be assigned to the volume, see FatFS
* @param[in] name Name to be assigned to the volume, see FatFS
* @p f_mount() documentation because there are several
* options
* @param[in] mountnow immediate mount option
* options.
* @param[in] mountnow Immediate mount option.
* @return The operation result.
*
* @api
@ -541,7 +538,7 @@ msg_t drvFatFSMount(const char *name, bool mountnow) {
/**
* @brief Unmounts a FatFS volume.
*
* @param[in] ffdp pointer to a @p vfs_fatfs_driver_c structure
* @param[in] name Name of the volume to be unmounted.
* @return The operation result.
*
* @api

View File

@ -170,8 +170,7 @@ typedef struct vfs_fatfs_driver {
extern "C" {
#endif
void __drv_fatfs_init(void);
vfs_driver_c *drvFatFSObjectInit(vfs_fatfs_driver_c *vffdp,
const char *rootname);
vfs_driver_c *drvFatFSObjectInit(vfs_fatfs_driver_c *vffdp);
msg_t drvFatFSMount(const char *name, bool mountnow);
msg_t drvFatFSUnmount(const char *name);
#ifdef __cplusplus

View File

@ -95,21 +95,22 @@ static msg_t match_driver(vfs_overlay_driver_c *odp,
vfs_driver_c **vdpp) {
char fname[VFS_CFG_NAMELEN_MAX + 1];
msg_t err;
vfs_driver_c **pp;
do {
unsigned i;
err = vfs_parse_get_fname(pathp, fname, VFS_CFG_PATHLEN_MAX);
VFS_BREAK_ON_ERROR(err);
/* Searching among registered drivers.*/
pp = &odp->drivers[0];
while (pp < &odp->drivers[odp->next_driver]) {
if (strncmp(fname, (*pp)->rootname, VFS_CFG_NAMELEN_MAX) == 0) {
*vdpp = *pp;
i = 0U;
while (i < odp->next_driver) {
if (strncmp(fname, odp->names[i], VFS_CFG_NAMELEN_MAX) == 0) {
*vdpp = odp->drivers[i];
return VFS_RET_SUCCESS;
}
pp++;
i++;
}
err = VFS_RET_ENOENT;
@ -436,7 +437,7 @@ static msg_t node_dir_next(void *instance, vfs_node_info_t *nip) {
if (odnp->index < drvp->next_driver) {
nip->attr = VFS_NODE_ATTR_ISDIR | VFS_NODE_ATTR_READONLY;
nip->size = (vfs_offset_t)0;
strcpy(nip->name, drvp->drivers[odnp->index]->rootname);
strcpy(nip->name, drvp->names[odnp->index]);
odnp->index++;
@ -485,22 +486,19 @@ void __drv_overlay_init(void) {
/**
* @brief VFS overlay object initialization.
*
* @param[out] vodp pointer to a @p vfs_overlay_driver_c structure
* @param[in] overlaid_drv pointer to a driver to be overlaid or @p NULL
* @param[in] path_prefix prefix to be added to the paths or @p NULL, it
* must be a normalized absolute path
* @param[in] rootname name to be attributed to this object
* @param[out] vodp Pointer to a @p vfs_overlay_driver_c structure.
* @param[in] overlaid_drv Pointer to a driver to be overlaid or @p NULL.
* @param[in] path_prefix Prefix to be added to the paths or @p NULL, it
* must be a normalized absolute path.
* @return A pointer to this initialized object.
*
* @api
*/
vfs_driver_c *drvOverlayObjectInit(vfs_overlay_driver_c *vodp,
vfs_driver_c *overlaid_drv,
const char *path_prefix,
const char *rootname) {
const char *path_prefix) {
__base_object_objinit_impl(vodp, &driver_vmt);
vodp->rootname = rootname;
vodp->overlaid_drv = overlaid_drv;
vodp->path_prefix = path_prefix;
vodp->path_cwd = NULL;
@ -512,20 +510,26 @@ vfs_driver_c *drvOverlayObjectInit(vfs_overlay_driver_c *vodp,
/**
* @brief Registers a VFS driver as an overlay.
*
* @param[in] vodp pointer to a @p vfs_overlay_driver_c structure
* @param[in] vodp Pointer to a @p vfs_overlay_driver_c structure.
* @param[in] vdp Pointer to a @p vfs_driver_c structure to
* be registered.
* @param[in] name Name to be associated to the registered driver.
* @return The operation result.
*
* @api
*/
msg_t drvOverlayRegisterDriver(vfs_overlay_driver_c *vodp,
vfs_driver_c *vdp) {
vfs_driver_c *vdp,
const char *name) {
msg_t err;
if (vodp->next_driver >= DRV_CFG_OVERLAY_DRV_MAX) {
err = VFS_RET_ENOMEM;
}
else {
vodp->drivers[vodp->next_driver++] = vdp;
vodp->names[vodp->next_driver] = name;
vodp->drivers[vodp->next_driver] = vdp;
vodp->next_driver++;
err = VFS_RET_SUCCESS;
}

View File

@ -116,6 +116,7 @@ typedef struct vfs_overlay_dir_node {
/* Next registration slot.*/ \
unsigned next_driver; \
/* Registration slots.*/ \
const char *names[DRV_CFG_OVERLAY_DRV_MAX]; \
vfs_driver_c *drivers[DRV_CFG_OVERLAY_DRV_MAX];
/**
@ -150,10 +151,10 @@ extern "C" {
void __drv_overlay_init(void);
vfs_driver_c *drvOverlayObjectInit(vfs_overlay_driver_c *vodp,
vfs_driver_c *overlaid_drv,
const char *path_prefix,
const char *rootname);
const char *path_prefix);
msg_t drvOverlayRegisterDriver(vfs_overlay_driver_c *vodp,
vfs_driver_c *vdp);
vfs_driver_c *vdp,
const char *name);
#ifdef __cplusplus
}
#endif

View File

@ -315,19 +315,16 @@ void __drv_streams_init(void) {
/**
* @brief VFS streams object initialization.
*
* @param[out] vsdp pointer to a @p vfs_streams_driver_c structure
* @param[in] rootname name to be attributed to this object
* @param[in] streams pointer to an array of @p drv_streams_element_t objects
* @param[out] vsdp Pointer to a @p vfs_streams_driver_c structure.
* @param[in] streams Pointer to an array of @p drv_streams_element_t objects.
* @return A pointer to this initialized object.
*
* @api
*/
vfs_driver_c *drvStreamsObjectInit(vfs_streams_driver_c *vsdp,
const char *rootname,
const drv_streams_element_t *streams) {
__base_object_objinit_impl(vsdp, &driver_vmt);
vsdp->rootname = rootname;
vsdp->streams = streams;
return (vfs_driver_c *)vsdp;

View File

@ -183,7 +183,6 @@ extern "C" {
#endif
void __drv_streams_init(void);
vfs_driver_c *drvStreamsObjectInit(vfs_streams_driver_c *vsdp,
const char *rootname,
const drv_streams_element_t *streams);
#ifdef __cplusplus
}

View File

@ -81,8 +81,7 @@
* @brief @p vfs_driver_c specific data.
*/
#define __vfs_driver_data \
__base_object_data \
const char *rootname;
__base_object_data
/**
* @brief @p vfs_driver_c virtual methods table.