summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorbernard <[email protected]>2017-10-25 18:41:53 +0800
committerbernard <[email protected]>2017-10-25 18:41:53 +0800
commitcc9667b7a92cedf1876478d339e15530db0580a2 (patch)
treeefd30be226d893c3ca4b85eb086d3b4689faba5e /components
parent1f76e1b8ecfeee8945d030dfb2f8235b87fcad66 (diff)
[DFS] Fix the RAMFS compiling issue.
Diffstat (limited to 'components')
-rw-r--r--components/dfs/filesystems/ramfs/dfs_ramfs.c26
-rw-r--r--components/dfs/filesystems/ramfs/dfs_ramfs.h9
2 files changed, 23 insertions, 12 deletions
diff --git a/components/dfs/filesystems/ramfs/dfs_ramfs.c b/components/dfs/filesystems/ramfs/dfs_ramfs.c
index 5143b975f9..ea9c086cfa 100644
--- a/components/dfs/filesystems/ramfs/dfs_ramfs.c
+++ b/components/dfs/filesystems/ramfs/dfs_ramfs.c
@@ -27,6 +27,8 @@
#include <rtthread.h>
#include <dfs.h>
#include <dfs_fs.h>
+#include <dfs_file.h>
+
#include "dfs_ramfs.h"
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)
struct ramfs_dirent *dirent;
struct dfs_ramfs *ramfs;
- ramfs = (struct dfs_ramfs*)fd->fs->data;
- RT_ASSERT(ramfs != NULL);
dirent = (struct ramfs_dirent*)fd->data;
RT_ASSERT(dirent != NULL);
+ ramfs = dirent->fs;
+ RT_ASSERT(ramfs != NULL);
+
if (count + fd->pos > fd->size)
{
rt_uint8_t *ptr;
@@ -187,7 +190,7 @@ int dfs_ramfs_open(struct dfs_fd *file)
struct dfs_ramfs *ramfs;
struct ramfs_dirent *dirent;
- ramfs = (struct dfs_ramfs *)file->fs->data;
+ ramfs = (struct dfs_ramfs *)file->data;
RT_ASSERT(ramfs != NULL);
if (file->flags & O_DIRECTORY)
@@ -241,6 +244,8 @@ int dfs_ramfs_open(struct dfs_fd *file)
rt_list_init(&(dirent->list));
dirent->data = NULL;
dirent->size = 0;
+ dirent->fs = ramfs;
+
/* add to the root directory */
rt_list_insert_after(&(ramfs->root.list), &(dirent->list));
}
@@ -264,10 +269,10 @@ int dfs_ramfs_open(struct dfs_fd *file)
file->data = dirent;
file->size = dirent->size;
- if (file->flags & O_APPEND)
- file->pos = file->size;
- else
- file->pos = 0;
+ if (file->flags & O_APPEND)
+ file->pos = file->size;
+ else
+ file->pos = 0;
return 0;
}
@@ -305,11 +310,13 @@ int dfs_ramfs_getdents(struct dfs_fd *file,
struct ramfs_dirent *dirent;
struct dfs_ramfs *ramfs;
- ramfs = (struct dfs_ramfs *)file->fs->data;
dirent = (struct ramfs_dirent *)file->data;
if (dirent != &(ramfs->root))
return -EINVAL;
+ ramfs = dirent->fs;
+ RT_ASSERT(ramfs != RT_NULL);
+
/* make integer count */
count = (count / sizeof(struct dirent));
if (count == 0)
@@ -325,7 +332,7 @@ int dfs_ramfs_getdents(struct dfs_fd *file,
if (index >= (rt_size_t)file->pos)
{
d = dirp + count;
- d->d_type = DFS_DT_REG;
+ d->d_type = DT_REG;
d->d_namlen = RT_NAME_MAX;
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
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)
return ramfs;
}
+
diff --git a/components/dfs/filesystems/ramfs/dfs_ramfs.h b/components/dfs/filesystems/ramfs/dfs_ramfs.h
index 6e91f8981a..b568706f68 100644
--- a/components/dfs/filesystems/ramfs/dfs_ramfs.h
+++ b/components/dfs/filesystems/ramfs/dfs_ramfs.h
@@ -30,15 +30,17 @@
#include <rtservice.h>
#define RAMFS_NAME_MAX 32
-#define RAMFS_MAGIC 0x0A0A0A0A
+#define RAMFS_MAGIC 0x0A0A0A0A
struct ramfs_dirent
{
rt_list_t list;
- char name[RAMFS_NAME_MAX]; /* dirent name */
+ struct dfs_ramfs *fs; /* file system ref */
+
+ char name[RAMFS_NAME_MAX]; /* dirent name */
rt_uint8_t* data;
- rt_size_t size; /* file size */
+ rt_size_t size; /* file size */
};
/**
@@ -56,3 +58,4 @@ int dfs_ramfs_init(void);
struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t* pool, rt_size_t size);
#endif
+