Changeset 750 for soft


Ignore:
Timestamp:
Jan 2, 2016, 4:40:33 PM (8 years ago)
Author:
alain
Message:

Makes _fat_buffer_from_cache() an external function, to implement the giet_fat_mmap system call.

Location:
soft/giet_vm/giet_fat32
Files:
2 edited

Legend:

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

    r746 r750  
    4545#include <mmc_driver.h>
    4646#include <tty0.h>
     47#include <stdio.h>
    4748
    4849//////////////////////////////////////////////////////////////////////////////////
     
    112113                            unsigned int buf_vaddr,
    113114                            unsigned int count );
    114 
    115 //////////////////////////////////////////////////////////////////////////////////
    116 // The following function returns in the "desc" argument a pointer on a buffer
    117 // descriptor contained in a File_Cache, or in the Fat_Cache.
    118 // The searched buffer is idenfified by the "inode" and "cluster_id" arguments.
    119 // If the "inode" pointer is not NULL, the searched cache is a File-Cache.
    120 // If the "inode" pointer is NULL, the searched cache is the Fat-Cache,
    121 // The "cluster_id" argument is the buffer index in the file (or in the FAT).
    122 // In case of miss, it allocate a 4 Kbytes buffer and a cluster descriptor
    123 // from the local kernel heap, and calls the _fat_ioc_access() function to load
    124 // the missing cluster from the block device.
    125 // It returns 0 on success.
    126 // It returns 1 on error.
    127 //////////////////////////////////////////////////////////////////////////////////
    128 
    129 static unsigned int _get_buffer_from_cache( fat_inode_t*        inode,
    130                                             unsigned int        cluster_id,
    131                                             fat_cache_desc_t**  desc );
    132115
    133116////////////////////////////////////////////////////////////////////////////////
     
    963946
    964947
    965 //////////////////////////////////////////////////////////////////////
    966 static unsigned int _get_buffer_from_cache( fat_inode_t*        inode,
    967                                             unsigned int        cluster_id,
    968                                             fat_cache_desc_t**  desc )
    969 {
    970     // get cache pointer and levels
    971     fat_cache_node_t*   node;         // pointer on a 64-tree node
    972     unsigned int        level;        // cache level
    973 
    974     if ( inode == NULL )   // searched cache is the Fat-Cache
    975     {
    976         node   = _fat.fat_cache_root;
    977         level  = _fat.fat_cache_levels;
    978 
    979 #if (GIET_DEBUG_FAT & 1)
    980 if ( _get_proctime() > GIET_DEBUG_FAT )
    981 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): enters in FAT-Cache"
    982         " for cluster_id = %d\n", cluster_id );
    983 #endif
    984     }
    985     else                   // searched cache is a File-Cache
    986     {
    987         // add cache levels if needed
    988         while ( _get_levels_from_size( (cluster_id + 1) * 4096 ) > inode->levels )
    989         {
    990 #if (GIET_DEBUG_FAT & 1)
    991 if ( _get_proctime() > GIET_DEBUG_FAT )
    992 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): adding a File-Cache level\n" );
    993 #endif
    994 
    995             inode->cache = _allocate_one_cache_node( inode->cache );
    996             inode->levels++;
    997         }
    998 
    999         node   = inode->cache;
    1000         level  = inode->levels;
    1001 
    1002 #if (GIET_DEBUG_FAT & 1)
    1003 if ( _get_proctime() > GIET_DEBUG_FAT )
    1004 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): enters in File-Cache <%s>"
    1005         " for cluster_id = %d\n", inode->name , cluster_id );
    1006 #endif
    1007     }
    1008 
    1009     // search the 64-tree cache from top to bottom
    1010     while ( level )
    1011     {
    1012         // compute child index at each level
    1013         unsigned int index = (cluster_id >> (6*(level-1))) & 0x3F;
    1014 
    1015         if ( level == 1 )        // last level => children are cluster descriptors
    1016         {
    1017             fat_cache_desc_t* pdesc = (fat_cache_desc_t*)node->children[index];
    1018 
    1019             if ( pdesc == NULL )      // miss
    1020             {
    1021                 // get missing cluster index lba
    1022                 unsigned int lba;
    1023                 unsigned int next;
    1024                 unsigned int current = inode->cluster;
    1025                 unsigned int count   = cluster_id;
    1026 
    1027                 if ( inode == NULL )      // searched cache is the Fat-Cache
    1028                 {
    1029 
    1030 #if (GIET_DEBUG_FAT & 1)
    1031 if ( _get_proctime() > GIET_DEBUG_FAT )
    1032 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): miss in FAT-Cache for cluster_id %d\n",
    1033         cluster_id );
    1034 #endif
    1035                     lba = _fat.fat_lba + (cluster_id << 3);
    1036                 }
    1037                 else                      // searched cache is a File-Cache
    1038                 {
    1039 
    1040 #if (GIET_DEBUG_FAT & 1)
    1041 if ( _get_proctime() > GIET_DEBUG_FAT )
    1042 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): miss in File-Cache <%s> "
    1043         "for cluster_id %d\n", inode->name, cluster_id );
    1044 #endif
    1045                     while ( count )
    1046                     {
    1047                         if ( _get_fat_entry( current , &next ) ) return 1;
    1048                         current = next;
    1049                         count--;
    1050                     }
    1051                     lba = _cluster_to_lba( current );
    1052                 }
    1053 
    1054                 // allocate 4K buffer
    1055                 void* buf = _malloc( 4096 );
    1056 
    1057                 // load one cluster (8 blocks) from block device
    1058                 if ( _fat_ioc_access( 1,         // descheduling
    1059                                       1,         // to memory
    1060                                       lba,
    1061                                       (unsigned int)buf,
    1062                                       8 ) )
    1063                 {
    1064                     _free( buf );
    1065                     _printf("\n[FAT ERROR] _get_buffer_from_cache()"
    1066                             ": cannot access block device for lba = %x\n", lba );
    1067                     return 1;
    1068                 }
    1069 
    1070                 // allocate buffer descriptor
    1071                 pdesc          = _malloc( sizeof(fat_cache_desc_t) );
    1072                 pdesc->lba     = lba;
    1073                 pdesc->buffer  = buf;
    1074                 pdesc->dirty   = 0;
    1075                 node->children[index] = pdesc;
    1076 
    1077 #if (GIET_DEBUG_FAT & 1)
    1078 if ( _get_proctime() > GIET_DEBUG_FAT )
    1079 _printf("\n[DEBUG FAT] _get_buffer_from_cache(): buffer loaded from device"
    1080         " at vaddr = %x\n", (unsigned int)buf );
    1081 #endif
    1082             }
    1083 
    1084             // return pdesc pointer
    1085             *desc = pdesc;
    1086 
    1087             // prepare next iteration
    1088             level--;
    1089         }
    1090         else                      // not last level => children are 64-tree nodes
    1091         {
    1092             fat_cache_node_t* child = (fat_cache_node_t*)node->children[index];
    1093             if ( child == NULL )  // miss
    1094             {
    1095                 // allocate a cache node if miss
    1096                 child = _allocate_one_cache_node( NULL );
    1097                 node->children[index] = child;   
    1098             }
    1099 
    1100             // prepare next iteration
    1101             node = child;
    1102             level--;
    1103         }
    1104     } // end while
    1105 
    1106     return 0;
    1107 }  // end _get_buffer_from_cache()
    1108 
    1109948
    1110949
     
    11701009    fat_cache_desc_t*  pdesc;
    11711010    unsigned int*      buffer;
    1172     if ( _get_buffer_from_cache( NULL,               // Fat-Cache
     1011    if ( _fat_buffer_from_cache( NULL,               // Fat-Cache
    11731012                                 cluster_id,
    11741013                                 &pdesc ) ) return 1;
     
    11951034    fat_cache_desc_t*  pdesc;
    11961035    unsigned int*      buffer;
    1197     if ( _get_buffer_from_cache( NULL,               // Fat-Cache
     1036    if ( _fat_buffer_from_cache( NULL,               // Fat-Cache
    11981037                                 cluster_id,
    11991038                                 &pdesc ) )  return 1;           
     
    16791518    {
    16801519        // get one 4 Kytes buffer from File_Cache 
    1681         if ( _get_buffer_from_cache( inode,
     1520        if ( _fat_buffer_from_cache( inode,
    16821521                                     cluster_id,
    16831522                                     &pdesc ) )   return 1;
     
    17611600    {
    17621601        // get one 4 Kytes buffer from File_Cache 
    1763         if ( _get_buffer_from_cache( parent,
     1602        if ( _fat_buffer_from_cache( parent,
    17641603                                     cluster_id,
    17651604                                     &pdesc ) )   return 1;
     
    18191658        if ( offset >= 4096 )  // new buffer required
    18201659        {
    1821             if ( _get_buffer_from_cache( parent,
     1660            if ( _fat_buffer_from_cache( parent,
    18221661                                         cluster_id + 1,
    18231662                                         &pdesc ) )      return 1;
     
    19931832    fat_cache_desc_t*  pdesc;
    19941833
    1995     if ( _get_buffer_from_cache( inode->parent,
     1834    if ( _fat_buffer_from_cache( inode->parent,
    19961835                                 cluster_id,
    19971836                                 &pdesc ) ) return 1;
     
    20101849                break;
    20111850
    2012             if ( _get_buffer_from_cache( inode->parent,
     1851            if ( _fat_buffer_from_cache( inode->parent,
    20131852                                         cluster_id - 1,
    20141853                                         &pdesc ) )   return 1;
     
    20461885    unsigned int       offset     = (inode->dentry & 0x7F)<<5;
    20471886
    2048     if ( _get_buffer_from_cache( inode->parent,
     1887    if ( _fat_buffer_from_cache( inode->parent,
    20491888                                 cluster_id,
    20501889                                 &pdesc ) )    return 1;
     
    21311970        // get one 4 Kytes buffer from parent File_Cache 
    21321971        fat_cache_desc_t*  pdesc;
    2133         if ( _get_buffer_from_cache( parent,
     1972        if ( _fat_buffer_from_cache( parent,
    21341973                                     cluster_id,
    21351974                                     &pdesc ) )    return 2;
     
    21481987            ord  = _read_entry( LDIR_ORD , buffer + offset , 0 );
    21491988
    2150             if (ord == NO_MORE_ENTRY)                 // no more entry in directory => break
     1989            if (ord == NO_MORE_ENTRY)                 // no more entry => break
    21511990            {
    21521991                found = -1;
     
    31873026
    31883027
    3189 /////////////////////////////////////////////////////////////////////////////////
    3190 // The following function implements the "giet_fat_read()" system call,
    3191 // but can also be used by the kernel in physical addressing mode.
     3028///////////////////////////////////////////////////////////////////////////////////
     3029// The following function implements the "giet_fat_read()" and "giet_fat_pread')"
     3030// system calls, but can also be used by the kernel in physical addressing mode.
    31923031// It transfers <count> bytes from the File_Cache associated to the file
    31933032// identified by <fd_id>, to the destination buffer defined by <vaddr>.
     
    31963035// the physical  address is computed as extend[15:0] | vaddr[31:0]
    31973036// In case of miss in the File_Cache, it loads all involved clusters into cache.
    3198 /////////////////////////////////////////////////////////////////////////////////
     3037///////////////////////////////////////////////////////////////////////////////////
    31993038// Returns the number of bytes actually transfered on success.
    32003039// Returns a negative value on error:
     
    32073046               unsigned int vaddr,          // destination buffer vaddr
    32083047               unsigned int count,          // number of bytes to read
    3209                unsigned int extend )        // physical address extension
     3048               unsigned int extend,         // physical address extension
     3049               unsigned int offset,         // forced file offset
     3050               unsigned int modes )         // special modes
    32103051{
    32113052
     
    32173058if ( _get_proctime() > GIET_DEBUG_FAT )
    32183059_printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] enters at cycle %d\n"
    3219         "  fd = %d / vaddr = %x / bytes = %x / extend = %x\n",
     3060        "  fd = %d / vaddr = %x / bytes = %x / extend = %x / forced_offset = %x\n",
    32203061        x , y , p , _get_proctime(),
    3221         fd_id , vaddr , count , extend );
     3062        fd_id , vaddr , count , extend , offset );
    32223063#endif
    32233064
     
    32253066    if( _fat.initialized != FAT_INITIALIZED )
    32263067    {
    3227         _printf("\n[FAT ERROR] _fat_read(): FAT not initialized\n");
     3068        _printf("\n[FAT ERROR] in _fat_read(): FAT not initialized\n");
    32283069        return GIET_FAT32_NOT_INITIALIZED;
    32293070    }
     
    32323073    if ( fd_id >= GIET_OPEN_FILES_MAX )
    32333074    {
    3234         _printf("\n[FAT ERROR] _fat_read(): illegal file descriptor\n");
     3075        _printf("\n[FAT ERROR] in _fat_read(): illegal file descriptor\n");
    32353076        return GIET_FAT32_INVALID_FD;
    32363077    }
    32373078
    3238     // check file is open
     3079    // check file open
    32393080    if ( _fat.fd[fd_id].allocated == 0 )
    32403081    {
    3241         _printf("\n[FAT ERROR] _fat_read(): file not open\n");
     3082        _printf("\n[FAT ERROR] in _fat_read(): file not open\n");
    32423083        return GIET_FAT32_NOT_OPEN;
    32433084    }
     
    32493090    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
    32503091           
     3092    // get special modes
     3093    unsigned int physical_addressing = modes & FAT_PADDR_MODE;
     3094    unsigned int forced_offset       = modes & FAT_FORCED_OFFSET;
     3095
    32513096    // get file inode pointer and offset
    32523097    fat_inode_t* inode  = _fat.fd[fd_id].inode;
    3253     unsigned int seek   = _fat.fd[fd_id].seek;
     3098    unsigned int seek   = forced_offset ? offset : _fat.fd[fd_id].seek;
    32543099
    32553100    // check seek versus file size
     
    32593104        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    32603105
    3261         _printf("\n[FAT ERROR] _fat_read(): seek larger than file size"
     3106        _printf("\n[FAT ERROR] in _fat_read(): offset larger than file size"
    32623107                " / seek = %x / file_size = %x\n",
    32633108                seek , inode->size );
     
    32933138        unsigned char*     cbuf;
    32943139        fat_cache_desc_t*  pdesc;
    3295         if ( _get_buffer_from_cache( inode,
     3140        if ( _fat_buffer_from_cache( inode,
    32963141                                     cluster_id,
    32973142                                     &pdesc ) )
     
    33003145            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    33013146
    3302             _printf("\n[FAT ERROR] _fat_read(): cannot load file <%s>\n",
     3147            _printf("\n[FAT ERROR] in _fat_read(): cannot load file <%s>\n",
    33033148                    inode->name );
    33043149            return GIET_FAT32_IO_ERROR;
     
    33383183
    33393184        // move data
    3340         if ( (extend & 0xFFFF0000) == 0 )         // no physical addressing
     3185        if ( physical_addressing == 0 )           // no physical addressing
    33413186        {
    33423187            char* dest = (char*)(vaddr + done);
     
    33463191        {
    33473192            unsigned int flags;
    3348             paddr_t pdest    = (((paddr_t)(extend & 0x0000FFFF))<<32) + vaddr + done;
     3193            paddr_t pdest    = (((paddr_t)extend)<<32) + vaddr + done;
    33493194            paddr_t psource  = _v2p_translate( (unsigned int)source, &flags );
    33503195            _physical_memcpy( pdest , psource , nbytes );
     
    33603205#endif
    33613206
    3362     // update seek
    3363     _fat.fd[fd_id].seek += done;
     3207    // update seek if required
     3208    if ( forced_offset == 0 ) _fat.fd[fd_id].seek += done;
    33643209
    33653210    // release lock
     
    33793224// identified by <fd_id>, from the source buffer defined by <vaddr>.
    33803225// It uses the current file offset defined in the file descriptor.
    3381 // If the <extend> 16 MSB bits are non zero, it uses physical addressing:
    3382 // the physical  address is computed as extend[15:0] | vaddr[31:0]
     3226// If required by the <modes> argument, the physical  address is computed
     3227// as extend[15:0] | vaddr[31:0]
    33833228// It increases the file size and allocate new clusters if (count + offset)
    33843229// is larger than the current file size. Then it loads and updates all
     
    33973242                unsigned int vaddr,    // source buffer vaddr
    33983243                unsigned int count,    // number of bytes to write
    3399                 unsigned int extend )  // physical address extension
     3244                unsigned int extend,   // physical address extension
     3245                unsigned int modes )   // special modes
    34003246{
    34013247    // checking FAT initialized
     
    34433289        return GIET_FAT32_READ_ONLY;
    34443290    }
     3291
     3292    // get special modes
     3293    unsigned int physical_addressing = modes & FAT_PADDR_MODE;
    34453294
    34463295    // get file inode pointer and seek
     
    35443393        unsigned char*     cbuf;
    35453394        fat_cache_desc_t*  pdesc;
    3546         if ( _get_buffer_from_cache( inode,   
     3395        if ( _fat_buffer_from_cache( inode,   
    35473396                                     cluster_id, 
    35483397                                     &pdesc ) )   
     
    35903439
    35913440        // move data
    3592         if ( (extend & 0xFFFF0000) == 0 )     // no physical addressing
     3441        if ( physical_addressing == 0 )     // no physical addressing
    35933442        {
    35943443            char* source = (char*)(vaddr + done);
     
    35983447        {
    35993448            unsigned int flags;
    3600             paddr_t      psource = (((paddr_t)(extend & 0x0000FFFF))<<32) + vaddr + done;
     3449            paddr_t      psource = (((paddr_t)extend)<<32) + vaddr + done;
    36013450            paddr_t      pdest   = _v2p_translate( (unsigned int)dest , &flags );
    36023451            _physical_memcpy( pdest , psource , nbytes );
     
    44374286    else if ( !info.is_dir )
    44384287    {
    4439         _printf("\n[FAT ERROR] _fat_readdir(): not a directory\n" );
     4288        _printf("\n[FAT ERROR] in _fat_readdir(): not a directory\n" );
    44404289        return GIET_FAT32_NOT_A_DIRECTORY;
    44414290    }
     
    44544303    while ( 1 )
    44554304    {
    4456         if ( _fat_read( fd_id, (unsigned int)&buf, sizeof(buf), 0 ) != sizeof(buf) )
    4457         {
    4458             _printf("\n[FAT ERROR] _fat_readdir(): can't read entry\n" );
     4305        if ( _fat_read( fd_id,
     4306                        (unsigned int)&buf,
     4307                        DIR_ENTRY_SIZE,
     4308                        0, 0, 0 )  != sizeof(buf) )
     4309        {
     4310            _printf("\n[FAT ERROR] in _fat_readdir(): can't read entry\n" );
    44594311            return GIET_FAT32_IO_ERROR;
    44604312        }
     
    45164368
    45174369    return GIET_FAT32_OK;
    4518 }
     4370}  // end _fat_readdir()
    45194371
    45204372
     
    46274479
    46284480
     4481//////////////////////////////////////////////////////////////////////////////////
     4482// The following function returns in the "desc" argument a pointer on a buffer
     4483// descriptor contained in a File_Cache, or in the Fat_Cache.
     4484// The searched buffer is idenfified by the "inode" and "cluster_id" arguments.
     4485// If the "inode" pointer is not NULL, the searched cache is a File-Cache.
     4486// If the "inode" pointer is NULL, the searched cache is the Fat-Cache,
     4487// The "cluster_id" argument is the buffer index in the file (or in the FAT).
     4488// In case of miss, it allocate a 4 Kbytes buffer and a cluster descriptor
     4489// from the local kernel heap, and calls the _fat_ioc_access() function to load
     4490// the missing cluster from the block device.
     4491//////////////////////////////////////////////////////////////////////////////////
     4492// It returns 0 on success.
     4493// It returns 1 on error.
     4494//////////////////////////////////////////////////////////////////////////////////
     4495int _fat_buffer_from_cache( fat_inode_t*        inode,
     4496                            unsigned int        cluster,
     4497                            fat_cache_desc_t**  desc )
     4498{
     4499    // get cache pointer and levels
     4500    fat_cache_node_t*   node;         // pointer on a 64-tree node
     4501    unsigned int        level;        // cache level
     4502
     4503    if ( inode == NULL )   // searched cache is the Fat-Cache
     4504    {
     4505        node   = _fat.fat_cache_root;
     4506        level  = _fat.fat_cache_levels;
     4507
     4508#if (GIET_DEBUG_FAT & 1)
     4509if ( _get_proctime() > GIET_DEBUG_FAT )
     4510_printf("\n[DEBUG FAT] _fat_buffer_from_cache(): enters in FAT-Cache"
     4511        " for cluster = %d\n", cluster );
     4512#endif
     4513    }
     4514    else                   // searched cache is a File-Cache
     4515    {
     4516        // add cache levels if needed
     4517        while ( _get_levels_from_size( (cluster + 1) * 4096 ) > inode->levels )
     4518        {
     4519#if (GIET_DEBUG_FAT & 1)
     4520if ( _get_proctime() > GIET_DEBUG_FAT )
     4521_printf("\n[DEBUG FAT] _fat_buffer_from_cache(): adding a File-Cache level\n" );
     4522#endif
     4523
     4524            inode->cache = _allocate_one_cache_node( inode->cache );
     4525            inode->levels++;
     4526        }
     4527
     4528        node   = inode->cache;
     4529        level  = inode->levels;
     4530
     4531#if (GIET_DEBUG_FAT & 1)
     4532if ( _get_proctime() > GIET_DEBUG_FAT )
     4533_printf("\n[DEBUG FAT] _fat_buffer_from_cache(): enters in File-Cache <%s>"
     4534        " for cluster = %d\n", inode->name , cluster );
     4535#endif
     4536    }
     4537
     4538    // search the 64-tree cache from top to bottom
     4539    while ( level )
     4540    {
     4541        // compute child index at each level
     4542        unsigned int index = (cluster >> (6*(level-1))) & 0x3F;
     4543
     4544        if ( level == 1 )        // last level => children are cluster descriptors
     4545        {
     4546            fat_cache_desc_t* pdesc = (fat_cache_desc_t*)node->children[index];
     4547
     4548            if ( pdesc == NULL )      // miss
     4549            {
     4550                // get missing cluster index lba
     4551                unsigned int lba;
     4552                unsigned int next;
     4553                unsigned int current = inode->cluster;
     4554                unsigned int count   = cluster;
     4555
     4556                if ( inode == NULL )      // searched cache is the Fat-Cache
     4557                {
     4558
     4559#if (GIET_DEBUG_FAT & 1)
     4560if ( _get_proctime() > GIET_DEBUG_FAT )
     4561_printf("\n[DEBUG FAT] _fat_buffer_from_cache(): miss in FAT-Cache for cluster %d\n",
     4562        cluster );
     4563#endif
     4564                    lba = _fat.fat_lba + (cluster << 3);
     4565                }
     4566                else                      // searched cache is a File-Cache
     4567                {
     4568
     4569#if (GIET_DEBUG_FAT & 1)
     4570if ( _get_proctime() > GIET_DEBUG_FAT )
     4571_printf("\n[DEBUG FAT] _fat_buffer_from_cache(): miss in File-Cache <%s> "
     4572        "for cluster %d\n", inode->name, cluster );
     4573#endif
     4574                    while ( count )
     4575                    {
     4576                        if ( _get_fat_entry( current , &next ) ) return 1;
     4577                        current = next;
     4578                        count--;
     4579                    }
     4580                    lba = _cluster_to_lba( current );
     4581                }
     4582
     4583                // allocate a 4 Kbytes buffer in cluster running the calling thread
     4584                void* buf = _malloc( 4096 );
     4585
     4586                // load one cluster (8 blocks) from block device
     4587                if ( _fat_ioc_access( 1,         // descheduling
     4588                                      1,         // to memory
     4589                                      lba,
     4590                                      (unsigned int)buf,
     4591                                      8 ) )
     4592                {
     4593                    _free( buf );
     4594                    _printf("\n[FAT ERROR] _fat_buffer_from_cache()"
     4595                            ": cannot access block device for lba = %x\n", lba );
     4596                    return 1;
     4597                }
     4598
     4599                // allocate buffer descriptor
     4600                pdesc          = _malloc( sizeof(fat_cache_desc_t) );
     4601                pdesc->lba     = lba;
     4602                pdesc->buffer  = buf;
     4603                pdesc->dirty   = 0;
     4604                node->children[index] = pdesc;
     4605
     4606#if (GIET_DEBUG_FAT & 1)
     4607if ( _get_proctime() > GIET_DEBUG_FAT )
     4608_printf("\n[DEBUG FAT] _fat_buffer_from_cache(): buffer loaded from device"
     4609        " at vaddr = %x\n", (unsigned int)buf );
     4610#endif
     4611            }
     4612
     4613            // return pdesc pointer
     4614            *desc = pdesc;
     4615
     4616            // prepare next iteration
     4617            level--;
     4618        }
     4619        else                      // not last level => children are 64-tree nodes
     4620        {
     4621            fat_cache_node_t* child = (fat_cache_node_t*)node->children[index];
     4622            if ( child == NULL )  // miss
     4623            {
     4624                // allocate a cache node if miss
     4625                child = _allocate_one_cache_node( NULL );
     4626                node->children[index] = child;   
     4627            }
     4628
     4629            // prepare next iteration
     4630            node = child;
     4631            level--;
     4632        }
     4633    } // end while
     4634
     4635    return 0;
     4636}  // end _fat_buffer_from_cache()
     4637
     4638
     4639
     4640
    46294641// Local Variables:
    46304642// tab-width: 4
  • soft/giet_vm/giet_fat32/fat32.h

    r709 r750  
    127127
    128128#define FAT_INITIALIZED         0xBABEF00D
     129#define FAT_PADDR_MODE          0x00000001    // mask for physical address mode
     130#define FAT_FORCED_OFFSET       0X00000002    // mask for forced offset mode
    129131
    130132/********************************************************************************
     
    217219extern int _fat_init();         
    218220
    219 extern int _fat_open( char*        pathname,               // path from root
    220                       unsigned int flags );                // O_CREATE/O_RDONLY
    221 
    222 extern int _fat_close( unsigned int fd_id );               // file descriptor
    223 
    224 extern int _fat_file_info( unsigned int     fd_id,         // file descriptor
    225                            fat_file_info_t* info );        // file info struct
    226 
    227 extern int _fat_read( unsigned int fd_id,                  // file descriptor 
    228                       unsigned int vaddr,                  // destination buffer
    229                       unsigned int count,                  // number of bytes
    230                       unsigned int extend );               // physical addressing
    231 
    232 extern int _fat_write( unsigned int fd_id,                 // file descriptor
    233                        unsigned int vaddr,                         // source buffer
    234                        unsigned int count,                 // number of bytes
    235                        unsigned int extend );              // physical addressing
    236 
    237 extern int _fat_lseek( unsigned int fd_id,                 // file descriptor
    238                        unsigned int offset,                // new offset value
    239                        unsigned int whence );              // command type
    240 
    241 extern int _fat_remove( char*        pathname,             // path from root
    242                         unsigned int should_be_dir );      // for checking
    243 
    244 extern int _fat_rename( char*  old_path,                   // path from root
    245                         char*  new_path );                 // path from root
    246 
    247 extern int _fat_mkdir( char* pathname );                   // path from root
    248 
    249 extern int _fat_opendir( char* pathname );                 // path from root
    250 
    251 extern int _fat_closedir( unsigned int fd_id );            // file descriptor
    252 
    253 extern int _fat_readdir( unsigned int  fd_id,              // file descriptor
    254                          fat_dirent_t* entry );            // directory entry
    255 
    256 extern int _fat_load_no_cache( char*        pathname,      // path from root
    257                                unsigned int buffer_vbase,  // buffer base
    258                                unsigned int buffer_size ); // buffer size
     221extern int _fat_open( char*        pathname,                    // path from root
     222                      unsigned int flags );                     // O_CREATE/O_RDONLY
     223
     224extern int _fat_close( unsigned int fd_id );                    // file descriptor
     225
     226extern int _fat_file_info( unsigned int     fd_id,              // file descriptor
     227                           fat_file_info_t* info );             // file info struct
     228
     229extern int _fat_read( unsigned int fd_id,                       // file descriptor 
     230                      unsigned int vaddr,                       // destination buffer
     231                      unsigned int count,                       // number of bytes
     232                      unsigned int extend,                      // paddr extension
     233                      unsigned int offset,                      // forced offset
     234                      unsigned int modes );                     // special modes
     235
     236extern int _fat_write( unsigned int fd_id,                      // file descriptor
     237                       unsigned int vaddr,                              // source buffer
     238                       unsigned int count,                      // number of bytes
     239                       unsigned int extend,                     // paddr extension
     240                       unsigned int modes );                    // special modes
     241
     242extern int _fat_lseek( unsigned int fd_id,                      // file descriptor
     243                       unsigned int offset,                     // new offset value
     244                       unsigned int whence );                   // command type
     245
     246extern int _fat_remove( char*        pathname,                  // path from root
     247                        unsigned int should_be_dir );           // for checking
     248
     249extern int _fat_rename( char*  old_path,                        // path from root
     250                        char*  new_path );                      // path from root
     251
     252extern int _fat_mkdir( char* pathname );                        // path from root
     253
     254extern int _fat_opendir( char* pathname );                      // path from root
     255
     256extern int _fat_closedir( unsigned int fd_id );                 // file descriptor
     257
     258extern int _fat_readdir( unsigned int  fd_id,                   // file descriptor
     259                         fat_dirent_t* entry );                 // directory entry
     260
     261extern int _fat_load_no_cache( char*        pathname,           // path from root
     262                               unsigned int buffer_vbase,       // buffer base
     263                               unsigned int buffer_size );      // buffer size
     264
     265extern int _fat_buffer_from_cache( fat_inode_t*        inode,   // inode pointer
     266                                   unsigned int        cluster, // cluster index
     267                                   fat_cache_desc_t**  desc );  // buffer descriptor
    259268
    260269/*******************************************************************************/
Note: See TracChangeset for help on using the changeset viewer.