Changeset 664


Ignore:
Timestamp:
Jul 27, 2015, 5:56:15 PM (9 years ago)
Author:
guerin
Message:

fat32: generic error codes

Instead of having unique error codes per function, define an error
code map. Return more meaningful codes to the user.

Location:
soft/giet_vm/giet_fat32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_fat32/fat32.c

    r661 r664  
    637637#if (GIET_DEBUG_FAT & 1)
    638638if ( _get_proctime() > GIET_DEBUG_FAT )
    639 _printf("\n[DEBUG FAT] _fat_ioc_access() : enters at cycle %d\n"
     639_printf("\n[DEBUG FAT] _fat_ioc_access(): enters at cycle %d\n"
    640640        "  to_mem = %d / vaddr = %x / paddr = %l / sectors = %d / lba = %x\n",
    641641        _get_proctime(), to_mem, buf_vaddr, buf_paddr, count, lba );
     
    659659    return( _rdk_access( use_irq , to_mem , lba , buf_paddr , count ) );
    660660#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");
    662662    _exit();
    663663#endif
     
    707707    if ( cluster < 2 )
    708708    {
    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");
    710710        _exit();
    711711    }
     
    987987#if (GIET_DEBUG_FAT & 1)
    988988if ( _get_proctime() > GIET_DEBUG_FAT )
    989 _printf("\n[DEBUG FAT] _get_buffer_from_cache() : enters in FAT-Cache"
     989_printf("\n[DEBUG FAT] _get_buffer_from_cache(): enters in FAT-Cache"
    990990        " for cluster_id = %d\n", cluster_id );
    991991#endif
     
    999999#if (GIET_DEBUG_FAT & 1)
    10001000if ( _get_proctime() > GIET_DEBUG_FAT )
    1001 _printf("\n[DEBUG FAT] _get_buffer_from_cache() : enters in File-Cache <%s>"
     1001_printf("\n[DEBUG FAT] _get_buffer_from_cache(): enters in File-Cache <%s>"
    10021002        " for cluster_id = %d\n", inode->name , cluster_id );
    10031003#endif
     
    10281028#if (GIET_DEBUG_FAT & 1)
    10291029if ( _get_proctime() > GIET_DEBUG_FAT )
    1030 _printf("\n[DEBUG FAT] _get_buffer_from_cache() : miss in FAT-Cache for cluster_id %d\n",
     1030_printf("\n[DEBUG FAT] _get_buffer_from_cache(): miss in FAT-Cache for cluster_id %d\n",
    10311031        cluster_id );
    10321032#endif
     
    10381038#if (GIET_DEBUG_FAT & 1)
    10391039if ( _get_proctime() > GIET_DEBUG_FAT )
    1040 _printf("\n[DEBUG FAT] _get_buffer_from_cache() : miss in File-Cache <%s> "
     1040_printf("\n[DEBUG FAT] _get_buffer_from_cache(): miss in File-Cache <%s> "
    10411041        "for cluster_id %d\n", inode->name, cluster_id );
    10421042#endif
     
    10611061                {
    10621062                    _free( buf );
    1063                     _printf("\n[FAT ERROR] in _get_buffer_from_cache()"
    1064                             " : cannot access block device for lba = %x\n", lba );
     1063                    _printf("\n[FAT ERROR] _get_buffer_from_cache()"
     1064                            ": cannot access block device for lba = %x\n", lba );
    10651065                    return 1;
    10661066                }
     
    10751075#if (GIET_DEBUG_FAT & 1)
    10761076if ( _get_proctime() > GIET_DEBUG_FAT )
    1077 _printf("\n[DEBUG FAT] _get_buffer_from_cache() : buffer loaded from device"
     1077_printf("\n[DEBUG FAT] _get_buffer_from_cache(): buffer loaded from device"
    10781078        " at vaddr = %x\n", (unsigned int)buf );
    10791079#endif
     
    11201120                              1 ) )              // one block
    11211121        {
    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");
    11231123            return 1;
    11241124        }
     
    11411141                          1 ) )             // one block
    11421142    {
    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");
    11441144        return 1;
    11451145    }
     
    11471147#if (GIET_DEBUG_FAT & 1)
    11481148if ( _get_proctime() > GIET_DEBUG_FAT )
    1149 _printf("\n[DEBUG FAT] _update_fs_info() : nb_free = %x / first_free = %x\n",
     1149_printf("\n[DEBUG FAT] _update_fs_info(): nb_free = %x / first_free = %x\n",
    11501150        _fat.free_clusters_number , _fat.first_free_cluster );
    11511151#endif
     
    12171217#if (GIET_DEBUG_FAT & 1)
    12181218if ( _get_proctime() > GIET_DEBUG_FAT )
    1219 _printf("\n[DEBUG FAT] _allocate_one_buffer() : adding a cache level\n" );
     1219_printf("\n[DEBUG FAT] _allocate_one_buffer(): adding a cache level\n" );
    12201220#endif
    12211221
     
    12381238            if ( pdesc != NULL )      // slot not empty!!!
    12391239            {
    1240                 _printf("\n[FAT ERROR] in allocate_one buffer() : slot not empty "
     1240                _printf("\n[FAT ERROR] allocate_one buffer(): slot not empty "
    12411241                        "in File-Cache <%s> / cluster_id = %d\n", inode->name , cluster_id );
    12421242                _exit();
     
    12451245#if (GIET_DEBUG_FAT & 1)
    12461246if ( _get_proctime() > GIET_DEBUG_FAT )
    1247 _printf("\n[DEBUG FAT] _allocate_one_buffer() : buffer allocated to <%s> for cluster_id %d\n",
     1247_printf("\n[DEBUG FAT] _allocate_one_buffer(): buffer allocated to <%s> for cluster_id %d\n",
    12481248        inode->name, cluster_id );
    12491249#endif
     
    13011301    if ( found == 0 )
    13021302    {
    1303         _printf("\n[FAT_ERROR] in _allocate_one_cluster() : unconsistent FAT state");
     1303        _printf("\n[FAT_ERROR] _allocate_one_cluster(): unconsistent FAT state");
    13041304        return 1;
    13051305    }
     
    13141314#if (GIET_DEBUG_FAT & 1)
    13151315if ( _get_proctime() > GIET_DEBUG_FAT )
    1316 _printf("\n[DEBUG FAT] _allocate_one_cluster() : cluster = %x / first_free = %x\n",
     1316_printf("\n[DEBUG FAT] _allocate_one_cluster(): cluster = %x / first_free = %x\n",
    13171317        free , current );
    13181318#endif
     
    13511351                                          8 ) )
    13521352                    {
    1353                         _printf("\n[FAT_ERROR] in _update_device from_cache() : "
     1353                        _printf("\n[FAT_ERROR] _update_device from_cache(): "
    13541354                                " cannot access lba = %x\n", pdesc->lba );
    13551355                        ret = 1;
     
    13611361#if (GIET_DEBUG_FAT & 1)
    13621362if ( _get_proctime() > GIET_DEBUG_FAT )
    1363 _printf("\n[DEBUG FAT] _update_device_from_cache() : cluster_id = %d for <%s>\n",
     1363_printf("\n[DEBUG FAT] _update_device_from_cache(): cluster_id = %d for <%s>\n",
    13641364        index , string );
    13651365#endif
     
    14041404                // check dirty
    14051405                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");
    14071407
    14081408                _free( pdesc->buffer );
     
    14401440    if ( nb_required_clusters > _fat.free_clusters_number )
    14411441    {
    1442         _printf("\n[FAT ERROR] in _clusters_allocate() : required_clusters = %d"
     1442        _printf("\n[FAT ERROR] _clusters_allocate(): required_clusters = %d"
    14431443                " / free_clusters = %d\n", nb_required_clusters , _fat.free_clusters_number );
    14441444        return 1;
     
    14471447#if (GIET_DEBUG_FAT & 1)
    14481448if ( _get_proctime() > GIET_DEBUG_FAT )
    1449 _printf("\n[DEBUG FAT] _clusters_allocate() : enters for <%s> / nb_current_clusters = %d "
     1449_printf("\n[DEBUG FAT] _clusters_allocate(): enters for <%s> / nb_current_clusters = %d "
    14501450        "/ nb_required_clusters = %d\n",
    14511451        inode->name , nb_current_clusters , nb_required_clusters );
     
    14971497#if (GIET_DEBUG_FAT & 1)
    14981498if ( _get_proctime() > GIET_DEBUG_FAT )
    1499 _printf("\n[DEBUG FAT] _clusters_allocate() : done for cluster_id = %d / cluster = %x\n",
     1499_printf("\n[DEBUG FAT] _clusters_allocate(): done for cluster_id = %d / cluster = %x\n",
    15001500        cluster_id , new );
    15011501#endif
     
    17421742#if (GIET_DEBUG_FAT & 1)
    17431743if ( _get_proctime() > GIET_DEBUG_FAT )
    1744 _printf("\n[DEBUG FAT] _add_dir_entry() : try to add <%s> in <%s> / nb_lfn = %d\n",
     1744_printf("\n[DEBUG FAT] _add_dir_entry(): try to add <%s> in <%s> / nb_lfn = %d\n",
    17451745        child->name , parent->name, nb_lfn );
    17461746#endif
     
    17871787#if (GIET_DEBUG_FAT & 1)
    17881788if ( _get_proctime() > GIET_DEBUG_FAT )
    1789 _printf("\n[DEBUG FAT] _add_dir_entry() : get NO_MORE directory entry : "
     1789_printf("\n[DEBUG FAT] _add_dir_entry(): get NO_MORE directory entry : "
    17901790        " buffer = %x / offset = %x / cluster_id = %d\n",
    17911791        (unsigned int)buffer , offset , cluster_id );
     
    18191819            if ( cluster_id == 63 )   // we need to increase depth of File-Cache
    18201820            {
    1821                 _printf("\n[FAT ERROR] in add_dir_entry() File Cache depth extension "
     1821                _printf("\n[FAT ERROR] add_dir_entry() File Cache depth extension "
    18221822                        " not implemented\n" );
    18231823                _exit();  // TODO   
     
    18391839#if (GIET_DEBUG_FAT & 1)
    18401840if ( _get_proctime() > GIET_DEBUG_FAT )
    1841 _printf("\n[DEBUG FAT] _add_dir_entry() : FSM step = %d /"
     1841_printf("\n[DEBUG FAT] _add_dir_entry(): FSM step = %d /"
    18421842        " offset = %x / nb_lfn = %d\n", step, offset, nb_lfn );
    18431843#endif
     
    19711971if ( _get_proctime() > GIET_DEBUG_FAT )
    19721972{
    1973     _printf("\n[DEBUG FAT] _add_dir_entry() : <%s> successfully added in <%s>\n",
     1973    _printf("\n[DEBUG FAT] _add_dir_entry(): <%s> successfully added in <%s>\n",
    19741974            child->name , parent->name );
    19751975}
     
    20862086#if (GIET_DEBUG_FAT & 1)
    20872087if ( _get_proctime() > GIET_DEBUG_FAT )
    2088 _printf("\n[DEBUG FAT] _get_child_from_parent() : search <%s> in directory <%s>\n",
     2088_printf("\n[DEBUG FAT] _get_child_from_parent(): search <%s> in directory <%s>\n",
    20892089        name , parent->name );
    20902090#endif
     
    20982098#if (GIET_DEBUG_FAT & 1)
    20992099if ( _get_proctime() > GIET_DEBUG_FAT )
    2100 _printf("\n[DEBUG FAT] _get_child_from_parent() : found inode <%s> in directory <%s>\n",
     2100_printf("\n[DEBUG FAT] _get_child_from_parent(): found inode <%s> in directory <%s>\n",
    21012101        name , parent->name );
    21022102#endif
     
    21292129#if (GIET_DEBUG_FAT & 1)
    21302130if ( _get_proctime() > GIET_DEBUG_FAT )
    2131 _printf("\n[DEBUG FAT] _get_child_from_parent() : does not found inode <%s>"
     2131_printf("\n[DEBUG FAT] _get_child_from_parent(): does not found inode <%s>"
    21322132        " in directory <%s> => search in cache\n", name , parent->name );
    21332133#endif
     
    21492149#if (GIET_DEBUG_FAT & 1)
    21502150if ( _get_proctime() > GIET_DEBUG_FAT )
    2151 _printf("\n[DEBUG FAT] _get_child_from_parent() : scan buffer %d for <%s>\n",
     2151_printf("\n[DEBUG FAT] _get_child_from_parent(): scan buffer %d for <%s>\n",
    21522152        cluster_id , name );
    21532153#endif
     
    22182218#if (GIET_DEBUG_FAT & 1)
    22192219if ( _get_proctime() > GIET_DEBUG_FAT )
    2220 _printf("\n[DEBUG FAT] _get_child_from_parent() : found end of directory in <%s>\n",
     2220_printf("\n[DEBUG FAT] _get_child_from_parent(): found end of directory in <%s>\n",
    22212221        parent->name );
    22222222#endif
     
    22402240#if (GIET_DEBUG_FAT & 1)
    22412241if ( _get_proctime() > GIET_DEBUG_FAT )
    2242 _printf("\n[DEBUG FAT] _get_child_from_parent() : found <%s> on device\n", name );
     2242_printf("\n[DEBUG FAT] _get_child_from_parent(): found <%s> on device\n", name );
    22432243#endif
    22442244        return 0;
     
    22622262#if (GIET_DEBUG_FAT & 1)
    22632263if ( _get_proctime() > GIET_DEBUG_FAT )
    2264 _printf("\n[DEBUG FAT] _get_inode_from_path() : enters for path <%s>\n", pathname );
     2264_printf("\n[DEBUG FAT] _get_inode_from_path(): enters for path <%s>\n", pathname );
    22652265#endif
    22662266
     
    22712271#if (GIET_DEBUG_FAT & 1)
    22722272if ( _get_proctime() > GIET_DEBUG_FAT )
    2273 _printf("\n[DEBUG FAT] _get_inode_from_path() : found root inode for <%s>\n",
     2273_printf("\n[DEBUG FAT] _get_inode_from_path(): found root inode for <%s>\n",
    22742274        pathname );
    22752275#endif
     
    22992299#if (GIET_DEBUG_FAT & 1)
    23002300if ( _get_proctime() > GIET_DEBUG_FAT )
    2301 _printf("\n[DEBUG FAT] _get_inode_from_path() : got name <%s>\n", name );
     2301_printf("\n[DEBUG FAT] _get_inode_from_path(): got name <%s>\n", name );
    23022302#endif
    23032303
     
    23302330    #if (GIET_DEBUG_FAT & 1)
    23312331    if ( _get_proctime() > GIET_DEBUG_FAT )
    2332     _printf("\n[DEBUG FAT] _get_inode_from_path() : neither parent, nor child found for <%s>\n",
     2332    _printf("\n[DEBUG FAT] _get_inode_from_path(): neither parent, nor child found for <%s>\n",
    23332333            pathname );
    23342334    #endif
     
    23482348#if (GIET_DEBUG_FAT & 1)
    23492349if ( _get_proctime() > GIET_DEBUG_FAT )
    2350 _printf("\n[DEBUG FAT] _get_inode_from_path() : found inode for <%s>\n",
     2350_printf("\n[DEBUG FAT] _get_inode_from_path(): found inode for <%s>\n",
    23512351        pathname );
    23522352#endif
     
    23582358#if (GIET_DEBUG_FAT & 1)
    23592359if ( _get_proctime() > GIET_DEBUG_FAT )
    2360 _printf("\n[DEBUG FAT] _get_inode_from_path() : found only parent inode for <%s>\n",
     2360_printf("\n[DEBUG FAT] _get_inode_from_path(): found only parent inode for <%s>\n",
    23612361        pathname );
    23622362#endif
     
    24232423                              8 ) )
    24242424        {
    2425             _printf("\n[FAT ERROR] in _next_cluster_no_cache() : "
     2425            _printf("\n[FAT ERROR] _next_cluster_no_cache(): "
    24262426                    "cannot load lba = %x into fat_buffer\n", lba );
    24272427            return 1;
     
    24492449#if (GIET_DEBUG_FAT & 1)
    24502450if ( _get_proctime() > GIET_DEBUG_FAT )
    2451 _printf("\n[DEBUG FAT] _file_info_no_cache() : enters for path <%s>\n", pathname );
     2451_printf("\n[DEBUG FAT] _file_info_no_cache(): enters for path <%s>\n", pathname );
    24522452#endif
    24532453
     
    24862486#if (GIET_DEBUG_FAT & 1)
    24872487if ( _get_proctime() > GIET_DEBUG_FAT )
    2488 _printf("\n[DEBUG FAT] _file_info_no_cache() : search name <%s>"
     2488_printf("\n[DEBUG FAT] _file_info_no_cache(): search name <%s>"
    24892489        " in cluster %x\n", name , parent_cluster );
    24902490#endif
     
    25062506                                      8 ) )
    25072507                {
    2508                     _printf("\n[FAT ERROR] in _file_info_no_cache() : "
     2508                    _printf("\n[FAT ERROR] _file_info_no_cache(): "
    25092509                            "cannot load lba = %x into data_buffer\n", lba );
    25102510                    return 1;
     
    25852585        if ( found == 2 )  // found end of directory => error
    25862586        {
    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",
    25882588                    name );
    25892589            return 1;
     
    25942594             ((pathname[nb_read] != 0) && (child_is_dir == 0)) )
    25952595        {
    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 );
    25972597            return 1;
    25982598        }
     
    26052605#if (GIET_DEBUG_FAT & 1)
    26062606if ( _get_proctime() > GIET_DEBUG_FAT )
    2607 _printf("\n[DEBUG FAT] _file_info_no_cache() : success for <%s> / "
     2607_printf("\n[DEBUG FAT] _file_info_no_cache(): success for <%s> / "
    26082608        "file_size = %x / file_cluster = %x\n", pathname, child_size, child_cluster );
    26092609#endif
     
    26382638// that are loaded in the Fat-Descriptor temporary block_buffer.
    26392639/////////////////////////////////////////////////////////////////////////////
    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,
    26422644/////////////////////////////////////////////////////////////////////////////
    26432645int _fat_init( unsigned int kernel_mode ) 
     
    26462648#if GIET_DEBUG_FAT
    26472649if ( _get_proctime() > GIET_DEBUG_FAT )
    2648 _printf("\n[DEBUG FAT] _fat_init() : enters at cycle %d\n", _get_proctime() );
     2650_printf("\n[DEBUG FAT] _fat_init(): enters at cycle %d\n", _get_proctime() );
    26492651#endif
    26502652
     
    26522654    if ( _fat.initialised == FAT_INITIALISED )
    26532655    {
    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;
    26562658    }
    26572659
     
    26632665                          1 ) )                               // one block
    26642666    {
    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;
    26672669    }
    26682670
     
    26722674if ( _get_proctime() > GIET_DEBUG_FAT )
    26732675{
    2674     _printf("\n[DEBUG FAT] _fat_init() : Boot sector loaded\n");
     2676    _printf("\n[DEBUG FAT] _fat_init(): Boot sector loaded\n");
    26752677    _display_one_block( _fat.block_buffer, "block device", _fat.block_buffer_lba );
    26762678}
     
    26802682    if( _read_entry( BPB_BYTSPERSEC, _fat.block_buffer, 1 ) != 512 )
    26812683    {
    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;
    26842686    }
    26852687    if( _read_entry( BPB_SECPERCLUS, _fat.block_buffer, 1 ) != 8 )
    26862688    {
    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;
    26892691    }
    26902692    if( _read_entry( BPB_NUMFATS, _fat.block_buffer, 1 ) != 1 )
    26912693    {
    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;
    26942696    }
    26952697    if( (_read_entry( BPB_FAT32_FATSZ32, _fat.block_buffer, 1 ) & 0xF) != 0 )
    26962698    {
    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;
    26992701    }
    27002702    if( _read_entry( BPB_FAT32_ROOTCLUS, _fat.block_buffer, 1 ) != 2 )
    27012703    {
    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;
    27042706    }
    27052707
     
    27232725                          1 ) )                             // one block
    27242726    {
    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;
    27272729    }
    27282730
     
    27322734if ( _get_proctime() > GIET_DEBUG_FAT )
    27332735{
    2734     _printf("\n[DEBUG FAT] _fat_init() : FS-INFO sector loaded\n");
     2736    _printf("\n[DEBUG FAT] _fat_init(): FS-INFO sector loaded\n");
    27352737    _display_one_block( _fat.block_buffer, "block device", _fat.block_buffer_lba );
    27362738}
     
    27722774#endif
    27732775
    2774     return 0;
     2776    return GIET_FAT32_OK;
    27752777}  // end _fat_init()
    27762778
     
    27892791// A node name (file or directory) cannot be larger than 31 characters.
    27902792///////////////////////////////////////////////////////////////////////////////
    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
    28032800///////////////////////////////////////////////////////////////////////////////
    28042801int _fat_open( char*        pathname,     // absolute path from root
     
    28222819unsigned int p       = procid & ((1<<P_WIDTH)-1);
    28232820if ( _get_proctime() > GIET_DEBUG_FAT )
    2824 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] enters for path <%s> / "
     2821_printf("\n[DEBUG FAT] _fat_open(): P[%d,%d,%d] enters for path <%s> / "
    28252822        " create = %d / read_only = %d\n",
    28262823        x, y, p, pathname , create , read_only );
     
    28302827    if( _fat.initialised != FAT_INITIALISED )
    28312828    {
    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;
    28342831    }
    28352832
     
    28432840    {
    28442841        _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"
    28462843                " for file <%s>\n", pathname );
    2847         return -2;
     2844        return GIET_FAT32_FILE_NOT_FOUND;
    28482845    }
    28492846    else if ( code == 3 ) 
    28502847    {
    28512848        _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"
    28532850                " for file <%s>\n", pathname );
    2854         return -3;
     2851        return GIET_FAT32_NAME_TOO_LONG;
    28552852    }
    28562853    else if ( (code == 1) && (create == 0) )   
    28572854    {
    28582855        _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"
    28602857                " for file <%s>\n", pathname );
    2861         return -4;
     2858        return GIET_FAT32_FILE_NOT_FOUND;
    28622859    }
    28632860    else if ( (code == 1) && (create != 0) )   // file name not found => create
     
    28682865#if GIET_DEBUG_FAT
    28692866if ( _get_proctime() > GIET_DEBUG_FAT )
    2870 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] create a new file <%s>\n",
     2867_printf("\n[DEBUG FAT] _fat_open(): P[%d,%d,%d] create a new file <%s>\n",
    28712868        x , y , p , pathname );
    28722869#endif
     
    28922889        {
    28932890            _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"
    28952892                    " for file <%s>\n" , pathname );
    2896             return -5;
     2893            return GIET_FAT32_IO_ERROR;
    28972894        }
    28982895
     
    29032900        {
    29042901            _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 "
    29062903                    " for parent of file <%s>\n", pathname );
    2907             return -6;
     2904            return GIET_FAT32_IO_ERROR;
    29082905        }
    29092906
     
    29142911        {
    29152912            _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"
    29172914                    " for file <%s>\n", pathname );
    2918             return -7;
     2915            return GIET_FAT32_IO_ERROR;
    29192916        }
    29202917
     
    29232920        {
    29242921            _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"
    29262923                    " for file <%s>\n", pathname );
    2927             return -8;
     2924            return GIET_FAT32_IO_ERROR;
    29282925        }
    29292926
     
    29382935#if GIET_DEBUG_FAT
    29392936if ( _get_proctime() > GIET_DEBUG_FAT )
    2940 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] found file <%s> on device : inode = %x\n",
     2937_printf("\n[DEBUG FAT] _fat_open(): P[%d,%d,%d] found file <%s> on device : inode = %x\n",
    29412938        x , y , p , pathname , child );
    29422939#endif
     
    29542951    {
    29552952        _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;
    29582955    }
    29592956
     
    29812978        {
    29822979            _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;
    29852982        }
    29862983
     
    29892986        {
    29902987            _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;
    29932990        }
    29942991    }
     
    29992996#if GIET_DEBUG_FAT
    30002997if ( _get_proctime() > GIET_DEBUG_FAT )
    3001 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] got fd = %d for <%s> / "
     2998_printf("\n[DEBUG FAT] _fat_open(): P[%d,%d,%d] got fd = %d for <%s> / "
    30022999        "read_only = %d\n",
    30033000        x , y , p , fd_id , pathname , read_only );
     
    30163013// and releases the memory allocated to the File_Cache.
    30173014/////////////////////////////////////////////////////////////////////////////////
    3018 // Returns 0 on success.
    3019 // Returns negative value if error:
    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
    30243021/////////////////////////////////////////////////////////////////////////////////
    30253022int _fat_close( unsigned int fd_id )
     
    30283025    if( _fat.initialised != FAT_INITIALISED )
    30293026    {
    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;
    30323029    }
    30333030
    30343031    if( (fd_id >= GIET_OPEN_FILES_MAX) )
    30353032    {
    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;
    30383035    }
    30393036
     
    30443041    {
    30453042        _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;
    30483045    }
    30493046
     
    30693066        {
    30703067            _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 "
    30723069                    "for file <%s>\n", inode->name );
    3073             return -4;
     3070            return GIET_FAT32_IO_ERROR;
    30743071        }
    30753072
     
    30863083        {
    30873084            _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 "
    30893086                    "for directory <%s>\n", inode->parent->name );
    3090             return -4;
     3087            return GIET_FAT32_IO_ERROR;
    30913088        }
    30923089
     
    31143111    _spin_lock_release( &_fat.fat_lock );
    31153112
    3116     return 0;
     3113    return GIET_FAT32_OK;
    31173114} // end fat_close()
    31183115
     
    31253122// identified by the "fd_id" argument.
    31263123/////////////////////////////////////////////////////////////////////////////////
    3127 // Returns  0 if success.
    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
    31323129/////////////////////////////////////////////////////////////////////////////////
    31333130int _fat_file_info( unsigned int     fd_id,
     
    31363133    if ( _fat.initialised != FAT_INITIALISED )
    31373134    {
    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;
    31403137    }
    31413138
    31423139    if ( fd_id >= GIET_OPEN_FILES_MAX )
    31433140    {
    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;
    31463143    }
    31473144
    31483145    if ( _fat.fd[fd_id].allocated == 0 )
    31493146    {
    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;
    31523149    }
    31533150
     
    31563153    info->is_dir = _fat.fd[fd_id].inode->is_dir;
    31573154
    3158     return 0;
     3155    return GIET_FAT32_OK;
    31593156} // end _fat_file_info()
    31603157
     
    31683165// In case of miss in the File_Cache, it loads all involved clusters into cache.
    31693166/////////////////////////////////////////////////////////////////////////////////
    3170 // Returns number of bytes actually transfered if success .
    3171 // Returns 0 if EOF encountered (offset + count > file_size).
    3172 // Returns a negative value if error:
    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
    31773174/////////////////////////////////////////////////////////////////////////////////
    31783175int _fat_read( unsigned int fd_id,     // file descriptor index
     
    31833180    if( _fat.initialised != FAT_INITIALISED )
    31843181    {
    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;
    31873184    }
    31883185
     
    31903187    if ( fd_id >= GIET_OPEN_FILES_MAX )
    31913188    {
    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;
    31943191    }
    31953192
     
    31973194    if ( _fat.fd[fd_id].allocated == 0 )
    31983195    {
    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;
    32013198    }
    32023199
     
    32123209    {
    32133210        _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"
    32153212                " / seek = %x / count = %x / file_size = %x\n",
    32163213                seek , count , inode->size );
     
    32323229unsigned int p       = procid & ((1<<P_WIDTH)-1);
    32333230if ( _get_proctime() > GIET_DEBUG_FAT )
    3234 _printf("\n[DEBUG FAT] _fat_read() : P[%d,%d,%d] enters for file <%s> "
     3231_printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] enters for file <%s> "
    32353232        " / bytes = %x / offset = %x\n"
    32363233        "first_cluster_id = %x / first_byte_to_move = %x"
     
    32533250        {
    32543251            _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",
    32563253                    inode->name );
    3257             return -4;
     3254            return GIET_FAT32_IO_ERROR;
    32583255        }
    32593256        cbuf = pdesc->buffer;
     
    32613258#if GIET_DEBUG_FAT
    32623259if ( _get_proctime() > GIET_DEBUG_FAT )
    3263 _printf("\n[DEBUG FAT] _fat_read() : P[%d,%d,%d] moves cluster_id %d from Cache-File <%s>\n",
     3260_printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] moves cluster_id %d from Cache-File <%s>\n",
    32643261        x , y , p , cluster_id, inode->name );
    32653262#endif
     
    32973294#if GIET_DEBUG_FAT
    32983295if ( _get_proctime() > GIET_DEBUG_FAT )
    3299 _printf("\n[DEBUG FAT] _fat_read() : P[%d,%d,%d] loaded file <%s> from Cache-File\n",
     3296_printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] loaded file <%s> from Cache-File\n",
    33003297        x , y , p , inode->name );
    33013298#endif
     
    33213318// involved clusters in the cache.
    33223319/////////////////////////////////////////////////////////////////////////////////
    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
    33323328/////////////////////////////////////////////////////////////////////////////////
    33333329int _fat_write( unsigned int fd_id,    // file descriptor index
     
    33383334    if( _fat.initialised != FAT_INITIALISED )
    33393335    {
    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;
    33423338    }
    33433339
     
    33493345    {
    33503346        _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;
    33533349    }
    33543350
     
    33573353    {
    33583354        _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;
    33613357    }
    33623358
     
    33653361    {
    33663362        _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",
    33683364                _fat.fd[fd_id].inode->name );
    3369         return -4;
     3365        return GIET_FAT32_READ_ONLY;
    33703366    }
    33713367
     
    33803376unsigned int p       = procid & ((1<<P_WIDTH)-1);
    33813377if ( _get_proctime() > GIET_DEBUG_FAT )
    3382 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] enters for file <%s> "
     3378_printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] enters for file <%s> "
    33833379        " / bytes = %x / seek = %x\n",
    33843380        x , y , p , inode->name , count , seek );
     
    34073403#if GIET_DEBUG_FAT
    34083404if ( _get_proctime() > GIET_DEBUG_FAT )
    3409 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] allocates new clusters for file <%s>"
     3405_printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] allocates new clusters for file <%s>"
    34103406        " / current = %d / required = %d\n",
    34113407        x , y , p , inode->name , old_clusters , new_clusters );
     
    34173413            {
    34183414                _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"
    34203416                        " for file <%s>\n", _fat.fd[fd_id].inode->name );
    3421                 return -5;
     3417                return GIET_FAT32_NO_FREE_SPACE;
    34223418            }
    34233419        }
     
    34273423        {
    34283424            _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"
    34303426                    " for file <%s>\n", _fat.fd[fd_id].inode->name );
    3431             return -6;
     3427            return GIET_FAT32_IO_ERROR;
    34323428        }
    34333429           
     
    34353431#if GIET_DEBUG_FAT
    34363432if ( _get_proctime() > GIET_DEBUG_FAT )
    3437 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] updates size for file <%s> / size = %x\n",
     3433_printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] updates size for file <%s> / size = %x\n",
    34383434        x , y , p , inode->name , (new_size - old_size) );
    34393435#endif
     
    34513447#if GIET_DEBUG_FAT
    34523448if ( _get_proctime() > GIET_DEBUG_FAT )
    3453 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] starts loop on clusters for file <%s>\n"
     3449_printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] starts loop on clusters for file <%s>\n"
    34543450        "  first_cluster_id = %d / first_byte_to_move = %x"
    34553451        " / last_cluster_id = %d / last_byte_to_move = %x\n",
     
    34713467        {
    34723468            _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",
    34743470                    inode->name );
    3475             return -7;
     3471            return GIET_FAT32_IO_ERROR;
    34763472        }
    34773473       
     
    34813477#if GIET_DEBUG_FAT
    34823478if ( _get_proctime() > GIET_DEBUG_FAT )
    3483 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] move cluster_id %d to Cache-file <%s>\n",
     3479_printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] move cluster_id %d to Cache-file <%s>\n",
    34843480        x , y , p , cluster_id, inode->name );
    34853481#endif
     
    35213517#if GIET_DEBUG_FAT
    35223518if ( _get_proctime() > GIET_DEBUG_FAT )
    3523 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] store file <%s> into Cache-File\n",
     3519_printf("\n[DEBUG FAT] _fat_write(): P[%d,%d,%d] store file <%s> into Cache-File\n",
    35243520        x , y , p , inode->name );
    35253521#endif
     
    35403536// Accepted values for whence are SEEK_SET and SEEK_CUR.
    35413537/////////////////////////////////////////////////////////////////////////////////
    3542 // Returns new seek value (bytes) if success.
    3543 // Returns negative value if error:
    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
    35483544/////////////////////////////////////////////////////////////////////////////////
    35493545int _fat_lseek( unsigned int fd_id,
     
    35543550    if( _fat.initialised != FAT_INITIALISED )
    35553551    {
    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;
    35583554    }
    35593555
     
    35613557    if ( fd_id >= GIET_OPEN_FILES_MAX )
    35623558    {
    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;
    35653561    }
    35663562
     
    35723568    {
    35733569        _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;
    35763572    }
    35773573
     
    35843580    {
    35853581        _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;
    35883584    }
    35893585
     
    35973593unsigned int p       = procid & ((1<<P_WIDTH)-1);
    35983594if ( _get_proctime() > GIET_DEBUG_FAT )
    3599 _printf("\n[DEBUG FAT] _fat_lseek() : P[%d,%d,%d] set seek = %x for file <%s>\n",
     3595_printf("\n[DEBUG FAT] _fat_lseek(): P[%d,%d,%d] set seek = %x for file <%s>\n",
    36003596        x , y , p , new_seek , _fat.fd[fd_id].inode->name );
    36013597#endif
     
    36203616// The Fat_Cache is updated.
    36213617/////////////////////////////////////////////////////////////////////////////////
    3622 // Returns 0 if success.
    3623 // Returns negative value if error
    3624 //   -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
    36323628/////////////////////////////////////////////////////////////////////////////////
    36333629int _fat_remove( char*        pathname,
     
    36423638unsigned int p       = procid & ((1<<P_WIDTH)-1);
    36433639if ( _get_proctime() > GIET_DEBUG_FAT )
    3644 _printf("\n[DEBUG FAT] _fat_remove() : P[%d,%d,%d] enters for path <%s>\n",
     3640_printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] enters for path <%s>\n",
    36453641        x, y, p, pathname );
    36463642#endif
     
    36493645    if( _fat.initialised != FAT_INITIALISED )
    36503646    {
    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;
    36533649    }
    36543650
     
    36613657#if GIET_DEBUG_FAT
    36623658if ( _get_proctime() > GIET_DEBUG_FAT )
    3663 _printf("\n[DEBUG FAT] _fat_remove() : P[%d,%d,%d] found inode %x for <%s> / code = %d\n",
     3659_printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] found inode %x for <%s> / code = %d\n",
    36643660        x , y , p , (unsigned int)inode , pathname , code );
    36653661#endif
     
    36683664    {
    36693665        _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",
    36713667                pathname );
    3672         return -2;
     3668        return GIET_FAT32_FILE_NOT_FOUND;
    36733669    }
    36743670    else if ( code == 3 )
    36753671    {
    36763672        _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",
    36783674                pathname );
    3679         return -3;
     3675        return GIET_FAT32_NAME_TOO_LONG;
    36803676    }
    36813677
     
    36843680    {
    36853681        _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",
    36873683                pathname );
    3688         return -4;
     3684        return GIET_FAT32_IS_DIRECTORY;
    36893685    }
    36903686    if ( (inode->is_dir == 0) && (should_be_dir != 0) )
    36913687    {
    36923688        _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",
    36943690                pathname );
    3695         return -4;
     3691        return GIET_FAT32_NOT_A_DIRECTORY;
    36963692    }
    36973693
    36983694#if GIET_DEBUG_FAT
    36993695if ( _get_proctime() > GIET_DEBUG_FAT )
    3700 _printf("\n[DEBUG FAT] _fat_remove() : P[%d,%d,%d] checked inode type for <%s>\n",
     3696_printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] checked inode type for <%s>\n",
    37013697        x , y , p , pathname );
    37023698#endif
     
    37063702    {
    37073703        _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",
    37093705                pathname );
    3710         return -5;
     3706        return GIET_FAT32_IS_OPEN;
    37113707    }
    37123708
     
    37183714        {
    37193715            _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",
    37213717                    pathname );
    3722             return -6;
     3718            return GIET_FAT32_IO_ERROR;
    37233719        }
    37243720        else if ( entries > 2 )
    37253721        {
    37263722            _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",
    37283724                    pathname );
    3729             return -7;
     3725            return GIET_FAT32_DIRECTORY_NOT_EMPTY;
    37303726        }
    37313727    }
     
    37333729#if GIET_DEBUG_FAT
    37343730if ( _get_proctime() > GIET_DEBUG_FAT )
    3735 _printf("\n[DEBUG FAT] _fat_remove() : P[%d,%d,%d] checked remove condition OK for <%s>\n",
     3731_printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] checked remove condition OK for <%s>\n",
    37363732        x , y , p , pathname );
    37373733#endif
     
    37413737    {
    37423738        _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",
    37443740                pathname );
    3745         return -8;
     3741        return GIET_FAT32_IO_ERROR;
    37463742    }
    37473743
     
    37513747#if GIET_DEBUG_FAT
    37523748if ( _get_proctime() > GIET_DEBUG_FAT )
    3753 _printf("\n[DEBUG FAT] _fat_remove() : P[%d,%d,%d] removed  <%s> from FS\n",
     3749_printf("\n[DEBUG FAT] _fat_remove(): P[%d,%d,%d] removed  <%s> from FS\n",
    37543750        x, y, p, pathname );
    37553751#endif
    37563752   
    3757     return 0;
     3753    return GIET_FAT32_OK;
    37583754       
    37593755}  // end _fat_remove()
     
    37723768// The removed entry is only removed after the new entry is actually created.
    37733769/////////////////////////////////////////////////////////////////////////////////
    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
    37883778/////////////////////////////////////////////////////////////////////////////////
    37893779int _fat_rename( char*  old_path,
     
    38043794unsigned int p       = procid & ((1<<P_WIDTH)-1);
    38053795if ( _get_proctime() > GIET_DEBUG_FAT )
    3806 _printf("\n[DEBUG FAT] _fat_rename() : P[%d,%d,%d] enters to move <%s> to <%s>\n",
     3796_printf("\n[DEBUG FAT] _fat_rename(): P[%d,%d,%d] enters to move <%s> to <%s>\n",
    38073797        x , y , p , old_path , new_path );
    38083798#endif
     
    38113801    if( _fat.initialised != FAT_INITIALISED )
    38123802    {
    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;
    38153805    }
    38163806
     
    38223812    {
    38233813        _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;
    38263816    }
    38273817    else
     
    38393829        {
    38403830            _spin_lock_release( &_fat.fat_lock );
    3841             return 0;
     3831            return GIET_FAT32_OK;
    38423832        }
    38433833
     
    38533843    {
    38543844        _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;
    38573847    }
    38583848
     
    38613851    {
    38623852        _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;
    38653855    }
    38663856
     
    38693859{
    38703860if ( to_remove )
    3871 _printf("\n[DEBUG FAT] _fat_rename() : old_parent = %s / old = %s / new_parent = %s "
     3861_printf("\n[DEBUG FAT] _fat_rename(): old_parent = %s / old = %s / new_parent = %s "
    38723862        "/ to_remove = %s\n",
    38733863        old_parent->name , old->name , new_parent->name , to_remove->name );
    38743864else
    3875 _printf("\n[DEBUG FAT] _fat_rename() : old_parent = %s / old = %s / new_parent = %s "
     3865_printf("\n[DEBUG FAT] _fat_rename(): old_parent = %s / old = %s / new_parent = %s "
    38763866        "/ no remove\n",
    38773867        old_parent->name , old->name , new_parent->name );
     
    38883878            {
    38893879                _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",
    38913881                        to_remove->name );
    3892                 return -4;
     3882                return GIET_FAT32_IO_ERROR;
    38933883            }
    38943884            else if ( entries > 2 )
    38953885            {
    38963886                _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",
    38983888                        to_remove->name );
    3899                 return -5;
     3889                return GIET_FAT32_DIRECTORY_NOT_EMPTY;
    39003890            }
    39013891        }
     
    39053895            {
    39063896                _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",
    39083898                        to_remove->name );
    3909                 return -6;
     3899                return GIET_FAT32_IS_OPEN;
    39103900            }
    39113901        }
     
    39143904#if GIET_DEBUG_FAT
    39153905if ( _get_proctime() > GIET_DEBUG_FAT )
    3916 _printf("\n[FAT DEBUG] _fat_rename() : P[%d,%d,%d] checked remove condition OK\n",
     3906_printf("\n[FAT DEBUG] _fat_rename(): P[%d,%d,%d] checked remove condition OK\n",
    39173907        x , y , p );
    39183908#endif
     
    39393929    {
    39403930        _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",
    39423932                new->name , new_parent->name );
    3943         return -7;
     3933        return GIET_FAT32_IO_ERROR;
    39443934    }
    39453935
     
    39533943    {
    39543944        _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",
    39563946                    new_parent->name );
    3957         return -8;
     3947        return GIET_FAT32_IO_ERROR;
    39583948    }
    39593949
     
    39623952    {
    39633953        _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",
    39653955                old->name , old_parent->name );
    3966         return -9;
     3956        return GIET_FAT32_IO_ERROR;
    39673957    }
    39683958 
     
    39793969    {
    39803970        _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",
    39823972                    old_parent->name );
    3983         return -10;
     3973        return GIET_FAT32_IO_ERROR;
    39843974    }
    39853975
     
    39903980        {
    39913981            _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",
    39933983                    to_remove->name );
    3994             return -11;
     3984            return GIET_FAT32_IO_ERROR;
    39953985        }
    39963986    }
     
    39993989    _spin_lock_release( &_fat.fat_lock );
    40003990
    4001     return 0;
     3991    return GIET_FAT32_OK;
    40023992}  // end _fat_rename()
    40033993
     
    40144004// The DATA region on block device is updated.
    40154005/////////////////////////////////////////////////////////////////////////////////
    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
    40284014/////////////////////////////////////////////////////////////////////////////////
    40294015int _fat_mkdir( char* pathname )
     
    40394025unsigned int p       = procid & ((1<<P_WIDTH)-1);
    40404026if ( _get_proctime() > GIET_DEBUG_FAT )
    4041 _printf("\n[DEBUG FAT] _fat_mkdir() : P[%d,%d,%d] enters for path <%s>\n",
     4027_printf("\n[DEBUG FAT] _fat_mkdir(): P[%d,%d,%d] enters for path <%s>\n",
    40424028        x, y, p, pathname );
    40434029#endif
     
    40464032    if( _fat.initialised != FAT_INITIALISED )
    40474033    {
    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;
    40504036    }
    40514037
     
    40594045    {
    40604046        _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"
    40624048                " for directory <%s>\n", pathname );
    4063         return -2;
     4049        return GIET_FAT32_FILE_NOT_FOUND;
    40644050    }
    40654051    else if ( code == 3 ) 
    40664052    {
    40674053        _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"
    40694055                " for directory  <%s>\n", pathname );
    4070         return -3;
     4056        return GIET_FAT32_NAME_TOO_LONG;
    40714057    }
    40724058    else if ( code == 0 )
    40734059    {
    40744060        _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",
    40764062                pathname );
    4077         return -4;
     4063        return GIET_FAT32_FILE_EXISTS;
    40784064    }
    40794065    else if ( code == 1 )   // directory not found => create
     
    40834069#if GIET_DEBUG_FAT
    40844070if ( _get_proctime() > GIET_DEBUG_FAT )
    4085 _printf("\n[DEBUG FAT] _fat_mkdir() : P[%d,%d,%d] create new directory <%s>\n",
     4071_printf("\n[DEBUG FAT] _fat_mkdir(): P[%d,%d,%d] create new directory <%s>\n",
    40864072        x , y , p , pathname );
    40874073#endif
     
    40964082        {
    40974083            _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"
    40994085                    " for directory <%s>\n" , pathname );
    4100             return -5;
     4086            return GIET_FAT32_NO_FREE_SPACE;
    41014087        }
    41024088
     
    41254111        {
    41264112            _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"
    41284114                    " for directory <%s>\n" , pathname );
    4129             return -6;
     4115            return GIET_FAT32_IO_ERROR;
    41304116        }
    41314117
     
    41364122        {
    41374123            _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 "
    41394125                    " for parent of directory <%s>\n", pathname );
    4140             return -7;
     4126            return GIET_FAT32_IO_ERROR;
    41414127        }
    41424128
     
    41474133        {
    41484134            _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"
    41504136                    " for directory <%s>\n", pathname );
    4151             return -8;
     4137            return GIET_FAT32_IO_ERROR;
    41524138        }
    41534139
     
    41564142        {
    41574143            _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"
    41594145                    " for directory <%s>\n", pathname );
    4160             return -9;
     4146            return GIET_FAT32_IO_ERROR;
    41614147        }
    41624148
     
    41674153        {
    41684154            _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"
    41704156                    " for directory <%s>\n", pathname );
    4171             return -10;
     4157            return GIET_FAT32_IO_ERROR;
    41724158        }
    41734159    }  // end create directory
     
    41764162    _spin_lock_release( &_fat.fat_lock );
    41774163
    4178     return 0;
     4164    return GIET_FAT32_OK;
    41794165}  // end _fat_mkdir()
    41804166
     
    41914177// A node name cannot be larger than 31 characters.
    41924178///////////////////////////////////////////////////////////////////////////////
    4193 // Returns file descriptor for the directory index on success
     4179// Returns a file descriptor for the directory index on success
    41944180// 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
    42014186///////////////////////////////////////////////////////////////////////////////
    42024187extern int _fat_opendir( char* pathname )
     
    42094194    if ( !_fat.fd[fd_id].inode->is_dir )
    42104195    {
    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",
    42124197                pathname );
    4213         return -11;
     4198        return GIET_FAT32_NOT_A_DIRECTORY;
    42144199    }
    42154200
     
    42244209// Same behavior as _fat_close(), no check for directory.
    42254210/////////////////////////////////////////////////////////////////////////////////
    4226 // Returns 0 on 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
    42324217/////////////////////////////////////////////////////////////////////////////////
    42334218extern int _fat_closedir( unsigned int fd_id )
     
    42454230// This includes the cluster, size, is_dir and name info for each entry.
    42464231/////////////////////////////////////////////////////////////////////////////////
    4247 // Returns 0 on success, or 1 if there are no more entries.
     4232// Returns GIET_FAT32_OK on success.
    42484233// 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
    42544240/////////////////////////////////////////////////////////////////////////////////
    42554241extern int _fat_readdir( unsigned int  fd_id,
     
    42734259    else if ( !info.is_dir )
    42744260    {
    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;
    42774263    }
    42784264
     
    42814267        if ( _fat_read( fd_id, &buf, sizeof(buf) ) != sizeof(buf) )
    42824268        {
    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;
    42854271        }
    42864272
     
    42954281            _spin_lock_release( &_fat.fat_lock );
    42964282
    4297             return 1;
     4283            return GIET_FAT32_NO_MORE_ENTRIES;
    42984284        }
    42994285        else if ( ord == FREE_ENTRY )           // free entry => skip
     
    43424328    }
    43434329
    4344     return 0;
     4330    return GIET_FAT32_OK;
    43454331}
    43464332
     
    43564342// It uses only the 512 bytes buffer defined in the FAT descriptor.
    43574343///////////////////////////////////////////////////////////////////////////////
    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
    43654350///////////////////////////////////////////////////////////////////////////////
    43664351int _fat_load_no_cache( char*        pathname,
     
    43714356    if( _fat.initialised != FAT_INITIALISED )
    43724357    {
    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;
    43754360    }
    43764361
     
    43844369unsigned int p       = procid & ((1<<P_WIDTH)-1);
    43854370if ( _get_proctime() > GIET_DEBUG_FAT )
    4386 _printf("\n[DEBUG FAT] _fat_load_no_cache() : P[%d,%d,%d] enters for file <%s>\n",
     4371_printf("\n[DEBUG FAT] _fat_load_no_cache(): P[%d,%d,%d] enters for file <%s>\n",
    43874372        x , y , p , pathname );
    43884373#endif
     
    43934378                              &file_size ) )
    43944379    {
    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",
    43964381        pathname );
    4397         return -2;
     4382        return GIET_FAT32_FILE_NOT_FOUND;
    43984383    }
    43994384
     
    44014386    if ( file_size > buffer_size )
    44024387    {
    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 : "
    44044389                "file_size = %x / buffer_size = %x", file_size , buffer_size );
    4405         return -3;
     4390        return GIET_FAT32_BUFFER_TOO_SMALL;
    44064391    }
    44074392
     
    44244409                             8 ) )      // 8 blocks
    44254410        {
    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;
    44284413        }
    44294414         
     
    44334418        if ( _next_cluster_no_cache( cluster , &next ) )
    44344419        {
    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 "
    44364421                    " for cluster = %x\n", cluster );
    4437             return -5;
     4422            return GIET_FAT32_IO_ERROR;
    44384423        }
    44394424       
     
    44464431#if GIET_DEBUG_FAT
    44474432if ( _get_proctime() > GIET_DEBUG_FAT )
    4448 _printf("\n[DEBUG FAT] _fat_load_no_cache() : P[%d,%d,%d] loaded <%s> at vaddr = %x"
     4433_printf("\n[DEBUG FAT] _fat_load_no_cache(): P[%d,%d,%d] loaded <%s> at vaddr = %x"
    44494434        " / size = %x\n", x , y , p , pathname , buffer_vbase , file_size );
    44504435#endif
    44514436
    4452     return 0;
     4437    return GIET_FAT32_OK;
    44534438}  // end _fat_load_no_cache()
    44544439
  • soft/giet_vm/giet_fat32/fat32_shared.h

    r663 r664  
    4747#define SEEK_CUR                1
    4848
     49/********************************************************************************
     50  Error codes map.
     51********************************************************************************/
     52
     53#define GIET_FAT32_OK                   (  0)
     54#define GIET_FAT32_NOT_INITIALIZED      (- 1)
     55#define GIET_FAT32_INVALID_BOOT_SECTOR  (- 2)
     56#define GIET_FAT32_IO_ERROR             (- 3)
     57#define GIET_FAT32_FILE_NOT_FOUND       (- 4)
     58#define GIET_FAT32_INVALID_FD           (- 5)
     59#define GIET_FAT32_NAME_TOO_LONG        (- 6)
     60#define GIET_FAT32_TOO_MANY_OPEN_FILES  (- 7)
     61#define GIET_FAT32_NOT_OPEN             (- 8)
     62#define GIET_FAT32_IS_OPEN              (- 9)
     63#define GIET_FAT32_READ_ONLY            (-10)
     64#define GIET_FAT32_NO_FREE_SPACE        (-11)
     65#define GIET_FAT32_INVALID_ARG          (-12)
     66#define GIET_FAT32_NOT_A_DIRECTORY      (-13)
     67#define GIET_FAT32_IS_DIRECTORY         (-14)
     68#define GIET_FAT32_DIRECTORY_NOT_EMPTY  (-15)
     69#define GIET_FAT32_MOVE_INTO_SUBDIR     (-16)
     70#define GIET_FAT32_FILE_EXISTS          (-17)
     71#define GIET_FAT32_NO_MORE_ENTRIES      (-18)
     72#define GIET_FAT32_BUFFER_TOO_SMALL     (-19)
     73
    4974#endif // _FAT32_SHARED
    5075
Note: See TracChangeset for help on using the changeset viewer.