提交 cc9667b7 编写于 作者: B bernard

[DFS] Fix the RAMFS compiling issue.

上级 1f76e1b8
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <rtthread.h> #include <rtthread.h>
#include <dfs.h> #include <dfs.h>
#include <dfs_fs.h> #include <dfs_fs.h>
#include <dfs_file.h>
#include "dfs_ramfs.h" #include "dfs_ramfs.h"
int dfs_ramfs_mount(struct dfs_filesystem *fs, int dfs_ramfs_mount(struct dfs_filesystem *fs,
...@@ -131,11 +133,12 @@ int dfs_ramfs_write(struct dfs_fd *fd, const void *buf, size_t count) ...@@ -131,11 +133,12 @@ int dfs_ramfs_write(struct dfs_fd *fd, const void *buf, size_t count)
struct ramfs_dirent *dirent; struct ramfs_dirent *dirent;
struct dfs_ramfs *ramfs; struct dfs_ramfs *ramfs;
ramfs = (struct dfs_ramfs*)fd->fs->data;
RT_ASSERT(ramfs != NULL);
dirent = (struct ramfs_dirent*)fd->data; dirent = (struct ramfs_dirent*)fd->data;
RT_ASSERT(dirent != NULL); RT_ASSERT(dirent != NULL);
ramfs = dirent->fs;
RT_ASSERT(ramfs != NULL);
if (count + fd->pos > fd->size) if (count + fd->pos > fd->size)
{ {
rt_uint8_t *ptr; rt_uint8_t *ptr;
...@@ -187,7 +190,7 @@ int dfs_ramfs_open(struct dfs_fd *file) ...@@ -187,7 +190,7 @@ int dfs_ramfs_open(struct dfs_fd *file)
struct dfs_ramfs *ramfs; struct dfs_ramfs *ramfs;
struct ramfs_dirent *dirent; struct ramfs_dirent *dirent;
ramfs = (struct dfs_ramfs *)file->fs->data; ramfs = (struct dfs_ramfs *)file->data;
RT_ASSERT(ramfs != NULL); RT_ASSERT(ramfs != NULL);
if (file->flags & O_DIRECTORY) if (file->flags & O_DIRECTORY)
...@@ -241,6 +244,8 @@ int dfs_ramfs_open(struct dfs_fd *file) ...@@ -241,6 +244,8 @@ int dfs_ramfs_open(struct dfs_fd *file)
rt_list_init(&(dirent->list)); rt_list_init(&(dirent->list));
dirent->data = NULL; dirent->data = NULL;
dirent->size = 0; dirent->size = 0;
dirent->fs = ramfs;
/* add to the root directory */ /* add to the root directory */
rt_list_insert_after(&(ramfs->root.list), &(dirent->list)); rt_list_insert_after(&(ramfs->root.list), &(dirent->list));
} }
...@@ -305,11 +310,13 @@ int dfs_ramfs_getdents(struct dfs_fd *file, ...@@ -305,11 +310,13 @@ int dfs_ramfs_getdents(struct dfs_fd *file,
struct ramfs_dirent *dirent; struct ramfs_dirent *dirent;
struct dfs_ramfs *ramfs; struct dfs_ramfs *ramfs;
ramfs = (struct dfs_ramfs *)file->fs->data;
dirent = (struct ramfs_dirent *)file->data; dirent = (struct ramfs_dirent *)file->data;
if (dirent != &(ramfs->root)) if (dirent != &(ramfs->root))
return -EINVAL; return -EINVAL;
ramfs = dirent->fs;
RT_ASSERT(ramfs != RT_NULL);
/* make integer count */ /* make integer count */
count = (count / sizeof(struct dirent)); count = (count / sizeof(struct dirent));
if (count == 0) if (count == 0)
...@@ -325,7 +332,7 @@ int dfs_ramfs_getdents(struct dfs_fd *file, ...@@ -325,7 +332,7 @@ int dfs_ramfs_getdents(struct dfs_fd *file,
if (index >= (rt_size_t)file->pos) if (index >= (rt_size_t)file->pos)
{ {
d = dirp + count; d = dirp + count;
d->d_type = DFS_DT_REG; d->d_type = DT_REG;
d->d_namlen = RT_NAME_MAX; d->d_namlen = RT_NAME_MAX;
d->d_reclen = (rt_uint16_t)sizeof(struct dirent); d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
rt_strncpy(d->d_name, dirent->name, RAMFS_NAME_MAX); rt_strncpy(d->d_name, dirent->name, RAMFS_NAME_MAX);
...@@ -451,3 +458,4 @@ struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t *pool, rt_size_t size) ...@@ -451,3 +458,4 @@ struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t *pool, rt_size_t size)
return ramfs; return ramfs;
} }
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
struct ramfs_dirent struct ramfs_dirent
{ {
rt_list_t list; rt_list_t list;
struct dfs_ramfs *fs; /* file system ref */
char name[RAMFS_NAME_MAX]; /* dirent name */ char name[RAMFS_NAME_MAX]; /* dirent name */
rt_uint8_t* data; rt_uint8_t* data;
...@@ -56,3 +58,4 @@ int dfs_ramfs_init(void); ...@@ -56,3 +58,4 @@ int dfs_ramfs_init(void);
struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t* pool, rt_size_t size); struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t* pool, rt_size_t size);
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册