Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(dfs_v2/cromfs): add cromfs mmap #8218

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions components/dfs/dfs_v2/filesystems/cromfs/dfs_cromfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

#include "zlib.h"

#ifdef RT_USING_PAGECACHE
#include "dfs_pcache.h"
#endif

/**********************************/

#define CROMFS_PATITION_HEAD_SIZE 256
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1297,6 +1316,21 @@ static int cromfs_readlink(cromfs_info *ci, char *path, char *buf, int len)
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;
Expand Down
20 changes: 16 additions & 4 deletions components/dfs/dfs_v2/src/dfs_pcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down