2121 * Date Author Notes
2222 * 2005-02-22 Bernard The first version.
2323 * 2011-12-08 Bernard Merges rename patch from iamcacy.
24+ * 2015-05-27 Bernard Fix the fd clear issue.
2425 */
2526
2627#include <dfs.h>
@@ -97,7 +98,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
9798 {
9899 /* clear fd */
99100 rt_free (fd -> path );
100- rt_memset ( fd , 0 , sizeof ( * fd )) ;
101+ fd -> path = RT_NULL ;
101102
102103 return - DFS_STATUS_ENOSYS ;
103104 }
@@ -106,7 +107,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
106107 {
107108 /* clear fd */
108109 rt_free (fd -> path );
109- rt_memset ( fd , 0 , sizeof ( * fd )) ;
110+ fd -> path = RT_NULL ;
110111
111112 dfs_log (DFS_DEBUG_INFO , ("open failed" ));
112113
@@ -143,7 +144,7 @@ int dfs_file_close(struct dfs_fd *fd)
143144 return result ;
144145
145146 rt_free (fd -> path );
146- rt_memset ( fd , 0 , sizeof ( struct dfs_fd )) ;
147+ fd -> path = RT_NULL ;
147148
148149 return result ;
149150}
@@ -165,7 +166,7 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
165166 return - DFS_STATUS_EINVAL ;
166167
167168 fs = fd -> fs ;
168- if (fs -> ops -> ioctl != RT_NULL )
169+ if (fs -> ops -> ioctl != RT_NULL )
169170 return fs -> ops -> ioctl (fd , cmd , args );
170171
171172 return - DFS_STATUS_ENOSYS ;
@@ -186,11 +187,11 @@ int dfs_file_read(struct dfs_fd *fd, void *buf, rt_size_t len)
186187 struct dfs_filesystem * fs ;
187188 int result = 0 ;
188189
189- if (fd == RT_NULL )
190+ if (fd == RT_NULL )
190191 return - DFS_STATUS_EINVAL ;
191192
192193 fs = (struct dfs_filesystem * )fd -> fs ;
193- if (fs -> ops -> read == RT_NULL )
194+ if (fs -> ops -> read == RT_NULL )
194195 return - DFS_STATUS_ENOSYS ;
195196
196197 if ((result = fs -> ops -> read (fd , buf , len )) < 0 )
@@ -213,7 +214,7 @@ int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, rt_size_t nbytes)
213214 struct dfs_filesystem * fs ;
214215
215216 /* parameter check */
216- if (fd == RT_NULL || fd -> type != FT_DIRECTORY )
217+ if (fd == RT_NULL || fd -> type != FT_DIRECTORY )
217218 return - DFS_STATUS_EINVAL ;
218219
219220 fs = (struct dfs_filesystem * )fd -> fs ;
@@ -267,7 +268,7 @@ int dfs_file_unlink(const char *path)
267268 result = fs -> ops -> unlink (fs , dfs_subdir (fs -> path , fullpath ));
268269 }
269270 else
270- result = fs -> ops -> unlink (fs , fullpath );
271+ result = fs -> ops -> unlink (fs , fullpath );
271272 }
272273 else result = - DFS_STATUS_ENOSYS ;
273274
@@ -528,7 +529,7 @@ void ls(const char *pathname)
528529
529530 /* build full path for each file */
530531 fullpath = dfs_normalize_path (path , dirent .d_name );
531- if (fullpath == RT_NULL )
532+ if (fullpath == RT_NULL )
532533 break ;
533534
534535 if (dfs_file_stat (fullpath , & stat ) == 0 )
@@ -555,7 +556,7 @@ void ls(const char *pathname)
555556 {
556557 rt_kprintf ("No such directory\n" );
557558 }
558- if (pathname == RT_NULL )
559+ if (pathname == RT_NULL )
559560 rt_free (path );
560561}
561562FINSH_FUNCTION_EXPORT (ls , list directory contents );
@@ -632,15 +633,15 @@ static void copyfile(const char *src, const char *dst)
632633 read_bytes = dfs_file_read (& src_fd , block_ptr , BUF_SZ );
633634 if (read_bytes > 0 )
634635 {
635- int length ;
636-
636+ int length ;
637+
637638 length = dfs_file_write (& fd , block_ptr , read_bytes );
638- if (length != read_bytes )
639- {
640- /* write failed. */
641- rt_kprintf ("Write file data failed, errno=%d\n" , length );
642- break ;
643- }
639+ if (length != read_bytes )
640+ {
641+ /* write failed. */
642+ rt_kprintf ("Write file data failed, errno=%d\n" , length );
643+ break ;
644+ }
644645 }
645646 } while (read_bytes > 0 );
646647
@@ -652,7 +653,6 @@ static void copyfile(const char *src, const char *dst)
652653extern int mkdir (const char * path , mode_t mode );
653654static void copydir (const char * src , const char * dst )
654655{
655- struct dfs_fd fd ;
656656 struct dirent dirent ;
657657 struct stat stat ;
658658 int length ;
0 commit comments