Changeset 204 for trunk/kernel/vfs
- Timestamp:
- Jul 17, 2017, 8:42:59 AM (7 years ago)
- Location:
- trunk/kernel/vfs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/vfs/devfs.c
r188 r204 53 53 ///////////////////////////////////////////// 54 54 void devfs_ctx_init( devfs_ctx_t * devfs_ctx, 55 xptr_t devfs_ root_inode_xp,55 xptr_t devfs_dev_inode_xp, 56 56 xptr_t devfs_external_inode_xp ) 57 57 { 58 devfs_ctx-> root_inode_xp = devfs_root_inode_xp;58 devfs_ctx->dev_inode_xp = devfs_dev_inode_xp; 59 59 devfs_ctx->external_inode_xp = devfs_external_inode_xp; 60 60 … … 74 74 /////////////////////////////////////////////////// 75 75 void devfs_global_init( xptr_t parent_inode_xp, 76 xptr_t * devfs_ root_inode_xp,76 xptr_t * devfs_dev_inode_xp, 77 77 xptr_t * devfs_external_inode_xp ) 78 78 { … … 86 86 "dev", 87 87 NULL, 88 devfs_ root_inode_xp );88 devfs_dev_inode_xp ); 89 89 90 90 nolock_assert( (error == 0) , __FUNCTION__ , "cannot create <dev>\n" ); … … 94 94 INODE_TYPE_DIR, 95 95 FS_TYPE_DEVFS, 96 *devfs_ root_inode_xp,97 " dev",96 *devfs_dev_inode_xp, 97 "external", 98 98 NULL, 99 99 devfs_external_inode_xp ); … … 102 102 } 103 103 104 ////////////////////////////////////////////////// 105 void devfs_local_init( xptr_t devfs_root_inode_xp, 106 xptr_t devfs_external_inode_xp ) 104 /////////////////////////////////////////////////// 105 void devfs_local_init( xptr_t devfs_dev_inode_xp, 106 xptr_t devfs_external_inode_xp, 107 xptr_t * devfs_internal_inode_xp ) 107 108 { 108 109 char node_name[16]; … … 110 111 cxy_t chdev_cxy; 111 112 xptr_t inode_xp; 112 xptr_t internal_inode_xp;113 113 uint32_t channel; 114 114 … … 118 118 INODE_TYPE_DIR, 119 119 FS_TYPE_DEVFS, 120 devfs_ root_inode_xp,120 devfs_dev_inode_xp, 121 121 node_name, 122 122 NULL, 123 &internal_inode_xp );124 125 // create ICUchdev inode126 chdev_xp = chdev_dir. icu[local_cxy];127 if( chdev_xp != XPTR_NULL) 123 devfs_internal_inode_xp ); 124 125 // create MMC chdev inode 126 chdev_xp = chdev_dir.mmc[local_cxy]; 127 if( chdev_xp != XPTR_NULL) 128 128 { 129 129 vfs_add_child_in_parent( local_cxy, 130 130 INODE_TYPE_DEV, 131 131 FS_TYPE_DEVFS, 132 internal_inode_xp, 133 "icu", 134 GET_PTR( chdev_xp ), 135 &inode_xp ); 136 } 137 138 // create MMC chdev inode 139 chdev_xp = chdev_dir.mmc[local_cxy]; 140 if( chdev_xp != XPTR_NULL) 141 { 142 vfs_add_child_in_parent( local_cxy, 143 INODE_TYPE_DEV, 144 FS_TYPE_DEVFS, 145 internal_inode_xp, 132 *devfs_internal_inode_xp, 146 133 "mmc", 147 134 GET_PTR( chdev_xp ), … … 159 146 INODE_TYPE_DEV, 160 147 FS_TYPE_DEVFS, 161 internal_inode_xp,148 *devfs_internal_inode_xp, 162 149 node_name, 163 150 GET_PTR( chdev_xp ), -
trunk/kernel/vfs/devfs.h
r188 r204 51 51 typedef struct devfs_ctx_s 52 52 { 53 xptr_t root_inode_xp;/*! extended pointer on DEVFS root inode */53 xptr_t dev_inode_xp; /*! extended pointer on DEVFS root inode */ 54 54 xptr_t external_inode_xp; /*! extended pointer on DEVFS external inode */ 55 55 } … … 69 69 ***************************************************************************************** 70 70 * @ devfs_ctx : local pointer on DEVFS context. 71 * @ devfs_ root_inode_xp : [out] extended pointer on created<dev> inode.72 * @ devfs_external_inode_xp : [out] extended pointer on created<external> inode.71 * @ devfs_dev_inode_xp : [out] extended pointer on <dev> inode. 72 * @ devfs_external_inode_xp : [out] extended pointer on <external> inode. 73 73 ****************************************************************************************/ 74 74 void devfs_ctx_init( devfs_ctx_t * devfs_ctx, 75 xptr_t devfs_ root_inode_xp,75 xptr_t devfs_dev_inode_xp, 76 76 xptr_t devfs_external_inode_xp ); 77 77 … … 91 91 ***************************************************************************************** 92 92 * @ parent_inode_xp : extended pointer on the parent VFS inode. 93 * @ devfs_ root_inode_xp: [out] extended pointer on created <dev> inode.93 * @ devfs_dev_inode_xp : [out] extended pointer on created <dev> inode. 94 94 * @ devfs_external_inode_xp : [out] extended pointer on created <external> inode. 95 95 ****************************************************************************************/ 96 96 void devfs_global_init( xptr_t parent_inode_xp, 97 xptr_t * devfs_ root_inode_xp,97 xptr_t * devfs_dev_inode_xp, 98 98 xptr_t * devfs_external_inode_xp ); 99 99 … … 108 108 * a pseudo-file, linked to the DEVFS "internal" parent directory. 109 109 ***************************************************************************************** 110 * @ devfs_ root_inode_xp: extended pointer on DEVFS root inode.110 * @ devfs_dev_inode_xp : extended pointer on DEVFS root inode. 111 111 * @ devfs_external_inode_xp : extended pointer on DEVFS external inode. 112 * @ devfs_internal_inode_xp : [out] extended pointer on created <internal> inode. 112 113 ****************************************************************************************/ 113 void devfs_local_init( xptr_t devfs_root_inode_xp, 114 xptr_t devfs_external_inode_xp ); 114 void devfs_local_init( xptr_t devfs_dev_inode_xp, 115 xptr_t devfs_external_inode_xp, 116 xptr_t * devfs_internal_inode_xp ); 115 117 116 118 #endif /* _DEVFS_H_ */ -
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" ); -
trunk/kernel/vfs/vfs.h
r188 r204 450 450 451 451 /****************************************************************************************** 452 * This debug function diplays the name of the inode identified by the <inode_xp> 453 * argument, and all children names for a directory. 454 ***************************************************************************************** 455 * @ inode_xp : extended pointer on the remote inode. 456 *****************************************************************************************/ 457 void vfs_inode_display( xptr_t inode_xp ); 458 459 460 461 462 463 464 /****************************************************************************************** 452 465 * This function TODO 453 466 *****************************************************************************************/ … … 617 630 * It can be executed by any thread running in any cluster, as this function 618 631 * uses the rpc_dentry_create_client() and rpc_inode_create client() if required. 619 * - The dentry is created in the cluster containing the existing <parent_xp> inode. 620 * - the inode and its associated mapper are created in cluster identified by <child_cxy>. 621 * - The new dentry name is defined by the <name> argument. 622 * - The new inode and the parent inode can have different FS types. 632 * This is done in three steps: 633 * 1) The dentry is created in the cluster containing the existing <parent_xp> inode. 634 * The new dentry name is defined by the <name> argument. 635 * 2) The inode and its associated mapper are created in cluster identified by <child_cxy>. 636 * The new inode and the parent inode can have different FS types. 637 * 3) The "child_xp" field in created dentry (pointing on thecreated inode) is updated. 623 638 ****************************************************************************************** 624 639 * @ child_cxy : target cluster for child inode. … … 629 644 * @ extend : fs_type_specific inode extension. 630 645 * @ child_xp : [out] buffer for extended pointer on child inode. 631 * @ return 0 if success / ENO ENT if entry not found in parent directory646 * @ return 0 if success / ENOMEM if dentry or inode cannot be created. 632 647 *****************************************************************************************/ 633 648 error_t vfs_add_child_in_parent( cxy_t child_cxy,
Note: See TracChangeset
for help on using the changeset viewer.