21
21
* Date Author Notes
22
22
* 2005-02-22 Bernard The first version.
23
23
* 2011-12-08 Bernard Merges rename patch from iamcacy.
24
+ * 2015-05-27 Bernard Fix the fd clear issue.
24
25
*/
25
26
26
27
#include <dfs.h>
@@ -97,7 +98,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
97
98
{
98
99
/* clear fd */
99
100
rt_free (fd -> path );
100
- rt_memset ( fd , 0 , sizeof ( * fd )) ;
101
+ fd -> path = RT_NULL ;
101
102
102
103
return - DFS_STATUS_ENOSYS ;
103
104
}
@@ -106,7 +107,7 @@ int dfs_file_open(struct dfs_fd *fd, const char *path, int flags)
106
107
{
107
108
/* clear fd */
108
109
rt_free (fd -> path );
109
- rt_memset ( fd , 0 , sizeof ( * fd )) ;
110
+ fd -> path = RT_NULL ;
110
111
111
112
dfs_log (DFS_DEBUG_INFO , ("open failed" ));
112
113
@@ -143,7 +144,7 @@ int dfs_file_close(struct dfs_fd *fd)
143
144
return result ;
144
145
145
146
rt_free (fd -> path );
146
- rt_memset ( fd , 0 , sizeof ( struct dfs_fd )) ;
147
+ fd -> path = RT_NULL ;
147
148
148
149
return result ;
149
150
}
@@ -165,7 +166,7 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args)
165
166
return - DFS_STATUS_EINVAL ;
166
167
167
168
fs = fd -> fs ;
168
- if (fs -> ops -> ioctl != RT_NULL )
169
+ if (fs -> ops -> ioctl != RT_NULL )
169
170
return fs -> ops -> ioctl (fd , cmd , args );
170
171
171
172
return - DFS_STATUS_ENOSYS ;
@@ -186,11 +187,11 @@ int dfs_file_read(struct dfs_fd *fd, void *buf, rt_size_t len)
186
187
struct dfs_filesystem * fs ;
187
188
int result = 0 ;
188
189
189
- if (fd == RT_NULL )
190
+ if (fd == RT_NULL )
190
191
return - DFS_STATUS_EINVAL ;
191
192
192
193
fs = (struct dfs_filesystem * )fd -> fs ;
193
- if (fs -> ops -> read == RT_NULL )
194
+ if (fs -> ops -> read == RT_NULL )
194
195
return - DFS_STATUS_ENOSYS ;
195
196
196
197
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)
213
214
struct dfs_filesystem * fs ;
214
215
215
216
/* parameter check */
216
- if (fd == RT_NULL || fd -> type != FT_DIRECTORY )
217
+ if (fd == RT_NULL || fd -> type != FT_DIRECTORY )
217
218
return - DFS_STATUS_EINVAL ;
218
219
219
220
fs = (struct dfs_filesystem * )fd -> fs ;
@@ -267,7 +268,7 @@ int dfs_file_unlink(const char *path)
267
268
result = fs -> ops -> unlink (fs , dfs_subdir (fs -> path , fullpath ));
268
269
}
269
270
else
270
- result = fs -> ops -> unlink (fs , fullpath );
271
+ result = fs -> ops -> unlink (fs , fullpath );
271
272
}
272
273
else result = - DFS_STATUS_ENOSYS ;
273
274
@@ -528,7 +529,7 @@ void ls(const char *pathname)
528
529
529
530
/* build full path for each file */
530
531
fullpath = dfs_normalize_path (path , dirent .d_name );
531
- if (fullpath == RT_NULL )
532
+ if (fullpath == RT_NULL )
532
533
break ;
533
534
534
535
if (dfs_file_stat (fullpath , & stat ) == 0 )
@@ -555,7 +556,7 @@ void ls(const char *pathname)
555
556
{
556
557
rt_kprintf ("No such directory\n" );
557
558
}
558
- if (pathname == RT_NULL )
559
+ if (pathname == RT_NULL )
559
560
rt_free (path );
560
561
}
561
562
FINSH_FUNCTION_EXPORT (ls , list directory contents );
@@ -632,15 +633,15 @@ static void copyfile(const char *src, const char *dst)
632
633
read_bytes = dfs_file_read (& src_fd , block_ptr , BUF_SZ );
633
634
if (read_bytes > 0 )
634
635
{
635
- int length ;
636
-
636
+ int length ;
637
+
637
638
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
+ }
644
645
}
645
646
} while (read_bytes > 0 );
646
647
@@ -652,7 +653,6 @@ static void copyfile(const char *src, const char *dst)
652
653
extern int mkdir (const char * path , mode_t mode );
653
654
static void copydir (const char * src , const char * dst )
654
655
{
655
- struct dfs_fd fd ;
656
656
struct dirent dirent ;
657
657
struct stat stat ;
658
658
int length ;
0 commit comments