remove struct _uffs_data in dfs_uffs.c
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2022 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
2c22680aff
commit
7494880ac2
|
@ -276,17 +276,10 @@ static int dfs_uffs_statfs(struct dfs_filesystem* fs,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct _uffs_data
|
|
||||||
{
|
|
||||||
int fd; /* the handle of an open file/entry */
|
|
||||||
char * path; /* the path of the file/entry */
|
|
||||||
};
|
|
||||||
|
|
||||||
static int dfs_uffs_open(struct dfs_fd* file)
|
static int dfs_uffs_open(struct dfs_fd* file)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int oflag, mode;
|
int oflag, mode;
|
||||||
struct _uffs_data * uffs_data;
|
|
||||||
char * file_path;
|
char * file_path;
|
||||||
|
|
||||||
oflag = file->flags;
|
oflag = file->flags;
|
||||||
|
@ -344,18 +337,10 @@ static int dfs_uffs_open(struct dfs_fd* file)
|
||||||
return uffs_result_to_dfs(uffs_get_error());
|
return uffs_result_to_dfs(uffs_get_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
uffs_data = rt_malloc(sizeof(struct _uffs_data));
|
|
||||||
if (uffs_data == RT_NULL)
|
|
||||||
return -DFS_STATUS_ENOMEM;
|
|
||||||
|
|
||||||
/* save file info */
|
|
||||||
uffs_data->fd = fd;
|
|
||||||
uffs_data->path = file->path;
|
|
||||||
|
|
||||||
/* save this pointer, it will be used when calling read()£¬write(),
|
/* save this pointer, it will be used when calling read()£¬write(),
|
||||||
* flush(), seek(), and will be free when calling close()*/
|
* flush(), seek(), and will be free when calling close()*/
|
||||||
|
|
||||||
file->data = uffs_data;
|
file->data = (void *)fd;
|
||||||
file->pos = uffs_seek(fd, 0, USEEK_CUR);
|
file->pos = uffs_seek(fd, 0, USEEK_CUR);
|
||||||
file->size = uffs_seek(fd, 0, USEEK_END);
|
file->size = uffs_seek(fd, 0, USEEK_END);
|
||||||
uffs_seek(fd, file->pos, USEEK_SET);
|
uffs_seek(fd, file->pos, USEEK_SET);
|
||||||
|
@ -370,7 +355,7 @@ static int dfs_uffs_open(struct dfs_fd* file)
|
||||||
static int dfs_uffs_close(struct dfs_fd* file)
|
static int dfs_uffs_close(struct dfs_fd* file)
|
||||||
{
|
{
|
||||||
int oflag;
|
int oflag;
|
||||||
struct _uffs_data * uffs_data;
|
int fd;
|
||||||
|
|
||||||
oflag = file->flags;
|
oflag = file->flags;
|
||||||
if (oflag & DFS_O_DIRECTORY)
|
if (oflag & DFS_O_DIRECTORY)
|
||||||
|
@ -382,15 +367,10 @@ static int dfs_uffs_close(struct dfs_fd* file)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* regular file operations */
|
/* regular file operations */
|
||||||
uffs_data = (struct _uffs_data *)(file->data);
|
fd = (int)(file->data);
|
||||||
RT_ASSERT(uffs_data != RT_NULL);
|
|
||||||
|
|
||||||
if (uffs_close(uffs_data->fd) == 0)
|
if (uffs_close(fd) == 0)
|
||||||
{
|
|
||||||
/* release memory */
|
|
||||||
rt_free(uffs_data);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return uffs_result_to_dfs(uffs_get_error());
|
return uffs_result_to_dfs(uffs_get_error());
|
||||||
}
|
}
|
||||||
|
@ -403,13 +383,9 @@ static int dfs_uffs_ioctl(struct dfs_fd * file, int cmd, void* args)
|
||||||
static int dfs_uffs_read(struct dfs_fd * file, void* buf, rt_size_t len)
|
static int dfs_uffs_read(struct dfs_fd * file, void* buf, rt_size_t len)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct _uffs_data * uffs_data;
|
|
||||||
int char_read;
|
int char_read;
|
||||||
|
|
||||||
uffs_data = (struct _uffs_data *)(file->data);
|
fd = (int)(file->data);
|
||||||
RT_ASSERT(uffs_data != RT_NULL);
|
|
||||||
|
|
||||||
fd = uffs_data->fd;
|
|
||||||
char_read = uffs_read(fd, buf, len);
|
char_read = uffs_read(fd, buf, len);
|
||||||
if (char_read < 0)
|
if (char_read < 0)
|
||||||
return uffs_result_to_dfs(uffs_get_error());
|
return uffs_result_to_dfs(uffs_get_error());
|
||||||
|
@ -424,12 +400,9 @@ static int dfs_uffs_write(struct dfs_fd* file,
|
||||||
rt_size_t len)
|
rt_size_t len)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct _uffs_data * uffs_data;
|
|
||||||
int char_write;
|
int char_write;
|
||||||
|
|
||||||
uffs_data = (struct _uffs_data *)(file->data);
|
fd = (int)(file->data);
|
||||||
RT_ASSERT(uffs_data != RT_NULL);
|
|
||||||
fd = uffs_data->fd;
|
|
||||||
|
|
||||||
char_write = uffs_write(fd, buf, len);
|
char_write = uffs_write(fd, buf, len);
|
||||||
if (char_write < 0)
|
if (char_write < 0)
|
||||||
|
@ -444,11 +417,8 @@ static int dfs_uffs_flush(struct dfs_fd* file)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int result;
|
int result;
|
||||||
struct _uffs_data * uffs_data;
|
|
||||||
|
|
||||||
uffs_data = (struct _uffs_data *)(file->data);
|
fd = (int)(file->data);
|
||||||
RT_ASSERT(uffs_data != RT_NULL);
|
|
||||||
fd = uffs_data->fd;
|
|
||||||
|
|
||||||
result = uffs_flush(fd);
|
result = uffs_flush(fd);
|
||||||
if (result < 0 )
|
if (result < 0 )
|
||||||
|
@ -460,12 +430,9 @@ static int dfs_uffs_seek(struct dfs_fd* file,
|
||||||
rt_off_t offset)
|
rt_off_t offset)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct _uffs_data * uffs_data;
|
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
uffs_data = (struct _uffs_data *)(file->data);
|
fd = (int)(file->data);
|
||||||
RT_ASSERT(uffs_data != RT_NULL);
|
|
||||||
fd = uffs_data->fd;
|
|
||||||
|
|
||||||
/* set offset as current offset */
|
/* set offset as current offset */
|
||||||
result = uffs_seek(fd, offset, USEEK_SET);
|
result = uffs_seek(fd, offset, USEEK_SET);
|
||||||
|
|
Loading…
Reference in New Issue