- Timestamp:
- Feb 10, 2016, 1:23:36 AM (9 years ago)
- Location:
- soft/giet_vm/giet_fat32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r783 r787 1 ///////////////////////////////////////////////////////////////////////////////// 1 ////////////////////////////////////////////////////////////////////////////////// 2 2 // Date : 01/06/2015 3 3 // Authors : Alain Greiner … … 148 148 static unsigned int _update_dir_entry( fat_inode_t* inode ); 149 149 150 static unsigned int _add_dir_entry( fat_inode_t* child, 151 fat_inode_t* parent ); 150 static unsigned int _add_dir_entry( fat_inode_t* child ); 152 151 153 152 static unsigned int _remove_dir_entry( fat_inode_t* inode ); 154 153 155 static void _add_special_directories( fat_inode_t* child, 156 fat_inode_t* parent ); 154 static void _add_special_directories( fat_inode_t* child ); 157 155 158 156 static unsigned int _one_cluster_allocate( fat_inode_t* inode, … … 620 618 unsigned int cluster ) 621 619 { 622 623 #if GIET_DEBUG_FAT624 if ( _get_proctime() > GIET_DEBUG_FAT )625 _printf("\n[DEBUG FAT] _allocate_one_buffer(): in cache <%s> for cluster_id %d\n",626 inode->name, cluster_id );627 #endif628 629 620 // add cache levels if needed 630 621 while ( _get_levels_from_size( (cluster_id + 1) * 4096 ) > inode->levels ) … … 633 624 #if GIET_DEBUG_FAT 634 625 if ( _get_proctime() > GIET_DEBUG_FAT ) 635 _printf("\n[DEBUG FAT] _allocate_one_buffer(): adding a cache level\n" ); 626 _printf("\n[DEBUG FAT] _allocate_one_buffer(): adding a cache level for %s\n", 627 inode->name ); 636 628 #endif 637 629 … … 834 826 unsigned int* cluster ) 835 827 { 828 829 #if GIET_DEBUG_FAT 830 if ( _get_proctime() > GIET_DEBUG_FAT ) 831 _printf("\n[DEBUG FAT] _one_cluster_allocate(): enter for <%s>\n", inode->name ); 832 #endif 833 836 834 // Check free cluster available 837 835 if ( _fat.free_clusters_number == 0 ) … … 887 885 _fat.free_cluster_hint = new; 888 886 889 if ( nb_current_clusters == 0 ) // first cluster : inode and directory entry890 {891 // update inode887 // update cluster chaining 888 if ( nb_current_clusters == 0 ) // first cluster : update cluster field in inode 889 { 892 890 inode->cluster = new; 893 894 // update directory entry 895 _update_dir_entry( inode ); 896 } 897 else // update previous last cluster in FAT 891 } 892 else // not the last : update previous last cluster in FAT 898 893 { 899 894 if ( _set_fat_entry( last , new ) ) … … 922 917 #if GIET_DEBUG_FAT 923 918 if ( _get_proctime() > GIET_DEBUG_FAT ) 924 _printf("\n[DEBUG FAT] _one_cluster_allocate(): for <%s>\n" 925 " nb_clusters = %d / last_cluster = %x / new_cluster = %x\n", 926 inode->name , nb_current_clusters , last , new ); 919 _printf("\n[DEBUG FAT] _one_cluster_allocate(): for <%s> cluster = %x\n", 920 inode->name , new ); 927 921 #endif 928 922 … … 933 927 } // end _one_cluster_allocate() 934 928 929 //////////////////////////////////////////////////////////// 930 // recursive function called by _all_clusters_release() 935 931 //////////////////////////////////////////////////////////// 936 932 static unsigned int _cluster_release( unsigned int cluster ) … … 1008 1004 1009 1005 /////////////////////////////////////////////////////////// 1010 static void _add_special_directories( fat_inode_t* child, 1011 fat_inode_t* parent ) 1012 { 1013 // get first File-Cache buffer for child 1006 static void _add_special_directories( fat_inode_t* child ) 1007 { 1008 // get File-Cache buffer for child and cluster_id = 0 1014 1009 fat_cache_desc_t* pdesc = (fat_cache_desc_t*)child->cache->children[0]; 1015 1010 unsigned char* entry; … … 1017 1012 unsigned int i; 1018 1013 unsigned int cluster; 1019 unsigned int size;1020 1014 1021 1015 // set "." entry (32 bytes) 1016 entry = pdesc->buffer; 1022 1017 cluster = child->cluster; 1023 size = child->size;1024 entry = pdesc->buffer;1025 1018 1026 1019 for ( i = 0 ; i < 32 ; i++ ) … … 1033 1026 else if (i == 26) entry[i] = cluster>>0; // cluster.B0 1034 1027 else if (i == 27) entry[i] = cluster>>8; // cluster.B1 1035 else if (i == 28) entry[i] = size>>0; // size.B01036 else if (i == 29) entry[i] = size>>8; // size.B11037 else if (i == 30) entry[i] = size>>16; // size.B21038 else if (i == 31) entry[i] = size>>24; // size.B31039 1028 else entry[i] = 0x00; 1040 1029 } 1041 1030 1042 1031 // set ".." entry (32 bytes) 1043 cluster = parent->cluster;1044 size = parent->size;1045 1032 entry = pdesc->buffer + 32; 1033 cluster = child->parent->cluster; 1034 1035 // handling special case when parent is root directory 1036 if ( cluster == 2 ) cluster = 0; 1046 1037 1047 1038 for ( i = 0 ; i < 32 ; i++ ) … … 1054 1045 else if (i == 26) entry[i] = cluster>>0; // cluster.B0 1055 1046 else if (i == 27) entry[i] = cluster>>8; // cluster.B1 1056 else if (i == 28) entry[i] = size>>0; // size.B01057 else if (i == 29) entry[i] = size>>8; // size.B11058 else if (i == 30) entry[i] = size>>16; // size.B21059 else if (i == 31) entry[i] = size>>24; // size.B31060 1047 else entry[i] = 0x00; 1061 1048 } … … 1304 1291 1305 1292 1306 /////////////////////////////////////////////////////////// 1307 static unsigned int _add_dir_entry( fat_inode_t* child, 1308 fat_inode_t* parent ) 1293 ////////////////////////////////////////////////////////// 1294 static unsigned int _add_dir_entry( fat_inode_t* child ) 1309 1295 { 1310 1296 // get child attributes … … 1312 1298 unsigned int size = child->size; 1313 1299 unsigned int cluster = child->cluster; 1300 fat_inode_t* parent = child->parent; 1301 1302 if ( parent == NULL ) return 1; 1314 1303 1315 1304 // compute number of required 32 bytes entries to store … … 1320 1309 unsigned char checksum; 1321 1310 if ( _get_sfn_name( child->name, 1322 1323 1324 1325 1311 &length, 1312 &nb_lfn, 1313 sfn, 1314 &checksum ) ) return 1; 1326 1315 1327 1316 #if GIET_DEBUG_FAT … … 1379 1368 #endif 1380 1369 1381 // enter FSM :1370 // enter FSM to modify parent directory: 1382 1371 // The new child requires to write 3, 4, or 5 directory entries. 1383 1372 // To actually register the new child, we use a 5 steps FSM … … 1536 1525 case 1: // write NOMORE entry 1537 1526 { 1527 entry [0] = 0x00; 1538 1528 step--; 1539 entry [0] = 0x00;1540 1529 break; 1541 1530 } … … 1553 1542 1554 1543 return 0; 1555 } // end _add_dir_entry 1544 } // end _add_dir_entry() 1556 1545 1557 1546 … … 2531 2520 2532 2521 // add an entry in the parent directory Cache_file 2533 if ( _add_dir_entry( child , parent ) ) 2522 // and update the dentry field in child inode 2523 if ( _add_dir_entry( child ) ) 2534 2524 { 2535 2525 _spin_lock_release( &_fat.fat_lock ); … … 3632 3622 old->size, 3633 3623 0, // count 3634 0, // dentry 3624 0, // dentry set by _add_dir_entry() 3635 3625 0 ); // no cache_allocate 3636 3626 … … 3639 3629 new->cache = old->cache; 3640 3630 3631 // add "new" to "new_parent" directory in Inode-Tree 3632 _add_inode_in_tree( new , new_parent ); 3633 3641 3634 // add "new" to "new_parent" directory File-Cache 3642 if ( _add_dir_entry( new , new_parent ) ) 3635 // and update the dentry field in new inode 3636 if ( _add_dir_entry( new ) ) 3643 3637 { 3644 3638 _spin_lock_release( &_fat.fat_lock ); … … 3650 3644 } 3651 3645 3652 // add "new" to "new_parent" directory in Inode-Tree3653 _add_inode_in_tree( new , new_parent );3654 3655 3646 // updates "new_parent" directory on device 3656 3647 if ( _update_device_from_cache( new_parent->levels, … … 3796 3787 // allocate a new inode and an empty Cache-File 3797 3788 child = _allocate_one_inode( name, 3798 1, // it's a directory3799 0xFFFFFFFF, // cluster index not defined yet3800 0, // size = 0 for adirectory3801 0, // count3802 0, // dentry set by _add_dir_entry()3803 1 ); // cache_allocate3789 1, // it's a directory 3790 END_OF_CHAIN_CLUSTER_MAX, // cluster set later 3791 0, // size = 0 for directory 3792 0, // count 3793 0, // dentry set later 3794 1 ); // cache_allocate 3804 3795 3805 3796 // introduce inode in Inode-Tree 3806 3797 _add_inode_in_tree( child , parent ); 3807 3798 3808 // allocate cluster from FAT3799 // allocate one cluster from FAT for child 3809 3800 unsigned int cluster; 3810 if ( _one_cluster_allocate( inode, &cluster ) )3801 if ( _one_cluster_allocate( child , &cluster ) ) 3811 3802 { 3812 3803 _spin_lock_release( &_fat.fat_lock ); … … 3821 3812 child->cluster = cluster; 3822 3813 3823 // allocate and initialise one 4 Kbytes buffer and associated descriptor 3824 _allocate_one_buffer( child, 3825 0, // cluster_id, 3826 cluster ); 3827 3828 _add_special_directories( child, 3829 parent ); 3830 3831 // add an entry in the parent directory Cache_file 3832 if ( _add_dir_entry( child , parent ) ) 3833 { 3814 // add new entry in parent directory File-Cache 3815 // and update dentry field in child inode 3816 if ( _add_dir_entry( child ) ) 3817 { 3834 3818 _spin_lock_release( &_fat.fat_lock ); 3835 3819 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); … … 3839 3823 return GIET_FAT32_IO_ERROR; 3840 3824 } 3825 3826 // add "." and ".." directories in child directory 3827 _add_special_directories( child ); 3841 3828 3842 3829 // update DATA region on block device for parent directory -
soft/giet_vm/giet_fat32/fat32.h
r783 r787 170 170 unsigned int size; // number of bytes 171 171 unsigned int count; // reference count / 0 if dir 172 unsigned short dentry; // directoryentry index in parent172 unsigned short dentry; // NORMAL dir_entry index in parent 173 173 unsigned char levels; // number of levels in file_cache 174 174 unsigned char is_dir; // directory if non zero
Note: See TracChangeset
for help on using the changeset viewer.