diff options
| author | bernard.xiong <[email protected]> | 2010-10-19 08:18:24 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2010-10-19 08:18:24 +0000 |
| commit | b4a98e4457c3a58301b41db5db50bfbca4546255 (patch) | |
| tree | 161b79af9aa9f3cebeab41905ec795a69658c2e9 /components/dfs/filesystems | |
| parent | 14a0eaf61780622995868dc00e9fb0bf7dddd4f8 (diff) | |
Improve the Device File System of the POSIX compatibility
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1015 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/dfs/filesystems')
| -rw-r--r-- | components/dfs/filesystems/elmfat/dfs_elm.c | 50 | ||||
| -rw-r--r-- | components/dfs/filesystems/nfs/dfs_nfs.c | 14 | ||||
| -rw-r--r-- | components/dfs/filesystems/nfs/rpc/types.h | 6 | ||||
| -rw-r--r-- | components/dfs/filesystems/skeleton/skeleton.c | 81 | ||||
| -rw-r--r-- | components/dfs/filesystems/skeleton/skeleton.h | 8 |
5 files changed, 135 insertions, 24 deletions
diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 43facf04eb..a130e40ff8 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -1,9 +1,12 @@ -#include <dfs_fs.h>
-#include <dfs_def.h>
-
#include "ffconf.h"
#include "ff.h"
+/* ELM FatFs provide a DIR struct */
+#define HAVE_DIR_STRUCTURE
+
+#include <dfs_fs.h>
+#include <dfs_def.h>
+
static rt_device_t disk[_DRIVES] = {0};
static int elm_result_to_dfs(FRESULT result)
@@ -67,7 +70,7 @@ int dfs_elm_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* d break;
}
}
- if (index == _DRIVES) return -DFS_STATUS_EMMOUNT;
+ if (index == _DRIVES) return -DFS_STATUS_ENOSPC;
/* get device */
disk[index] = fs->dev_id;
@@ -94,14 +97,31 @@ int dfs_elm_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* d int dfs_elm_unmount(struct dfs_filesystem* fs)
{
FATFS *fat;
+ FRESULT result;
+ rt_uint32_t index;
+
fat = (FATFS*) fs->data;
RT_ASSERT(fat != RT_NULL);
- /* elm not support unmount */
- rt_kprintf("elm fatfs not support unmount\n");
+ /* find the device index and then umount it */
+ for (index = 0; index < _DRIVES; index ++)
+ {
+ if (disk[index] == fs->dev_id)
+ {
+ result = f_mount(index, RT_NULL);
- return 0;
+ if (result == FR_OK)
+ {
+ fs->data = RT_NULL;
+ disk[index] = RT_NULL;
+ rt_free(fat);
+ return DFS_STATUS_OK;
+ }
+ }
+ }
+
+ return -DFS_STATUS_ENOENT;
}
int dfs_elm_mkfs(const char* device_name)
@@ -134,7 +154,7 @@ int dfs_elm_mkfs(const char* device_name) return -DFS_STATUS_EIO;
}
-int dfs_elm_statfs(struct dfs_filesystem* fs, struct _statfs *buf)
+int dfs_elm_statfs(struct dfs_filesystem* fs, struct statfs *buf)
{
FATFS *f;
FRESULT res;
@@ -374,19 +394,19 @@ int dfs_elm_lseek(struct dfs_fd* file, rt_off_t offset) return elm_result_to_dfs(result);
}
-int dfs_elm_getdents(struct dfs_fd* file, struct _dirent* dirp, rt_uint32_t count)
+int dfs_elm_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count)
{
DIR* dir;
FILINFO fno;
FRESULT result;
rt_uint32_t index;
- struct _dirent* d;
+ struct dirent* d;
dir = (DIR*)(file->data);
RT_ASSERT(dir != RT_NULL);
/* make integer count */
- count = (count / sizeof(struct _dirent)) * sizeof(struct _dirent);
+ count = (count / sizeof(struct dirent)) * sizeof(struct dirent);
if ( count == 0 ) return -DFS_STATUS_EINVAL;
#if _USE_LFN
@@ -416,11 +436,11 @@ int dfs_elm_getdents(struct dfs_fd* file, struct _dirent* dirp, rt_uint32_t coun else d->d_type = DFS_DT_REG;
d->d_namlen = rt_strlen(fn);
- d->d_reclen = (rt_uint16_t)sizeof(struct _dirent);
+ d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
rt_strncpy(d->d_name, fn, rt_strlen(fn) + 1);
index ++;
- if ( index * sizeof(struct _dirent) >= count )
+ if ( index * sizeof(struct dirent) >= count )
break;
}
@@ -431,7 +451,7 @@ int dfs_elm_getdents(struct dfs_fd* file, struct _dirent* dirp, rt_uint32_t coun if (index == 0)
return elm_result_to_dfs(result);
- return index * sizeof(struct _dirent);
+ return index * sizeof(struct dirent);
}
int dfs_elm_unlink(struct dfs_filesystem* fs, const char* path)
@@ -501,7 +521,7 @@ int dfs_elm_rename(struct dfs_filesystem* fs, const char* oldpath, const char* n return elm_result_to_dfs(result);
}
-int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct _stat *st)
+int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct stat *st)
{
FILINFO file_info;
FRESULT result;
diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c index 5824dfd806..a463b0dab4 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/filesystems/nfs/dfs_nfs.c @@ -722,7 +722,7 @@ int nfs_open(struct dfs_fd* file) return 0; } -int nfs_stat(struct dfs_filesystem* fs, const char *path, struct _stat *st) +int nfs_stat(struct dfs_filesystem* fs, const char *path, struct stat *st) { GETATTR3args args; GETATTR3res res; @@ -984,11 +984,11 @@ int nfs_rename(struct dfs_filesystem* fs, const char *src, const char *dest) return ret; } -int nfs_getdents(struct dfs_fd* file, struct _dirent* dirp, rt_uint32_t count) +int nfs_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count) { nfs_dir *dir; rt_uint32_t index; - struct _dirent* d; + struct dirent* d; struct nfs_filesystem* nfs; char *name; @@ -999,7 +999,7 @@ int nfs_getdents(struct dfs_fd* file, struct _dirent* dirp, rt_uint32_t count) nfs = (struct nfs_filesystem *)file->fs->data; /* make integer count */ - count = (count / sizeof(struct _dirent)) * sizeof(struct _dirent); + count = (count / sizeof(struct dirent)) * sizeof(struct dirent); if ( count == 0 ) return -DFS_STATUS_EINVAL; index = 0; @@ -1015,15 +1015,15 @@ int nfs_getdents(struct dfs_fd* file, struct _dirent* dirp, rt_uint32_t count) d->d_type &= DFS_DT_REG; d->d_namlen = rt_strlen(name); - d->d_reclen = (rt_uint16_t)sizeof(struct _dirent); + d->d_reclen = (rt_uint16_t)sizeof(struct dirent); rt_strncpy(d->d_name, name, rt_strlen(name) + 1); index ++; - if ( index * sizeof(struct _dirent) >= count ) + if ( index * sizeof(struct dirent) >= count ) break; } - return index * sizeof(struct _dirent); + return index * sizeof(struct dirent); } static const struct dfs_filesystem_operation _nfs = diff --git a/components/dfs/filesystems/nfs/rpc/types.h b/components/dfs/filesystems/nfs/rpc/types.h index 29f16cccb3..d16f8bca9f 100644 --- a/components/dfs/filesystems/nfs/rpc/types.h +++ b/components/dfs/filesystems/nfs/rpc/types.h @@ -43,7 +43,6 @@ typedef unsigned int u_int; typedef unsigned char u_char; typedef unsigned long u_long; -#endif typedef rt_int8_t int8_t; typedef rt_uint8_t uint8_t; @@ -51,6 +50,10 @@ typedef rt_int16_t int16_t; typedef rt_uint16_t uint16_t; typedef rt_int32_t int32_t; typedef rt_uint32_t uint32_t; +#else +#include <sys/types.h> +#include <stdint.h> +#endif typedef long long int64_t; typedef unsigned long long uint64_t; @@ -60,7 +63,6 @@ typedef int enum_t; #ifndef RT_USING_NEWLIB typedef rt_int32_t ssize_t; -typedef unsigned long mode_t; typedef unsigned long dev_t; #endif diff --git a/components/dfs/filesystems/skeleton/skeleton.c b/components/dfs/filesystems/skeleton/skeleton.c new file mode 100644 index 0000000000..516879d59e --- /dev/null +++ b/components/dfs/filesystems/skeleton/skeleton.c @@ -0,0 +1,81 @@ +/*
+ * A skeleton of file system in Device File System
+ */
+#include <rtthread.h>
+#include <dfs.h>
+#include <dfs_fs.h>
+
+#include "dfs_skt_fs.h"
+
+int dfs_skt_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data)
+{
+ return DFS_STATUS_OK;
+}
+
+int dfs_skt_unmount(struct dfs_filesystem* fs)
+{
+ return DFS_STATUS_OK;
+}
+
+int dfs_skt_ioctl(struct dfs_fd* file, int cmd, void* args)
+{
+ return -DFS_STATUS_EIO;
+}
+
+int dfs_skt_read(struct dfs_fd* file, void *buf, rt_size_t count)
+{
+ return count;
+}
+
+int dfs_skt_lseek(struct dfs_fd* file, rt_off_t offset)
+{
+ return -DFS_STATUS_EIO;
+}
+
+int dfs_skt_close(struct dfs_fd* file)
+{
+ return DFS_STATUS_OK;
+}
+
+int dfs_skt_open(struct dfs_fd* file)
+{
+ return DFS_STATUS_OK;
+}
+
+int dfs_skt_stat(struct dfs_filesystem* fs, const char *path, struct stat *st)
+{
+ return DFS_STATUS_OK;
+}
+
+int dfs_skt_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count)
+{
+ return count * sizeof(struct dirent);
+}
+
+static const struct dfs_filesystem_operation _skt_fs =
+{
+ "skt",
+ dfs_skt_mount,
+ dfs_skt_unmount,
+ RT_NULL,
+ RT_NULL,
+
+ dfs_skt_open,
+ dfs_skt_close,
+ dfs_skt_ioctl,
+ dfs_skt_read,
+ RT_NULL,
+ RT_NULL,
+ dfs_skt_lseek,
+ dfs_skt_getdents,
+ RT_NULL,
+ dfs_skt_stat,
+ RT_NULL,
+};
+
+int dfs_skt_init(void)
+{
+ /* register rom file system */
+ dfs_register(&_skt_fs);
+ return 0;
+}
diff --git a/components/dfs/filesystems/skeleton/skeleton.h b/components/dfs/filesystems/skeleton/skeleton.h new file mode 100644 index 0000000000..cacbf36b62 --- /dev/null +++ b/components/dfs/filesystems/skeleton/skeleton.h @@ -0,0 +1,8 @@ +#ifndef __SKELETON_H__
+#define __SKELETON_H__
+
+#include <rtthread.h>
+
+int dfs_skt_init(void);
+
+#endif
|
