diff --git a/sys/fs/constfs/constfs.c b/sys/fs/constfs/constfs.c index f3fcbe1c8f..3152db1b4d 100644 --- a/sys/fs/constfs/constfs.c +++ b/sys/fs/constfs/constfs.c @@ -33,46 +33,34 @@ #include "debug.h" /* File system operations */ -static int constfs_mount(vfs_mount_t *mountp); -static int constfs_umount(vfs_mount_t *mountp); -static int constfs_unlink(vfs_mount_t *mountp, const char *name); static int constfs_stat(vfs_mount_t *mountp, const char *restrict name, struct stat *restrict buf); static int constfs_statvfs(vfs_mount_t *mountp, const char *restrict path, struct statvfs *restrict buf); /* File operations */ -static int constfs_close(vfs_file_t *filp); static int constfs_fstat(vfs_file_t *filp, struct stat *buf); static off_t constfs_lseek(vfs_file_t *filp, off_t off, int whence); static int constfs_open(vfs_file_t *filp, const char *name, int flags, mode_t mode, const char *abs_path); static ssize_t constfs_read(vfs_file_t *filp, void *dest, size_t nbytes); -static ssize_t constfs_write(vfs_file_t *filp, const void *src, size_t nbytes); /* Directory operations */ static int constfs_opendir(vfs_DIR *dirp, const char *dirname, const char *abs_path); static int constfs_readdir(vfs_DIR *dirp, vfs_dirent_t *entry); -static int constfs_closedir(vfs_DIR *dirp); static const vfs_file_system_ops_t constfs_fs_ops = { - .mount = constfs_mount, - .umount = constfs_umount, - .unlink = constfs_unlink, .statvfs = constfs_statvfs, .stat = constfs_stat, }; static const vfs_file_ops_t constfs_file_ops = { - .close = constfs_close, .fstat = constfs_fstat, .lseek = constfs_lseek, .open = constfs_open, .read = constfs_read, - .write = constfs_write, }; static const vfs_dir_ops_t constfs_dir_ops = { .opendir = constfs_opendir, .readdir = constfs_readdir, - .closedir = constfs_closedir, }; const vfs_file_system_t constfs_file_system = { @@ -91,28 +79,6 @@ const vfs_file_system_t constfs_file_system = { */ static void _constfs_write_stat(const constfs_file_t *fp, struct stat *restrict buf); -static int constfs_mount(vfs_mount_t *mountp) -{ - /* perform any extra initialization here */ - (void) mountp; /* prevent warning: unused parameter */ - return 0; -} - -static int constfs_umount(vfs_mount_t *mountp) -{ - /* free resources and perform any clean up here */ - (void) mountp; /* prevent warning: unused parameter */ - return 0; -} - -static int constfs_unlink(vfs_mount_t *mountp, const char *name) -{ - /* Removing files is prohibited */ - (void) mountp; /* prevent warning: unused parameter */ - (void) name; /* prevent warning: unused parameter */ - return -EROFS; -} - static int constfs_stat(vfs_mount_t *mountp, const char *restrict name, struct stat *restrict buf) { (void) name; @@ -162,13 +128,6 @@ static int constfs_statvfs(vfs_mount_t *mountp, const char *restrict path, struc return 0; } -static int constfs_close(vfs_file_t *filp) -{ - /* perform any necessary clean ups */ - (void) filp; /* prevent warning: unused parameter */ - return 0; -} - static int constfs_fstat(vfs_file_t *filp, struct stat *buf) { constfs_file_t *fp = filp->private_data.ptr; @@ -244,18 +203,6 @@ static ssize_t constfs_read(vfs_file_t *filp, void *dest, size_t nbytes) return nbytes; } -static ssize_t constfs_write(vfs_file_t *filp, const void *src, size_t nbytes) -{ - DEBUG("constfs_write: %p, %p, %lu\n", (void *)filp, src, (unsigned long)nbytes); - /* Read only file system */ - DEBUG("constfs_write: read only FS\n"); - /* prevent warning: unused parameter */ - (void) filp; - (void) src; - (void) nbytes; - return -EBADF; -} - static int constfs_opendir(vfs_DIR *dirp, const char *dirname, const char *abs_path) { (void) abs_path; @@ -298,14 +245,6 @@ static int constfs_readdir(vfs_DIR *dirp, vfs_dirent_t *entry) return 1; } -static int constfs_closedir(vfs_DIR *dirp) -{ - /* Just an example, it's not necessary to define closedir if there is - * nothing to clean up */ - (void) dirp; - return 0; -} - static void _constfs_write_stat(const constfs_file_t *fp, struct stat *restrict buf) { /* buffer is cleared by vfs already */ diff --git a/sys/vfs/vfs.c b/sys/vfs/vfs.c index 90fbbf9aef..6a9a7f549e 100644 --- a/sys/vfs/vfs.c +++ b/sys/vfs/vfs.c @@ -609,7 +609,7 @@ int vfs_rename(const char *from_path, const char *to_path) DEBUG("vfs_rename: rename not supported by fs!\n"); /* remember to decrement the open_files count */ atomic_fetch_sub(&mountp->open_files, 1); - return -EPERM; + return -EROFS; } const char *rel_to; vfs_mount_t *mountp_to; @@ -668,7 +668,7 @@ int vfs_unlink(const char *name) DEBUG("vfs_unlink: unlink not supported by fs!\n"); /* remember to decrement the open_files count */ atomic_fetch_sub(&mountp->open_files, 1); - return -EPERM; + return -EROFS; } res = mountp->fs->fs_op->unlink(mountp, rel_path); DEBUG("vfs_unlink: unlink %p, \"%s\"", (void *)mountp, rel_path); @@ -705,7 +705,7 @@ int vfs_mkdir(const char *name, mode_t mode) DEBUG("vfs_mkdir: mkdir not supported by fs!\n"); /* remember to decrement the open_files count */ atomic_fetch_sub(&mountp->open_files, 1); - return -EPERM; + return -EROFS; } res = mountp->fs->fs_op->mkdir(mountp, rel_path, mode); DEBUG("vfs_mkdir: mkdir %p, \"%s\"", (void *)mountp, rel_path); @@ -742,7 +742,7 @@ int vfs_rmdir(const char *name) DEBUG("vfs_rmdir: rmdir not supported by fs!\n"); /* remember to decrement the open_files count */ atomic_fetch_sub(&mountp->open_files, 1); - return -EPERM; + return -EROFS; } res = mountp->fs->fs_op->rmdir(mountp, rel_path); DEBUG("vfs_rmdir: rmdir %p, \"%s\"", (void *)mountp, rel_path); diff --git a/tests/unittests/tests-vfs/tests-vfs-file-system-ops.c b/tests/unittests/tests-vfs/tests-vfs-file-system-ops.c index 91da825557..05070109a4 100644 --- a/tests/unittests/tests-vfs/tests-vfs-file-system-ops.c +++ b/tests/unittests/tests-vfs/tests-vfs-file-system-ops.c @@ -96,28 +96,28 @@ static void test_vfs_null_fs_ops_rename(void) { TEST_ASSERT_EQUAL_INT(0, _test_vfs_fs_op_mount_res); int res = vfs_rename("/test/foo", "/test/bar"); - TEST_ASSERT_EQUAL_INT(-EPERM, res); + TEST_ASSERT_EQUAL_INT(-EROFS, res); } static void test_vfs_null_fs_ops_unlink(void) { TEST_ASSERT_EQUAL_INT(0, _test_vfs_fs_op_mount_res); int res = vfs_unlink("/test/foo"); - TEST_ASSERT_EQUAL_INT(-EPERM, res); + TEST_ASSERT_EQUAL_INT(-EROFS, res); } static void test_vfs_null_fs_ops_mkdir(void) { TEST_ASSERT_EQUAL_INT(0, _test_vfs_fs_op_mount_res); int res = vfs_mkdir("/test/foodir", 0); - TEST_ASSERT_EQUAL_INT(-EPERM, res); + TEST_ASSERT_EQUAL_INT(-EROFS, res); } static void test_vfs_null_fs_ops_rmdir(void) { TEST_ASSERT_EQUAL_INT(0, _test_vfs_fs_op_mount_res); int res = vfs_rmdir("/test/foodir"); - TEST_ASSERT_EQUAL_INT(-EPERM, res); + TEST_ASSERT_EQUAL_INT(-EROFS, res); } static void test_vfs_null_fs_ops_stat(void)