[DFS] Fix the RAMFS compiling issue.

This commit is contained in:
bernard 2017-10-25 18:41:53 +08:00
parent 1f76e1b8ec
commit cc9667b7a9
2 changed files with 23 additions and 12 deletions

View File

@ -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)
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)
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)
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));
} }
@ -264,10 +269,10 @@ int dfs_ramfs_open(struct dfs_fd *file)
file->data = dirent; file->data = dirent;
file->size = dirent->size; file->size = dirent->size;
if (file->flags & O_APPEND) if (file->flags & O_APPEND)
file->pos = file->size; file->pos = file->size;
else else
file->pos = 0; file->pos = 0;
return 0; return 0;
} }
@ -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,
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)
return ramfs; return ramfs;
} }

View File

@ -30,15 +30,17 @@
#include <rtservice.h> #include <rtservice.h>
#define RAMFS_NAME_MAX 32 #define RAMFS_NAME_MAX 32
#define RAMFS_MAGIC 0x0A0A0A0A #define RAMFS_MAGIC 0x0A0A0A0A
struct ramfs_dirent struct ramfs_dirent
{ {
rt_list_t list; 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_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); struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t* pool, rt_size_t size);
#endif #endif