From 2d0cbb43b54da74d358fb612775ca2696a160553 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Mon, 27 Dec 2021 08:14:37 +0000 Subject: [PATCH] Added CWD support to the FatFS driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15263 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/vfs/drivers/fatfs/drvfatfs.c | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/os/vfs/drivers/fatfs/drvfatfs.c b/os/vfs/drivers/fatfs/drvfatfs.c index e2d724903..809d8aa78 100644 --- a/os/vfs/drivers/fatfs/drvfatfs.c +++ b/os/vfs/drivers/fatfs/drvfatfs.c @@ -45,6 +45,8 @@ /* Module local variables. */ /*===========================================================================*/ +static msg_t drv_set_cwd(void *instance, const char *path); +static msg_t drv_get_cwd(void *instance, char *buf, size_t size); static msg_t drv_open_dir(void *instance, const char *path, vfs_directory_node_c **vdnpp); @@ -54,6 +56,8 @@ static msg_t drv_open_file(void *instance, vfs_file_node_c **vfnpp); static const struct vfs_fatfs_driver_vmt driver_vmt = { + .set_cwd = drv_set_cwd, + .get_cwd = drv_get_cwd, .open_dir = drv_open_dir, .open_file = drv_open_file }; @@ -203,6 +207,45 @@ static BYTE translate_oflag(int oflag) { return (BYTE)0; } +static msg_t drv_set_cwd(void *instance, const char *path) { +#if FF_FS_RPATH >= 1 + + (void)instance; + + return translate_error(f_chdir((const TCHAR *)path)); +#else + + (void)instance; + + if (strcmp(path, "/") != 0) { + return VFS_RET_ENOENT; + } + + return VFS_RET_SUCCESS; +#endif +} + +static msg_t drv_get_cwd(void *instance, char *buf, size_t size) { +#if FF_FS_RPATH >= 2 + + (void)instance; + + return translate_error(f_getcwd((TCHAR *)buf, (UINT)size)); +#else + + (void)instance; + + if (size < 2) { + return VFS_RET_ERANGE; + } + + buf[0] = '/'; + buf[1] = '\0'; + + return VFS_RET_SUCCESS; +#endif +} + static msg_t drv_open_dir(void *instance, const char *path, vfs_directory_node_c **vdnpp) {