Changeset 664 for soft/giet_vm/giet_fat32/fat32.c
- Timestamp:
- Jul 27, 2015, 5:56:15 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r661 r664 637 637 #if (GIET_DEBUG_FAT & 1) 638 638 if ( _get_proctime() > GIET_DEBUG_FAT ) 639 _printf("\n[DEBUG FAT] _fat_ioc_access() 639 _printf("\n[DEBUG FAT] _fat_ioc_access(): enters at cycle %d\n" 640 640 " to_mem = %d / vaddr = %x / paddr = %l / sectors = %d / lba = %x\n", 641 641 _get_proctime(), to_mem, buf_vaddr, buf_paddr, count, lba ); … … 659 659 return( _rdk_access( use_irq , to_mem , lba , buf_paddr , count ) ); 660 660 #else 661 _printf("\n[FAT ERROR] in _fat_ioc_access(): no IOC driver\n");661 _printf("\n[FAT ERROR] _fat_ioc_access(): no IOC driver\n"); 662 662 _exit(); 663 663 #endif … … 707 707 if ( cluster < 2 ) 708 708 { 709 _printf("\n[FAT ERROR] in _cluster_to_lba() cluster smaller than 2\n");709 _printf("\n[FAT ERROR] _cluster_to_lba(): cluster smaller than 2\n"); 710 710 _exit(); 711 711 } … … 987 987 #if (GIET_DEBUG_FAT & 1) 988 988 if ( _get_proctime() > GIET_DEBUG_FAT ) 989 _printf("\n[DEBUG FAT] _get_buffer_from_cache() 989 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): enters in FAT-Cache" 990 990 " for cluster_id = %d\n", cluster_id ); 991 991 #endif … … 999 999 #if (GIET_DEBUG_FAT & 1) 1000 1000 if ( _get_proctime() > GIET_DEBUG_FAT ) 1001 _printf("\n[DEBUG FAT] _get_buffer_from_cache() 1001 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): enters in File-Cache <%s>" 1002 1002 " for cluster_id = %d\n", inode->name , cluster_id ); 1003 1003 #endif … … 1028 1028 #if (GIET_DEBUG_FAT & 1) 1029 1029 if ( _get_proctime() > GIET_DEBUG_FAT ) 1030 _printf("\n[DEBUG FAT] _get_buffer_from_cache() 1030 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): miss in FAT-Cache for cluster_id %d\n", 1031 1031 cluster_id ); 1032 1032 #endif … … 1038 1038 #if (GIET_DEBUG_FAT & 1) 1039 1039 if ( _get_proctime() > GIET_DEBUG_FAT ) 1040 _printf("\n[DEBUG FAT] _get_buffer_from_cache() 1040 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): miss in File-Cache <%s> " 1041 1041 "for cluster_id %d\n", inode->name, cluster_id ); 1042 1042 #endif … … 1061 1061 { 1062 1062 _free( buf ); 1063 _printf("\n[FAT ERROR] in_get_buffer_from_cache()"1064 " 1063 _printf("\n[FAT ERROR] _get_buffer_from_cache()" 1064 ": cannot access block device for lba = %x\n", lba ); 1065 1065 return 1; 1066 1066 } … … 1075 1075 #if (GIET_DEBUG_FAT & 1) 1076 1076 if ( _get_proctime() > GIET_DEBUG_FAT ) 1077 _printf("\n[DEBUG FAT] _get_buffer_from_cache() 1077 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): buffer loaded from device" 1078 1078 " at vaddr = %x\n", (unsigned int)buf ); 1079 1079 #endif … … 1120 1120 1 ) ) // one block 1121 1121 { 1122 _printf("\n[FAT_ERROR] in _update_fs_info()cannot read block\n");1122 _printf("\n[FAT_ERROR] _update_fs_info(): cannot read block\n"); 1123 1123 return 1; 1124 1124 } … … 1141 1141 1 ) ) // one block 1142 1142 { 1143 _printf("\n[FAT_ERROR] in _update_fs_info()cannot write block\n");1143 _printf("\n[FAT_ERROR] _update_fs_info(): cannot write block\n"); 1144 1144 return 1; 1145 1145 } … … 1147 1147 #if (GIET_DEBUG_FAT & 1) 1148 1148 if ( _get_proctime() > GIET_DEBUG_FAT ) 1149 _printf("\n[DEBUG FAT] _update_fs_info() 1149 _printf("\n[DEBUG FAT] _update_fs_info(): nb_free = %x / first_free = %x\n", 1150 1150 _fat.free_clusters_number , _fat.first_free_cluster ); 1151 1151 #endif … … 1217 1217 #if (GIET_DEBUG_FAT & 1) 1218 1218 if ( _get_proctime() > GIET_DEBUG_FAT ) 1219 _printf("\n[DEBUG FAT] _allocate_one_buffer() 1219 _printf("\n[DEBUG FAT] _allocate_one_buffer(): adding a cache level\n" ); 1220 1220 #endif 1221 1221 … … 1238 1238 if ( pdesc != NULL ) // slot not empty!!! 1239 1239 { 1240 _printf("\n[FAT ERROR] in allocate_one buffer(): slot not empty "1240 _printf("\n[FAT ERROR] allocate_one buffer(): slot not empty " 1241 1241 "in File-Cache <%s> / cluster_id = %d\n", inode->name , cluster_id ); 1242 1242 _exit(); … … 1245 1245 #if (GIET_DEBUG_FAT & 1) 1246 1246 if ( _get_proctime() > GIET_DEBUG_FAT ) 1247 _printf("\n[DEBUG FAT] _allocate_one_buffer() 1247 _printf("\n[DEBUG FAT] _allocate_one_buffer(): buffer allocated to <%s> for cluster_id %d\n", 1248 1248 inode->name, cluster_id ); 1249 1249 #endif … … 1301 1301 if ( found == 0 ) 1302 1302 { 1303 _printf("\n[FAT_ERROR] in _allocate_one_cluster(): unconsistent FAT state");1303 _printf("\n[FAT_ERROR] _allocate_one_cluster(): unconsistent FAT state"); 1304 1304 return 1; 1305 1305 } … … 1314 1314 #if (GIET_DEBUG_FAT & 1) 1315 1315 if ( _get_proctime() > GIET_DEBUG_FAT ) 1316 _printf("\n[DEBUG FAT] _allocate_one_cluster() 1316 _printf("\n[DEBUG FAT] _allocate_one_cluster(): cluster = %x / first_free = %x\n", 1317 1317 free , current ); 1318 1318 #endif … … 1351 1351 8 ) ) 1352 1352 { 1353 _printf("\n[FAT_ERROR] in _update_device from_cache(): "1353 _printf("\n[FAT_ERROR] _update_device from_cache(): " 1354 1354 " cannot access lba = %x\n", pdesc->lba ); 1355 1355 ret = 1; … … 1361 1361 #if (GIET_DEBUG_FAT & 1) 1362 1362 if ( _get_proctime() > GIET_DEBUG_FAT ) 1363 _printf("\n[DEBUG FAT] _update_device_from_cache() 1363 _printf("\n[DEBUG FAT] _update_device_from_cache(): cluster_id = %d for <%s>\n", 1364 1364 index , string ); 1365 1365 #endif … … 1404 1404 // check dirty 1405 1405 if ( pdesc->dirty ) 1406 _printf("\n[FAT ERROR] in _release_cache_memory(): dirty cluster\n");1406 _printf("\n[FAT ERROR] _release_cache_memory(): dirty cluster\n"); 1407 1407 1408 1408 _free( pdesc->buffer ); … … 1440 1440 if ( nb_required_clusters > _fat.free_clusters_number ) 1441 1441 { 1442 _printf("\n[FAT ERROR] in _clusters_allocate(): required_clusters = %d"1442 _printf("\n[FAT ERROR] _clusters_allocate(): required_clusters = %d" 1443 1443 " / free_clusters = %d\n", nb_required_clusters , _fat.free_clusters_number ); 1444 1444 return 1; … … 1447 1447 #if (GIET_DEBUG_FAT & 1) 1448 1448 if ( _get_proctime() > GIET_DEBUG_FAT ) 1449 _printf("\n[DEBUG FAT] _clusters_allocate() 1449 _printf("\n[DEBUG FAT] _clusters_allocate(): enters for <%s> / nb_current_clusters = %d " 1450 1450 "/ nb_required_clusters = %d\n", 1451 1451 inode->name , nb_current_clusters , nb_required_clusters ); … … 1497 1497 #if (GIET_DEBUG_FAT & 1) 1498 1498 if ( _get_proctime() > GIET_DEBUG_FAT ) 1499 _printf("\n[DEBUG FAT] _clusters_allocate() 1499 _printf("\n[DEBUG FAT] _clusters_allocate(): done for cluster_id = %d / cluster = %x\n", 1500 1500 cluster_id , new ); 1501 1501 #endif … … 1742 1742 #if (GIET_DEBUG_FAT & 1) 1743 1743 if ( _get_proctime() > GIET_DEBUG_FAT ) 1744 _printf("\n[DEBUG FAT] _add_dir_entry() 1744 _printf("\n[DEBUG FAT] _add_dir_entry(): try to add <%s> in <%s> / nb_lfn = %d\n", 1745 1745 child->name , parent->name, nb_lfn ); 1746 1746 #endif … … 1787 1787 #if (GIET_DEBUG_FAT & 1) 1788 1788 if ( _get_proctime() > GIET_DEBUG_FAT ) 1789 _printf("\n[DEBUG FAT] _add_dir_entry() 1789 _printf("\n[DEBUG FAT] _add_dir_entry(): get NO_MORE directory entry : " 1790 1790 " buffer = %x / offset = %x / cluster_id = %d\n", 1791 1791 (unsigned int)buffer , offset , cluster_id ); … … 1819 1819 if ( cluster_id == 63 ) // we need to increase depth of File-Cache 1820 1820 { 1821 _printf("\n[FAT ERROR] inadd_dir_entry() File Cache depth extension "1821 _printf("\n[FAT ERROR] add_dir_entry() File Cache depth extension " 1822 1822 " not implemented\n" ); 1823 1823 _exit(); // TODO … … 1839 1839 #if (GIET_DEBUG_FAT & 1) 1840 1840 if ( _get_proctime() > GIET_DEBUG_FAT ) 1841 _printf("\n[DEBUG FAT] _add_dir_entry() 1841 _printf("\n[DEBUG FAT] _add_dir_entry(): FSM step = %d /" 1842 1842 " offset = %x / nb_lfn = %d\n", step, offset, nb_lfn ); 1843 1843 #endif … … 1971 1971 if ( _get_proctime() > GIET_DEBUG_FAT ) 1972 1972 { 1973 _printf("\n[DEBUG FAT] _add_dir_entry() 1973 _printf("\n[DEBUG FAT] _add_dir_entry(): <%s> successfully added in <%s>\n", 1974 1974 child->name , parent->name ); 1975 1975 } … … 2086 2086 #if (GIET_DEBUG_FAT & 1) 2087 2087 if ( _get_proctime() > GIET_DEBUG_FAT ) 2088 _printf("\n[DEBUG FAT] _get_child_from_parent() 2088 _printf("\n[DEBUG FAT] _get_child_from_parent(): search <%s> in directory <%s>\n", 2089 2089 name , parent->name ); 2090 2090 #endif … … 2098 2098 #if (GIET_DEBUG_FAT & 1) 2099 2099 if ( _get_proctime() > GIET_DEBUG_FAT ) 2100 _printf("\n[DEBUG FAT] _get_child_from_parent() 2100 _printf("\n[DEBUG FAT] _get_child_from_parent(): found inode <%s> in directory <%s>\n", 2101 2101 name , parent->name ); 2102 2102 #endif … … 2129 2129 #if (GIET_DEBUG_FAT & 1) 2130 2130 if ( _get_proctime() > GIET_DEBUG_FAT ) 2131 _printf("\n[DEBUG FAT] _get_child_from_parent() 2131 _printf("\n[DEBUG FAT] _get_child_from_parent(): does not found inode <%s>" 2132 2132 " in directory <%s> => search in cache\n", name , parent->name ); 2133 2133 #endif … … 2149 2149 #if (GIET_DEBUG_FAT & 1) 2150 2150 if ( _get_proctime() > GIET_DEBUG_FAT ) 2151 _printf("\n[DEBUG FAT] _get_child_from_parent() 2151 _printf("\n[DEBUG FAT] _get_child_from_parent(): scan buffer %d for <%s>\n", 2152 2152 cluster_id , name ); 2153 2153 #endif … … 2218 2218 #if (GIET_DEBUG_FAT & 1) 2219 2219 if ( _get_proctime() > GIET_DEBUG_FAT ) 2220 _printf("\n[DEBUG FAT] _get_child_from_parent() 2220 _printf("\n[DEBUG FAT] _get_child_from_parent(): found end of directory in <%s>\n", 2221 2221 parent->name ); 2222 2222 #endif … … 2240 2240 #if (GIET_DEBUG_FAT & 1) 2241 2241 if ( _get_proctime() > GIET_DEBUG_FAT ) 2242 _printf("\n[DEBUG FAT] _get_child_from_parent() 2242 _printf("\n[DEBUG FAT] _get_child_from_parent(): found <%s> on device\n", name ); 2243 2243 #endif 2244 2244 return 0; … … 2262 2262 #if (GIET_DEBUG_FAT & 1) 2263 2263 if ( _get_proctime() > GIET_DEBUG_FAT ) 2264 _printf("\n[DEBUG FAT] _get_inode_from_path() 2264 _printf("\n[DEBUG FAT] _get_inode_from_path(): enters for path <%s>\n", pathname ); 2265 2265 #endif 2266 2266 … … 2271 2271 #if (GIET_DEBUG_FAT & 1) 2272 2272 if ( _get_proctime() > GIET_DEBUG_FAT ) 2273 _printf("\n[DEBUG FAT] _get_inode_from_path() 2273 _printf("\n[DEBUG FAT] _get_inode_from_path(): found root inode for <%s>\n", 2274 2274 pathname ); 2275 2275 #endif … … 2299 2299 #if (GIET_DEBUG_FAT & 1) 2300 2300 if ( _get_proctime() > GIET_DEBUG_FAT ) 2301 _printf("\n[DEBUG FAT] _get_inode_from_path() 2301 _printf("\n[DEBUG FAT] _get_inode_from_path(): got name <%s>\n", name ); 2302 2302 #endif 2303 2303 … … 2330 2330 #if (GIET_DEBUG_FAT & 1) 2331 2331 if ( _get_proctime() > GIET_DEBUG_FAT ) 2332 _printf("\n[DEBUG FAT] _get_inode_from_path() 2332 _printf("\n[DEBUG FAT] _get_inode_from_path(): neither parent, nor child found for <%s>\n", 2333 2333 pathname ); 2334 2334 #endif … … 2348 2348 #if (GIET_DEBUG_FAT & 1) 2349 2349 if ( _get_proctime() > GIET_DEBUG_FAT ) 2350 _printf("\n[DEBUG FAT] _get_inode_from_path() 2350 _printf("\n[DEBUG FAT] _get_inode_from_path(): found inode for <%s>\n", 2351 2351 pathname ); 2352 2352 #endif … … 2358 2358 #if (GIET_DEBUG_FAT & 1) 2359 2359 if ( _get_proctime() > GIET_DEBUG_FAT ) 2360 _printf("\n[DEBUG FAT] _get_inode_from_path() 2360 _printf("\n[DEBUG FAT] _get_inode_from_path(): found only parent inode for <%s>\n", 2361 2361 pathname ); 2362 2362 #endif … … 2423 2423 8 ) ) 2424 2424 { 2425 _printf("\n[FAT ERROR] in _next_cluster_no_cache(): "2425 _printf("\n[FAT ERROR] _next_cluster_no_cache(): " 2426 2426 "cannot load lba = %x into fat_buffer\n", lba ); 2427 2427 return 1; … … 2449 2449 #if (GIET_DEBUG_FAT & 1) 2450 2450 if ( _get_proctime() > GIET_DEBUG_FAT ) 2451 _printf("\n[DEBUG FAT] _file_info_no_cache() 2451 _printf("\n[DEBUG FAT] _file_info_no_cache(): enters for path <%s>\n", pathname ); 2452 2452 #endif 2453 2453 … … 2486 2486 #if (GIET_DEBUG_FAT & 1) 2487 2487 if ( _get_proctime() > GIET_DEBUG_FAT ) 2488 _printf("\n[DEBUG FAT] _file_info_no_cache() 2488 _printf("\n[DEBUG FAT] _file_info_no_cache(): search name <%s>" 2489 2489 " in cluster %x\n", name , parent_cluster ); 2490 2490 #endif … … 2506 2506 8 ) ) 2507 2507 { 2508 _printf("\n[FAT ERROR] in _file_info_no_cache(): "2508 _printf("\n[FAT ERROR] _file_info_no_cache(): " 2509 2509 "cannot load lba = %x into data_buffer\n", lba ); 2510 2510 return 1; … … 2585 2585 if ( found == 2 ) // found end of directory => error 2586 2586 { 2587 _printf("\n[FAT ERROR] in _file_info_no_cache(): <%s> not found\n",2587 _printf("\n[FAT ERROR] _file_info_no_cache(): <%s> not found\n", 2588 2588 name ); 2589 2589 return 1; … … 2594 2594 ((pathname[nb_read] != 0) && (child_is_dir == 0)) ) 2595 2595 { 2596 _printf("\n[FAT ERROR] in _file_info_no_cache(): illegal type for <%s>\n", name );2596 _printf("\n[FAT ERROR] _file_info_no_cache(): illegal type for <%s>\n", name ); 2597 2597 return 1; 2598 2598 } … … 2605 2605 #if (GIET_DEBUG_FAT & 1) 2606 2606 if ( _get_proctime() > GIET_DEBUG_FAT ) 2607 _printf("\n[DEBUG FAT] _file_info_no_cache() 2607 _printf("\n[DEBUG FAT] _file_info_no_cache(): success for <%s> / " 2608 2608 "file_size = %x / file_cluster = %x\n", pathname, child_size, child_cluster ); 2609 2609 #endif … … 2638 2638 // that are loaded in the Fat-Descriptor temporary block_buffer. 2639 2639 ///////////////////////////////////////////////////////////////////////////// 2640 // Returns 0 if success. 2641 // Returns -1 if error. 2640 // Returns GIET_FAT32_OK on success. 2641 // Returns a negative value on error: 2642 // GIET_FAT32_IO_ERROR, 2643 // GIET_FAT32_INVALID_BOOT_SECTOR, 2642 2644 ///////////////////////////////////////////////////////////////////////////// 2643 2645 int _fat_init( unsigned int kernel_mode ) … … 2646 2648 #if GIET_DEBUG_FAT 2647 2649 if ( _get_proctime() > GIET_DEBUG_FAT ) 2648 _printf("\n[DEBUG FAT] _fat_init() 2650 _printf("\n[DEBUG FAT] _fat_init(): enters at cycle %d\n", _get_proctime() ); 2649 2651 #endif 2650 2652 … … 2652 2654 if ( _fat.initialised == FAT_INITIALISED ) 2653 2655 { 2654 _printf("\n[FAT ERROR] in _fat_init() : FAT already initialised\n");2655 return -1;2656 _printf("\n[FAT WARNING] _fat_init(): FAT already initialized\n"); 2657 return GIET_FAT32_OK; 2656 2658 } 2657 2659 … … 2663 2665 1 ) ) // one block 2664 2666 { 2665 _printf("\n[FAT ERROR] in _fat_init()cannot load VBR\n");2666 return -1;2667 _printf("\n[FAT ERROR] _fat_init(): cannot load VBR\n"); 2668 return GIET_FAT32_IO_ERROR; 2667 2669 } 2668 2670 … … 2672 2674 if ( _get_proctime() > GIET_DEBUG_FAT ) 2673 2675 { 2674 _printf("\n[DEBUG FAT] _fat_init() 2676 _printf("\n[DEBUG FAT] _fat_init(): Boot sector loaded\n"); 2675 2677 _display_one_block( _fat.block_buffer, "block device", _fat.block_buffer_lba ); 2676 2678 } … … 2680 2682 if( _read_entry( BPB_BYTSPERSEC, _fat.block_buffer, 1 ) != 512 ) 2681 2683 { 2682 _printf("\n[FAT ERROR] The sector size must be 512 bytes\n");2683 return -1;2684 _printf("\n[FAT ERROR] _fat_init(): The sector size must be 512 bytes\n"); 2685 return GIET_FAT32_INVALID_BOOT_SECTOR; 2684 2686 } 2685 2687 if( _read_entry( BPB_SECPERCLUS, _fat.block_buffer, 1 ) != 8 ) 2686 2688 { 2687 _printf("\n[FAT ERROR] The cluster size must be 8 blocks\n");2688 return -1;2689 _printf("\n[FAT ERROR] _fat_init(): The cluster size must be 8 blocks\n"); 2690 return GIET_FAT32_INVALID_BOOT_SECTOR; 2689 2691 } 2690 2692 if( _read_entry( BPB_NUMFATS, _fat.block_buffer, 1 ) != 1 ) 2691 2693 { 2692 _printf("\n[FAT ERROR] The number of FAT copies in FAT region must be 1\n");2693 return -1;2694 _printf("\n[FAT ERROR] _fat_init(): The number of FAT copies in FAT region must be 1\n"); 2695 return GIET_FAT32_INVALID_BOOT_SECTOR; 2694 2696 } 2695 2697 if( (_read_entry( BPB_FAT32_FATSZ32, _fat.block_buffer, 1 ) & 0xF) != 0 ) 2696 2698 { 2697 _printf("\n[FAT ERROR] The FAT region must be multiple of 16 sectors\n");2698 return -1;2699 _printf("\n[FAT ERROR] _fat_init(): The FAT region must be multiple of 16 sectors\n"); 2700 return GIET_FAT32_INVALID_BOOT_SECTOR; 2699 2701 } 2700 2702 if( _read_entry( BPB_FAT32_ROOTCLUS, _fat.block_buffer, 1 ) != 2 ) 2701 2703 { 2702 _printf("\n[FAT ERROR] The root directory must be at cluster 2\n");2703 return -1;2704 _printf("\n[FAT ERROR] _fat_init(): The root directory must be at cluster 2\n"); 2705 return GIET_FAT32_INVALID_BOOT_SECTOR; 2704 2706 } 2705 2707 … … 2723 2725 1 ) ) // one block 2724 2726 { 2725 _printf("\n[FAT ERROR] in _fat_init()cannot load FS_INFO Sector\n");2726 return -1;2727 _printf("\n[FAT ERROR] _fat_init(): cannot load FS_INFO Sector\n"); 2728 return GIET_FAT32_IO_ERROR; 2727 2729 } 2728 2730 … … 2732 2734 if ( _get_proctime() > GIET_DEBUG_FAT ) 2733 2735 { 2734 _printf("\n[DEBUG FAT] _fat_init() 2736 _printf("\n[DEBUG FAT] _fat_init(): FS-INFO sector loaded\n"); 2735 2737 _display_one_block( _fat.block_buffer, "block device", _fat.block_buffer_lba ); 2736 2738 } … … 2772 2774 #endif 2773 2775 2774 return 0;2776 return GIET_FAT32_OK; 2775 2777 } // end _fat_init() 2776 2778 … … 2789 2791 // A node name (file or directory) cannot be larger than 31 characters. 2790 2792 /////////////////////////////////////////////////////////////////////////////// 2791 // Returns file descriptor index if success 2792 // Returns a negative value if error: 2793 // -1 : "fat not initialised" 2794 // -2 : "path to parent not found" 2795 // -3 : "one name in path too long" 2796 // -4 : "file not found" 2797 // -5 : "Cannot update parent directory" 2798 // -6 : "Cannot update DATA region" 2799 // -7 : "Cannot update FAT region" 2800 // -8 : "Cannot update FS_INFO sector" 2801 // -9 : "file descriptor array full" 2802 // -10 : "cannot truncate file" 2793 // Returns a file descriptor index on success. 2794 // Returns a negative value on error: 2795 // GIET_FAT32_NOT_INITIALIZED, 2796 // GIET_FAT32_FILE_NOT_FOUND, 2797 // GIET_FAT32_NAME_TOO_LONG, 2798 // GIET_FAT32_IO_ERROR, 2799 // GIET_FAT32_TOO_MANY_OPEN_FILES 2803 2800 /////////////////////////////////////////////////////////////////////////////// 2804 2801 int _fat_open( char* pathname, // absolute path from root … … 2822 2819 unsigned int p = procid & ((1<<P_WIDTH)-1); 2823 2820 if ( _get_proctime() > GIET_DEBUG_FAT ) 2824 _printf("\n[DEBUG FAT] _fat_open() 2821 _printf("\n[DEBUG FAT] _fat_open(): P[%d,%d,%d] enters for path <%s> / " 2825 2822 " create = %d / read_only = %d\n", 2826 2823 x, y, p, pathname , create , read_only ); … … 2830 2827 if( _fat.initialised != FAT_INITIALISED ) 2831 2828 { 2832 _printf("\n[FAT ERROR] in _fat_open() : FAT not initialised\n");2833 return -1;2829 _printf("\n[FAT ERROR] _fat_open(): FAT not initialized\n"); 2830 return GIET_FAT32_NOT_INITIALIZED; 2834 2831 } 2835 2832 … … 2843 2840 { 2844 2841 _spin_lock_release( &_fat.fat_lock ); 2845 _printf("\n[FAT ERROR] in _fat_open(): path to parent not found"2842 _printf("\n[FAT ERROR] _fat_open(): path to parent not found" 2846 2843 " for file <%s>\n", pathname ); 2847 return -2;2844 return GIET_FAT32_FILE_NOT_FOUND; 2848 2845 } 2849 2846 else if ( code == 3 ) 2850 2847 { 2851 2848 _spin_lock_release( &_fat.fat_lock ); 2852 _printf("\n[FAT ERROR] in _fat_open(): one name in path too long"2849 _printf("\n[FAT ERROR] _fat_open(): one name in path too long" 2853 2850 " for file <%s>\n", pathname ); 2854 return -3;2851 return GIET_FAT32_NAME_TOO_LONG; 2855 2852 } 2856 2853 else if ( (code == 1) && (create == 0) ) 2857 2854 { 2858 2855 _spin_lock_release( &_fat.fat_lock ); 2859 _printf("\n[FAT ERROR] in _fat_open(): file not found"2856 _printf("\n[FAT ERROR] _fat_open(): file not found" 2860 2857 " for file <%s>\n", pathname ); 2861 return -4;2858 return GIET_FAT32_FILE_NOT_FOUND; 2862 2859 } 2863 2860 else if ( (code == 1) && (create != 0) ) // file name not found => create … … 2868 2865 #if GIET_DEBUG_FAT 2869 2866 if ( _get_proctime() > GIET_DEBUG_FAT ) 2870 _printf("\n[DEBUG FAT] _fat_open() 2867 _printf("\n[DEBUG FAT] _fat_open(): P[%d,%d,%d] create a new file <%s>\n", 2871 2868 x , y , p , pathname ); 2872 2869 #endif … … 2892 2889 { 2893 2890 _spin_lock_release( &_fat.fat_lock ); 2894 _printf("\n[FAT ERROR] in _fat_open(): cannot update parent directory"2891 _printf("\n[FAT ERROR] _fat_open(): cannot update parent directory" 2895 2892 " for file <%s>\n" , pathname ); 2896 return -5;2893 return GIET_FAT32_IO_ERROR; 2897 2894 } 2898 2895 … … 2903 2900 { 2904 2901 _spin_lock_release( &_fat.fat_lock ); 2905 _printf("\n[FAT ERROR] in _fat_open(): cannot update DATA region "2902 _printf("\n[FAT ERROR] _fat_open(): cannot update DATA region " 2906 2903 " for parent of file <%s>\n", pathname ); 2907 return -6;2904 return GIET_FAT32_IO_ERROR; 2908 2905 } 2909 2906 … … 2914 2911 { 2915 2912 _spin_lock_release( &_fat.fat_lock ); 2916 _printf("\n[FAT ERROR] in _fat_open(): cannot update FAT region"2913 _printf("\n[FAT ERROR] _fat_open(): cannot update FAT region" 2917 2914 " for file <%s>\n", pathname ); 2918 return -7;2915 return GIET_FAT32_IO_ERROR; 2919 2916 } 2920 2917 … … 2923 2920 { 2924 2921 _spin_lock_release( &_fat.fat_lock ); 2925 _printf("\n[FAT ERROR] in _fat_open(): cannot update FS-INFO"2922 _printf("\n[FAT ERROR] _fat_open(): cannot update FS-INFO" 2926 2923 " for file <%s>\n", pathname ); 2927 return -8;2924 return GIET_FAT32_IO_ERROR; 2928 2925 } 2929 2926 … … 2938 2935 #if GIET_DEBUG_FAT 2939 2936 if ( _get_proctime() > GIET_DEBUG_FAT ) 2940 _printf("\n[DEBUG FAT] _fat_open() 2937 _printf("\n[DEBUG FAT] _fat_open(): P[%d,%d,%d] found file <%s> on device : inode = %x\n", 2941 2938 x , y , p , pathname , child ); 2942 2939 #endif … … 2954 2951 { 2955 2952 _spin_lock_release( &_fat.fat_lock ); 2956 _printf("\n[FAT ERROR] in _fat_open(): File-Descriptors-Array full\n");2957 return -9;2953 _printf("\n[FAT ERROR] _fat_open(): File-Descriptors-Array full\n"); 2954 return GIET_FAT32_TOO_MANY_OPEN_FILES; 2958 2955 } 2959 2956 … … 2981 2978 { 2982 2979 _spin_lock_release( &_fat.fat_lock ); 2983 _printf("\n[FAT ERROR] in _fat_open(): can't truncate file\n");2984 return -10;2980 _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n"); 2981 return GIET_FAT32_IO_ERROR; 2985 2982 } 2986 2983 … … 2989 2986 { 2990 2987 _spin_lock_release( &_fat.fat_lock ); 2991 _printf("\n[FAT ERROR] in _fat_open(): can't truncate file\n");2992 return -10;2988 _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n"); 2989 return GIET_FAT32_IO_ERROR; 2993 2990 } 2994 2991 } … … 2999 2996 #if GIET_DEBUG_FAT 3000 2997 if ( _get_proctime() > GIET_DEBUG_FAT ) 3001 _printf("\n[DEBUG FAT] _fat_open() 2998 _printf("\n[DEBUG FAT] _fat_open(): P[%d,%d,%d] got fd = %d for <%s> / " 3002 2999 "read_only = %d\n", 3003 3000 x , y , p , fd_id , pathname , read_only ); … … 3016 3013 // and releases the memory allocated to the File_Cache. 3017 3014 ///////////////////////////////////////////////////////////////////////////////// 3018 // Returns 0on success.3019 // Returns negative value iferror:3020 // -1 : "FAT not initialised"3021 // -2 : "Illegal file descriptor"3022 // -3 : "File not open"3023 // -4 : "Cannot update DATA regions"3015 // Returns GIET_FAT32_OK on success. 3016 // Returns a negative value on error: 3017 // GIET_FAT32_NOT_INITIALIZED, 3018 // GIET_FAT32_INVALID_FD, 3019 // GIET_FAT32_NOT_OPEN, 3020 // GIET_FAT32_IO_ERROR 3024 3021 ///////////////////////////////////////////////////////////////////////////////// 3025 3022 int _fat_close( unsigned int fd_id ) … … 3028 3025 if( _fat.initialised != FAT_INITIALISED ) 3029 3026 { 3030 _printf("\n[FAT ERROR] in _fat_close() : FAT not initialised\n");3031 return -1;3027 _printf("\n[FAT ERROR] _fat_close(): FAT not initialized\n"); 3028 return GIET_FAT32_NOT_INITIALIZED; 3032 3029 } 3033 3030 3034 3031 if( (fd_id >= GIET_OPEN_FILES_MAX) ) 3035 3032 { 3036 _printf("\n[FAT ERROR] in _fat_close(): illegal file descriptor index\n");3037 return -2;3033 _printf("\n[FAT ERROR] _fat_close(): illegal file descriptor index\n"); 3034 return GIET_FAT32_INVALID_FD; 3038 3035 } 3039 3036 … … 3044 3041 { 3045 3042 _spin_lock_release( &_fat.fat_lock ); 3046 _printf("\n[FAT ERROR] in _fat_close(): file not open\n");3047 return -3;3043 _printf("\n[FAT ERROR] _fat_close(): file not open\n"); 3044 return GIET_FAT32_NOT_OPEN; 3048 3045 } 3049 3046 … … 3069 3066 { 3070 3067 _spin_lock_release( &_fat.fat_lock ); 3071 _printf("\n[FAT ERROR] in _fat_close(): cannot write dirty clusters "3068 _printf("\n[FAT ERROR] _fat_close(): cannot write dirty clusters " 3072 3069 "for file <%s>\n", inode->name ); 3073 return -4;3070 return GIET_FAT32_IO_ERROR; 3074 3071 } 3075 3072 … … 3086 3083 { 3087 3084 _spin_lock_release( &_fat.fat_lock ); 3088 _printf("\n[FAT ERROR] in _fat_close(): cannot write dirty clusters "3085 _printf("\n[FAT ERROR] _fat_close(): cannot write dirty clusters " 3089 3086 "for directory <%s>\n", inode->parent->name ); 3090 return -4;3087 return GIET_FAT32_IO_ERROR; 3091 3088 } 3092 3089 … … 3114 3111 _spin_lock_release( &_fat.fat_lock ); 3115 3112 3116 return 0;3113 return GIET_FAT32_OK; 3117 3114 } // end fat_close() 3118 3115 … … 3125 3122 // identified by the "fd_id" argument. 3126 3123 ///////////////////////////////////////////////////////////////////////////////// 3127 // Returns 0 ifsuccess.3128 // Returns negative value if error.3129 // -1 : "FAT not initialised"3130 // -2 : "Illegal file descriptor"3131 // -3 : "File not open"3124 // Returns GIET_FAT32_OK on success. 3125 // Returns a negative value on error: 3126 // GIET_FAT32_NOT_INITIALIZED, 3127 // GIET_FAT32_INVALID_FD, 3128 // GIET_FAT32_NOT_OPEN 3132 3129 ///////////////////////////////////////////////////////////////////////////////// 3133 3130 int _fat_file_info( unsigned int fd_id, … … 3136 3133 if ( _fat.initialised != FAT_INITIALISED ) 3137 3134 { 3138 _printf("\n[FAT ERROR] in _fat_file_info() : FAT not initialised\n");3139 return -1;3135 _printf("\n[FAT ERROR] _fat_file_info(): FAT not initialized\n"); 3136 return GIET_FAT32_NOT_INITIALIZED; 3140 3137 } 3141 3138 3142 3139 if ( fd_id >= GIET_OPEN_FILES_MAX ) 3143 3140 { 3144 _printf("\n[FAT ERROR] in _fat_file_info(): illegal file descriptor index\n");3145 return -2;3141 _printf("\n[FAT ERROR] _fat_file_info(): illegal file descriptor index\n"); 3142 return GIET_FAT32_INVALID_FD; 3146 3143 } 3147 3144 3148 3145 if ( _fat.fd[fd_id].allocated == 0 ) 3149 3146 { 3150 _printf("\n[FAT ERROR] in _fat_file_info(): file not open\n");3151 return -3;3147 _printf("\n[FAT ERROR] _fat_file_info(): file not open\n"); 3148 return GIET_FAT32_NOT_OPEN; 3152 3149 } 3153 3150 … … 3156 3153 info->is_dir = _fat.fd[fd_id].inode->is_dir; 3157 3154 3158 return 0;3155 return GIET_FAT32_OK; 3159 3156 } // end _fat_file_info() 3160 3157 … … 3168 3165 // In case of miss in the File_Cache, it loads all involved clusters into cache. 3169 3166 ///////////////////////////////////////////////////////////////////////////////// 3170 // Returns number of bytes actually transfered if success.3171 // Returns 0 if EOF encountered (offset + count > file_size).3172 // Returns a negative value iferror:3173 // -1 : "fat not initialised"3174 // -2 : "illegal file descriptor"3175 // -2 : "file not open"3176 // -3 : "cannot load file from device"3167 // Returns number of bytes actually transfered on success. 3168 // Returns 0 if EOF is encountered (offset + count > file_size). 3169 // Returns a negative value on error: 3170 // GIET_FAT32_NOT_INITIALIZED, 3171 // GIET_FAT32_INVALID_FD, 3172 // GIET_FAT32_NOT_OPEN, 3173 // GIET_FAT32_IO_ERROR 3177 3174 ///////////////////////////////////////////////////////////////////////////////// 3178 3175 int _fat_read( unsigned int fd_id, // file descriptor index … … 3183 3180 if( _fat.initialised != FAT_INITIALISED ) 3184 3181 { 3185 _printf("\n[FAT ERROR] in _fat_write() : FAT not initialised\n");3186 return -1;3182 _printf("\n[FAT ERROR] _fat_write(): FAT not initialized\n"); 3183 return GIET_FAT32_NOT_INITIALIZED; 3187 3184 } 3188 3185 … … 3190 3187 if ( fd_id >= GIET_OPEN_FILES_MAX ) 3191 3188 { 3192 _printf("\n[FAT ERROR] in _fat_read(): illegal file descriptor\n");3193 return -2;3189 _printf("\n[FAT ERROR] _fat_read(): illegal file descriptor\n"); 3190 return GIET_FAT32_INVALID_FD; 3194 3191 } 3195 3192 … … 3197 3194 if ( _fat.fd[fd_id].allocated == 0 ) 3198 3195 { 3199 _printf("\n[FAT ERROR] in _fat_read(): file not open\n");3200 return -3;3196 _printf("\n[FAT ERROR] _fat_read(): file not open\n"); 3197 return GIET_FAT32_NOT_OPEN; 3201 3198 } 3202 3199 … … 3212 3209 { 3213 3210 _spin_lock_release( &_fat.fat_lock ); 3214 _printf("\n[FAT ERROR] in _fat_read(): file too small"3211 _printf("\n[FAT ERROR] _fat_read(): file too small" 3215 3212 " / seek = %x / count = %x / file_size = %x\n", 3216 3213 seek , count , inode->size ); … … 3232 3229 unsigned int p = procid & ((1<<P_WIDTH)-1); 3233 3230 if ( _get_proctime() > GIET_DEBUG_FAT ) 3234 _printf("\n[DEBUG FAT] _fat_read() 3231 _printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] enters for file <%s> " 3235 3232 " / bytes = %x / offset = %x\n" 3236 3233 "first_cluster_id = %x / first_byte_to_move = %x" … … 3253 3250 { 3254 3251 _spin_lock_release( &_fat.fat_lock ); 3255 _printf("\n[FAT ERROR] in _fat_read(): cannot load file <%s>\n",3252 _printf("\n[FAT ERROR] _fat_read(): cannot load file <%s>\n", 3256 3253 inode->name ); 3257 return -4;3254 return GIET_FAT32_IO_ERROR; 3258 3255 } 3259 3256 cbuf = pdesc->buffer; … … 3261 3258 #if GIET_DEBUG_FAT 3262 3259 if ( _get_proctime() > GIET_DEBUG_FAT ) 3263 _printf("\n[DEBUG FAT] _fat_read() 3260 _printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] moves cluster_id %d from Cache-File <%s>\n", 3264 3261 x , y , p , cluster_id, inode->name ); 3265 3262 #endif … … 3297 3294 #if GIET_DEBUG_FAT 3298 3295 if ( _get_proctime() > GIET_DEBUG_FAT ) 3299 _printf("\n[DEBUG FAT] _fat_read() 3296 _printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] loaded file <%s> from Cache-File\n", 3300 3297 x , y , p , inode->name ); 3301 3298 #endif … … 3321 3318 // involved clusters in the cache. 3322 3319 ///////////////////////////////////////////////////////////////////////////////// 3323 // Returns number of bytes actually written if success. 3324 // Returns a negative value if error: 3325 // -1 : "FAT not initialised" 3326 // -2 : "Illegal file descriptor" 3327 // -3 : "File not open" 3328 // -4 : "File not writable" 3329 // -5 : "No free clusters" 3330 // -6 : "Cannot update parent directory entry" 3331 // -7 : "Cannot access File-Cache" 3320 // Returns number of bytes actually written on success. 3321 // Returns a negative value on error: 3322 // GIET_FAT32_NOT_INITIALIZED, 3323 // GIET_FAT32_INVALID_FD, 3324 // GIET_FAT32_NOT_OPEN, 3325 // GIET_FAT32_READ_ONLY, 3326 // GIET_FAT32_NO_FREE_SPACE, 3327 // GIET_FAT32_IO_ERROR 3332 3328 ///////////////////////////////////////////////////////////////////////////////// 3333 3329 int _fat_write( unsigned int fd_id, // file descriptor index … … 3338 3334 if( _fat.initialised != FAT_INITIALISED ) 3339 3335 { 3340 _printf("\n[FAT ERROR] in _fat_write(): FAT not initialised\n");3341 return -1;3336 _printf("\n[FAT ERROR] _fat_write(): FAT not initialised\n"); 3337 return GIET_FAT32_NOT_INITIALIZED; 3342 3338 } 3343 3339 … … 3349 3345 { 3350 3346 _spin_lock_release( &_fat.fat_lock ); 3351 _printf("\n[FAT ERROR] in _fat_write(): illegal file descriptor\n");3352 return -2;3347 _printf("\n[FAT ERROR] _fat_write(): illegal file descriptor\n"); 3348 return GIET_FAT32_INVALID_FD; 3353 3349 } 3354 3350 … … 3357 3353 { 3358 3354 _spin_lock_release( &_fat.fat_lock ); 3359 _printf("\n[FAT ERROR] in _fat_write(): file not open\n" );3360 return -3;3355 _printf("\n[FAT ERROR] _fat_write(): file not open\n" ); 3356 return GIET_FAT32_NOT_OPEN; 3361 3357 } 3362 3358 … … 3365 3361 { 3366 3362 _spin_lock_release( &_fat.fat_lock ); 3367 _printf("\n[FAT ERROR] in _fat_write(): file <%s> is read-only\n",3363 _printf("\n[FAT ERROR] _fat_write(): file <%s> is read-only\n", 3368 3364 _fat.fd[fd_id].inode->name ); 3369 return -4;3365 return GIET_FAT32_READ_ONLY; 3370 3366 } 3371 3367 … … 3380 3376 unsigned int p = procid & ((1<<P_WIDTH)-1); 3381 3377 if ( _get_proctime() > GIET_DEBUG_FAT ) 3382 _printf("\n[DEBUG FAT] _fat_write() 3378 _printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] enters for file <%s> " 3383 3379 " / bytes = %x / seek = %x\n", 3384 3380 x , y , p , inode->name , count , seek ); … … 3407 3403 #if GIET_DEBUG_FAT 3408 3404 if ( _get_proctime() > GIET_DEBUG_FAT ) 3409 _printf("\n[DEBUG FAT] _fat_write() 3405 _printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] allocates new clusters for file <%s>" 3410 3406 " / current = %d / required = %d\n", 3411 3407 x , y , p , inode->name , old_clusters , new_clusters ); … … 3417 3413 { 3418 3414 _spin_lock_release( &_fat.fat_lock ); 3419 _printf("\n[FAT ERROR] in _fat_write(): no free clusters"3415 _printf("\n[FAT ERROR] _fat_write(): no free clusters" 3420 3416 " for file <%s>\n", _fat.fd[fd_id].inode->name ); 3421 return -5;3417 return GIET_FAT32_NO_FREE_SPACE; 3422 3418 } 3423 3419 } … … 3427 3423 { 3428 3424 _spin_lock_release( &_fat.fat_lock ); 3429 _printf("\n[FAT ERROR] in _fat_write(): cannot update parent directory entry"3425 _printf("\n[FAT ERROR] _fat_write(): cannot update parent directory entry" 3430 3426 " for file <%s>\n", _fat.fd[fd_id].inode->name ); 3431 return -6;3427 return GIET_FAT32_IO_ERROR; 3432 3428 } 3433 3429 … … 3435 3431 #if GIET_DEBUG_FAT 3436 3432 if ( _get_proctime() > GIET_DEBUG_FAT ) 3437 _printf("\n[DEBUG FAT] _fat_write() 3433 _printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] updates size for file <%s> / size = %x\n", 3438 3434 x , y , p , inode->name , (new_size - old_size) ); 3439 3435 #endif … … 3451 3447 #if GIET_DEBUG_FAT 3452 3448 if ( _get_proctime() > GIET_DEBUG_FAT ) 3453 _printf("\n[DEBUG FAT] _fat_write() 3449 _printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] starts loop on clusters for file <%s>\n" 3454 3450 " first_cluster_id = %d / first_byte_to_move = %x" 3455 3451 " / last_cluster_id = %d / last_byte_to_move = %x\n", … … 3471 3467 { 3472 3468 _spin_lock_release( &_fat.fat_lock ); 3473 _printf("\n[FAT ERROR] in _fat_write(): cannot load file <%s>\n",3469 _printf("\n[FAT ERROR] _fat_write(): cannot load file <%s>\n", 3474 3470 inode->name ); 3475 return -7;3471 return GIET_FAT32_IO_ERROR; 3476 3472 } 3477 3473 … … 3481 3477 #if GIET_DEBUG_FAT 3482 3478 if ( _get_proctime() > GIET_DEBUG_FAT ) 3483 _printf("\n[DEBUG FAT] _fat_write() 3479 _printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] move cluster_id %d to Cache-file <%s>\n", 3484 3480 x , y , p , cluster_id, inode->name ); 3485 3481 #endif … … 3521 3517 #if GIET_DEBUG_FAT 3522 3518 if ( _get_proctime() > GIET_DEBUG_FAT ) 3523 _printf("\n[DEBUG FAT] _fat_write() 3519 _printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] store file <%s> into Cache-File\n", 3524 3520 x , y , p , inode->name ); 3525 3521 #endif … … 3540 3536 // Accepted values for whence are SEEK_SET and SEEK_CUR. 3541 3537 ///////////////////////////////////////////////////////////////////////////////// 3542 // Returns new seek value ( bytes) ifsuccess.3543 // Returns negative value iferror:3544 // -1 : "FAT not initialised"3545 // -2 : "Illegal file descriptor"3546 // -3 : "File not open"3547 // -4 : "Illegal whence argument"3538 // Returns new seek value (in bytes) on success. 3539 // Returns a negative value on error: 3540 // GIET_FAT32_NOT_INITIALIZED, 3541 // GIET_FAT32_INVALID_FD, 3542 // GIET_FAT32_NOT_OPEN, 3543 // GIET_FAT32_INVALID_ARG 3548 3544 ///////////////////////////////////////////////////////////////////////////////// 3549 3545 int _fat_lseek( unsigned int fd_id, … … 3554 3550 if( _fat.initialised != FAT_INITIALISED ) 3555 3551 { 3556 _printf("\n[FAT ERROR] in _fat_lseek() : FAT not initialised\n");3557 return -1;3552 _printf("\n[FAT ERROR] _fat_lseek(): FAT not initialized\n"); 3553 return GIET_FAT32_NOT_INITIALIZED; 3558 3554 } 3559 3555 … … 3561 3557 if ( fd_id >= GIET_OPEN_FILES_MAX ) 3562 3558 { 3563 _printf("\n[FAT ERROR] in _fat_lseek(): illegal file descriptor\n");3564 return -2;3559 _printf("\n[FAT ERROR] _fat_lseek(): illegal file descriptor\n"); 3560 return GIET_FAT32_INVALID_FD; 3565 3561 } 3566 3562 … … 3572 3568 { 3573 3569 _spin_lock_release( &_fat.fat_lock ); 3574 _printf("\n[FAT ERROR] in _fat_lseek(): file not open\n");3575 return -3;3570 _printf("\n[FAT ERROR] _fat_lseek(): file not open\n"); 3571 return GIET_FAT32_NOT_OPEN; 3576 3572 } 3577 3573 … … 3584 3580 { 3585 3581 _spin_lock_release( &_fat.fat_lock ); 3586 _printf("\n[FAT ERROR] in _fat_user_lseek() : illegal whence valuel\n");3587 return -4;3582 _printf("\n[FAT ERROR] _fat_lseek(): illegal whence value\n"); 3583 return GIET_FAT32_INVALID_ARG; 3588 3584 } 3589 3585 … … 3597 3593 unsigned int p = procid & ((1<<P_WIDTH)-1); 3598 3594 if ( _get_proctime() > GIET_DEBUG_FAT ) 3599 _printf("\n[DEBUG FAT] _fat_lseek() 3595 _printf("\n[DEBUG FAT] _fat_lseek(): P[%d,%d,%d] set seek = %x for file <%s>\n", 3600 3596 x , y , p , new_seek , _fat.fd[fd_id].inode->name ); 3601 3597 #endif … … 3620 3616 // The Fat_Cache is updated. 3621 3617 ///////////////////////////////////////////////////////////////////////////////// 3622 // Returns 0 ifsuccess.3623 // Returns negative value if error3624 // -1 : "FAT not initialised"3625 // -2 : "File/Directory not found"3626 // -3 : "Name too long in path"3627 // -4 : "Has the wrong type"3628 // -5 : "File still open"3629 // -6 : "Cannot scan directory"3630 // -7 : "Directory not empty"3631 // -8 : "Cannot remove file/dir from FS"3618 // Returns GIET_FAT32_OK on success. 3619 // Returns a negative value on error: 3620 // GIET_FAT32_NOT_INITIALIZED, 3621 // GIET_FAT32_FILE_NOT_FOUND, 3622 // GIET_FAT32_NAME_TOO_LONG, 3623 // GIET_FAT32_IS_DIRECTORY, 3624 // GIET_FAT32_NOT_A_DIRECTORY, 3625 // GIET_FAT32_IS_OPEN, 3626 // GIET_FAT32_IO_ERROR, 3627 // GIET_FAT32_DIRECTORY_NOT_EMPTY 3632 3628 ///////////////////////////////////////////////////////////////////////////////// 3633 3629 int _fat_remove( char* pathname, … … 3642 3638 unsigned int p = procid & ((1<<P_WIDTH)-1); 3643 3639 if ( _get_proctime() > GIET_DEBUG_FAT ) 3644 _printf("\n[DEBUG FAT] _fat_remove() 3640 _printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] enters for path <%s>\n", 3645 3641 x, y, p, pathname ); 3646 3642 #endif … … 3649 3645 if( _fat.initialised != FAT_INITIALISED ) 3650 3646 { 3651 _printf("\n[FAT ERROR] in _fat_remove() : FAT not initialised\n");3652 return -1;3647 _printf("\n[FAT ERROR] _fat_remove(): FAT not initialized\n"); 3648 return GIET_FAT32_NOT_INITIALIZED; 3653 3649 } 3654 3650 … … 3661 3657 #if GIET_DEBUG_FAT 3662 3658 if ( _get_proctime() > GIET_DEBUG_FAT ) 3663 _printf("\n[DEBUG FAT] _fat_remove() 3659 _printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] found inode %x for <%s> / code = %d\n", 3664 3660 x , y , p , (unsigned int)inode , pathname , code ); 3665 3661 #endif … … 3668 3664 { 3669 3665 _spin_lock_release( &_fat.fat_lock ); 3670 _printf("\n[FAT ERROR] in _fat_remove(): file <%s> not found\n",3666 _printf("\n[FAT ERROR] _fat_remove(): file <%s> not found\n", 3671 3667 pathname ); 3672 return -2;3668 return GIET_FAT32_FILE_NOT_FOUND; 3673 3669 } 3674 3670 else if ( code == 3 ) 3675 3671 { 3676 3672 _spin_lock_release( &_fat.fat_lock ); 3677 _printf("\n[FAT ERROR] in _fat_remove(): name too long in <%s>\n",3673 _printf("\n[FAT ERROR] _fat_remove(): name too long in <%s>\n", 3678 3674 pathname ); 3679 return -3;3675 return GIET_FAT32_NAME_TOO_LONG; 3680 3676 } 3681 3677 … … 3684 3680 { 3685 3681 _spin_lock_release( &_fat.fat_lock ); 3686 _printf("\n[FAT ERROR] in _fat_remove(): <%s> is a directory\n",3682 _printf("\n[FAT ERROR] _fat_remove(): <%s> is a directory\n", 3687 3683 pathname ); 3688 return -4;3684 return GIET_FAT32_IS_DIRECTORY; 3689 3685 } 3690 3686 if ( (inode->is_dir == 0) && (should_be_dir != 0) ) 3691 3687 { 3692 3688 _spin_lock_release( &_fat.fat_lock ); 3693 _printf("\n[FAT ERROR] in _fat_remove(): <%s> is not a directory\n",3689 _printf("\n[FAT ERROR] _fat_remove(): <%s> is not a directory\n", 3694 3690 pathname ); 3695 return -4;3691 return GIET_FAT32_NOT_A_DIRECTORY; 3696 3692 } 3697 3693 3698 3694 #if GIET_DEBUG_FAT 3699 3695 if ( _get_proctime() > GIET_DEBUG_FAT ) 3700 _printf("\n[DEBUG FAT] _fat_remove() 3696 _printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] checked inode type for <%s>\n", 3701 3697 x , y , p , pathname ); 3702 3698 #endif … … 3706 3702 { 3707 3703 _spin_lock_release( &_fat.fat_lock ); 3708 _printf("\n[FAT ERROR] in _fat_remove(): file <%s> still referenced\n",3704 _printf("\n[FAT ERROR] _fat_remove(): file <%s> still referenced\n", 3709 3705 pathname ); 3710 return -5;3706 return GIET_FAT32_IS_OPEN; 3711 3707 } 3712 3708 … … 3718 3714 { 3719 3715 _spin_lock_release( &_fat.fat_lock ); 3720 _printf("\n[FAT ERROR] in _fat_remove(): cannot scan directory <%s>\n",3716 _printf("\n[FAT ERROR] _fat_remove(): cannot scan directory <%s>\n", 3721 3717 pathname ); 3722 return -6;3718 return GIET_FAT32_IO_ERROR; 3723 3719 } 3724 3720 else if ( entries > 2 ) 3725 3721 { 3726 3722 _spin_lock_release( &_fat.fat_lock ); 3727 _printf("\n[FAT ERROR] in _fat_remove(): directory <%s> not empty\n",3723 _printf("\n[FAT ERROR] _fat_remove(): directory <%s> not empty\n", 3728 3724 pathname ); 3729 return -7;3725 return GIET_FAT32_DIRECTORY_NOT_EMPTY; 3730 3726 } 3731 3727 } … … 3733 3729 #if GIET_DEBUG_FAT 3734 3730 if ( _get_proctime() > GIET_DEBUG_FAT ) 3735 _printf("\n[DEBUG FAT] _fat_remove() 3731 _printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] checked remove condition OK for <%s>\n", 3736 3732 x , y , p , pathname ); 3737 3733 #endif … … 3741 3737 { 3742 3738 _spin_lock_release( &_fat.fat_lock ); 3743 _printf("\n[FAT ERROR] in _fat_remove(): cannot remove <%s> from FS\n",3739 _printf("\n[FAT ERROR] _fat_remove(): cannot remove <%s> from FS\n", 3744 3740 pathname ); 3745 return -8;3741 return GIET_FAT32_IO_ERROR; 3746 3742 } 3747 3743 … … 3751 3747 #if GIET_DEBUG_FAT 3752 3748 if ( _get_proctime() > GIET_DEBUG_FAT ) 3753 _printf("\n[DEBUG FAT] _fat_remove() 3749 _printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] removed <%s> from FS\n", 3754 3750 x, y, p, pathname ); 3755 3751 #endif 3756 3752 3757 return 0;3753 return GIET_FAT32_OK; 3758 3754 3759 3755 } // end _fat_remove() … … 3772 3768 // The removed entry is only removed after the new entry is actually created. 3773 3769 ///////////////////////////////////////////////////////////////////////////////// 3774 // Returns 0 if success. 3775 // Returns a negative value if error: 3776 // -1 : "FAT not initialised" 3777 // -2 : "old_path not found" 3778 // -3 : "new_path not found" 3779 // -4 : "cannot scan to_remove directory" 3780 // -5 : "to_remove directory not empty" 3781 // -6 : "to_remove file still referenced" 3782 // -7 : "cannot add new node to new_parent directory" 3783 // -8 : "cannot update new_parent directory on device" 3784 // -9 : "cannot remove old node from old_parent directory" 3785 // -10 : "cannot update old_parent directory on device" 3786 // -11 : "cannot remove to_remove node from FS" 3787 // -12 : "cannot move into its own subdirectory" 3770 // Returns GIET_FAT32_OK on success. 3771 // Returns a negative value on error: 3772 // GIET_FAT32_NOT_INITIALIZED, 3773 // GIET_FAT32_FILE_NOT_FOUND, 3774 // GIET_FAT32_MOVE_INTO_SUBDIR, 3775 // GIET_FAT32_IO_ERROR, 3776 // GIET_FAT32_DIRECTORY_NOT_EMPTY, 3777 // GIET_FAT32_IS_OPEN 3788 3778 ///////////////////////////////////////////////////////////////////////////////// 3789 3779 int _fat_rename( char* old_path, … … 3804 3794 unsigned int p = procid & ((1<<P_WIDTH)-1); 3805 3795 if ( _get_proctime() > GIET_DEBUG_FAT ) 3806 _printf("\n[DEBUG FAT] _fat_rename() 3796 _printf("\n[DEBUG FAT] _fat_rename(): P[%d,%d,%d] enters to move <%s> to <%s>\n", 3807 3797 x , y , p , old_path , new_path ); 3808 3798 #endif … … 3811 3801 if( _fat.initialised != FAT_INITIALISED ) 3812 3802 { 3813 _printf("\n[FAT ERROR] in _fat_rename() : FAT not initialised\n");3814 return -1;3803 _printf("\n[FAT ERROR] _fat_rename(): FAT not initialized\n"); 3804 return GIET_FAT32_NOT_INITIALIZED; 3815 3805 } 3816 3806 … … 3822 3812 { 3823 3813 _spin_lock_release( &_fat.fat_lock ); 3824 _printf("\n[FAT ERROR] in _fat_rename(): <%s> not found\n", old_path );3825 return -2;3814 _printf("\n[FAT ERROR] _fat_rename(): <%s> not found\n", old_path ); 3815 return GIET_FAT32_FILE_NOT_FOUND; 3826 3816 } 3827 3817 else … … 3839 3829 { 3840 3830 _spin_lock_release( &_fat.fat_lock ); 3841 return 0;3831 return GIET_FAT32_OK; 3842 3832 } 3843 3833 … … 3853 3843 { 3854 3844 _spin_lock_release( &_fat.fat_lock ); 3855 _printf("\n[FAT ERROR] in _fat_rename(): <%s> not found\n", new_path );3856 return -3;3845 _printf("\n[FAT ERROR] _fat_rename(): <%s> not found\n", new_path ); 3846 return GIET_FAT32_FILE_NOT_FOUND; 3857 3847 } 3858 3848 … … 3861 3851 { 3862 3852 _spin_lock_release( &_fat.fat_lock ); 3863 _printf("\n[FAT ERROR] in _fat_rename(): can't move %s into its own subdirectory\n", old_path );3864 return -12;3853 _printf("\n[FAT ERROR] _fat_rename(): can't move %s into its own subdirectory\n", old_path ); 3854 return GIET_FAT32_MOVE_INTO_SUBDIR; 3865 3855 } 3866 3856 … … 3869 3859 { 3870 3860 if ( to_remove ) 3871 _printf("\n[DEBUG FAT] _fat_rename() 3861 _printf("\n[DEBUG FAT] _fat_rename(): old_parent = %s / old = %s / new_parent = %s " 3872 3862 "/ to_remove = %s\n", 3873 3863 old_parent->name , old->name , new_parent->name , to_remove->name ); 3874 3864 else 3875 _printf("\n[DEBUG FAT] _fat_rename() 3865 _printf("\n[DEBUG FAT] _fat_rename(): old_parent = %s / old = %s / new_parent = %s " 3876 3866 "/ no remove\n", 3877 3867 old_parent->name , old->name , new_parent->name ); … … 3888 3878 { 3889 3879 _spin_lock_release( &_fat.fat_lock ); 3890 _printf("\n[FAT ERROR] in _fat_rename(): cannot scan directory <%s>\n",3880 _printf("\n[FAT ERROR] _fat_rename(): cannot scan directory <%s>\n", 3891 3881 to_remove->name ); 3892 return -4;3882 return GIET_FAT32_IO_ERROR; 3893 3883 } 3894 3884 else if ( entries > 2 ) 3895 3885 { 3896 3886 _spin_lock_release( &_fat.fat_lock ); 3897 _printf("\n[FAT ERROR] in _fat_rename(): directory <%s> not empty\n",3887 _printf("\n[FAT ERROR] _fat_rename(): directory <%s> not empty\n", 3898 3888 to_remove->name ); 3899 return -5;3889 return GIET_FAT32_DIRECTORY_NOT_EMPTY; 3900 3890 } 3901 3891 } … … 3905 3895 { 3906 3896 _spin_lock_release( &_fat.fat_lock ); 3907 _printf("\n[FAT ERROR] in _fat_rename(): file <%s> still referenced\n",3897 _printf("\n[FAT ERROR] _fat_rename(): file <%s> still referenced\n", 3908 3898 to_remove->name ); 3909 return -6;3899 return GIET_FAT32_IS_OPEN; 3910 3900 } 3911 3901 } … … 3914 3904 #if GIET_DEBUG_FAT 3915 3905 if ( _get_proctime() > GIET_DEBUG_FAT ) 3916 _printf("\n[FAT DEBUG] _fat_rename() 3906 _printf("\n[FAT DEBUG] _fat_rename(): P[%d,%d,%d] checked remove condition OK\n", 3917 3907 x , y , p ); 3918 3908 #endif … … 3939 3929 { 3940 3930 _spin_lock_release( &_fat.fat_lock ); 3941 _printf("\n[FAT ERROR] in _fat_rename(): cannot add <%s> into <%s>\n",3931 _printf("\n[FAT ERROR] _fat_rename(): cannot add <%s> into <%s>\n", 3942 3932 new->name , new_parent->name ); 3943 return -7;3933 return GIET_FAT32_IO_ERROR; 3944 3934 } 3945 3935 … … 3953 3943 { 3954 3944 _spin_lock_release( &_fat.fat_lock ); 3955 _printf("\n[FAT ERROR] in _fat_rename(): cannot update <%s> on device\n",3945 _printf("\n[FAT ERROR] _fat_rename(): cannot update <%s> on device\n", 3956 3946 new_parent->name ); 3957 return -8;3947 return GIET_FAT32_IO_ERROR; 3958 3948 } 3959 3949 … … 3962 3952 { 3963 3953 _spin_lock_release( &_fat.fat_lock ); 3964 _printf("\n[FAT ERROR] in _fat_rename(): cannot remove <%s> from <%s>\n",3954 _printf("\n[FAT ERROR] _fat_rename(): cannot remove <%s> from <%s>\n", 3965 3955 old->name , old_parent->name ); 3966 return -9;3956 return GIET_FAT32_IO_ERROR; 3967 3957 } 3968 3958 … … 3979 3969 { 3980 3970 _spin_lock_release( &_fat.fat_lock ); 3981 _printf("\n[FAT ERROR] in _fat_rename(): cannot update <%s> on device\n",3971 _printf("\n[FAT ERROR] _fat_rename(): cannot update <%s> on device\n", 3982 3972 old_parent->name ); 3983 return -10;3973 return GIET_FAT32_IO_ERROR; 3984 3974 } 3985 3975 … … 3990 3980 { 3991 3981 _spin_lock_release( &_fat.fat_lock ); 3992 _printf("\n[FAT ERROR] in _fat_rename(): cannot remove <%s> from FS\n",3982 _printf("\n[FAT ERROR] _fat_rename(): cannot remove <%s> from FS\n", 3993 3983 to_remove->name ); 3994 return -11;3984 return GIET_FAT32_IO_ERROR; 3995 3985 } 3996 3986 } … … 3999 3989 _spin_lock_release( &_fat.fat_lock ); 4000 3990 4001 return 0;3991 return GIET_FAT32_OK; 4002 3992 } // end _fat_rename() 4003 3993 … … 4014 4004 // The DATA region on block device is updated. 4015 4005 ///////////////////////////////////////////////////////////////////////////////// 4016 // Returns 0 if success. 4017 // Returns a negative value if error: 4018 // -1 : "Fat not initialised" 4019 // -2 : "Path to parent not found" 4020 // -3 : "One name in path too long" 4021 // -4 : "Directory already exist" 4022 // -5 : "No free cluster" 4023 // -6 : "Cannot update parent directory" 4024 // -7 : "Cannot update parent DATA region" 4025 // -8 : "Cannot update FAT region" 4026 // -9 : "Cannot update FS-INFO" 4027 // -10 : "Cannot update directory DATA region" 4006 // Returns GIET_FAT32_OK on success. 4007 // Returns a negative value on error: 4008 // GIET_FAT32_NOT_INITIALIZED, 4009 // GIET_FAT32_FILE_NOT_FOUND, 4010 // GIET_FAT32_NAME_TOO_LONG, 4011 // GIET_FAT32_FILE_EXISTS, 4012 // GIET_FAT32_NO_FREE_SPACE, 4013 // GIET_FAT32_IO_ERROR 4028 4014 ///////////////////////////////////////////////////////////////////////////////// 4029 4015 int _fat_mkdir( char* pathname ) … … 4039 4025 unsigned int p = procid & ((1<<P_WIDTH)-1); 4040 4026 if ( _get_proctime() > GIET_DEBUG_FAT ) 4041 _printf("\n[DEBUG FAT] _fat_mkdir() 4027 _printf("\n[DEBUG FAT] _fat_mkdir(): P[%d,%d,%d] enters for path <%s>\n", 4042 4028 x, y, p, pathname ); 4043 4029 #endif … … 4046 4032 if( _fat.initialised != FAT_INITIALISED ) 4047 4033 { 4048 _printf("\n[FAT ERROR] in _fat_mkdir() : FAT not initialised\n");4049 return -1;4034 _printf("\n[FAT ERROR] _fat_mkdir(): FAT not initialized\n"); 4035 return GIET_FAT32_NOT_INITIALIZED; 4050 4036 } 4051 4037 … … 4059 4045 { 4060 4046 _spin_lock_release( &_fat.fat_lock ); 4061 _printf("\n[FAT ERROR] in _fat_mkdir(): path to parent not found"4047 _printf("\n[FAT ERROR] _fat_mkdir(): path to parent not found" 4062 4048 " for directory <%s>\n", pathname ); 4063 return -2;4049 return GIET_FAT32_FILE_NOT_FOUND; 4064 4050 } 4065 4051 else if ( code == 3 ) 4066 4052 { 4067 4053 _spin_lock_release( &_fat.fat_lock ); 4068 _printf("\n[FAT ERROR] in _fat_mkdir(): one name in path too long"4054 _printf("\n[FAT ERROR] _fat_mkdir(): one name in path too long" 4069 4055 " for directory <%s>\n", pathname ); 4070 return -3;4056 return GIET_FAT32_NAME_TOO_LONG; 4071 4057 } 4072 4058 else if ( code == 0 ) 4073 4059 { 4074 4060 _spin_lock_release( &_fat.fat_lock ); 4075 _printf("\n[FAT ERROR] in _fat_mkdir(): directory <%s> already exist\n",4061 _printf("\n[FAT ERROR] _fat_mkdir(): directory <%s> already exist\n", 4076 4062 pathname ); 4077 return -4;4063 return GIET_FAT32_FILE_EXISTS; 4078 4064 } 4079 4065 else if ( code == 1 ) // directory not found => create … … 4083 4069 #if GIET_DEBUG_FAT 4084 4070 if ( _get_proctime() > GIET_DEBUG_FAT ) 4085 _printf("\n[DEBUG FAT] _fat_mkdir() 4071 _printf("\n[DEBUG FAT] _fat_mkdir(): P[%d,%d,%d] create new directory <%s>\n", 4086 4072 x , y , p , pathname ); 4087 4073 #endif … … 4096 4082 { 4097 4083 _spin_lock_release( &_fat.fat_lock ); 4098 _printf("\n[FAT ERROR] in _fat_mkdir(): no free cluster"4084 _printf("\n[FAT ERROR] _fat_mkdir(): no free cluster" 4099 4085 " for directory <%s>\n" , pathname ); 4100 return -5;4086 return GIET_FAT32_NO_FREE_SPACE; 4101 4087 } 4102 4088 … … 4125 4111 { 4126 4112 _spin_lock_release( &_fat.fat_lock ); 4127 _printf("\n[FAT ERROR] in _fat_mkdir(): cannot update parent directory"4113 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update parent directory" 4128 4114 " for directory <%s>\n" , pathname ); 4129 return -6;4115 return GIET_FAT32_IO_ERROR; 4130 4116 } 4131 4117 … … 4136 4122 { 4137 4123 _spin_lock_release( &_fat.fat_lock ); 4138 _printf("\n[FAT ERROR] in _fat_mkdir(): cannot update DATA region "4124 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update DATA region " 4139 4125 " for parent of directory <%s>\n", pathname ); 4140 return -7;4126 return GIET_FAT32_IO_ERROR; 4141 4127 } 4142 4128 … … 4147 4133 { 4148 4134 _spin_lock_release( &_fat.fat_lock ); 4149 _printf("\n[FAT ERROR] in _fat_mkdir(): cannot update FAT region"4135 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update FAT region" 4150 4136 " for directory <%s>\n", pathname ); 4151 return -8;4137 return GIET_FAT32_IO_ERROR; 4152 4138 } 4153 4139 … … 4156 4142 { 4157 4143 _spin_lock_release( &_fat.fat_lock ); 4158 _printf("\n[FAT ERROR] in _fat_mkdir(): cannot update FS-INFO"4144 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update FS-INFO" 4159 4145 " for directory <%s>\n", pathname ); 4160 return -9;4146 return GIET_FAT32_IO_ERROR; 4161 4147 } 4162 4148 … … 4167 4153 { 4168 4154 _spin_lock_release( &_fat.fat_lock ); 4169 _printf("\n[FAT ERROR] in _fat_mkdir(): cannot update DATA region"4155 _printf("\n[FAT ERROR] _fat_mkdir(): cannot update DATA region" 4170 4156 " for directory <%s>\n", pathname ); 4171 return -10;4157 return GIET_FAT32_IO_ERROR; 4172 4158 } 4173 4159 } // end create directory … … 4176 4162 _spin_lock_release( &_fat.fat_lock ); 4177 4163 4178 return 0;4164 return GIET_FAT32_OK; 4179 4165 } // end _fat_mkdir() 4180 4166 … … 4191 4177 // A node name cannot be larger than 31 characters. 4192 4178 /////////////////////////////////////////////////////////////////////////////// 4193 // Returns file descriptor for the directory index on success4179 // Returns a file descriptor for the directory index on success 4194 4180 // Returns a negative value on error: 4195 // -1 : "FAT not initialized" 4196 // -2 : "path to parent not found" 4197 // -3 : "one name in path too long" 4198 // -4 : "directory not found" 4199 // -9 : "file descriptor array full" 4200 // -11 : "not a directory" 4181 // GIET_FAT32_NOT_INITIALIZED, 4182 // GIET_FAT32_NAME_TOO_LONG, 4183 // GIET_FAT32_FILE_NOT_FOUND, 4184 // GIET_FAT32_TOO_MANY_OPEN_FILES, 4185 // GIET_FAT32_NOT_A_DIRECTORY 4201 4186 /////////////////////////////////////////////////////////////////////////////// 4202 4187 extern int _fat_opendir( char* pathname ) … … 4209 4194 if ( !_fat.fd[fd_id].inode->is_dir ) 4210 4195 { 4211 _printf("\n[FAT ERROR] in _fat_opendir(): <%s> is not a directory\n",4196 _printf("\n[FAT ERROR] _fat_opendir(): <%s> is not a directory\n", 4212 4197 pathname ); 4213 return -11;4198 return GIET_FAT32_NOT_A_DIRECTORY; 4214 4199 } 4215 4200 … … 4224 4209 // Same behavior as _fat_close(), no check for directory. 4225 4210 ///////////////////////////////////////////////////////////////////////////////// 4226 // Returns 0on success.4227 // Returns negative value on error:4228 // -1 : "FAT not initialized"4229 // -2 : "Illegal file descriptor"4230 // -3 : "File not open"4231 // -4 : "Cannot update DATA regions"4211 // Returns GIET_FAT32_OK on success. 4212 // Returns a negative value on error: 4213 // GIET_FAT32_NOT_INITIALIZED, 4214 // GIET_FAT32_INVALID_FD, 4215 // GIET_FAT32_NOT_OPEN, 4216 // GIET_FAT32_IO_ERROR 4232 4217 ///////////////////////////////////////////////////////////////////////////////// 4233 4218 extern int _fat_closedir( unsigned int fd_id ) … … 4245 4230 // This includes the cluster, size, is_dir and name info for each entry. 4246 4231 ///////////////////////////////////////////////////////////////////////////////// 4247 // Returns 0 on success, or 1 if there are no more entries.4232 // Returns GIET_FAT32_OK on success. 4248 4233 // Returns a negative value on error: 4249 // -1 : "FAT not initialized" 4250 // -2 : "illegal file descriptor" 4251 // -3 : "file not open" 4252 // -4 : "not a directory" 4253 // -5 : "can't read entry" 4234 // GIET_FAT32_NOT_INITIALIZED, 4235 // GIET_FAT32_INVALID_FD, 4236 // GIET_FAT32_NOT_OPEN, 4237 // GIET_FAT32_NOT_A_DIRECTORY, 4238 // GIET_FAT32_IO_ERROR, 4239 // GIET_FAT32_NO_MORE_ENTRIES 4254 4240 ///////////////////////////////////////////////////////////////////////////////// 4255 4241 extern int _fat_readdir( unsigned int fd_id, … … 4273 4259 else if ( !info.is_dir ) 4274 4260 { 4275 _printf("\n[FAT ERROR] in _fat_readdir(): not a directory\n" );4276 return -4;4261 _printf("\n[FAT ERROR] _fat_readdir(): not a directory\n" ); 4262 return GIET_FAT32_NOT_A_DIRECTORY; 4277 4263 } 4278 4264 … … 4281 4267 if ( _fat_read( fd_id, &buf, sizeof(buf) ) != sizeof(buf) ) 4282 4268 { 4283 _printf("\n[FAT ERROR] in _fat_readdir(): can't read entry\n" );4284 return -5;4269 _printf("\n[FAT ERROR] _fat_readdir(): can't read entry\n" ); 4270 return GIET_FAT32_IO_ERROR; 4285 4271 } 4286 4272 … … 4295 4281 _spin_lock_release( &_fat.fat_lock ); 4296 4282 4297 return 1;4283 return GIET_FAT32_NO_MORE_ENTRIES; 4298 4284 } 4299 4285 else if ( ord == FREE_ENTRY ) // free entry => skip … … 4342 4328 } 4343 4329 4344 return 0;4330 return GIET_FAT32_OK; 4345 4331 } 4346 4332 … … 4356 4342 // It uses only the 512 bytes buffer defined in the FAT descriptor. 4357 4343 /////////////////////////////////////////////////////////////////////////////// 4358 // Returns 0 if success. 4359 // Returns negative value if error: 4360 // -1 : "FAT not initialised" 4361 // -2 : "File not found" 4362 // -3 : "Buffer too small" 4363 // -4 : "Cannot access block device" 4364 // -5 : "Cannot access FAT on block device" 4344 // Returns GIET_FAT32_OK on success. 4345 // Returns negative value on error: 4346 // GIET_FAT32_NOT_INITIALIZED 4347 // GIET_FAT32_FILE_NOT_FOUND 4348 // GIET_FAT32_BUFFER_TOO_SMALL 4349 // GIET_FAT32_IO_ERROR 4365 4350 /////////////////////////////////////////////////////////////////////////////// 4366 4351 int _fat_load_no_cache( char* pathname, … … 4371 4356 if( _fat.initialised != FAT_INITIALISED ) 4372 4357 { 4373 _printf("\n[FAT ERROR] in _fat_load_no_cache() : FAT not initialised\n");4374 return -1;4358 _printf("\n[FAT ERROR] _fat_load_no_cache(): FAT not initialized\n"); 4359 return GIET_FAT32_NOT_INITIALIZED; 4375 4360 } 4376 4361 … … 4384 4369 unsigned int p = procid & ((1<<P_WIDTH)-1); 4385 4370 if ( _get_proctime() > GIET_DEBUG_FAT ) 4386 _printf("\n[DEBUG FAT] _fat_load_no_cache() 4371 _printf("\n[DEBUG FAT] _fat_load_no_cache(): P[%d,%d,%d] enters for file <%s>\n", 4387 4372 x , y , p , pathname ); 4388 4373 #endif … … 4393 4378 &file_size ) ) 4394 4379 { 4395 _printf("\n[FAT ERROR] in _fat_load_no_cache(): file <%s> not found\n",4380 _printf("\n[FAT ERROR] _fat_load_no_cache(): file <%s> not found\n", 4396 4381 pathname ); 4397 return -2;4382 return GIET_FAT32_FILE_NOT_FOUND; 4398 4383 } 4399 4384 … … 4401 4386 if ( file_size > buffer_size ) 4402 4387 { 4403 _printf("\n[FAT ERROR] in _fat_load_no_cache(): buffer too small : "4388 _printf("\n[FAT ERROR] _fat_load_no_cache(): buffer too small : " 4404 4389 "file_size = %x / buffer_size = %x", file_size , buffer_size ); 4405 return -3;4390 return GIET_FAT32_BUFFER_TOO_SMALL; 4406 4391 } 4407 4392 … … 4424 4409 8 ) ) // 8 blocks 4425 4410 { 4426 _printf("\n[FAT ERROR] in _fat_no _cache_read(): cannot load lba %x", lba );4427 return -4;4411 _printf("\n[FAT ERROR] _fat_load_no_cache(): cannot load lba %x", lba ); 4412 return GIET_FAT32_IO_ERROR; 4428 4413 } 4429 4414 … … 4433 4418 if ( _next_cluster_no_cache( cluster , &next ) ) 4434 4419 { 4435 _printf("\n[FAT ERROR] in _fat_no _cache_read(): cannot get next cluster "4420 _printf("\n[FAT ERROR] _fat_load_no_cache(): cannot get next cluster " 4436 4421 " for cluster = %x\n", cluster ); 4437 return -5;4422 return GIET_FAT32_IO_ERROR; 4438 4423 } 4439 4424 … … 4446 4431 #if GIET_DEBUG_FAT 4447 4432 if ( _get_proctime() > GIET_DEBUG_FAT ) 4448 _printf("\n[DEBUG FAT] _fat_load_no_cache() 4433 _printf("\n[DEBUG FAT] _fat_load_no_cache(): P[%d,%d,%d] loaded <%s> at vaddr = %x" 4449 4434 " / size = %x\n", x , y , p , pathname , buffer_vbase , file_size ); 4450 4435 #endif 4451 4436 4452 return 0;4437 return GIET_FAT32_OK; 4453 4438 } // end _fat_load_no_cache() 4454 4439
Note: See TracChangeset
for help on using the changeset viewer.