Changeset 709 for soft/giet_vm/giet_fat32/fat32.c
- Timestamp:
- Oct 1, 2015, 4:20:46 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r707 r709 38 38 #include <vmem.h> 39 39 #include <kernel_malloc.h> 40 #include <ctx_handler.h> 40 41 #include <bdv_driver.h> 41 42 #include <hba_driver.h> … … 93 94 #if GIET_DEBUG_FAT 94 95 static void _display_fat_descriptor(); 95 #endif96 97 /////////////////////////////////////////////////////////////////////////////////98 // This debug function displays the sequence of clusters allocated to a99 // file (or directory) identified by the "inode" argument.100 /////////////////////////////////////////////////////////////////////////////////101 102 #if GIET_DEBUG_FAT103 static void _display_clusters_list( fat_inode_t* inode );104 96 #endif 105 97 … … 593 585 594 586 595 #if GIET_DEBUG_FAT587 #if 0 596 588 //////////////////////////////////////////////////////// 597 589 static void _display_clusters_list( fat_inode_t* inode ) … … 2832 2824 } 2833 2825 2834 // takes the lock 2826 // takes the FAT lock and register it in thread context 2827 static_scheduler_t* psched = _get_sched(); 2828 unsigned int ltid = _get_thread_ltid(); 2835 2829 _spin_lock_acquire( &_fat.fat_lock ); 2830 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT ); 2836 2831 2837 2832 // get inode pointer … … 2841 2836 { 2842 2837 _spin_lock_release( &_fat.fat_lock ); 2838 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2839 2843 2840 _printf("\n[FAT ERROR] _fat_open(): path to parent not found" 2844 2841 " for file <%s>\n", pathname ); … … 2848 2845 { 2849 2846 _spin_lock_release( &_fat.fat_lock ); 2847 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2848 2850 2849 _printf("\n[FAT ERROR] _fat_open(): one name in path too long" 2851 2850 " for file <%s>\n", pathname ); … … 2855 2854 { 2856 2855 _spin_lock_release( &_fat.fat_lock ); 2856 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2857 2857 2858 _printf("\n[FAT ERROR] _fat_open(): file not found" 2858 2859 " for file <%s>\n", pathname ); … … 2890 2891 { 2891 2892 _spin_lock_release( &_fat.fat_lock ); 2893 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2894 2892 2895 _printf("\n[FAT ERROR] _fat_open(): cannot update parent directory" 2893 2896 " for file <%s>\n" , pathname ); … … 2901 2904 { 2902 2905 _spin_lock_release( &_fat.fat_lock ); 2906 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2907 2903 2908 _printf("\n[FAT ERROR] _fat_open(): cannot update DATA region " 2904 2909 " for parent of file <%s>\n", pathname ); … … 2912 2917 { 2913 2918 _spin_lock_release( &_fat.fat_lock ); 2919 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2920 2914 2921 _printf("\n[FAT ERROR] _fat_open(): cannot update FAT region" 2915 2922 " for file <%s>\n", pathname ); … … 2921 2928 { 2922 2929 _spin_lock_release( &_fat.fat_lock ); 2930 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2931 2923 2932 _printf("\n[FAT ERROR] _fat_open(): cannot update FS-INFO" 2924 2933 " for file <%s>\n", pathname ); … … 2952 2961 { 2953 2962 _spin_lock_release( &_fat.fat_lock ); 2963 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2964 2954 2965 _printf("\n[FAT ERROR] _fat_open(): File-Descriptors-Array full\n"); 2955 2966 return GIET_FAT32_TOO_MANY_OPEN_FILES; … … 2979 2990 { 2980 2991 _spin_lock_release( &_fat.fat_lock ); 2992 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2993 2981 2994 _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n"); 2982 2995 return GIET_FAT32_IO_ERROR; … … 2987 3000 { 2988 3001 _spin_lock_release( &_fat.fat_lock ); 3002 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3003 2989 3004 _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n"); 2990 3005 return GIET_FAT32_IO_ERROR; … … 2994 3009 // releases the lock 2995 3010 _spin_lock_release( &_fat.fat_lock ); 3011 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3012 2996 3013 2997 3014 #if GIET_DEBUG_FAT … … 3036 3053 } 3037 3054 3038 // takes lock 3055 // takes the FAT lock and register it in thread context 3056 static_scheduler_t* psched = _get_sched(); 3057 unsigned int ltid = _get_thread_ltid(); 3039 3058 _spin_lock_acquire( &_fat.fat_lock ); 3059 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT ); 3040 3060 3041 3061 if( _fat.fd[fd_id].allocated == 0 ) 3042 3062 { 3043 3063 _spin_lock_release( &_fat.fat_lock ); 3064 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3065 3044 3066 _printf("\n[FAT ERROR] _fat_close(): file not open\n"); 3045 3067 return GIET_FAT32_NOT_OPEN; … … 3067 3089 { 3068 3090 _spin_lock_release( &_fat.fat_lock ); 3091 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3092 3069 3093 _printf("\n[FAT ERROR] _fat_close(): cannot write dirty clusters " 3070 3094 "for file <%s>\n", inode->name ); … … 3084 3108 { 3085 3109 _spin_lock_release( &_fat.fat_lock ); 3110 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3111 3086 3112 _printf("\n[FAT ERROR] _fat_close(): cannot write dirty clusters " 3087 3113 "for directory <%s>\n", inode->parent->name ); … … 3111 3137 // release lock 3112 3138 _spin_lock_release( &_fat.fat_lock ); 3139 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3113 3140 3114 3141 return GIET_FAT32_OK; … … 3161 3188 3162 3189 ///////////////////////////////////////////////////////////////////////////////// 3163 // The following function implements the "giet_fat_read()" system call. 3164 // It transfers "count" bytes from the File_Cache associated to the file 3165 // identified by "fd_id", to the user "buffer", from the current file offset. 3190 // The following function implements the "giet_fat_read()" system call, 3191 // but can also be used by the kernel in physical addressing mode. 3192 // It transfers <count> bytes from the File_Cache associated to the file 3193 // identified by <fd_id>, to the destination buffer defined by <vaddr>. 3194 // It uses the current file offset defined in the file descriptor. 3195 // If the <extend> 16 MSB bits are non zero, it uses physical addressing: 3196 // the physical address is computed as extend[15:0] | vaddr[31:0] 3166 3197 // In case of miss in the File_Cache, it loads all involved clusters into cache. 3167 3198 ///////////////////////////////////////////////////////////////////////////////// … … 3175 3206 ///////////////////////////////////////////////////////////////////////////////// 3176 3207 int _fat_read( unsigned int fd_id, // file descriptor index 3177 paddr_t buffer, // destination buffer3208 unsigned int vaddr, // destination buffer vaddr 3178 3209 unsigned int count, // number of bytes to read 3179 unsigned int phys ) // use physical_memcpy 3180 { 3181 // checking FAT initialized 3182 if( _fat.initialized != FAT_INITIALIZED ) 3183 { 3184 _printf("\n[FAT ERROR] _fat_write(): FAT not initialized\n"); 3185 return GIET_FAT32_NOT_INITIALIZED; 3186 } 3187 3188 // check fd_id overflow 3189 if ( fd_id >= GIET_OPEN_FILES_MAX ) 3190 { 3191 _printf("\n[FAT ERROR] _fat_read(): illegal file descriptor\n"); 3192 return GIET_FAT32_INVALID_FD; 3193 } 3194 3195 // check file is open 3196 if ( _fat.fd[fd_id].allocated == 0 ) 3197 { 3198 _printf("\n[FAT ERROR] _fat_read(): file not open\n"); 3199 return GIET_FAT32_NOT_OPEN; 3200 } 3201 3202 // takes lock 3203 _spin_lock_acquire( &_fat.fat_lock ); 3204 3205 // get file inode pointer and offset 3206 fat_inode_t* inode = _fat.fd[fd_id].inode; 3207 unsigned int seek = _fat.fd[fd_id].seek; 3208 3209 // check count & seek versus file size 3210 if ( count + seek > inode->size && !inode->is_dir ) 3211 { 3212 _spin_lock_release( &_fat.fat_lock ); 3213 _printf("\n[FAT ERROR] _fat_read(): file too small" 3214 " / seek = %x / count = %x / file_size = %x\n", 3215 seek , count , inode->size ); 3216 return 0; 3217 } 3218 3219 // compute first_cluster_id and first_byte_to_move 3220 unsigned int first_cluster_id = seek >> 12; 3221 unsigned int first_byte_to_move = seek & 0xFFF; 3222 3223 // compute last_cluster and last_byte_to_move 3224 unsigned int last_cluster_id = (seek + count - 1) >> 12; 3225 unsigned int last_byte_to_move = (seek + count - 1) & 0xFFF; 3210 unsigned int extend ) // physical address extension 3211 { 3226 3212 3227 3213 #if GIET_DEBUG_FAT … … 3231 3217 unsigned int p = procid & ((1<<P_WIDTH)-1); 3232 3218 if ( _get_proctime() > GIET_DEBUG_FAT ) 3233 _printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] enters for file <%s> " 3234 " / bytes = %x / offset = %x\n" 3235 "first_cluster_id = %x / first_byte_to_move = %x" 3219 _printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] enters at cycle %d\n" 3220 " fd = %d / vaddr = %x / bytes = %x / extend = %x\n", 3221 x , y , p , _get_proctime(), 3222 fd_id , vaddr , count , extend ); 3223 #endif 3224 3225 // checking FAT initialized 3226 if( _fat.initialized != FAT_INITIALIZED ) 3227 { 3228 _printf("\n[FAT ERROR] _fat_read(): FAT not initialized\n"); 3229 return GIET_FAT32_NOT_INITIALIZED; 3230 } 3231 3232 // check fd_id overflow 3233 if ( fd_id >= GIET_OPEN_FILES_MAX ) 3234 { 3235 _printf("\n[FAT ERROR] _fat_read(): illegal file descriptor\n"); 3236 return GIET_FAT32_INVALID_FD; 3237 } 3238 3239 // check file is open 3240 if ( _fat.fd[fd_id].allocated == 0 ) 3241 { 3242 _printf("\n[FAT ERROR] _fat_read(): file not open\n"); 3243 return GIET_FAT32_NOT_OPEN; 3244 } 3245 3246 // takes the FAT lock and register it in thread context 3247 static_scheduler_t* psched = _get_sched(); 3248 unsigned int ltid = _get_thread_ltid(); 3249 _spin_lock_acquire( &_fat.fat_lock ); 3250 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT ); 3251 3252 3253 // get file inode pointer and offset 3254 fat_inode_t* inode = _fat.fd[fd_id].inode; 3255 unsigned int seek = _fat.fd[fd_id].seek; 3256 3257 // check count & seek versus file size 3258 if ( count + seek > inode->size && !inode->is_dir ) 3259 { 3260 _spin_lock_release( &_fat.fat_lock ); 3261 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3262 3263 _printf("\n[FAT ERROR] _fat_read(): file too small" 3264 " / seek = %x / count = %x / file_size = %x\n", 3265 seek , count , inode->size ); 3266 return 0; 3267 } 3268 3269 // compute first_cluster_id and first_byte_to_move 3270 unsigned int first_cluster_id = seek >> 12; 3271 unsigned int first_byte_to_move = seek & 0xFFF; 3272 3273 // compute last_cluster and last_byte_to_move 3274 unsigned int last_cluster_id = (seek + count - 1) >> 12; 3275 unsigned int last_byte_to_move = (seek + count - 1) & 0xFFF; 3276 3277 #if GIET_DEBUG_FAT 3278 if ( _get_proctime() > GIET_DEBUG_FAT ) 3279 _printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] search file <%s> with seek = %x\n " 3280 " first_cluster_id = %x / first_byte_to_move = %x" 3236 3281 " / last_cluster_id = %x / last_byte_to_move = %x\n", 3237 x , y , p , inode->name , count ,seek ,3282 x , y , p , inode->name , seek , 3238 3283 first_cluster_id , first_byte_to_move , last_cluster_id , last_byte_to_move ); 3239 3284 #endif … … 3252 3297 { 3253 3298 _spin_lock_release( &_fat.fat_lock ); 3299 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3300 3254 3301 _printf("\n[FAT ERROR] _fat_read(): cannot load file <%s>\n", 3255 3302 inode->name ); … … 3289 3336 } 3290 3337 3291 // move data 3292 if ( !phys ) 3293 { 3294 void* dest = (void*)(unsigned int)buffer + done; 3295 3296 memcpy( dest, source, nbytes ); 3297 } 3298 else 3338 // move data 3339 if ( (extend & 0xFFFF0000) == 0 ) // no physical addressing 3340 { 3341 char* dest = (char*)(vaddr + done); 3342 memcpy( dest , source , nbytes ); 3343 } 3344 else // physical addressing required 3299 3345 { 3300 3346 unsigned int flags; 3301 paddr_t pdest = buffer + done;3347 paddr_t pdest = (((paddr_t)(extend & 0x0000FFFF))<<32) + vaddr + done; 3302 3348 paddr_t psource = _v2p_translate( (unsigned int)source, &flags ); 3303 3304 _physical_memcpy( pdest, psource, nbytes ); 3349 _physical_memcpy( pdest , psource , nbytes ); 3305 3350 } 3306 3351 … … 3319 3364 // release lock 3320 3365 _spin_lock_release( &_fat.fat_lock ); 3366 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3321 3367 3322 3368 return done; … … 3327 3373 3328 3374 ///////////////////////////////////////////////////////////////////////////////// 3329 // The following function implements the "giet_fat_write()" system call. 3330 // It transfers "count" bytes to the fat_cache associated to the file 3331 // identified by "fd_id", from the user "buffer", using the current file offset. 3375 // The following function implements the "giet_fat_write()" system call, 3376 // but can also be used by the kernel in physical addressing mode. 3377 // It transfers <count> bytes to the File_Cache associated to the file 3378 // identified by <fd_id>, from the source buffer defined by <vaddr>. 3379 // It uses the current file offset defined in the file descriptor. 3380 // If the <extend> 16 MSB bits are non zero, it uses physical addressing: 3381 // the physical address is computed as extend[15:0] | vaddr[31:0] 3332 3382 // It increases the file size and allocate new clusters if (count + offset) 3333 3383 // is larger than the current file size. Then it loads and updates all … … 3344 3394 ///////////////////////////////////////////////////////////////////////////////// 3345 3395 int _fat_write( unsigned int fd_id, // file descriptor index 3346 void* buffer, // source buffer 3347 unsigned int count ) // number of bytes to write 3396 unsigned int vaddr, // source buffer vaddr 3397 unsigned int count, // number of bytes to write 3398 unsigned int extend ) // physical address extension 3348 3399 { 3349 3400 // checking FAT initialized … … 3354 3405 } 3355 3406 3356 // takes lock 3407 // takes the FAT lock and register it in thread context 3408 static_scheduler_t* psched = _get_sched(); 3409 unsigned int ltid = _get_thread_ltid(); 3357 3410 _spin_lock_acquire( &_fat.fat_lock ); 3411 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT ); 3412 3358 3413 3359 3414 // check fd_id overflow … … 3361 3416 { 3362 3417 _spin_lock_release( &_fat.fat_lock ); 3418 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3419 3363 3420 _printf("\n[FAT ERROR] _fat_write(): illegal file descriptor\n"); 3364 3421 return GIET_FAT32_INVALID_FD; … … 3369 3426 { 3370 3427 _spin_lock_release( &_fat.fat_lock ); 3428 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3429 3371 3430 _printf("\n[FAT ERROR] _fat_write(): file not open\n" ); 3372 3431 return GIET_FAT32_NOT_OPEN; … … 3377 3436 { 3378 3437 _spin_lock_release( &_fat.fat_lock ); 3438 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3439 3379 3440 _printf("\n[FAT ERROR] _fat_write(): file <%s> is read-only\n", 3380 3441 _fat.fd[fd_id].inode->name ); … … 3429 3490 { 3430 3491 _spin_lock_release( &_fat.fat_lock ); 3492 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3493 3431 3494 _printf("\n[FAT ERROR] _fat_write(): no free clusters" 3432 3495 " for file <%s>\n", _fat.fd[fd_id].inode->name ); … … 3439 3502 { 3440 3503 _spin_lock_release( &_fat.fat_lock ); 3504 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3505 3441 3506 _printf("\n[FAT ERROR] _fat_write(): cannot update parent directory entry" 3442 3507 " for file <%s>\n", _fat.fd[fd_id].inode->name ); … … 3483 3548 { 3484 3549 _spin_lock_release( &_fat.fat_lock ); 3550 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3551 3485 3552 _printf("\n[FAT ERROR] _fat_write(): cannot load file <%s>\n", 3486 3553 inode->name ); … … 3498 3565 3499 3566 // compute memcpy arguments 3500 unsigned char* source = (unsigned char*)buffer + done;3501 3567 unsigned char* dest; 3502 3568 unsigned int nbytes; … … 3522 3588 } 3523 3589 3524 //move date 3525 memcpy( dest , source , nbytes ); 3590 // move data 3591 if ( (extend & 0xFFFF0000) == 0 ) // no physical addressing 3592 { 3593 char* source = (char*)(vaddr + done); 3594 memcpy( dest , source , nbytes ); 3595 } 3596 else // physical addressing required 3597 { 3598 unsigned int flags; 3599 paddr_t psource = (((paddr_t)(extend & 0x0000FFFF))<<32) + vaddr + done; 3600 paddr_t pdest = _v2p_translate( (unsigned int)dest , &flags ); 3601 _physical_memcpy( pdest , psource , nbytes ); 3602 } 3603 3526 3604 done = done + nbytes; 3527 3605 … … 3539 3617 // release lock 3540 3618 _spin_lock_release( &_fat.fat_lock ); 3619 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3541 3620 3542 3621 return done; … … 3577 3656 } 3578 3657 3579 // takes lock 3658 // takes the FAT lock and register it in thread context 3659 static_scheduler_t* psched = _get_sched(); 3660 unsigned int ltid = _get_thread_ltid(); 3580 3661 _spin_lock_acquire( &_fat.fat_lock ); 3662 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT ); 3663 3581 3664 3582 3665 // check file open … … 3584 3667 { 3585 3668 _spin_lock_release( &_fat.fat_lock ); 3669 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3670 3586 3671 _printf("\n[FAT ERROR] _fat_lseek(): file not open\n"); 3587 3672 return GIET_FAT32_NOT_OPEN; … … 3596 3681 { 3597 3682 _spin_lock_release( &_fat.fat_lock ); 3683 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3684 3598 3685 _printf("\n[FAT ERROR] _fat_lseek(): illegal whence value\n"); 3599 3686 return GIET_FAT32_INVALID_ARG; … … 3615 3702 // release lock 3616 3703 _spin_lock_release( &_fat.fat_lock ); 3704 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3617 3705 3618 3706 return new_seek; … … 3665 3753 } 3666 3754 3667 // take the lock 3755 // takes the FAT lock and register it in thread context 3756 static_scheduler_t* psched = _get_sched(); 3757 unsigned int ltid = _get_thread_ltid(); 3668 3758 _spin_lock_acquire( &_fat.fat_lock ); 3759 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT ); 3760 3669 3761 3670 3762 // get searched file inode … … 3680 3772 { 3681 3773 _spin_lock_release( &_fat.fat_lock ); 3774 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3775 3682 3776 _printf("\n[FAT ERROR] _fat_remove(): file <%s> not found\n", 3683 3777 pathname ); … … 3687 3781 { 3688 3782 _spin_lock_release( &_fat.fat_lock ); 3783 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3784 3689 3785 _printf("\n[FAT ERROR] _fat_remove(): name too long in <%s>\n", 3690 3786 pathname ); … … 3696 3792 { 3697 3793 _spin_lock_release( &_fat.fat_lock ); 3794 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3795 3698 3796 _printf("\n[FAT ERROR] _fat_remove(): <%s> is a directory\n", 3699 3797 pathname ); … … 3703 3801 { 3704 3802 _spin_lock_release( &_fat.fat_lock ); 3803 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3804 3705 3805 _printf("\n[FAT ERROR] _fat_remove(): <%s> is not a directory\n", 3706 3806 pathname ); … … 3718 3818 { 3719 3819 _spin_lock_release( &_fat.fat_lock ); 3820 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3821 3720 3822 _printf("\n[FAT ERROR] _fat_remove(): file <%s> still referenced\n", 3721 3823 pathname ); … … 3730 3832 { 3731 3833 _spin_lock_release( &_fat.fat_lock ); 3834 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3835 3732 3836 _printf("\n[FAT ERROR] _fat_remove(): cannot scan directory <%s>\n", 3733 3837 pathname ); … … 3737 3841 { 3738 3842 _spin_lock_release( &_fat.fat_lock ); 3843 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3844 3739 3845 _printf("\n[FAT ERROR] _fat_remove(): directory <%s> not empty\n", 3740 3846 pathname ); … … 3753 3859 { 3754 3860 _spin_lock_release( &_fat.fat_lock ); 3861 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3862 3755 3863 _printf("\n[FAT ERROR] _fat_remove(): cannot remove <%s> from FS\n", 3756 3864 pathname ); … … 3760 3868 // release lock and return success 3761 3869 _spin_lock_release( &_fat.fat_lock ); 3870 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3762 3871 3763 3872 #if GIET_DEBUG_FAT … … 3821 3930 } 3822 3931 3823 // take the lock 3932 // takes the FAT lock and register it in thread context 3933 static_scheduler_t* psched = _get_sched(); 3934 unsigned int ltid = _get_thread_ltid(); 3824 3935 _spin_lock_acquire( &_fat.fat_lock ); 3936 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT ); 3937 3825 3938 3826 3939 // get "old" and "old_parent" inode pointers … … 3828 3941 { 3829 3942 _spin_lock_release( &_fat.fat_lock ); 3943 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3944 3830 3945 _printf("\n[FAT ERROR] _fat_rename(): <%s> not found\n", old_path ); 3831 3946 return GIET_FAT32_FILE_NOT_FOUND; … … 3845 3960 { 3846 3961 _spin_lock_release( &_fat.fat_lock ); 3962 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3963 3847 3964 return GIET_FAT32_OK; 3848 3965 } … … 3859 3976 { 3860 3977 _spin_lock_release( &_fat.fat_lock ); 3978 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3979 3861 3980 _printf("\n[FAT ERROR] _fat_rename(): <%s> not found\n", new_path ); 3862 3981 return GIET_FAT32_FILE_NOT_FOUND; … … 3867 3986 { 3868 3987 _spin_lock_release( &_fat.fat_lock ); 3869 _printf("\n[FAT ERROR] _fat_rename(): can't move %s into its own subdirectory\n", old_path ); 3988 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 3989 3990 _printf("\n[FAT ERROR] _fat_rename(): can't move %s into own directory\n", old_path ); 3870 3991 return GIET_FAT32_MOVE_INTO_SUBDIR; 3871 3992 } … … 3894 4015 { 3895 4016 _spin_lock_release( &_fat.fat_lock ); 4017 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4018 3896 4019 _printf("\n[FAT ERROR] _fat_rename(): cannot scan directory <%s>\n", 3897 4020 to_remove->name ); … … 3901 4024 { 3902 4025 _spin_lock_release( &_fat.fat_lock ); 4026 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4027 3903 4028 _printf("\n[FAT ERROR] _fat_rename(): directory <%s> not empty\n", 3904 4029 to_remove->name ); … … 3911 4036 { 3912 4037 _spin_lock_release( &_fat.fat_lock ); 4038 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4039 3913 4040 _printf("\n[FAT ERROR] _fat_rename(): file <%s> still referenced\n", 3914 4041 to_remove->name ); … … 3945 4072 { 3946 4073 _spin_lock_release( &_fat.fat_lock ); 4074 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4075 3947 4076 _printf("\n[FAT ERROR] _fat_rename(): cannot add <%s> into <%s>\n", 3948 4077 new->name , new_parent->name ); … … 3959 4088 { 3960 4089 _spin_lock_release( &_fat.fat_lock ); 4090 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4091 3961 4092 _printf("\n[FAT ERROR] _fat_rename(): cannot update <%s> on device\n", 3962 4093 new_parent->name ); … … 3968 4099 { 3969 4100 _spin_lock_release( &_fat.fat_lock ); 4101 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4102 3970 4103 _printf("\n[FAT ERROR] _fat_rename(): cannot remove <%s> from <%s>\n", 3971 4104 old->name , old_parent->name ); … … 3985 4118 { 3986 4119 _spin_lock_release( &_fat.fat_lock ); 4120 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4121 3987 4122 _printf("\n[FAT ERROR] _fat_rename(): cannot update <%s> on device\n", 3988 4123 old_parent->name ); … … 3996 4131 { 3997 4132 _spin_lock_release( &_fat.fat_lock ); 4133 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4134 3998 4135 _printf("\n[FAT ERROR] _fat_rename(): cannot remove <%s> from FS\n", 3999 4136 to_remove->name ); … … 4004 4141 // release lock 4005 4142 _spin_lock_release( &_fat.fat_lock ); 4143 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4006 4144 4007 4145 return GIET_FAT32_OK; … … 4052 4190 } 4053 4191 4054 // takes the lock 4192 // takes the FAT lock and register it in thread context 4193 static_scheduler_t* psched = _get_sched(); 4194 unsigned int ltid = _get_thread_ltid(); 4055 4195 _spin_lock_acquire( &_fat.fat_lock ); 4056 4196 _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT ); 4197 4057 4198 // get inode 4058 4199 unsigned int code = _get_inode_from_path( pathname , &inode ); … … 4061 4202 { 4062 4203 _spin_lock_release( &_fat.fat_lock ); 4204 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4205 4063 4206 _printf("\n[FAT ERROR] _fat_mkdir(): path to parent not found" 4064 4207 " for directory <%s>\n", pathname ); … … 4068 4211 { 4069 4212 _spin_lock_release( &_fat.fat_lock ); 4213 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4214 4070 4215 _printf("\n[FAT ERROR] _fat_mkdir(): one name in path too long" 4071 4216 " for directory <%s>\n", pathname ); … … 4075 4220 { 4076 4221 _spin_lock_release( &_fat.fat_lock ); 4222 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4223 4077 4224 _printf("\n[FAT ERROR] _fat_mkdir(): directory <%s> already exist\n", 4078 4225 pathname ); … … 4098 4245 { 4099 4246 _spin_lock_release( &_fat.fat_lock ); 4247 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4248 4100 4249 _printf("\n[FAT ERROR] _fat_mkdir(): no free cluster" 4101 4250 " for directory <%s>\n" , pathname ); … … 4127 4276 { 4128 4277 _spin_lock_release( &_fat.fat_lock ); 4278 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4279 4129 4280 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update parent directory" 4130 4281 " for directory <%s>\n" , pathname ); … … 4138 4289 { 4139 4290 _spin_lock_release( &_fat.fat_lock ); 4291 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4292 4140 4293 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update DATA region " 4141 4294 " for parent of directory <%s>\n", pathname ); … … 4149 4302 { 4150 4303 _spin_lock_release( &_fat.fat_lock ); 4304 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4305 4151 4306 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update FAT region" 4152 4307 " for directory <%s>\n", pathname ); … … 4158 4313 { 4159 4314 _spin_lock_release( &_fat.fat_lock ); 4315 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4316 4160 4317 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update FS-INFO" 4161 4318 " for directory <%s>\n", pathname ); … … 4169 4326 { 4170 4327 _spin_lock_release( &_fat.fat_lock ); 4328 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4329 4171 4330 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update DATA region" 4172 4331 " for directory <%s>\n", pathname ); … … 4177 4336 // release lock 4178 4337 _spin_lock_release( &_fat.fat_lock ); 4338 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 4179 4339 4180 4340 return GIET_FAT32_OK; … … 4293 4453 { 4294 4454 // seek back to this entry 4295 _spin_lock_acquire( &_fat.fat_lock ); 4296 _fat.fd[fd_id].seek -= DIR_ENTRY_SIZE; 4297 _spin_lock_release( &_fat.fat_lock ); 4455 _atomic_increment( &_fat.fd[fd_id].seek , -DIR_ENTRY_SIZE ); 4298 4456 4299 4457 return GIET_FAT32_NO_MORE_ENTRIES;
Note: See TracChangeset
for help on using the changeset viewer.