|
|
@@ -102,14 +102,20 @@ static int dfs_jffs2_mount(struct dfs_filesystem* fs,
|
|
|
for (index = 0; index < DEVICE_PART_MAX; index ++)
|
|
|
{
|
|
|
if (device_partition[index].dev == RT_NULL)
|
|
|
+ {
|
|
|
break;
|
|
|
+ }
|
|
|
}
|
|
|
if (index == DEVICE_PART_MAX)
|
|
|
+ {
|
|
|
return -ENOSPC;
|
|
|
+ }
|
|
|
|
|
|
mte = rt_malloc(sizeof(struct cyg_mtab_entry));
|
|
|
if (mte == RT_NULL)
|
|
|
+ {
|
|
|
return -ENOMEM;
|
|
|
+ }
|
|
|
|
|
|
mte->name = fs->path;
|
|
|
mte->fsname = "jffs2";
|
|
|
@@ -192,7 +198,9 @@ static int dfs_jffs2_statfs(struct dfs_filesystem* fs,
|
|
|
|
|
|
result = _find_fs(&mte, fs->dev_id);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return -ENOENT;
|
|
|
+ }
|
|
|
|
|
|
RT_ASSERT(mte->data != 0);
|
|
|
|
|
|
@@ -221,14 +229,20 @@ static int dfs_jffs2_open(struct dfs_fd* file)
|
|
|
|
|
|
jffs2_file = rt_malloc(sizeof(cyg_file));
|
|
|
if (jffs2_file == RT_NULL)
|
|
|
+ {
|
|
|
return -ENOMEM;
|
|
|
+ }
|
|
|
|
|
|
/* just escape '/' provided by dfs code */
|
|
|
name = file->fnode->path;
|
|
|
if ((name[0] == '/') && (name[1] == 0))
|
|
|
+ {
|
|
|
name = jffs2_root_path;
|
|
|
+ }
|
|
|
else /* name[0] still will be '/' */
|
|
|
+ {
|
|
|
name ++;
|
|
|
+ }
|
|
|
|
|
|
result = _find_fs(&mte, fs->dev_id);
|
|
|
if (result)
|
|
|
@@ -322,7 +336,9 @@ static int dfs_jffs2_close(struct dfs_fd* file)
|
|
|
result = jffs2_dir_colse(jffs2_file);
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
|
|
|
rt_free(jffs2_file);
|
|
|
return 0;
|
|
|
@@ -332,7 +348,9 @@ static int dfs_jffs2_close(struct dfs_fd* file)
|
|
|
result = jffs2_file_colse(jffs2_file);
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
|
|
|
/* release memory */
|
|
|
rt_free(jffs2_file);
|
|
|
@@ -366,7 +384,9 @@ static int dfs_jffs2_read(struct dfs_fd* file, void* buf, size_t len)
|
|
|
result = jffs2_file_read(jffs2_file, &uio_s);
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
|
|
|
/* update position */
|
|
|
file->pos = jffs2_file->f_offset;
|
|
|
@@ -398,7 +418,9 @@ static int dfs_jffs2_write(struct dfs_fd* file,
|
|
|
result = jffs2_file_write(jffs2_file, &uio_s);
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
|
|
|
/* update position */
|
|
|
file->pos = jffs2_file->f_offset;
|
|
|
@@ -427,7 +449,9 @@ static int dfs_jffs2_lseek(struct dfs_fd* file,
|
|
|
result = jffs2_file_lseek(jffs2_file, &offset, SEEK_SET);
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
/* update file position */
|
|
|
file->pos = offset;
|
|
|
return offset;
|
|
|
@@ -479,7 +503,9 @@ static int dfs_jffs2_getdents(struct dfs_fd* file,
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
/* if met a error or all entry are read over, break while*/
|
|
|
if (result || jffs2_d.d_name[0] == 0)
|
|
|
+ {
|
|
|
break;
|
|
|
+ }
|
|
|
|
|
|
#if defined (CYGPKG_FS_JFFS2_RET_DIRENT_DTYPE)
|
|
|
switch(jffs2_d.d_type & JFFS2_S_IFMT)
|
|
|
@@ -497,17 +523,25 @@ static int dfs_jffs2_getdents(struct dfs_fd* file,
|
|
|
if ((file->fnode->path[0] == '/') )
|
|
|
{
|
|
|
if (file->fnode->path[1] == 0)
|
|
|
+ {
|
|
|
strcpy(fullname, jffs2_d.d_name);
|
|
|
+ }
|
|
|
else
|
|
|
+ {
|
|
|
rt_sprintf(fullname, "%s/%s", file->fnode->path+1, jffs2_d.d_name);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
+ {
|
|
|
rt_sprintf(fullname, "%s/%s", file->fnode->path, jffs2_d.d_name);
|
|
|
+ }
|
|
|
rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
|
|
|
result = jffs2_porting_stat(mte, mte->root, fullname, (void *)&s);
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
|
|
|
rt_free(fullname);
|
|
|
/* convert to dfs stat structure */
|
|
|
@@ -525,10 +559,14 @@ static int dfs_jffs2_getdents(struct dfs_fd* file,
|
|
|
|
|
|
index ++;
|
|
|
if (index * sizeof(struct dirent) >= count)
|
|
|
+ {
|
|
|
break;
|
|
|
+ }
|
|
|
}
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
return index * sizeof(struct dirent);
|
|
|
}
|
|
|
|
|
|
@@ -540,11 +578,15 @@ static int dfs_jffs2_unlink(struct dfs_filesystem* fs, const char* path)
|
|
|
|
|
|
result = _find_fs(&mte, fs->dev_id);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return -ENOENT;
|
|
|
+ }
|
|
|
|
|
|
/* deal path */
|
|
|
if (path[0] == '/')
|
|
|
+ {
|
|
|
path++;
|
|
|
+ }
|
|
|
|
|
|
/* judge file type, dir is to be delete by rmdir, others by unlink */
|
|
|
rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
|
|
|
@@ -570,7 +612,9 @@ static int dfs_jffs2_unlink(struct dfs_filesystem* fs, const char* path)
|
|
|
}
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -583,17 +627,25 @@ static int dfs_jffs2_rename(struct dfs_filesystem* fs,
|
|
|
|
|
|
result = _find_fs(&mte, fs->dev_id);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return -ENOENT;
|
|
|
+ }
|
|
|
|
|
|
if (*oldpath == '/')
|
|
|
+ {
|
|
|
oldpath += 1;
|
|
|
+ }
|
|
|
if (*newpath == '/')
|
|
|
+ {
|
|
|
newpath += 1;
|
|
|
+ }
|
|
|
rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
|
|
|
result = jffs2_rename(mte, mte->root, oldpath, mte->root, newpath);
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -607,18 +659,24 @@ static int dfs_jffs2_stat(struct dfs_filesystem* fs, const char *path, struct st
|
|
|
RT_ASSERT(!((path[0] == '/') && (path[1] == 0)));
|
|
|
|
|
|
if (path[0] == '/')
|
|
|
+ {
|
|
|
path++;
|
|
|
+ }
|
|
|
|
|
|
result = _find_fs(&mte, fs->dev_id);
|
|
|
if (result)
|
|
|
+ {
|
|
|
return -ENOENT;
|
|
|
+ }
|
|
|
|
|
|
rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
|
|
|
result = jffs2_porting_stat(mte, mte->root, path, (void *)&s);
|
|
|
rt_mutex_release(&jffs2_lock);
|
|
|
|
|
|
if (result)
|
|
|
+ {
|
|
|
return jffs2_result_to_dfs(result);
|
|
|
+ }
|
|
|
/* convert to dfs stat structure */
|
|
|
switch(s.st_mode & JFFS2_S_IFMT)
|
|
|
{
|