1818#include <dfs_dentry.h>
1919#include <dfs_file.h>
2020#include <dfs_mnt.h>
21+ #include <dfs_vfs.h>
2122#include <devfs.h>
2223#include <unistd.h>
2324
@@ -34,10 +35,9 @@ struct devtmpfs_file
3435 char name [DIRENT_NAME_MAX ]; /* file name */
3536
3637 rt_uint32_t type ; /* file type */
37- rt_list_t subdirs ; /* file subdir list */
38- rt_list_t sibling ; /* file sibling list */
38+ struct dfs_vfs_node node ; /* file node in the devtmpfs */
3939
40- struct devtmpfs_sb * sb ; /* superblock ptr */
40+ struct devtmpfs_sb * sb ; /* superblock ptr */
4141
4242 rt_uint32_t mode ;
4343 char * link ;
@@ -48,7 +48,6 @@ struct devtmpfs_sb
4848 rt_uint32_t magic ; /* TMPFS_MAGIC */
4949 struct devtmpfs_file root ; /* root dir */
5050 rt_size_t df_size ; /* df size */
51- rt_list_t sibling ; /* sb sibling list */
5251 struct rt_spinlock lock ; /* tmpfs lock */
5352};
5453
@@ -111,15 +110,13 @@ static int _get_subdir(const char *path, char *name)
111110#if 0
112111static int _free_subdir (struct devtmpfs_file * dfile )
113112{
114- struct devtmpfs_file * file ;
115- rt_list_t * list , * temp_list ;
113+ struct devtmpfs_file * file , * tmp ;
116114 struct devtmpfs_sb * superblock ;
117115
118116 RT_ASSERT (dfile -> type == TMPFS_TYPE_DIR );
119117
120- rt_list_for_each_safe ( list , temp_list , & dfile -> subdirs )
118+ dfs_vfs_for_each_subnode ( file , tmp , dfile , node )
121119 {
122- file = rt_list_entry (list , struct devtmpfs_file , sibling );
123120 if (file -> type == TMPFS_TYPE_DIR )
124121 {
125122 _free_subdir (file );
@@ -134,7 +131,7 @@ static int _free_subdir(struct devtmpfs_file *dfile)
134131 RT_ASSERT (superblock );
135132
136133 rt_spin_lock (& superblock -> lock );
137- rt_list_remove ( & ( file -> sibling ) );
134+ dfs_vfs_remove_node ( & file -> node );
138135 rt_spin_unlock (& superblock -> lock );
139136
140137 rt_free (file );
@@ -152,14 +149,12 @@ static int devtmpfs_mount(struct dfs_mnt *mnt, unsigned long rwflag, const void
152149 {
153150 superblock -> df_size = sizeof (struct devtmpfs_sb );
154151 superblock -> magic = TMPFS_MAGIC ;
155- rt_list_init (& superblock -> sibling );
156152
157153 superblock -> root .name [0 ] = '/' ;
158154 superblock -> root .sb = superblock ;
159155 superblock -> root .type = TMPFS_TYPE_DIR ;
160156 superblock -> root .mode = S_IFDIR | (S_IRUSR | S_IRGRP | S_IROTH ) | (S_IXUSR | S_IXGRP | S_IXOTH );
161- rt_list_init (& superblock -> root .sibling );
162- rt_list_init (& superblock -> root .subdirs );
157+ dfs_vfs_init_node (& superblock -> root .node );
163158
164159 rt_spin_lock_init (& superblock -> lock );
165160
@@ -193,8 +188,7 @@ static struct devtmpfs_file *devtmpfs_file_lookup(struct devtmpfs_sb *superblock
193188{
194189 const char * subpath , * curpath , * filename = RT_NULL ;
195190 char subdir_name [DIRENT_NAME_MAX ];
196- struct devtmpfs_file * file , * curfile ;
197- rt_list_t * list ;
191+ struct devtmpfs_file * file , * curfile , * tmp ;
198192
199193 subpath = path ;
200194 while (* subpath == '/' && * subpath )
@@ -222,9 +216,8 @@ static struct devtmpfs_file *devtmpfs_file_lookup(struct devtmpfs_sb *superblock
222216
223217 rt_spin_lock (& superblock -> lock );
224218
225- rt_list_for_each ( list , & curfile -> subdirs )
219+ dfs_vfs_for_each_subnode ( file , tmp , curfile , node )
226220 {
227- file = rt_list_entry (list , struct devtmpfs_file , sibling );
228221 if (filename ) /* find file */
229222 {
230223 if (rt_strcmp (file -> name , filename ) == 0 )
@@ -293,7 +286,9 @@ static int devtmpfs_stat(struct dfs_dentry *dentry, struct stat *st)
293286
294287static int devtmpfs_getdents (struct dfs_file * file , struct dirent * dirp , uint32_t count )
295288{
296- struct devtmpfs_file * d_file ;
289+ rt_size_t index , end ;
290+ struct dirent * d ;
291+ struct devtmpfs_file * d_file , * n_file = RT_NULL , * tmp ;
297292 struct devtmpfs_sb * superblock ;
298293
299294 RT_ASSERT (file );
@@ -306,11 +301,6 @@ static int devtmpfs_getdents(struct dfs_file *file, struct dirent *dirp, uint32_
306301 d_file = devtmpfs_file_lookup (superblock , file -> dentry -> pathname );
307302 if (d_file )
308303 {
309- rt_size_t index , end ;
310- struct dirent * d ;
311- struct devtmpfs_file * n_file ;
312- rt_list_t * list ;
313-
314304 /* make integer count */
315305 count = (count / sizeof (struct dirent ));
316306 if (count == 0 )
@@ -322,12 +312,10 @@ static int devtmpfs_getdents(struct dfs_file *file, struct dirent *dirp, uint32_
322312 index = 0 ;
323313 count = 0 ;
324314
325- rt_list_for_each ( list , & d_file -> subdirs )
315+ dfs_vfs_for_each_subnode ( n_file , tmp , d_file , node )
326316 {
327317 if (index >= (rt_size_t )file -> fpos )
328318 {
329- n_file = rt_list_entry (list , struct devtmpfs_file , sibling );
330-
331319 d = dirp + count ;
332320 if (n_file -> type == TMPFS_TYPE_FILE )
333321 {
@@ -378,8 +366,7 @@ static int devtmpfs_symlink(struct dfs_dentry *parent_dentry, const char *target
378366
379367 strncpy (l_file -> name , linkpath , DIRENT_NAME_MAX - 1 );
380368
381- rt_list_init (& (l_file -> subdirs ));
382- rt_list_init (& (l_file -> sibling ));
369+ dfs_vfs_init_node (& l_file -> node );
383370 l_file -> sb = superblock ;
384371 l_file -> type = TMPFS_TYPE_FILE ;
385372 l_file -> mode = p_file -> mode ;
@@ -388,7 +375,7 @@ static int devtmpfs_symlink(struct dfs_dentry *parent_dentry, const char *target
388375 l_file -> link = rt_strdup (target );
389376
390377 rt_spin_lock (& superblock -> lock );
391- rt_list_insert_after ( & ( p_file -> subdirs ) , & ( l_file -> sibling ) );
378+ dfs_vfs_append_node ( & p_file -> node , & l_file -> node );
392379 rt_spin_unlock (& superblock -> lock );
393380 }
394381 }
@@ -460,7 +447,7 @@ static int devtmpfs_unlink(struct dfs_dentry *dentry)
460447 }
461448
462449 rt_spin_lock (& superblock -> lock );
463- rt_list_remove ( & ( d_file -> sibling ) );
450+ dfs_vfs_remove_node ( & d_file -> node );
464451 rt_spin_unlock (& superblock -> lock );
465452
466453 rt_free (d_file );
@@ -537,8 +524,7 @@ static struct dfs_vnode *devtmpfs_create_vnode(struct dfs_dentry *dentry, int ty
537524
538525 strncpy (d_file -> name , file_name , DIRENT_NAME_MAX );
539526
540- rt_list_init (& (d_file -> subdirs ));
541- rt_list_init (& (d_file -> sibling ));
527+ dfs_vfs_init_node (& d_file -> node );
542528 d_file -> sb = superblock ;
543529
544530 vnode -> nlink = 1 ;
@@ -563,7 +549,7 @@ static struct dfs_vnode *devtmpfs_create_vnode(struct dfs_dentry *dentry, int ty
563549 d_file -> mode = vnode -> mode ;
564550
565551 rt_spin_lock (& superblock -> lock );
566- rt_list_insert_after ( & ( p_file -> subdirs ) , & ( d_file -> sibling ) );
552+ dfs_vfs_append_node ( & p_file -> node , & d_file -> node );
567553 rt_spin_unlock (& superblock -> lock );
568554 }
569555
0 commit comments