Setting CWD works now but there are other problems. Added an error code handling macro for convenience.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15251 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
d53fa016d9
commit
107f03dc23
|
@ -347,7 +347,7 @@ static void cmd_cd(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
msg_t res;
|
msg_t res;
|
||||||
|
|
||||||
res = vfsChangeCurrentDirectory(argv[0]);
|
res = vfsChangeCurrentDirectory(argv[0]);
|
||||||
if (res != VFS_RET_SUCCESS) {
|
if (VFS_IS_ERROR(res)) {
|
||||||
chprintf(chp, "failed (%d)" SHELL_NEWLINE_STR, res);
|
chprintf(chp, "failed (%d)" SHELL_NEWLINE_STR, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,11 +374,11 @@ static void cmd_cwd(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
res = vfsGetCurrentDirectory(buf, VFS_CFG_PATHLEN_MAX + 1);
|
res = vfsGetCurrentDirectory(buf, VFS_CFG_PATHLEN_MAX + 1);
|
||||||
if (res == VFS_RET_SUCCESS) {
|
if (VFS_IS_ERROR(res)) {
|
||||||
chprintf(chp, "%s" SHELL_NEWLINE_STR, buf);
|
chprintf(chp, "Failed (%d)" SHELL_NEWLINE_STR, res);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chprintf(chp, "Failed (%d)" SHELL_NEWLINE_STR, res);
|
chprintf(chp, "%s" SHELL_NEWLINE_STR, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
|
@ -159,6 +159,36 @@ static msg_t build_path(vfs_overlay_driver_c *drvp,
|
||||||
return VFS_RET_SUCCESS;
|
return VFS_RET_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static msg_t build_absolute_path(vfs_overlay_driver_c *drvp,
|
||||||
|
char *buf,
|
||||||
|
const char *path) {
|
||||||
|
msg_t ret;
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
/* Initial buffer state, empty string.*/
|
||||||
|
*buf = '\0';
|
||||||
|
|
||||||
|
/* Relative paths handling.*/
|
||||||
|
if (!vfs_parse_is_separator(*path)) {
|
||||||
|
ret = vfs_path_append(buf,
|
||||||
|
get_current_directory(drvp),
|
||||||
|
VFS_CFG_PATHLEN_MAX);
|
||||||
|
VFS_BREAK_ON_ERROR(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adding the specified path.*/
|
||||||
|
ret = vfs_path_append(buf, path, VFS_CFG_PATHLEN_MAX);
|
||||||
|
VFS_BREAK_ON_ERROR(ret);
|
||||||
|
|
||||||
|
/* Normalization of the absolute path.*/
|
||||||
|
ret = vfs_path_normalize(buf, buf, VFS_CFG_PATHLEN_MAX);
|
||||||
|
|
||||||
|
} while (false);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static msg_t open_dir_absolute(vfs_overlay_driver_c *drvp,
|
static msg_t open_dir_absolute(vfs_overlay_driver_c *drvp,
|
||||||
const char *path,
|
const char *path,
|
||||||
vfs_directory_node_c **vdnpp) {
|
vfs_directory_node_c **vdnpp) {
|
||||||
|
@ -200,7 +230,7 @@ static msg_t open_dir_absolute(vfs_overlay_driver_c *drvp,
|
||||||
|
|
||||||
/* Searching for a match among registered overlays.*/
|
/* Searching for a match among registered overlays.*/
|
||||||
err = match_driver(drvp, &scanpath, &dp);
|
err = match_driver(drvp, &scanpath, &dp);
|
||||||
if (err == VFS_RET_SUCCESS) {
|
if (!VFS_IS_ERROR(err)) {
|
||||||
/* Delegating node creation to a registered driver.*/
|
/* Delegating node creation to a registered driver.*/
|
||||||
err = dp->vmt->open_dir((void *)dp,
|
err = dp->vmt->open_dir((void *)dp,
|
||||||
scanpath,
|
scanpath,
|
||||||
|
@ -231,45 +261,34 @@ static msg_t drv_set_cwd(void *instance, const char *path) {
|
||||||
do {
|
do {
|
||||||
vfs_overlay_driver_c *drvp = (vfs_overlay_driver_c *)instance;
|
vfs_overlay_driver_c *drvp = (vfs_overlay_driver_c *)instance;
|
||||||
vfs_directory_node_c *vdnp;
|
vfs_directory_node_c *vdnp;
|
||||||
size_t cwdoffset;
|
|
||||||
|
|
||||||
/* Taking a path buffer from the pool.*/
|
/* Taking a path buffer from the pool.*/
|
||||||
buf = vfs_buffer_take();
|
buf = vfs_buffer_take();
|
||||||
|
|
||||||
/* Putting a normalized prefix path into the buffer.*/
|
ret = build_absolute_path(drvp, buf, path);
|
||||||
ret = vfs_path_normalize(buf, drvp->path_prefix, VFS_CFG_PATHLEN_MAX);
|
|
||||||
VFS_BREAK_ON_ERROR(ret);
|
|
||||||
cwdoffset = (size_t)ret;
|
|
||||||
|
|
||||||
/* Appending the user CWD. Normalization prevents it to ".."
|
|
||||||
into the imposed prefix path.*/
|
|
||||||
ret = vfs_path_normalize(buf + cwdoffset,
|
|
||||||
path, VFS_CFG_PATHLEN_MAX - (size_t)ret);
|
|
||||||
VFS_BREAK_ON_ERROR(ret);
|
VFS_BREAK_ON_ERROR(ret);
|
||||||
|
|
||||||
/* Trying to access the directory in order to validate the
|
/* Trying to access the directory in order to validate the
|
||||||
combined path.*/
|
combined path.*/
|
||||||
ret = open_dir_absolute(drvp, buf, &vdnp);
|
// ret = open_dir_absolute(drvp, buf, &vdnp);
|
||||||
VFS_BREAK_ON_ERROR(ret);
|
// VFS_BREAK_ON_ERROR(ret);
|
||||||
vdnp->vmt->release((void *)vdnp);
|
// vdnp->vmt->release((void *)vdnp);
|
||||||
|
|
||||||
/* One-time allocation of the CWD buffer, this memory is allocated, once,
|
/* One-time allocation of the CWD buffer, this memory is allocated, once,
|
||||||
only if the application uses a CWD, it is never released.*/
|
only if the application uses a CWD, it is never released.*/
|
||||||
if (drvp->cwd_buffer == NULL) {
|
if (drvp->path_cwd == NULL) {
|
||||||
drvp->cwd_buffer = chCoreAlloc(VFS_CFG_PATHLEN_MAX + 1);
|
drvp->path_cwd = chCoreAlloc(VFS_CFG_PATHLEN_MAX + 1);
|
||||||
if (drvp->cwd_buffer == NULL) {
|
if (drvp->path_cwd == NULL) {
|
||||||
ret = VFS_RET_ENOMEM;
|
ret = VFS_RET_ENOMEM;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copying the validated path into the CWD buffer.*/
|
/* Copying the validated path into the CWD buffer.*/
|
||||||
strcpy(drvp->cwd_buffer, buf);
|
strcpy(drvp->path_cwd, buf);
|
||||||
drvp->path_cwd = drvp->cwd_buffer + cwdoffset;
|
|
||||||
|
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
|
|
||||||
/* Buffer returned.*/
|
/* Buffer returned.*/
|
||||||
vfs_buffer_release(buf);
|
vfs_buffer_release(buf);
|
||||||
|
|
||||||
|
@ -325,7 +344,7 @@ static msg_t drv_open_dir(void *instance,
|
||||||
|
|
||||||
/* Searching for a match among registered overlays.*/
|
/* Searching for a match among registered overlays.*/
|
||||||
err = match_driver(drvp, &scanpath, &dp);
|
err = match_driver(drvp, &scanpath, &dp);
|
||||||
if (err == VFS_RET_SUCCESS) {
|
if (!VFS_IS_ERROR(err)) {
|
||||||
/* Delegating node creation to a registered driver.*/
|
/* Delegating node creation to a registered driver.*/
|
||||||
err = dp->vmt->open_dir((void *)dp,
|
err = dp->vmt->open_dir((void *)dp,
|
||||||
scanpath,
|
scanpath,
|
||||||
|
@ -344,7 +363,7 @@ static msg_t drv_open_dir(void *instance,
|
||||||
err = build_path(drvp, path, buf);
|
err = build_path(drvp, path, buf);
|
||||||
|
|
||||||
/* Passing the combined path to the overlaid driver.*/
|
/* Passing the combined path to the overlaid driver.*/
|
||||||
if (err == VFS_RET_SUCCESS) {
|
if (!VFS_IS_ERROR(err)) {
|
||||||
err = drvp->overlaid_drv->vmt->open_dir((void *)drvp->overlaid_drv,
|
err = drvp->overlaid_drv->vmt->open_dir((void *)drvp->overlaid_drv,
|
||||||
buf,
|
buf,
|
||||||
vdnpp);
|
vdnpp);
|
||||||
|
@ -385,7 +404,7 @@ static msg_t drv_open_file(void *instance,
|
||||||
|
|
||||||
/* Searching for a match among registered overlays.*/
|
/* Searching for a match among registered overlays.*/
|
||||||
err = match_driver(drvp, &scanpath, &dp);
|
err = match_driver(drvp, &scanpath, &dp);
|
||||||
if (err == VFS_RET_SUCCESS) {
|
if (!VFS_IS_ERROR(err)) {
|
||||||
/* Delegating node creation to a registered driver.*/
|
/* Delegating node creation to a registered driver.*/
|
||||||
err = dp->vmt->open_file((void *)dp, scanpath, oflag, vfnpp);
|
err = dp->vmt->open_file((void *)dp, scanpath, oflag, vfnpp);
|
||||||
}
|
}
|
||||||
|
@ -402,7 +421,7 @@ static msg_t drv_open_file(void *instance,
|
||||||
err = build_path(drvp, path, buf);
|
err = build_path(drvp, path, buf);
|
||||||
|
|
||||||
/* Passing the combined path to the overlaid driver.*/
|
/* Passing the combined path to the overlaid driver.*/
|
||||||
if (err == VFS_RET_SUCCESS) {
|
if (!VFS_IS_ERROR(err)) {
|
||||||
err = drvp->overlaid_drv->vmt->open_file((void *)drvp->overlaid_drv,
|
err = drvp->overlaid_drv->vmt->open_file((void *)drvp->overlaid_drv,
|
||||||
path,
|
path,
|
||||||
oflag,
|
oflag,
|
||||||
|
@ -516,7 +535,6 @@ vfs_driver_c *drvOverlayObjectInit(vfs_overlay_driver_c *vodp,
|
||||||
vodp->overlaid_drv = overlaid_drv;
|
vodp->overlaid_drv = overlaid_drv;
|
||||||
vodp->path_prefix = path_prefix;
|
vodp->path_prefix = path_prefix;
|
||||||
vodp->path_cwd = NULL;
|
vodp->path_cwd = NULL;
|
||||||
vodp->cwd_buffer = NULL;
|
|
||||||
vodp->next_driver = 0U;
|
vodp->next_driver = 0U;
|
||||||
|
|
||||||
return (vfs_driver_c *)vodp;
|
return (vfs_driver_c *)vodp;
|
||||||
|
|
|
@ -113,9 +113,6 @@ typedef struct vfs_overlay_dir_node {
|
||||||
const char *path_prefix ; \
|
const char *path_prefix ; \
|
||||||
/* Current directory or NULL.*/ \
|
/* Current directory or NULL.*/ \
|
||||||
char *path_cwd; \
|
char *path_cwd; \
|
||||||
/* Buffer for absolute current directory or NULL. Contains the prefix
|
|
||||||
plus the current directory normalized.*/ \
|
|
||||||
char *cwd_buffer; \
|
|
||||||
/* Next registration slot.*/ \
|
/* Next registration slot.*/ \
|
||||||
unsigned next_driver; \
|
unsigned next_driver; \
|
||||||
/* Registration slots.*/ \
|
/* Registration slots.*/ \
|
||||||
|
|
|
@ -78,12 +78,14 @@
|
||||||
/* Module macros. */
|
/* Module macros. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
#define VFS_IS_ERROR(err) ((msg_t)(err) < VFS_RET_SUCCESS)
|
||||||
|
|
||||||
#define VFS_BREAK_ON_ERROR(err) \
|
#define VFS_BREAK_ON_ERROR(err) \
|
||||||
if ((err) < VFS_RET_SUCCESS) break
|
if (VFS_IS_ERROR(err)) break
|
||||||
|
|
||||||
#define VFS_RETURN_ON_ERROR(err) do { \
|
#define VFS_RETURN_ON_ERROR(err) do { \
|
||||||
msg_t __ret = (err); \
|
msg_t __ret = (err); \
|
||||||
if (__ret < VFS_RET_SUCCESS) { \
|
if (VFS_IS_ERROR(__ret)) { \
|
||||||
return __ret; \
|
return __ret; \
|
||||||
} \
|
} \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
Loading…
Reference in New Issue