Changeset 204 for trunk/kernel/vfs/vfs.c
- Timestamp:
- Jul 17, 2017, 8:42:59 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/vfs/vfs.c
r188 r204 215 215 xlist_root_init( XPTR( local_cxy , &inode->wait_root ) ); 216 216 217 // initialize dentries hash table , if new inode is a directory218 if( inode_type == INODE_TYPE_DIR )xhtab_init( &inode->children , XHTAB_DENTRY_TYPE );217 // initialize dentries hash table 218 xhtab_init( &inode->children , XHTAB_DENTRY_TYPE ); 219 219 220 220 // initialize inode locks … … 329 329 } 330 330 331 ////////////////////////////////////////////////////////////////////////////////////////// 331 ///////////////////////////////////////// 332 void vfs_inode_display( xptr_t inode_xp ) 333 { 334 cxy_t inode_cxy; 335 vfs_inode_t * inode_ptr; 336 xptr_t dentry_xp; 337 cxy_t dentry_cxy; 338 vfs_dentry_t * dentry_ptr; 339 340 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 341 342 // get inode cluster and local pointer 343 inode_cxy = GET_CXY( inode_xp ); 344 inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp ); 345 346 // get parent dentry 347 dentry_xp = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) ); 348 349 // get local copy of name 350 if( dentry_xp == XPTR_NULL ) // it is the VFS root 351 { 352 strcpy( name , "/" ); 353 } 354 else // not the VFS root 355 { 356 dentry_cxy = GET_CXY( dentry_xp ); 357 dentry_ptr = (vfs_dentry_t *)GET_PTR( dentry_xp ); 358 359 hal_remote_strcpy( XPTR( local_cxy , name ) , 360 XPTR( dentry_cxy , &dentry_ptr->name ) ); 361 } 362 363 // display inode header 364 printk("\n*** inode <%s> / inode_xp = %l / dentry_xp = %l ***\n", 365 name , inode_xp , dentry_xp ); 366 367 // display children from xhtab 368 xhtab_display( XPTR( inode_cxy , &inode_ptr->children ) ); 369 370 } // end vfs_inode_display() 371 372 //////////////////////////////////////////////////////////////////////////////////////////// 332 373 // Dentry related functions 333 374 ////////////////////////////////////////////////////////////////////////////////////////// … … 509 550 510 551 vfs_dmsg("\n[INFO] %s : enters for <%s> at cycle %d\n", 511 __FUNCTION__ , path , hal_get_cycles() );552 __FUNCTION__ , path , (uint32_t)hal_time_stamp() ); 512 553 513 554 // compute lookup working mode … … 619 660 else if (inode_type == INODE_TYPE_DEV ) 620 661 { 621 // TODO 662 // TODO [AG] 622 663 return 0; 623 664 } … … 628 669 return -1; 629 670 } 630 } // end vfs_ access()671 } // end vfs_move() 631 672 632 673 ////////////////////////////////////// … … 857 898 static void vfs_recursive_display( xptr_t inode_xp, 858 899 xptr_t name_xp, 900 xptr_t dentry_xp, 859 901 uint32_t indent ) 860 902 { … … 862 904 vfs_inode_t * inode_ptr; 863 905 vfs_inode_type_t inode_type; 864 xptr_t inode_children_xp; // extended pointer on children xhtab 865 866 xptr_t dentry_xp; 867 cxy_t dentry_cxy; 868 vfs_dentry_t * dentry_ptr; 906 xptr_t children_xp; // extended pointer on children xhtab 907 908 xptr_t child_dentry_xp; 909 cxy_t child_dentry_cxy; 910 vfs_dentry_t * child_dentry_ptr; 911 xptr_t child_inode_xp; 912 xptr_t child_dentry_name_xp; 869 913 870 914 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 871 872 xptr_t child_inode_xp;873 xptr_t dentry_name_xp;874 915 875 916 char * indent_str[] = { "", // level 0 … … 905 946 906 947 // display inode 907 printk(" %s %s : %s\n", indent_str[indent], vfs_inode_type_str( inode_type ), name ); 948 printk("%s%s <%s> inode_xp = %l / dentry_xp = %l\n", 949 indent_str[indent], vfs_inode_type_str( inode_type ), 950 name , inode_xp , dentry_xp ); 908 951 909 952 // scan directory entries … … 911 954 { 912 955 // get extended pointer on directory entries xhtab 913 inode_children_xp = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->children ));956 children_xp = XPTR( inode_cxy , &inode_ptr->children ); 914 957 915 958 // get xhtab lock 916 xhtab_read_lock( inode_children_xp );959 xhtab_read_lock( children_xp ); 917 960 918 961 // get first dentry from xhtab 919 dentry_xp = xhtab_get_first( inode_children_xp );920 921 while( dentry_xp != XPTR_NULL )962 child_dentry_xp = xhtab_get_first( children_xp ); 963 964 while( child_dentry_xp != XPTR_NULL ) 922 965 { 923 966 // get dentry cluster and local pointer 924 dentry_cxy = GET_CXY(dentry_xp );925 dentry_ptr = (vfs_dentry_t *)GET_PTR(dentry_xp );967 child_dentry_cxy = GET_CXY( child_dentry_xp ); 968 child_dentry_ptr = (vfs_dentry_t *)GET_PTR( child_dentry_xp ); 926 969 927 970 // get extended pointer on child inode 928 child_inode_xp = hal_remote_lwd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) ); 971 child_inode_xp = hal_remote_lwd( XPTR( child_dentry_cxy, 972 &child_dentry_ptr->child_xp ) ); 929 973 930 974 // get extended pointer on dentry name 931 dentry_name_xp = XPTR( dentry_cxy , &dentry_ptr->name );975 child_dentry_name_xp = XPTR( child_dentry_cxy , &child_dentry_ptr->name ); 932 976 933 977 // recursive call on child inode 934 vfs_recursive_display( child_inode_xp , dentry_name_xp , indent+1 ); 978 vfs_recursive_display( child_inode_xp, 979 child_dentry_name_xp, 980 child_dentry_xp, 981 indent+1 ); 935 982 936 983 // get next dentry 937 dentry_xp = xhtab_get_next( inode_children_xp );984 child_dentry_xp = xhtab_get_next( children_xp ); 938 985 } 939 986 940 987 // release xhtab lock 941 xhtab_read_unlock( inode_children_xp );988 xhtab_read_unlock( children_xp ); 942 989 } 943 990 } // end vfs_recursive_display() … … 946 993 void vfs_display( xptr_t inode_xp ) 947 994 { 948 xptr_t name_xp; // extended pointer on string containing the inode name995 xptr_t name_xp; 949 996 xptr_t dentry_xp; 950 997 cxy_t dentry_cxy; 951 998 vfs_dentry_t * dentry_ptr; 952 999 953 printk("\n@@@ %s enters\n", __FUNCTION__ );954 955 1000 // get target inode cluster and local pointer 956 1001 cxy_t inode_cxy = GET_CXY( inode_xp ); … … 977 1022 978 1023 // print header 979 printk("\n*** Current VFS content***\n");1024 printk("\n*** VFS ***\n"); 980 1025 981 1026 // call recursive function 982 vfs_recursive_display( inode_xp , name_xp , 0 );983 984 } // end vfs_di play()1027 vfs_recursive_display( inode_xp , name_xp , dentry_xp , 0 ); 1028 1029 } // end vfs_display() 985 1030 986 1031 ////////////////////////////////////////////////////////////////////////////////////////// … … 1015 1060 ////////////////////////////////////////////////////////////////////////////////////////// 1016 1061 // This static function is used by the vfs_lookup() function. 1017 // It takes an extended pointer on a remote inode (parent directory inode), a directory1062 // It takes an extended pointer on a remote parent directory inode, a directory 1018 1063 // entry name, and returns an extended pointer on the child inode. 1019 1064 // It can be used by any thread running in any cluster. … … 1050 1095 *child_xp = (xptr_t)hal_remote_lwd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) ); 1051 1096 return true; 1052 } 1097 1098 } // end vfs_get_child() 1053 1099 1054 1100 ////////////////////////////////////////////////////////////////////////////////////////// … … 1083 1129 while( (*ptr != 0) && (*ptr !='/') ) *(name++) = *(ptr++); 1084 1130 1131 // set NUL terminating character in name buffer 1132 *(name++) = 0; 1133 1085 1134 // return last an next 1086 1135 if( *ptr == 0 ) // last found character is NUL => last name in path … … 1095 1144 1096 1145 return 0; 1097 } 1146 1147 } // end vfs_get name_from_path() 1098 1148 1099 1149 ////////////////////////////////////////////// … … 1122 1172 error_t error; 1123 1173 1124 vfs_dmsg("\n[INFO] %s : enters for <%s> \n",1125 __FUNCTION__ , pathname );1174 vfs_dmsg("\n[INFO] %s : enters for <%s> at cycle %d\n", 1175 __FUNCTION__ , pathname , (uint32_t)hal_time_stamp() ); 1126 1176 1127 1177 this = CURRENT_THREAD; … … 1142 1192 1143 1193 // load from device if one intermediate node not found 1144 // exit when last name found (i.e. last == true)1194 // exit while loop when last name found (i.e. last == true) 1145 1195 do 1146 1196 { … … 1148 1198 vfs_get_name_from_path( current , name , &next , &last ); 1149 1199 1150 vfs_dmsg("\n[INFO] %s : looking for node<%s> / last = %d\n",1200 vfs_dmsg("\n[INFO] %s : looking for <%s> / last = %d\n", 1151 1201 __FUNCTION__ , name , last ); 1152 1202 1153 // search a child dentry matching name forparent inode1203 // search a child dentry matching name in parent inode 1154 1204 found = vfs_get_child( parent_xp, 1155 1205 name, … … 1158 1208 if( found == false ) // child inode not found in inode tree => try to load it 1159 1209 { 1160 vfs_dmsg("\n[INFO] %s : node<%s> not found, try to load it\n",1210 vfs_dmsg("\n[INFO] %s : <%s> not found, try to load it\n", 1161 1211 __FUNCTION__ , name ); 1162 1212 … … 1168 1218 parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp ); 1169 1219 1220 // get local pointer on parent inode context 1221 ctx_ptr = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) ); 1222 1170 1223 // get parent inode FS type 1171 ctx_ptr = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) ); 1172 fs_type = ctx_ptr->type; 1224 fs_type = hal_remote_lw( XPTR( parent_cxy , &ctx_ptr->type ) ); 1173 1225 1174 1226 // get child inode type … … 1179 1231 cxy_t child_cxy = vfs_cluster_random_select(); 1180 1232 1233 printk("\n@@@ name not found : <%s>\n", name ); 1234 1181 1235 // insert a new child dentry/inode in parent inode 1182 1236 error = vfs_add_child_in_parent( child_cxy, … … 1187 1241 name, 1188 1242 &child_xp ); 1189 1190 1243 if( error ) 1191 1244 { … … 1199 1252 } 1200 1253 1201 vfs_dmsg("\n[INFO] %s : node <%s> found / parent = %l / child = %l / last = %d\n", 1254 vfs_inode_display( child_xp ); 1255 1256 vfs_display( parent_xp ); 1257 1258 vfs_dmsg("\n[INFO] %s : found <%s> / parent = %l / child = %l / last = %d\n", 1202 1259 __FUNCTION__ , name , parent_xp , child_xp , last ); 1203 1260 … … 1334 1391 parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp ); 1335 1392 1336 // get parent inode context local pointer 1337 parent_ctx = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) ); 1338 1339 // create dentry 1393 // 1. create dentry 1340 1394 if( parent_cxy == local_cxy ) // parent cluster is the local cluster 1341 1395 { … … 1359 1413 printk("\n[ERROR] in %s : cannot create dentry in cluster %x\n", 1360 1414 __FUNCTION__ , parent_cxy ); 1361 return error;1362 } 1363 1364 // create child inode TODO : define attr / mode / uid / gid1415 return ENOMEM; 1416 } 1417 1418 // 2. create child inode TODO : define attr / mode / uid / gid 1365 1419 uint32_t attr = 0; 1366 1420 uint32_t mode = 0; … … 1403 1457 if( parent_cxy == local_cxy ) vfs_dentry_destroy( dentry ); 1404 1458 else rpc_vfs_dentry_destroy_client( parent_cxy , dentry ); 1405 return error; 1406 } 1459 return ENOMEM; 1460 } 1461 1462 // 3. update extended pointer on inode in dentry 1463 cxy_t dentry_cxy = GET_CXY( dentry_xp ); 1464 vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( dentry_xp ); 1465 hal_remote_swd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) , inode_xp ); 1407 1466 1408 1467 // success : return extended pointer on child inode … … 1422 1481 error_t vfs_move_page_to_mapper( page_t * page ) 1423 1482 { 1424 error_t 1483 error_t error = 0; 1425 1484 1426 1485 assert( (page != NULL) , __FUNCTION__ , "page pointer is NULL\n" );
Note: See TracChangeset
for help on using the changeset viewer.