diff --git a/components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.c b/components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.c index e985dc7905..0d82914df4 100644 --- a/components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.c +++ b/components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.c @@ -21,6 +21,10 @@ #include "zlib.h" +#ifdef RT_USING_PAGECACHE +#include "dfs_pcache.h" +#endif + /**********************************/ #define CROMFS_PATITION_HEAD_SIZE 256 @@ -502,6 +506,15 @@ static void cromfs_dirent_cache_destroy(cromfs_info *ci) /**********************************/ +#ifdef RT_USING_PAGECACHE +static ssize_t dfs_cromfs_page_read(struct dfs_file *file, struct dfs_page *page); + +static struct dfs_aspace_ops dfs_cromfs_aspace_ops = +{ + .read = dfs_cromfs_page_read +}; +#endif + static int dfs_cromfs_mount(struct dfs_mnt *mnt, unsigned long rwflag, const void *data) { struct rt_device_blk_geometry geometry; @@ -1066,24 +1079,27 @@ static int dfs_cromfs_stat(struct dfs_dentry *dentry, struct stat *st) } st->st_dev = 0; - st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH | - S_IWUSR | S_IWGRP | S_IWOTH; + st->st_mode = S_IFREG | (0777); if (file_type == CROMFS_DIRENT_ATTR_DIR) { st->st_mode &= ~S_IFREG; - st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + st->st_mode |= S_IFDIR; st->st_size = size; } else if(file_type == CROMFS_DIRENT_ATTR_SYMLINK) { st->st_mode &= ~S_IFREG; - st->st_mode |= S_IFLNK | S_IXUSR | S_IXGRP | S_IXOTH; + st->st_mode |= S_IFLNK; st->st_size = osize; } else { +#ifdef RT_USING_PAGECACHE + st->st_size = (dentry->vnode && dentry->vnode->aspace) ? dentry->vnode->size : osize; +#else st->st_size = osize; +#endif } st->st_mtime = 0; @@ -1201,21 +1217,24 @@ static struct dfs_vnode *dfs_cromfs_lookup (struct dfs_dentry *dentry) if (file_type == CROMFS_DIRENT_ATTR_DIR) { - vnode->mode = S_IFDIR | (0555); + vnode->mode = S_IFDIR | (0777); vnode->type = FT_DIRECTORY; vnode->size = size; } else if (file_type == CROMFS_DIRENT_ATTR_SYMLINK) { - vnode->mode = S_IFLNK | (0555); + vnode->mode = S_IFLNK | (0777); vnode->type = FT_SYMLINK; vnode->size = osize; } else { - vnode->mode = S_IFREG | (0555); + vnode->mode = S_IFREG | (0777); vnode->type = FT_REGULAR; vnode->size = osize; +#ifdef RT_USING_PAGECACHE + vnode->aspace = dfs_aspace_create(dentry, vnode, &dfs_cromfs_aspace_ops); +#endif } vnode->mnt = dentry->mnt; @@ -1297,6 +1316,21 @@ end1: return ret; } +#ifdef RT_USING_PAGECACHE +static ssize_t dfs_cromfs_page_read(struct dfs_file *file, struct dfs_page *page) +{ + int ret = -EINVAL; + + if (page->page) + { + off_t fpos = page->fpos; + ret = dfs_cromfs_read(file, page->page, page->size, &fpos); + } + + return ret; +} +#endif + static int dfs_cromfs_readlink(struct dfs_dentry *dentry, char *buf, int len) { cromfs_info *ci = NULL; diff --git a/components/dfs/dfs_v2/src/dfs_pcache.c b/components/dfs/dfs_v2/src/dfs_pcache.c index 920ddd1108..00118a756d 100644 --- a/components/dfs/dfs_v2/src/dfs_pcache.c +++ b/components/dfs/dfs_v2/src/dfs_pcache.c @@ -270,7 +270,10 @@ static void dfs_pcache_thread(void *parameter) page->len = page->size; } //rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, page->page, page->size); - aspace->ops->write(page); + if (aspace->ops->write) + { + aspace->ops->write(page); + } page->is_dirty = 0; @@ -739,7 +742,10 @@ static void dfs_page_release(struct dfs_page *page) page->len = page->size; } //rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, page->page, page->size); - aspace->ops->write(page); + if (aspace->ops->write) + { + aspace->ops->write(page); + } page->is_dirty = 0; } RT_ASSERT(page->is_dirty == 0); @@ -1066,6 +1072,8 @@ int dfs_aspace_read(struct dfs_file *file, void *buf, size_t count, off_t *pos) if (file && file->vnode && file->vnode->aspace) { + if (!(file->vnode->aspace->ops->read)) + return ret; struct dfs_vnode *vnode = file->vnode; struct dfs_aspace *aspace = vnode->aspace; @@ -1126,6 +1134,8 @@ int dfs_aspace_write(struct dfs_file *file, const void *buf, size_t count, off_t if (file && file->vnode && file->vnode->aspace) { + if (!(file->vnode->aspace->ops->write)) + return ret; struct dfs_vnode *vnode = file->vnode; struct dfs_aspace *aspace = vnode->aspace; @@ -1213,8 +1223,10 @@ int dfs_aspace_flush(struct dfs_aspace *aspace) page->len = page->size; } //rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, page->page, page->size); - - aspace->ops->write(page); + if (aspace->ops->write) + { + aspace->ops->write(page); + } page->is_dirty = 0; }