Changeset 188 for trunk/kernel/vfs/vfs.c
- Timestamp:
- Jul 12, 2017, 8:12:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/vfs/vfs.c
r124 r188 52 52 ////////////////////////////////////////////////////////////////////////////////////////// 53 53 54 extern vfs_ctx_t fs_context[FS_TYPES_NR]; // allocate in kernel_init.c 54 extern vfs_ctx_t fs_context[FS_TYPES_NR]; // allocated in kernel_init.c 55 55 56 56 57 ////////////////////////////////////////////////////////////////////////////////////////// 57 58 // Context related functions 58 59 ////////////////////////////////////////////////////////////////////////////////////////// 60 61 //////////////////////////////////////// 62 void vfs_ctx_init( vfs_fs_type_t type, 63 uint32_t attr, 64 uint32_t total_clusters, 65 uint32_t cluster_size, 66 xptr_t vfs_root_xp, 67 void * extend ) 68 { 69 vfs_ctx_t * vfs_ctx = &fs_context[type]; 70 71 vfs_ctx->type = type; 72 vfs_ctx->attr = attr; 73 vfs_ctx->total_clusters = total_clusters; 74 vfs_ctx->cluster_size = cluster_size; 75 vfs_ctx->vfs_root_xp = vfs_root_xp; 76 vfs_ctx->extend = extend; 77 78 spinlock_init( &vfs_ctx->lock ); 79 80 bitmap_init( vfs_ctx->bitmap , BITMAP_SIZE(CONFIG_VFS_MAX_INODES) ); 81 } 59 82 60 83 //////////////////////////////////////////// … … 101 124 ////////////////////////////////////////////////////////////////////////////////////////// 102 125 126 char * vfs_inode_type_str( uint32_t type ) 127 { 128 if ( type == INODE_TYPE_FILE ) return "FILE"; 129 else if( type == INODE_TYPE_DIR ) return "DIR "; 130 else if( type == INODE_TYPE_FIFO ) return "FIFO"; 131 else if( type == INODE_TYPE_PIPE ) return "PIPE"; 132 else if( type == INODE_TYPE_SOCK ) return "SOCK"; 133 else if( type == INODE_TYPE_DEV ) return "DEV "; 134 else if( type == INODE_TYPE_SYML ) return "SYML"; 135 else return "undefined"; 136 } 137 103 138 ////////////////////////////////////////////////////// 104 105 139 error_t vfs_inode_create( xptr_t dentry_xp, 106 140 vfs_fs_type_t fs_type, 107 141 vfs_inode_type_t inode_type, 142 void * extend, 108 143 uint32_t attr, 109 144 uint32_t rights, … … 175 210 inode->ctx = ctx; 176 211 inode->mapper = NULL; 212 inode->extend = extend; 177 213 178 214 // initialise threads waiting queue … … 307 343 kmem_req_t req; // request to kernel memory allocator 308 344 309 // check type andget pointer on context345 // get pointer on context 310 346 if ( fs_type == FS_TYPE_FATFS ) ctx = &fs_context[FS_TYPE_FATFS]; 311 347 else if( fs_type == FS_TYPE_RAMFS ) ctx = &fs_context[FS_TYPE_RAMFS]; … … 349 385 xhtab_insert( XPTR( local_cxy , &parent->children ), 350 386 name, 351 XPTR( local_cxy , &dentry-> xlist ) );387 XPTR( local_cxy , &dentry->list ) ); 352 388 353 389 // return extended pointer on dentry … … 372 408 kmem_free( &req ); 373 409 } 410 374 411 375 412 … … 797 834 798 835 799 ///////////////////////////////////////////////////////////////////////////////////////// r836 ////////////////////////////////////////////////////////////////////////////////////////// 800 837 // Inode Tree functions 801 838 ////////////////////////////////////////////////////////////////////////////////////////// 839 840 ///////////////////////////////// 841 cxy_t vfs_cluster_random_select() 842 { 843 uint32_t x_size = LOCAL_CLUSTER->x_size; 844 uint32_t y_size = LOCAL_CLUSTER->y_size; 845 uint32_t y_width = LOCAL_CLUSTER->y_width; 846 uint32_t index = ( hal_get_cycles() + hal_get_gid() ) % (x_size * y_size); 847 uint32_t x = index / y_size; 848 uint32_t y = index % y_size; 849 850 return (x<<y_width) + y; 851 } 852 853 854 ////////////////////////////////////////////////////////////////////////// 855 // This static function is called by the vfs_display() function. 856 ////////////////////////////////////////////////////////////////////////// 857 static void vfs_recursive_display( xptr_t inode_xp, 858 xptr_t name_xp, 859 uint32_t indent ) 860 { 861 cxy_t inode_cxy; 862 vfs_inode_t * inode_ptr; 863 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; 869 870 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 871 872 xptr_t child_inode_xp; 873 xptr_t dentry_name_xp; 874 875 char * indent_str[] = { "", // level 0 876 " ", // level 1 877 " ", // level 2 878 " ", // level 3 879 " ", // level 4 880 " ", // level 5 881 " ", // level 6 882 " ", // level 7 883 " ", // level 8 884 " ", // level 9 885 " ", // level 10 886 " ", // level 11 887 " ", // level 12 888 " ", // level 13 889 " ", // level 14 890 " " }; // level 15 891 892 assert( (inode_xp != XPTR_NULL) , __FUNCTION__ , "inode_xp cannot be NULL\n" ); 893 assert( (name_xp != XPTR_NULL) , __FUNCTION__ , "name_xp cannot be NULL\n" ); 894 assert( (indent < 16) , __FUNCTION__ , "depth cannot be larger than 15\n" ); 895 896 // get inode cluster and local pointer 897 inode_cxy = GET_CXY( inode_xp ); 898 inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp ); 899 900 // get inode type 901 inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) ); 902 903 // make a local copy of node name 904 hal_remote_strcpy( XPTR( local_cxy , name ) , name_xp ); 905 906 // display inode 907 printk(" %s %s : %s\n", indent_str[indent], vfs_inode_type_str( inode_type ), name ); 908 909 // scan directory entries 910 if( inode_type == INODE_TYPE_DIR ) 911 { 912 // get extended pointer on directory entries xhtab 913 inode_children_xp = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->children ) ); 914 915 // get xhtab lock 916 xhtab_read_lock( inode_children_xp ); 917 918 // get first dentry from xhtab 919 dentry_xp = xhtab_get_first( inode_children_xp ); 920 921 while( dentry_xp != XPTR_NULL ) 922 { 923 // get dentry cluster and local pointer 924 dentry_cxy = GET_CXY( dentry_xp ); 925 dentry_ptr = (vfs_dentry_t *)GET_PTR( dentry_xp ); 926 927 // get extended pointer on child inode 928 child_inode_xp = hal_remote_lwd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) ); 929 930 // get extended pointer on dentry name 931 dentry_name_xp = XPTR( dentry_cxy , &dentry_ptr->name ); 932 933 // recursive call on child inode 934 vfs_recursive_display( child_inode_xp , dentry_name_xp , indent+1 ); 935 936 // get next dentry 937 dentry_xp = xhtab_get_next( inode_children_xp ); 938 } 939 940 // release xhtab lock 941 xhtab_read_unlock( inode_children_xp ); 942 } 943 } // end vfs_recursive_display() 944 945 /////////////////////////////////// 946 void vfs_display( xptr_t inode_xp ) 947 { 948 xptr_t name_xp; // extended pointer on string containing the inode name 949 xptr_t dentry_xp; 950 cxy_t dentry_cxy; 951 vfs_dentry_t * dentry_ptr; 952 953 printk("\n@@@ %s enters\n", __FUNCTION__ ); 954 955 // get target inode cluster and local pointer 956 cxy_t inode_cxy = GET_CXY( inode_xp ); 957 vfs_inode_t * inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp ); 958 959 // get extended pointer on associated dentry 960 dentry_xp = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) ); 961 962 // check if target inode is the File System root 963 if( dentry_xp == XPTR_NULL ) 964 { 965 // build extended pointer on root name 966 name_xp = XPTR( local_cxy , "/" ); 967 } 968 else 969 { 970 // get dentry cluster and local pointer 971 dentry_cxy = GET_CXY( dentry_xp ); 972 dentry_ptr = (vfs_dentry_t *)GET_PTR( dentry_xp ); 973 974 // get extended pointer on dentry name 975 name_xp = XPTR( dentry_cxy , &dentry_ptr->name ); 976 } 977 978 // print header 979 printk("\n*** Current VFS content ***\n"); 980 981 // call recursive function 982 vfs_recursive_display( inode_xp , name_xp , 0 ); 983 984 } // end vfs_diplay() 802 985 803 986 ////////////////////////////////////////////////////////////////////////////////////////// … … 913 1096 return 0; 914 1097 } 915 1098 916 1099 ////////////////////////////////////////////// 917 1100 error_t vfs_lookup( xptr_t cwd_xp, … … 993 1176 else inode_type = INODE_TYPE_FILE; 994 1177 995 // insert a child dentry/inode in parent inode 996 error = vfs_add_child_in_parent( inode_type, 1178 // select a cluster for child inode 1179 cxy_t child_cxy = vfs_cluster_random_select(); 1180 1181 // insert a new child dentry/inode in parent inode 1182 error = vfs_add_child_in_parent( child_cxy, 1183 inode_type, 997 1184 fs_type, 998 1185 parent_xp, 1186 NULL, // fs_type_specific inode extend 999 1187 name, 1000 1188 &child_xp ); … … 1002 1190 if( error ) 1003 1191 { 1004 printk("\n[ERROR] in %s : inode %s not found in path %s\n",1192 printk("\n[ERROR] in %s : node %s not found in path %s\n", 1005 1193 __FUNCTION__ , name , pathname ); 1006 1194 return ENOENT; … … 1024 1212 // } 1025 1213 1026 printk("\n@@@ bloup 0 : parent lock owner = %l / child lock owner = %l\n", 1027 vfs_inode_owner( parent_xp ) , vfs_inode_owner( child_xp ) ); 1214 // TODO TODO TODO access device and load inode mapper if required... 1028 1215 1029 1216 // take lock on child inode if not last 1030 1217 if( last == false ) vfs_inode_lock( child_xp ); 1031 1218 1032 printk("\n@@@ bloup 1\n");1033 1034 1219 // release lock on parent inode 1035 1220 vfs_inode_unlock( parent_xp ); 1036 1037 printk("\n@@@ bloup 2\n");1038 1221 1039 1222 // update loop variables … … 1060 1243 1061 1244 } // end vfs_lookup() 1062 1063 1245 1064 1246 //////////////////////////////////////////// … … 1131 1313 } // end vfs_get_path() 1132 1314 1133 /////////////////////////////////////////////////////////////// 1134 error_t vfs_add_child_in_parent( vfs_inode_type_t inode_type, 1315 1316 ////////////////////////////////////////////////////////////// 1317 error_t vfs_add_child_in_parent( cxy_t child_cxy, 1318 vfs_inode_type_t inode_type, 1135 1319 vfs_fs_type_t fs_type, 1136 1320 xptr_t parent_xp, 1137 1321 char * name, 1322 void * extend, 1138 1323 xptr_t * child_xp ) 1139 1324 { … … 1174 1359 printk("\n[ERROR] in %s : cannot create dentry in cluster %x\n", 1175 1360 __FUNCTION__ , parent_cxy ); 1176 1177 1361 return error; 1178 1362 } 1179 1363 1180 // select a target cluster for child inode1181 uint32_t x_size = LOCAL_CLUSTER->x_size;1182 uint32_t y_size = LOCAL_CLUSTER->y_size;1183 uint32_t y_width = LOCAL_CLUSTER->y_width;1184 uint32_t index = ( hal_get_cycles() + hal_get_gid() ) % (x_size * y_size);1185 uint32_t x = index / y_size;1186 uint32_t y = index % y_size;1187 cxy_t child_cxy = (x<<y_width) + y;1188 1189 1364 // create child inode TODO : define attr / mode / uid / gid 1190 1365 uint32_t attr = 0; … … 1198 1373 fs_type, 1199 1374 inode_type, 1375 extend, 1200 1376 attr, 1201 1377 mode, … … 1210 1386 fs_type, 1211 1387 inode_type, 1388 extend, 1212 1389 attr, 1213 1390 mode,
Note: See TracChangeset
for help on using the changeset viewer.