|  | @@ -23,6 +23,7 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #include "dfs_jffs2.h"
 | 
	
		
			
				|  |  |  #include "porting.h"
 | 
	
		
			
				|  |  | +#include <string.h>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #define FILE_PATH_MAX   256 /* the longest file path */
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -31,10 +32,6 @@
 | 
	
		
			
				|  |  |  #if DEVICE_PART_MAX > 1
 | 
	
		
			
				|  |  |  	#error "support only one jffs2 partition on a flash device!"
 | 
	
		
			
				|  |  |  #endif
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -extern cyg_fileops jffs2_fileops;
 | 
	
		
			
				|  |  | -extern cyg_fileops jffs2_dirops;
 | 
	
		
			
				|  |  | -extern struct cyg_fstab_entry jffs2_fste;
 | 
	
		
			
				|  |  |  			
 | 
	
		
			
				|  |  |  /* make sure the following struct var had been initilased to 0! */ //fixme
 | 
	
		
			
				|  |  |  struct device_part 
 | 
	
	
		
			
				|  | @@ -165,7 +162,7 @@ static int dfs_jffs2_mount(struct dfs_filesystem* fs,
 | 
	
		
			
				|  |  |  	 * s_dev in struct super_block, and mte->data will be
 | 
	
		
			
				|  |  |  	 * filled with jffs2_sb(see the source of jffs2_mount.
 | 
	
		
			
				|  |  |  	 */
 | 
	
		
			
				|  |  | -	mte->data = (CYG_ADDRWORD)fs->dev_id;
 | 
	
		
			
				|  |  | +	mte->data = (CYG_ADDRWORD)fs->dev_id;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	device_partition[index].dev = fs->dev_id;	
 | 
	
		
			
				|  |  |  	/* after jffs2_mount, mte->data will not be dev_id any more */
 | 
	
	
		
			
				|  | @@ -175,7 +172,7 @@ static int dfs_jffs2_mount(struct dfs_filesystem* fs,
 | 
	
		
			
				|  |  |  		return jffs2_result_to_dfs(result);
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	/* save this pointer */
 | 
	
		
			
				|  |  | -	device_partition[index].mte = mte;	
 | 
	
		
			
				|  |  | +	device_partition[index].mte = mte;	
 | 
	
		
			
				|  |  |  	return 0;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -204,7 +201,6 @@ static int dfs_jffs2_unmount(struct dfs_filesystem* fs)
 | 
	
		
			
				|  |  |  	{
 | 
	
		
			
				|  |  |  		if (device_partition[index].dev == fs->dev_id)
 | 
	
		
			
				|  |  |  		{
 | 
	
		
			
				|  |  | -			struct cyg_mtab_entry * mte;
 | 
	
		
			
				|  |  |  			result = jffs2_umount(device_partition[index].mte);
 | 
	
		
			
				|  |  |  			if (result)
 | 
	
		
			
				|  |  |  				return jffs2_result_to_dfs(result);	
 | 
	
	
		
			
				|  | @@ -237,7 +233,7 @@ static int dfs_jffs2_statfs(struct dfs_filesystem* fs,
 | 
	
		
			
				|  |  |  		
 | 
	
		
			
				|  |  |  	RT_ASSERT(mte->data != NULL);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	jffs2_get_info_from_sb(mte->data, &info);
 | 
	
		
			
				|  |  | +	jffs2_get_info_from_sb((void *)mte->data, &info);
 | 
	
		
			
				|  |  |  	buf->f_bsize = info.sector_size; 
 | 
	
		
			
				|  |  |  	buf->f_blocks = info.nr_blocks;
 | 
	
		
			
				|  |  |  	buf->f_bfree = info.free_size; //fixme need test!
 | 
	
	
		
			
				|  | @@ -259,7 +255,7 @@ static int dfs_jffs2_open(struct dfs_fd* file)
 | 
	
		
			
				|  |  |  	int result;
 | 
	
		
			
				|  |  |  	cyg_file * jffs2_file;		
 | 
	
		
			
				|  |  |  	struct cyg_mtab_entry * mte;
 | 
	
		
			
				|  |  | -	const char * name;
 | 
	
		
			
				|  |  | +	const char * name;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	oflag = file->flags;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -311,7 +307,7 @@ static int dfs_jffs2_open(struct dfs_fd* file)
 | 
	
		
			
				|  |  |  	if (oflag & DFS_O_TRUNC) mode |= JFFS2_O_TRUNC;
 | 
	
		
			
				|  |  |  	/* Creates a new file. The function fails if the file is already existing. */
 | 
	
		
			
				|  |  |  	if (oflag & DFS_O_EXCL) mode |= JFFS2_O_EXCL;
 | 
	
		
			
				|  |  | -//	if (oflag & DFS_O_APPEND) mode |= JFFS2_O_APPEND;
 | 
	
		
			
				|  |  | +//	if (oflag & DFS_O_APPEND) mode |= JFFS2_O_APPEND;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      result = jffs2_open(mte, 0, name, mode, jffs2_file);
 | 
	
		
			
				|  |  |      if (result != 0)
 | 
	
	
		
			
				|  | @@ -325,16 +321,16 @@ static int dfs_jffs2_open(struct dfs_fd* file)
 | 
	
		
			
				|  |  |  	file->data = jffs2_file;
 | 
	
		
			
				|  |  |  	file->pos = jffs2_file->f_offset; 
 | 
	
		
			
				|  |  |  	file->size = 0;
 | 
	
		
			
				|  |  | -	jffs2_file_lseek(jffs2_file, &(file->size), SEEK_END);
 | 
	
		
			
				|  |  | -	jffs2_file->f_offset = file->pos;
 | 
	
		
			
				|  |  | +	jffs2_file_lseek(jffs2_file, (off_t *)(&(file->size)), SEEK_END);
 | 
	
		
			
				|  |  | +	jffs2_file->f_offset = (off_t)file->pos;
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  | -	if (oflag & DFS_O_APPEND)
 | 
	
		
			
				|  |  | +	if (oflag & DFS_O_APPEND)
 | 
	
		
			
				|  |  |  	{
 | 
	
		
			
				|  |  | -		file->pos = file->size;	
 | 
	
		
			
				|  |  | +		file->pos = file->size;	
 | 
	
		
			
				|  |  |   		jffs2_file->f_offset = file->size;
 | 
	
		
			
				|  |  |  	}	
 | 
	
		
			
				|  |  |  	return 0; 
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | +}				   
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  static int dfs_jffs2_close(struct dfs_fd* file)
 | 
	
		
			
				|  |  |  {
 | 
	
	
		
			
				|  | @@ -407,7 +403,7 @@ static int dfs_jffs2_write(struct dfs_fd* file,
 | 
	
		
			
				|  |  |  	RT_ASSERT(file->data != NULL);
 | 
	
		
			
				|  |  |  	jffs2_file = (cyg_file *)(file->data);	
 | 
	
		
			
				|  |  |      uio_s.uio_iov = &iovec;
 | 
	
		
			
				|  |  | -    uio_s.uio_iov->iov_base = buf;
 | 
	
		
			
				|  |  | +    uio_s.uio_iov->iov_base = (void *)buf;
 | 
	
		
			
				|  |  |      uio_s.uio_iov->iov_len = len;
 | 
	
		
			
				|  |  |      uio_s.uio_iovcnt = 1; //must be 1
 | 
	
		
			
				|  |  |      //uio_s.uio_offset //not used...
 | 
	
	
		
			
				|  | @@ -457,7 +453,7 @@ static int dfs_jffs2_getdents(struct dfs_fd* file,
 | 
	
		
			
				|  |  |  	struct CYG_IOVEC_TAG iovec;
 | 
	
		
			
				|  |  |  	struct jffs2_dirent jffs2_d;
 | 
	
		
			
				|  |  |  	struct dirent * d;
 | 
	
		
			
				|  |  | -	rt_uint32_t index;
 | 
	
		
			
				|  |  | +	rt_uint32_t index;
 | 
	
		
			
				|  |  |  	int result;
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	RT_ASSERT(file->data != RT_NULL);	
 | 
	
	
		
			
				|  | @@ -525,7 +521,7 @@ static int dfs_jffs2_unlink(struct dfs_filesystem* fs, const char* path)
 | 
	
		
			
				|  |  |  		path++;
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	/* judge file type, dir is to be delete by rmdir, others by unlink */
 | 
	
		
			
				|  |  | -	result = jffs2_ops_stat(mte, mte->root, path, &s);
 | 
	
		
			
				|  |  | +	result = jffs2_porting_stat(mte, mte->root, path, (void *)&s);
 | 
	
		
			
				|  |  |  	if (result)
 | 
	
		
			
				|  |  |  		return jffs2_result_to_dfs(result);
 | 
	
		
			
				|  |  |  		
 | 
	
	
		
			
				|  | @@ -555,12 +551,12 @@ static int dfs_jffs2_rename(struct dfs_filesystem* fs,
 | 
	
		
			
				|  |  |  			
 | 
	
		
			
				|  |  |  	result = _find_fs(&mte, fs->dev_id);		
 | 
	
		
			
				|  |  |  	if (result) 
 | 
	
		
			
				|  |  | -		return -DFS_STATUS_ENOENT;
 | 
	
		
			
				|  |  | +		return -DFS_STATUS_ENOENT;
 | 
	
		
			
				|  |  |  			
 | 
	
		
			
				|  |  |  	if (*oldpath == '/')
 | 
	
		
			
				|  |  |  		oldpath += 1;
 | 
	
		
			
				|  |  |  	if (*newpath == '/')
 | 
	
		
			
				|  |  | -		newpath += 1;
 | 
	
		
			
				|  |  | +		newpath += 1;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	result = jffs2_rename(mte, mte->root, oldpath, mte->root, newpath);
 | 
	
		
			
				|  |  |  	if (result)
 | 
	
	
		
			
				|  | @@ -572,19 +568,21 @@ static int dfs_jffs2_stat(struct dfs_filesystem* fs, const char *path, struct st
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |  	int result;
 | 
	
		
			
				|  |  |  	struct jffs2_stat s;
 | 
	
		
			
				|  |  | -	cyg_mtab_entry * mte;
 | 
	
		
			
				|  |  | +	cyg_mtab_entry * mte;
 | 
	
		
			
				|  |  |  		
 | 
	
		
			
				|  |  |  	/* deal the path for jffs2 */
 | 
	
		
			
				|  |  |  	RT_ASSERT(!((path[0] == '/') && (path[1] == 0)));
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	if (path[0] == '/')
 | 
	
		
			
				|  |  | -		path++;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +		path++;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	result = _find_fs(&mte, fs->dev_id);		
 | 
	
		
			
				|  |  |  	if (result) 
 | 
	
		
			
				|  |  | -		return -DFS_STATUS_ENOENT;
 | 
	
		
			
				|  |  | +		return -DFS_STATUS_ENOENT;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//	result = jffs2_ops_stat(mte, mte->root, path, &s);	
 | 
	
		
			
				|  |  | +	result = jffs2_porting_stat(mte, mte->root, path, (void *)&s);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	result = jffs2_ops_stat(mte, mte->root, path, &s);	
 | 
	
		
			
				|  |  |  	if (result)
 | 
	
		
			
				|  |  |  		return jffs2_result_to_dfs(result);
 | 
	
		
			
				|  |  |  	/* convert to dfs stat structure */
 | 
	
	
		
			
				|  | @@ -593,16 +591,16 @@ static int dfs_jffs2_stat(struct dfs_filesystem* fs, const char *path, struct st
 | 
	
		
			
				|  |  |  	case JFFS2_S_IFREG: 
 | 
	
		
			
				|  |  |  		st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
 | 
	
		
			
				|  |  |  		DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
 | 
	
		
			
				|  |  | -		break;
 | 
	
		
			
				|  |  | +		break;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	case JFFS2_S_IFDIR:
 | 
	
		
			
				|  |  | -		st->st_mode = DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
 | 
	
		
			
				|  |  | -		break;		
 | 
	
		
			
				|  |  | +		st->st_mode = DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
 | 
	
		
			
				|  |  | +		break;		
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	default: 
 | 
	
		
			
				|  |  | -		st->st_mode = DFS_DT_UNKNOWN; //fixme
 | 
	
		
			
				|  |  | +	default: 
 | 
	
		
			
				|  |  | +		st->st_mode = DFS_DT_UNKNOWN; //fixme
 | 
	
		
			
				|  |  |  		break; 
 | 
	
		
			
				|  |  | -	} 	
 | 
	
		
			
				|  |  | +	} 	
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	st->st_dev  = 0;
 | 
	
		
			
				|  |  |  	st->st_size = s.st_size;
 |