Changeset 627 for trunk/kernel/fs
- Timestamp:
- May 1, 2019, 5:13:47 PM (6 years ago)
- Location:
- trunk/kernel/fs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/fs/fatfs.c
r626 r627 491 491 // FS_INFO sector on the IOC device. It can be called by a thead running in any cluster. 492 492 // 493 // WARNING : The free_lock protecting exclusive access to these variables493 // WARNING : The lock protecting exclusive access to these variables 494 494 // must be taken by the calling function. 495 495 ////////////////////////////////////////////////////////////////////////////////////////// … … 618 618 // FS_INFO sector on the IOC device. It can be called by a thead running in any cluster. 619 619 // 620 // WARNING : The free_lock protecting exclusive access to these variables620 // WARNING : The lock protecting exclusive access to these variables 621 621 // must be taken by the calling function. 622 622 ////////////////////////////////////////////////////////////////////////////////////////// … … 853 853 uint32_t page_count_in_file; // index of page in file (index in linked list) 854 854 uint32_t next_cluster_id; // content of current FAT slot 855 xptr_t lock_xp; // extended pointer on FAT lock 855 856 856 857 assert( (searched_page_index > 0) , … … 865 866 #endif 866 867 868 // get local pointer on VFS context (same in all clusters) 869 vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS]; 870 867 871 // get local pointer on local FATFS context 868 fatfs_ctx_t * ctx = fs_context[FS_TYPE_FATFS].extend;872 fatfs_ctx_t * loc_fatfs_ctx = vfs_ctx->extend; 869 873 870 874 // get extended pointer and cluster on FAT mapper 871 xptr_t fat_mapper_xp = ctx->fat_mapper_xp; 872 cxy_t fat_mapper_cxy = GET_CXY( fat_mapper_xp ); 875 xptr_t fat_mapper_xp = loc_fatfs_ctx->fat_mapper_xp; 876 cxy_t fat_cxy = GET_CXY( fat_mapper_xp ); 877 878 // get local pointer on FATFS context in FAT cluster 879 fatfs_ctx_t * fat_fatfs_ctx = hal_remote_lpt( XPTR( fat_cxy , &vfs_ctx->extend ) ); 880 881 // build extended pointer on FAT lock in FAT cluster 882 lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->lock ); 883 884 // take FAT lock in read mode 885 remote_rwlock_rd_acquire( lock_xp ); 873 886 874 887 // initialize loop variable (1024 slots per page) … … 887 900 { 888 901 printk("\n[ERROR] in %s : cannot get next page from FAT mapper\n", __FUNCTION__); 902 remote_rwlock_rd_release( lock_xp ); 889 903 return -1; 890 904 } … … 895 909 896 910 // get FAT slot content 897 next_cluster_id = hal_remote_l32( XPTR( fat_mapper_cxy, 898 &buffer[current_slot_index] ) ); 911 next_cluster_id = hal_remote_l32( XPTR( fat_cxy, &buffer[current_slot_index] ) ); 899 912 900 913 #if (DEBUG_FATFS_GET_CLUSTER & 1) … … 904 917 __FUNCTION__, current_page_index, current_slot_index , next_cluster_id ); 905 918 #endif 906 907 919 // update loop variables 908 920 current_page_index = next_cluster_id >> 10; … … 914 926 { 915 927 printk("\n[ERROR] in %s : searched_cluster_id not found in FAT\n", __FUNCTION__ ); 928 remote_rwlock_rd_release( lock_xp ); 916 929 return -1; 917 930 } 918 931 932 // release FAT lock 933 remote_rwlock_rd_release( lock_xp ); 934 919 935 #if DEBUG_FATFS_GET_CLUSTER 920 936 cycle = (uint32_t)hal_get_cycles(); … … 1093 1109 fatfs_ctx->fs_info_buffer = buffer; 1094 1110 1095 remote_ queuelock_init( XPTR( local_cxy , &fatfs_ctx->free_lock ) , LOCK_FATFS_FREE );1111 remote_rwlock_init( XPTR( local_cxy , &fatfs_ctx->lock ) , LOCK_FATFS_FREE ); 1096 1112 1097 1113 #if (DEBUG_FATFS_CTX_INIT & 0x1) … … 2343 2359 2344 2360 // build relevant extended pointers on free clusters info in mapper cluster 2345 lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx-> free_lock );2361 lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->lock ); 2346 2362 hint_xp = XPTR( fat_cxy , &fat_fatfs_ctx->free_cluster_hint ); 2347 2363 free_xp = XPTR( fat_cxy , &fat_fatfs_ctx->free_clusters ); 2348 2364 2349 // take the lock protecting free clusters2350 remote_ queuelock_acquire( lock_xp );2365 // take the FAT lock in write mode 2366 remote_rwlock_wr_acquire( lock_xp ); 2351 2367 2352 2368 // get hint and free_clusters values from FATFS context in FAT cluster … … 2364 2380 { 2365 2381 printk("\n[ERROR] in %s : no more free FATFS clusters\n", __FUNCTION__ ); 2366 remote_ queuelock_acquire( lock_xp );2382 remote_rwlock_wr_release( lock_xp ); 2367 2383 return -1; 2368 2384 } … … 2383 2399 { 2384 2400 printk("\n[ERROR] in %s : cannot acces FAT mapper\n", __FUNCTION__ ); 2401 remote_rwlock_wr_release( lock_xp ); 2385 2402 return -1; 2386 2403 } … … 2393 2410 { 2394 2411 printk("\n[ERROR] in %s : selected cluster %x not free\n", __FUNCTION__, cluster ); 2395 remote_ queuelock_acquire( lock_xp );2412 remote_rwlock_wr_release( lock_xp ); 2396 2413 return -1; 2397 2414 } … … 2403 2420 { 2404 2421 printk("\n[ERROR] in %s : cannot update free cluster info\n", __FUNCTION__ ); 2405 remote_ queuelock_acquire( lock_xp );2422 remote_rwlock_wr_release( lock_xp ); 2406 2423 return -1; 2407 2424 } … … 2416 2433 { 2417 2434 printk("\n[ERROR] in %s : cannot update FAT on IOC device\n", __FUNCTION__ ); 2418 remote_ queuelock_acquire( lock_xp );2435 remote_rwlock_wr_release( lock_xp ); 2419 2436 return -1; 2420 2437 } 2421 2438 2422 // release free clusters busylock2423 remote_ queuelock_release( lock_xp );2439 // release FAT lock 2440 remote_rwlock_wr_release( lock_xp ); 2424 2441 2425 2442 #if DEBUG_FATFS_CLUSTER_ALLOC … … 2492 2509 fat_fatfs_ctx = hal_remote_lpt( XPTR( mapper_cxy , &vfs_ctx->extend ) ); 2493 2510 2494 // get extended pointer on free clusterslock in FAT cluster2495 lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx-> free_lock );2496 2497 // take lock protecting free clusters2498 remote_ queuelock_acquire( lock_xp );2511 // get extended pointer on FAT lock in FAT cluster 2512 lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->lock ); 2513 2514 // take FAT lock in write mode 2515 remote_rwlock_wr_acquire( lock_xp ); 2499 2516 2500 2517 // call the recursive function to release all clusters from FAT mapper … … 2505 2522 { 2506 2523 printk("\n[ERROR] in %s : cannot update FAT mapper\n", __FUNCTION__ ); 2507 remote_ queuelock_release( lock_xp );2524 remote_rwlock_wr_release( lock_xp ); 2508 2525 return -1; 2509 2526 } 2510 2511 // release lock protecting free cluster2512 remote_queuelock_release( lock_xp );2513 2527 2514 2528 #if (DEBUG_FATFS_RELEASE_INODE & 1) … … 2521 2535 { 2522 2536 printk("\n[ERROR] in %s : cannot update FAT on device\n", __FUNCTION__ ); 2537 remote_rwlock_wr_release( lock_xp ); 2523 2538 return -1; 2524 2539 } … … 2533 2548 { 2534 2549 printk("\n[ERROR] in %s: cannot update FS_INFO on device\n", __FUNCTION__ ); 2550 remote_rwlock_wr_release( lock_xp ); 2535 2551 return -1; 2536 2552 } 2553 2554 // release FAT lock 2555 remote_rwlock_wr_release( lock_xp ); 2537 2556 2538 2557 #if DEBUG_FATFS_RELEASE_INODE -
trunk/kernel/fs/fatfs.h
r626 r627 32 32 33 33 34 /////////////////////////////////////////////////////////////////////////////////////////// 35 // The FATFS File System implements a FAT32 read/write file system. 36 // 37 // The FATFS specific extensions to the generic VFS are the following: 38 // 39 // 1) The vfs_ctx_t "extend" field is a void* pointing on the fatfs_ctx_t structure. 40 // This structure contains various general informations such as the total 41 // number of sectors in FAT region, the number of bytes per sector, the number 42 // of sectors per cluster, the lba of FAT region, the lba of data region, or the 43 // cluster index for the root directory. It contains also an extended pointer 44 // on the FAT mapper. 45 // 46 // 2) The vfs_inode_t "extend" contains, for each inode, 47 // the first FAT cluster index (after cast to intptr). 48 // 49 // 3) The vfs_dentry_t "extend" field contains, for each dentry, the entry index 50 // in the FATFS directory (32 bytes per FATFS entry). 34 /************************************************************************************** 35 * The FATFS File System implements a FAT32 read/write file system. 36 * 37 * The FATFS specific extensions to the generic VFS are the following: 38 * 1) The vfs_ctx_t "extend" field is a void* pointing on the fatfs_ctx_t structure. 39 * This structure contains various general informations such as the total 40 * number of sectors in FAT region, the number of bytes per sector, the number 41 * of sectors per cluster, the lba of FAT region, the lba of data region, or the 42 * cluster index for the root directory. It contains also an extended pointer 43 * on the FAT mapper. 44 * 2) The vfs_inode_t "extend" contains, for each inode, 45 * the first FAT cluster index (after cast to intptr). 46 * 3) The vfs_dentry_t "extend" field contains, for each dentry, the entry index 47 * in the FATFS directory (32 bytes per FATFS entry). 48 *************************************************************************************/ 49 51 50 /////////////////////////////////////////////////////////////////////////////////////////// 52 51 … … 175 174 * This fatfs context is replicated in all clusters. 176 175 * 177 * WARNING : Almost all fields are constant values, but the <free_cluster_hint>, 178 * <free_clusters> and <free_lock> are shared variables. Moreover, the <fs_info_buffer>, 179 * only allocated in cluster 0, contains a copy of the FS_INFO sector. It is used by all 176 * WARNING 1 : All access to the FAT are protected by a remote_rwlock. 177 * - it is taken in READ mode by the fatfs_get_cluster() function to scan the 178 * linked list associated to a given inode. 179 * - it is taken in WRITE mode by the fatfs_cluster_alloc() and fatfs_release_inode() 180 * functions to modify the FAT in both the FAT mapper and on IOC device. 181 * 182 * WARNING é : Almost all fields are constant values, but the <free_cluster_hint>, 183 * <free_clusters> and <lock> are shared variables. The <fs_info_buffer>, only 184 * allocated in cluster 0, contains a copy of the FS_INFO sector. It is used by all 180 185 * kernel instances to synchronously update the free clusters info on IOC device. 181 186 * For these four variables, all kernel instances must use the values in cluster 0, 182 * and take the <free_lock> stored in this cluster for exclusive access to FAT.187 * containing the FAT mapper. 183 188 ****************************************************************************************/ 184 189 … … 198 203 uint32_t free_cluster_hint; /*! cluster[hint+1] is the first free */ 199 204 uint32_t free_clusters; /*! free clusters number */ 200 remote_ queuelock_t free_lock;/*! exclusive access to FAT */205 remote_rwlock_t lock; /*! exclusive access to FAT */ 201 206 uint8_t * fs_info_buffer; /*! local pointer on FS_INFO buffer */ 202 207 }
Note: See TracChangeset
for help on using the changeset viewer.