From 3c2c5df6e898ca10107a0c359d8d73e55222449a Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Tue, 14 Sep 2010 04:45:45 +0000 Subject: [PATCH] fix O_RDWR issue in ELM FatFs. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@912 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- components/dfs/filesystems/elmfat/dfs_elm.c | 3 +- components/dfs/filesystems/romfs/dfs_romfs.c | 2 +- components/dfs/filesystems/uffs/dfs_uffs.c | 92 ++++++++++++++++++++ components/dfs/filesystems/uffs/dfs_uffs.h | 20 +++++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 components/dfs/filesystems/uffs/dfs_uffs.c create mode 100644 components/dfs/filesystems/uffs/dfs_uffs.h diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index c2143d51a1..ebed2b8b5d 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -228,6 +228,7 @@ int dfs_elm_open(struct dfs_fd* file) mode = FA_READ; if (file->flags & DFS_O_WRONLY) mode |= FA_WRITE; + if ((file->flags & DFS_O_ACCMODE) & DFS_O_RDWR) mode |= FA_WRITE; /* Opens the file, if it is existing. If not, a new file is created. */ if (file->flags & DFS_O_CREAT) mode |= FA_OPEN_ALWAYS; /* Creates a new file. If the file is existing, it is truncated and overwritten. */ @@ -489,7 +490,7 @@ int dfs_elm_rename(struct dfs_filesystem* fs, const char* oldpath, const char* n const char *drivers_oldfn, *drivers_newfn; drivers_oldfn = oldpath; - drivers_newfn = oldpath; + drivers_newfn = newpath; #endif result = f_rename(drivers_oldfn, drivers_newfn); diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index 2f46698904..efd74e238b 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -113,7 +113,7 @@ int dfs_romfs_open(struct dfs_fd* file) root_dirent = (struct romfs_dirent*)file->fs->data; - if (file->flags & DFS_O_CREAT | DFS_O_WRONLY | DFS_O_APPEND | DFS_O_TRUNC) + if (file->flags & (DFS_O_CREAT | DFS_O_WRONLY | DFS_O_APPEND | DFS_O_TRUNC | DFS_O_RDWR)) return -DFS_STATUS_EINVAL; dirent = dfs_romfs_lookup(root_dirent, file->path); diff --git a/components/dfs/filesystems/uffs/dfs_uffs.c b/components/dfs/filesystems/uffs/dfs_uffs.c new file mode 100644 index 0000000000..43ce7d4496 --- /dev/null +++ b/components/dfs/filesystems/uffs/dfs_uffs.c @@ -0,0 +1,92 @@ +#include +#include +#include + +/* mount and unmount file system */ +static int dfs_uffs_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data) +{ +} + +static int dfs_uffs_unmount(struct dfs_filesystem* fs) +{ +} + +static int dfs_uffs_mkfs(const char* device_name) +{ + return -DFS_STATUS_EIO; +} + +static int dfs_uffs_statfs(struct dfs_filesystem* fs, struct _statfs *buf) +{ +} + +static int dfs_uffs_open(struct dfs_fd* fd) +{ +} + +static int dfs_uffs_close(struct dfs_fd* fd) +{ +} + +static int dfs_uffs_ioctl(struct dfs_fd* fd, int cmd, void *args) +{ +} + +static int dfs_uffs_read(struct dfs_fd* fd, void* buf, rt_size_t count) +{ +} + +static int dfs_uffs_write(struct dfs_fd* fd, const void* buf, rt_size_t count) +{ +} + +static int dfs_uffs_flush(struct dfs_fd* fd) +{ +} + +static int dfs_uffs_lseek(struct dfs_fd* fd, rt_off_t offset) +{ +} + +static int dfs_uffs_getdents(struct dfs_fd* fd, struct _dirent* dirp, rt_uint32_t count) +{ +} + +static int dfs_uffs_unlink(struct dfs_filesystem* fs, const char* pathname) +{ +} + +static int dfs_uffs_stat(struct dfs_filesystem* fs, const char* filename, struct _stat* buf) +{ +} + +static int dfs_uffs_rename(struct dfs_filesystem* fs, const char* oldpath, const char* newpath) +{ +} + +static const struct dfs_filesystem_operation _uffs = +{ + "uffs", + dfs_uffs_mount, + dfs_uffs_unmount, + dfs_uffs_mkfs, + dfs_uffs_statfs, + + dfs_uffs_open, + dfs_uffs_close, + dfs_uffs_ioctl, + dfs_uffs_read, + dfs_uffs_write, + dfs_uffs_flush, + dfs_uffs_lseek, + dfs_uffs_getdents, + dfs_uffs_unlink, + dfs_uffs_stat, + dfs_uffs_rename, +}; + +int dfs_uffs_init(void) +{ + /* register UFFS file system */ + return dfs_register(&_uffs); +} diff --git a/components/dfs/filesystems/uffs/dfs_uffs.h b/components/dfs/filesystems/uffs/dfs_uffs.h new file mode 100644 index 0000000000..0f6d497c7c --- /dev/null +++ b/components/dfs/filesystems/uffs/dfs_uffs.h @@ -0,0 +1,20 @@ +/* + * File : dfs_uffs.h + * This file is part of Device File System in RT-Thread RTOS + * COPYRIGHT (C) 2004-2010, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE. + * + * Change Logs: + * Date Author Notes + * 2010-09-02 Bernard The first version. + */ + +#ifndef __DFS_UFFS_H__ +#define __DFS_UFFS_H__ + +int dfs_uffs_init(void); + +#endif