add dfs_fd check code in dfs and fix a warning.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2547 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
goprife@gmail.com 2012-12-29 06:28:28 +00:00
parent c0fadff061
commit 58fc3334b0
2 changed files with 12 additions and 2 deletions

View File

@ -282,10 +282,12 @@ struct dirent
#endif
/* file descriptor */
#define DFS_FD_MAGIC 0xfdfd
struct dfs_fd
{
rt_uint16_t magic; /* file descriptor magic number */
rt_uint16_t type; /* Type (regular or socket) */
char *path; /* Name (below mount point) */
int type; /* Type (regular or socket) */
int ref_count; /* Descriptor reference count */
struct dfs_filesystem *fs; /* Resident file system */

View File

@ -47,7 +47,7 @@ struct dfs_fd fd_table[DFS_FD_MAX];
void dfs_init(void)
{
/* clear filesystem operations table */
rt_memset(filesystem_operation_table, 0, sizeof(filesystem_operation_table));
rt_memset((void *)filesystem_operation_table, 0, sizeof(filesystem_operation_table));
/* clear filesystem table */
rt_memset(filesystem_table, 0, sizeof(filesystem_table));
/* clean fd table */
@ -123,6 +123,7 @@ int fd_new(void)
d = &(fd_table[idx]);
d->ref_count = 1;
d->magic = DFS_FD_MAGIC;
__result:
dfs_unlock();
@ -153,6 +154,13 @@ struct dfs_fd *fd_get(int fd)
dfs_lock();
d = &fd_table[fd];
/* check dfs_fd valid or not */
if (d->magic != DFS_FD_MAGIC)
{
dfs_unlock();
return RT_NULL;
}
/* increase the reference count */
d->ref_count ++;
dfs_unlock();