Changeset 598 for trunk/kernel/fs


Ignore:
Timestamp:
Nov 10, 2018, 3:06:00 PM (5 years ago)
Author:
alain
Message:

1) Modify the devfs_user_move() function to support large user buffer transfer to/from TXT device.
2) Cosmetic: Improve debug.

Location:
trunk/kernel/fs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/fs/devfs.c

    r568 r598  
    104104
    105105#if DEBUG_DEVFS_INIT
    106 uint32_t cycle = (uint32_t)hal_get_cycles();
    107 if( DEBUG_DEVFS_INIT < cycle )
    108 printk("\n[DBG] %s : thread %x in process %x created <dev> inode / cycle %d\n",
    109 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid ,cycle );
     106uint32_t   cycle = (uint32_t)hal_get_cycles();
     107thread_t * this  = CURRENT_THREAD;
     108if( DEBUG_DEVFS_INIT < cycle )
     109printk("\n[%s] thread[%x,%x] created <dev> inode / cycle %d\n",
     110__FUNCTION__, this->process->pid, this->trdid, cycle );
    110111#endif
    111112
     
    124125cycle = (uint32_t)hal_get_cycles();
    125126if( DEBUG_DEVFS_INIT < cycle )
    126 printk("\n[DBG] %s : thread %x in process %x created <external> inode / cycle %d\n",
    127 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid , cycle );
     127printk("\n[%s] thread[%x,%x] created <external> inode / cycle %d\n",
     128__FUNCTION__, this->process->pid, this->trdid, cycle );
    128129#endif
    129130
     
    152153                             devfs_internal_inode_xp );
    153154#if DEBUG_DEVFS_INIT
    154 uint32_t cycle = (uint32_t)hal_get_cycles();
    155 trdid_t  trdid = CURRENT_THREAD->trdid;
    156 pid_t    pid   = CURRENT_THREAD->process->pid;
    157 if( DEBUG_DEVFS_INIT < cycle )
    158 printk("\n[DBG] %s : thread %x in process %x created <%s> in cluster %x / cycle %d\n",
    159 __FUNCTION__, trdid, pid, node_name, local_cxy, cycle );
     155uint32_t   cycle = (uint32_t)hal_get_cycles();
     156thread_t * this  = CURRENT_THREAD;
     157if( DEBUG_DEVFS_INIT < cycle )
     158printk("\n[%s] thread[%x,%x] created <%s> inode in cluster %x / cycle %d\n",
     159__FUNCTION__, this->process->pid, this->trdid, node_name, local_cxy, cycle );
    160160#endif
    161161
     
    175175cycle = (uint32_t)hal_get_cycles();
    176176if( DEBUG_DEVFS_INIT < cycle )
    177 printk("\n[DBG] %s : thread %x in process %x created <mmc> inode in cluster %x\n",
    178 __FUNCTION__, trdid, pid, local_cxy, cycle );
     177printk("\n[%s] thread[%x,%x] created <mmc> inode in cluster %x\n",
     178__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
    179179#endif
    180180
     
    198198cycle = (uint32_t)hal_get_cycles();
    199199if( DEBUG_DEVFS_INIT < cycle )
    200 printk("\n[DBG] %s : thread %x in process %x created <dma[%d]> inode in cluster %x\n",
    201 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     200printk("\n[%s] thread [%x,%x] created <dma[%d]> inode in cluster %x\n",
     201__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    202202#endif
    203203        }
     
    222222cycle = (uint32_t)hal_get_cycles();
    223223if( DEBUG_DEVFS_INIT < cycle )
    224 printk("\n[DBG] %s : thread %x in process %x created <iob> inode in cluster %x\n",
    225 __FUNCTION__, trdid, pid, local_cxy, cycle );
     224printk("\n[%s] thread[%x,%x] created <iob> inode in cluster %x\n",
     225__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
    226226#endif
    227227        }
     
    246246cycle = (uint32_t)hal_get_cycles();
    247247if( DEBUG_DEVFS_INIT < cycle )
    248 printk("\n[DBG] %s : thread %x in process %x created <pic> inode in cluster %x\n",
    249 __FUNCTION__, trdid, pid, local_cxy, cycle );
     248printk("\n[%s] thread[%x,%x] created <pic> inode in cluster %x\n",
     249__FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle );
    250250#endif
    251251        }
     
    272272cycle = (uint32_t)hal_get_cycles();
    273273if( DEBUG_DEVFS_INIT < cycle )
    274 printk("\n[DBG] %s : thread %x in process %x created <txt_rx[%d]> inode in cluster %x\n",
    275 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     274printk("\n[%s] thread[%x,%x] created <txt_rx[%d]> inode in cluster %x\n",
     275__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    276276#endif
    277277            }
     
    299299cycle = (uint32_t)hal_get_cycles();
    300300if( DEBUG_DEVFS_INIT < cycle )
    301 printk("\n[DBG] %s : thread %x in process %x created <txt_tx[%d]> inode in cluster %x\n",
    302 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     301printk("\n[%s] thread[%x,%x] created <txt_tx[%d]> inode in cluster %x\n",
     302__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    303303#endif
    304304            }
     
    326326cycle = (uint32_t)hal_get_cycles();
    327327if( DEBUG_DEVFS_INIT < cycle )
    328 printk("\n[DBG] %s : thread %x in process %x created <ioc[%d]> inode in cluster %x\n",
    329 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     328printk("\n[%s] thread[%x,%x] created <ioc[%d]> inode in cluster %x\n",
     329__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    330330#endif
    331331            }
     
    353353cycle = (uint32_t)hal_get_cycles();
    354354if( DEBUG_DEVFS_INIT < cycle )
    355 printk("\n[DBG] %s : thread %x in process %x created <fbf[%d]> inode in cluster %x\n",
    356 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     355printk("\n[%s] thread[%x,%x] created <fbf[%d]> inode in cluster %x\n",
     356__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    357357#endif
    358358            }
     
    380380cycle = (uint32_t)hal_get_cycles();
    381381if( DEBUG_DEVFS_INIT < cycle )
    382 printk("\n[DBG] %s : thread %x in process %x created <nic_rx[%d]> inode in cluster %x\n",
    383 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     382printk("\n[%s] thread[%x,%x] created <nic_rx[%d]> inode in cluster %x\n",
     383__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    384384#endif
    385385            }
     
    407407cycle = (uint32_t)hal_get_cycles();
    408408if( DEBUG_DEVFS_INIT < cycle )
    409 printk("\n[DBG] %s : thread %x in process %x created <nic_tx[%d]> inode in cluster %x\n",
    410 __FUNCTION__, trdid, pid, channel, local_cxy, cycle );
     409printk("\n[%s] thread[%x,%x] created <nic_tx[%d]> inode in cluster %x\n",
     410__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    411411#endif
    412412            }
     
    418418int devfs_user_move( bool_t     to_buffer,
    419419                     xptr_t     file_xp,
    420                      void     * u_buf,
     420                     char     * u_buf,
    421421                     uint32_t   size )
    422422{
    423     assert( ( file_xp != XPTR_NULL ) , "file_xp == XPTR_NULL" );
    424 
    425     assert( ( size < CONFIG_TXT_KBUF_SIZE ) , "string size too large" );
    426 
    427     xptr_t             chdev_xp;
    428     cxy_t              chdev_cxy;
    429     chdev_t          * chdev_ptr;    // associated chdev type
    430     uint32_t           func;         // chdev functionnal type
    431     uint32_t           channel;      // chdev channel index
    432     error_t            error;
    433 
    434     char               k_buf[CONFIG_TXT_KBUF_SIZE];  // local kernel buffer
     423    xptr_t           chdev_xp;
     424    cxy_t            chdev_cxy;
     425    chdev_t        * chdev_ptr;                    // associated chdev type
     426    uint32_t         func;                         // chdev functionnal type
     427    uint32_t         channel;                      // chdev channel index
     428    uint32_t         burst;                        // number of bytes in a burst
     429    uint32_t         todo;                         // number of bytes not yet moved
     430    error_t          error;
     431    uint32_t         i;
     432
     433    char             k_buf[CONFIG_TXT_KBUF_SIZE];  // local kernel buffer
     434
     435assert( ( file_xp != XPTR_NULL ) , "file_xp == XPTR_NULL" );
    435436
    436437#if (DEBUG_SYS_READ & 1)
     
    443444
    444445#if DEBUG_DEVFS_MOVE
    445 uint32_t cycle = (uint32_t)hal_get_cycles();
     446uint32_t   cycle = (uint32_t)hal_get_cycles();
     447thread_t * this  = CURRENT_THREAD;
    446448if( DEBUG_DEVFS_MOVE < cycle )
    447 printk("\n[DBG] %s : thread %x enter / to_mem %d / cycle %d\n",
    448 __FUNCTION__ , CURRENT_THREAD , to_buffer , cycle );
     449printk("\n[%s] thread[%x,%x] enter / to_mem %d / cycle %d\n",
     450__FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle );
    449451#endif
    450452
     
    460462    channel = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    461463
    462     // action depends on "func" and "to_buffer"
    463     if( func == DEV_FUNC_TXT )
    464     {
    465         if( to_buffer )     // TXT read
    466         {
    467             uint32_t i;
    468             for( i = 0 ; i < size ; i++ )
     464assert( ( func == DEV_FUNC_TXT ) , __FUNCTION__, "illegal device func_type");
     465
     466    // initialise number of bytes to move
     467    todo = size;
     468
     469    /////////////// TXT read
     470    if( to_buffer )
     471    {
     472        while( todo )
     473        {
     474            // set burst size
     475            if( todo > CONFIG_TXT_KBUF_SIZE ) burst = CONFIG_TXT_KBUF_SIZE;
     476            else                              burst = todo;
     477
     478            // read burst bytes from TXT device to kernel buffer
     479            for( i = 0 ; i < burst ; i++ )
    469480            {
    470481                error = dev_txt_read( channel , &k_buf[i] );
    471482
    472                 if( error )
    473                 {
    474                     return -1;
    475                 }
    476                 else
    477                 {
    478                     hal_strcpy_to_uspace( u_buf , k_buf , size );
    479                 }
    480              }
     483                if( error )  return -1;
     484            }
     485
     486            // move burst bytes from k_buf to u_buf                   
     487            hal_strcpy_to_uspace( u_buf , k_buf , burst );
     488
     489            // update loop variables
     490            todo  -= burst;
     491            u_buf += burst;
     492        }
    481493
    482494#if DEBUG_DEVFS_MOVE
    483495cycle = (uint32_t)hal_get_cycles();
    484496if( DEBUG_DEVFS_MOVE < cycle )
    485 printk("\n[DBG] %s : thread %x exit / to_mem %d / cycle %d\n",
    486 __FUNCTION__ , CURRENT_THREAD , to_buffer / cycle );
     497printk("\n[%s] thread[%x,%x] exit / to_mem %d / cycle %d\n",
     498__FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle );
    487499#endif
    488500
     
    491503#endif
    492504            return size;
     505    }
     506    ///////////// TXT write 
     507    else               
     508    {
     509        while( todo )
     510        {
     511            // set burst size
     512            if( todo > CONFIG_TXT_KBUF_SIZE ) burst = CONFIG_TXT_KBUF_SIZE;
     513            else                              burst = todo;
     514
     515            // move burst bytes from u_buf to k_buf
     516            hal_strcpy_from_uspace( k_buf , u_buf , burst );
     517
     518            // write burst bytes from kernel buffer to TXT device
     519            error = dev_txt_write( channel , k_buf , burst );
     520
     521            if( error ) return -1;
     522
     523            // update loop variables
     524            todo  -= burst;
     525            u_buf += burst;
    493526        }
    494         else                // TXT write 
    495         {
    496             hal_strcpy_from_uspace( k_buf , u_buf , size );
    497 
    498             error = dev_txt_write( channel , k_buf , size );
    499             if( error )
    500             {
    501                 return -1;
    502             }
    503             else
    504             {
    505527
    506528#if DEBUG_DEVFS_MOVE
    507529cycle = (uint32_t)hal_get_cycles();
    508530if( DEBUG_DEVFS_MOVE < cycle )
    509 printk("\n[DBG] %s : thread %x exit / to_mem %d / cycle %d\n",
    510 __FUNCTION__ , CURRENT_THREAD , to_buffer / cycle );
     531printk("\n[%s] thread[%x,%x] exit / to_mem %d / cycle %d\n",
     532__FUNCTION__, this->process->pid, this->trdid, to_buffer, cycle );
    511533#endif
    512534
     
    514536exit_devfs_write = hal_time_stamp();
    515537#endif
    516                 return size;
    517             }
    518         }
    519     }
    520     else
    521     {
    522         assert( false , "%s does not support direct user access",
    523           chdev_func_str(func) );
    524 
    525         return -1;
     538            return size;
    526539    }
    527540
  • trunk/kernel/fs/devfs.h

    r568 r598  
    119119                       
    120120/******************************************************************************************
    121  * This function moves <size> bytes between a device, and a - possibly distributed -
    122  * user space <buffer>. It uses the <file_xp> and <to_buffer> arguments, to call the
    123  * relevant device access function.
    124  * It is called by the sys_read() and sys_write() functions.
    125  * The <size> argument cannot be larger than the CONFIG_TXT_KBUF_SIZE configuration
    126  * parameter, as this function makes a copy between the user space buffer, and a local
    127  * kernel buffer allocated in the kernel stack.
     121 * This function is called by the sys_read() and sys_write() functions.
     122 * It moves <size> bytes between a TXT device, and an user space <u_buf> buffer.
     123 * It uses the <file_xp> and <to_buffer> arguments, to call the relevant device function.
     124 * It uses a kernel buffer allocated in the calling thread kernel stack.
     125 * If the <size> argument is larger than CONFIG_TXT_KBUF_SIZE, the user buffer is split
     126 * in smaller chunks to be copied from the user buffer to this kernel buffer.
    128127 ******************************************************************************************
    129128 * @ to_buffer : device -> buffer if true / buffer -> device if false.
     
    135134int devfs_user_move( bool_t   to_buffer,
    136135                     xptr_t   file_xp,
    137                      void   * u_buf,
     136                     char   * u_buf,
    138137                     uint32_t size );
    139138
  • trunk/kernel/fs/vfs.c

    r568 r598  
    126126//////////////////////////////////////////////////////////////////////////////////////////
    127127
    128 static const char * vfs_inode_type_str( vfs_inode_type_t type )
    129 {
    130     switch ( type ) {
    131     case INODE_TYPE_FILE: return "FILE";
    132     case INODE_TYPE_DIR:  return "DIR ";
    133     case INODE_TYPE_FIFO: return "FIFO";
    134     case INODE_TYPE_PIPE: return "PIPE";
    135     case INODE_TYPE_SOCK: return "SOCK";
    136     case INODE_TYPE_DEV:  return "DEV ";
    137     case INODE_TYPE_SYML: return "SYML";
    138     default:              return "undefined";
     128const char * vfs_inode_type_str( vfs_inode_type_t type )
     129{
     130    switch ( type )
     131    {
     132        case INODE_TYPE_FILE: return "FILE";
     133        case INODE_TYPE_DIR:  return "DIR ";
     134        case INODE_TYPE_FIFO: return "FIFO";
     135        case INODE_TYPE_PIPE: return "PIPE";
     136        case INODE_TYPE_SOCK: return "SOCK";
     137        case INODE_TYPE_DEV:  return "DEV ";
     138        case INODE_TYPE_SYML: return "SYML";
     139        default:              return "undefined";
    139140    }
    140141}
     
    168169else                         strcpy( name , "/" );
    169170if( DEBUG_VFS_INODE_CREATE < cycle )
    170 printk("\n[DBG] %s : thread %x in process %x enter for <%s> / cycle %d\n",
    171 __FUNCTION__, this->trdid, this->process->pid, name, cycle );
     171printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n",
     172__FUNCTION__, this->process->pid, this->trdid, name, cycle );
    172173#endif
    173174 
     
    247248cycle      = (uint32_t)hal_get_cycles();
    248249if( DEBUG_VFS_INODE_CREATE < cycle )
    249 printk("\n[DBG] %s : thread %x in process %x exit for <%s> / inode [%x,%x] / cycle %d\n",
    250 __FUNCTION__, this->trdid, this->process->pid, name, local_cxy, inode, cycle );
     250printk("\n[%s] thread[%x,%x] exit for <%s> / inode [%x,%x] / cycle %d\n",
     251__FUNCTION__, this->process->pid, this->trdid, name, local_cxy, inode, cycle );
    251252#endif
    252253 
     
    284285uint32_t cycle = (uint32_t)hal_get_cycles();
    285286if( DEBUG_VFS_INODE_LOAD < cycle )
    286 printk("\n[DBG] %s : thread %x enter for <%s> / cycle %d\n",
     287printk("\n[%s] thread %x enter for <%s> / cycle %d\n",
    287288__FUNCTION__, CURRENT_THREAD , name , cycle );
    288289#endif
     
    318319cycle = (uint32_t)hal_get_cycles();
    319320if( DEBUG_VFS_INODE_LOAD < cycle )
    320 printk("\n[DBG] %s : thread %x exit for <%s> / cycle %d\n",
     321printk("\n[%s] thread %x exit for <%s> / cycle %d\n",
    321322__FUNCTION__, CURRENT_THREAD , name , cycle );
    322323#endif
     
    444445
    445446#if DEBUG_VFS_DENTRY_CREATE
     447thread_t * this = CURRENT_THREAD;
    446448uint32_t cycle = (uint32_t)hal_get_cycles();
    447449if( DEBUG_VFS_DENTRY_CREATE < cycle )
    448 printk("\n[DBG] %s : thread %x in process %x enter for <%s> / parent_inode %x / cycle %d\n",
    449 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, name, parent, cycle );
     450printk("\n[%s] thread[%x,%x] enter for <%s> / parent_inode %x / cycle %d\n",
     451__FUNCTION__, this->process->pid, this->trdid, name, parent, cycle );
    450452#endif
    451453
     
    483485cycle = (uint32_t)hal_get_cycles();
    484486if( DEBUG_VFS_DENTRY_CREATE < cycle )
    485 printk("\n[DBG] %s : thread %x in process %x / dentry <%s> initialised / cycle %d\n",
    486 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, dentry->name, cycle );
     487printk("\n[%s] thread[%x,%x] / dentry <%s> initialised / cycle %d\n",
     488__FUNCTION__, this->process->pid, this->trdid, dentry->name, cycle );
    487489#endif
    488490
     
    497499cycle = (uint32_t)hal_get_cycles();
    498500if( DEBUG_VFS_DENTRY_CREATE < cycle )
    499 printk("\n[DBG] %s : thread %x in process %x / dentry <%s> registered / cycle %d\n",
    500 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, dentry->name, cycle );
     501printk("\n[%s] thread[%x,%x] / dentry <%s> registered / cycle %d\n",
     502__FUNCTION__, this->process->pid, this->trdid, dentry->name, cycle );
    501503#endif
    502504
     
    507509cycle = (uint32_t)hal_get_cycles();
    508510if( DEBUG_VFS_DENTRY_CREATE < cycle )
    509 printk("\n[DBG] %s : thread %x in process %x exit for <%s> / dentry %x / cycle %d\n",
    510 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, name, dentry, cycle );
     511printk("\n[%s] thread[%x,%x] exit for <%s> / dentry %x / cycle %d\n",
     512__FUNCTION__, this->process->pid, this->trdid, name, dentry, cycle );
    511513#endif
    512514
     
    556558
    557559#if DEBUG_VFS_FILE_CREATE
     560thread_t * this = CURRENT_THREAD;
    558561uint32_t cycle = (uint32_t)hal_get_cycles();
    559562if( DEBUG_VFS_OPEN < cycle )
    560 printk("\n[DBG] %s : thread %x in process %x enter for inode %x in cluster %x / cycle %d\n",
    561 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, inode, local_cxy, cycle );
     563printk("\n[%s] thread[%x,%x] enter for inode %x in cluster %x / cycle %d\n",
     564__FUNCTION__, this->process->pid, this->trdid, inode, local_cxy, cycle );
    562565#endif
    563566
     
    587590cycle = (uint32_t)hal_get_cycles();
    588591if( DEBUG_VFS_OPEN < cycle )
    589 printk("\n[DBG] %s : thread %x in process %x created file %x in cluster %x / cycle %d\n",
    590 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, file, local_cxy, cycle );
     592printk("\n[%s] thread[%x,%x] created file %x in cluster %x / cycle %d\n",
     593__FUNCTION__, this->process->pid, this->trdid, file, local_cxy, cycle );
    591594#endif
    592595
     
    609612
    610613#if DEBUG_VFS_CLOSE
     614thread_t * this = CURRENT_THREAD;
    611615uint32_t cycle = (uint32_t)hal_get_cycles();
    612616if( DEBUG_VFS_CLOSE < cycle )
    613 printk("\n[DBG] %s : thread %x in process %x deleted file %x in cluster %x / cycle %d\n",
    614 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, file, local_cxy, cycle );
     617printk("\n[%s] thread[%x,%x] deleted file %x in cluster %x / cycle %d\n",
     618__FUNCTION__, this->process->pid, this->trdid, file, local_cxy, cycle );
    615619#endif
    616620
     
    665669
    666670#if DEBUG_VFS_OPEN
     671thread_t * this = CURRENT_THREAD;
    667672uint32_t cycle = (uint32_t)hal_get_cycles();
    668673if( DEBUG_VFS_OPEN < cycle )
    669 printk("\n[DBG] %s :  thread %x in process %x enter for <%s> / cycle %d\n",
    670 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, path, cycle );
     674printk("\n[%s]   thread[%x,%x] enter for <%s> / cycle %d\n",
     675__FUNCTION__, this->process->pid, this->trdid, path, cycle );
    671676#endif
    672677
     
    714719cycle = (uint32_t)hal_get_cycles();
    715720if( DEBUG_VFS_OPEN < cycle )
    716 printk("\n[DBG] %s :  thread %x in process %x exit for <%s> / fdid %d / cluster %x / cycle %d\n",
    717 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, path,
    718 file_id, GET_CXY( file_xp ), cycle );
     721printk("\n[%s]   thread[%x,%x] exit for <%s> / fdid %d / cluster %x / cycle %d\n",
     722__FUNCTION__, this->process->pid, this->trdid, path, file_id, GET_CXY( file_xp ), cycle );
    719723#endif
    720724
     
    928932uint32_t cycle = (uint32_t)hal_get_cycles();
    929933if( DEBUG_VFS_CLOSE < cycle )
    930 printk("\n[DBG] %s : thread %x in process %x enter / fdid %d / cycle %d\n",
    931 __FUNCTION__, this->trdid, process->pid, file_id, cycle );
     934printk("\n[%s] thread[%x,%x] enter / fdid %d / cycle %d\n",
     935__FUNCTION__, process->pid, this->trdid, file_id, cycle );
    932936#endif
    933937
     
    956960#if (DEBUG_VFS_CLOSE & 1 )
    957961if( DEBUG_VFS_CLOSE < cycle )
    958 printk("\n[DBG] %s : reset fd_array[%d] for process %x in cluster %x\n",
     962printk("\n[%s] reset fd_array[%d] for process %x in cluster %x\n",
    959963__FUNCTION__, file_id, process_ptr, process_cxy );
    960964#endif
     
    981985#if (DEBUG_VFS_CLOSE & 1)
    982986if( DEBUG_VFS_CLOSE < cycle )
    983 printk("\n[DBG] %s : thread %x in process %x reset all fd-array copies\n",
    984 __FUNCTION__, this->trdid, process->pid );
     987printk("\n[%s] thread[%x,%x] reset all fd-array copies\n",
     988__FUNCTION__, process->pid, this->trdid );
    985989#endif
    986990
     
    10031007cycle = (uint32_t)hal_get_cycles();
    10041008if( DEBUG_VFS_CLOSE < cycle )
    1005 printk("\n[DBG] %s : thread %x in process %x exit / fdid %d closed / cycle %d\n",
    1006 __FUNCTION__, this->trdid, process->pid, file_id, cycle );
     1009printk("\n[%s] thread[%x,%x] exit / fdid %d closed / cycle %d\n",
     1010__FUNCTION__, process->pid, this->trdid, file_id, cycle );
    10071011#endif
    10081012
     
    10201024}
    10211025
    1022 ////////////////////////////////////////
    1023 error_t vfs_stat( xptr_t        file_xp,
    1024                   struct stat * k_stat )
    1025 {
    1026     assert( false , "not implemented file_xp: %x, k_stat ptr %x\n",
    1027       file_xp, k_stat );
     1026//////////////////////////////////////
     1027error_t vfs_stat( xptr_t     inode_xp,
     1028                  stat_t   * st )
     1029{
     1030    // get cluster and local pointer on inode descriptor
     1031    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     1032    cxy_t         inode_cxy = GET_CXY( inode_xp );
     1033
     1034    // get relevant infos from inode descriptor
     1035    uint32_t inum   = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->inum   ) );
     1036    uint32_t size   = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->size   ) );
     1037    uint32_t uid    = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->uid    ) );
     1038    uint32_t gid    = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->gid    ) );
     1039    uint32_t type   = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type   ) );
     1040    uint32_t rights = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->rights ) );
     1041
     1042    // set stat structure fields
     1043    st->st_ino  = inum;
     1044    st->st_gid  = gid;
     1045    st->st_uid  = uid;
     1046    st->st_size = size;
     1047    st->st_mode = (type << 16) | rights;
     1048
     1049#if DEBUG_VFS_STAT
     1050uint32_t cycle  = (uint32_t)hal_get_cycles();
     1051thread_t * this = CURRENT_THREAD;
     1052if( DEBUG_VFS_STAT < cycle )
     1053printk("\n[%s] thread[%x,%x] set stat %x for inode %x in cluster %x / cycle %d\n"
     1054       " %s / inum %d / size %d\n",
     1055__FUNCTION__, this->process->pid, this->trdid, st, inode_ptr, inode_cxy, cycle,
     1056vfs_inode_type_str( type ), inum, size );
     1057#endif
     1058
    10281059    return 0;
    10291060}
     
    11551186    vfs_inode_t      * inode_ptr;
    11561187    vfs_inode_type_t   inode_type;
     1188    uint32_t           inode_size;
     1189    uint32_t           inode_inum;
     1190    uint32_t           inode_attr;
     1191    uint32_t           inode_dirty;
    11571192    xptr_t             children_xp;    // extended pointer on children xhtab
    11581193
     
    11621197    xptr_t             child_inode_xp;
    11631198    xptr_t             child_dentry_name_xp;
     1199    mapper_t         * mapper_ptr;
    11641200
    11651201    char               name[CONFIG_VFS_MAX_NAME_LENGTH];
     
    11821218                                        "                              " };  // level 15
    11831219
    1184     assert( (inode_xp != XPTR_NULL) , "inode_xp cannot be NULL\n" );
    1185     assert( (name_xp  != XPTR_NULL) , "name_xp cannot be NULL\n" );
    1186     assert( (indent < 16)           , "depth cannot be larger than 15\n" );
     1220assert( (inode_xp != XPTR_NULL) , "inode_xp cannot be NULL\n" );
     1221assert( (name_xp  != XPTR_NULL) , "name_xp cannot be NULL\n" );
     1222assert( (indent < 16)           , "depth cannot be larger than 15\n" );
    11871223   
    11881224    // get inode cluster and local pointer
     
    11901226    inode_ptr = GET_PTR( inode_xp );
    11911227
    1192     // get inode type
    1193     inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
    1194 
    1195     // get local pointer on associated mapper
    1196     mapper_t * mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     1228    // get inode type, size, attr, mapper, and inum
     1229    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type   ) );
     1230    inode_size = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->size   ) );
     1231    inode_inum = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->inum   ) );
     1232    inode_attr = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->attr   ) );
     1233    mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
    11971234
    11981235    // make a local copy of node name
    11991236    hal_remote_strcpy( XPTR( local_cxy , name ) , name_xp );
    12001237
     1238    // compute dirty
     1239    inode_dirty = ((inode_attr & INODE_ATTR_DIRTY) != 0);
     1240
    12011241    // display inode
    1202     nolock_printk("%s%s <%s> : inode = %x / mapper = %x / cluster %x\n",
     1242    nolock_printk("%s%s <%s> : inum %d / %d bytes / dirty %d / cxy %x (inode %x / mapper %x)\n",
    12031243                  indent_str[indent], vfs_inode_type_str( inode_type ), name,
    1204                   inode_ptr , mapper_ptr , inode_cxy );
     1244                  inode_inum, inode_size, inode_dirty, inode_cxy, inode_ptr, mapper_ptr );
    12051245
    12061246    // scan directory entries 
     
    14471487uint32_t cycle = (uint32_t)hal_get_cycles();
    14481488if( DEBUG_VFS_LOOKUP < cycle )
    1449 printk("\n[DBG] %s : thread %x in process %x enter for <%s> / cycle %d\n",
    1450 __FUNCTION__, this->trdid, process->pid, pathname, cycle );
     1489printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n",
     1490__FUNCTION__, process->pid, this->trdid, pathname, cycle );
    14511491#endif
    14521492
     
    14791519#if (DEBUG_VFS_LOOKUP & 1)
    14801520if( DEBUG_VFS_LOOKUP < cycle )
    1481 printk("\n[DBG] %s : look for <%s> / last = %d\n",
     1521printk("\n[%s] look for <%s> / last = %d\n",
    14821522__FUNCTION__ , name , last );
    14831523#endif
     
    14931533#if (DEBUG_VFS_LOOKUP & 1)
    14941534if( DEBUG_VFS_LOOKUP < cycle )
    1495 printk("\n[DBG] %s : miss <%s> node => try to create it\n",
     1535printk("\n[%s] miss <%s> node => try to create it\n",
    14961536__FUNCTION__ , name );
    14971537#endif
     
    15401580#if (DEBUG_VFS_LOOKUP & 1)
    15411581if( DEBUG_VFS_LOOKUP < cycle )
    1542 printk("\n[DBG] %s : missing <%s> inode speculatively created / cxy %x / ptr %x\n",
     1582printk("\n[%s] missing <%s> inode speculatively created / cxy %x / ptr %x\n",
    15431583__FUNCTION__ , name , child_cxy, child_ptr );
    15441584#endif
     
    15671607#if (DEBUG_VFS_LOOKUP & 1)
    15681608if( DEBUG_VFS_LOOKUP < cycle )
    1569 printk("\n[DBG] %s : created node <%s> in path %s / type DIR\n",
     1609printk("\n[%s] created node <%s> in path %s / type DIR\n",
    15701610__FUNCTION__ , name, pathname );
    15711611#endif
     
    15771617#if (DEBUG_VFS_LOOKUP & 1)
    15781618if( DEBUG_VFS_LOOKUP < cycle )
    1579 printk("\n[DBG] %s : created node <%s> in path %s / type FILE\n",
     1619printk("\n[%s] created node <%s> in path %s / type FILE\n",
    15801620__FUNCTION__ , name, pathname );
    15811621#endif
     
    16141654#if (DEBUG_VFS_LOOKUP & 1)
    16151655if( DEBUG_VFS_LOOKUP < cycle )
    1616 printk("\n[DBG] %s : load mapper from device for node <%s> in path %s\n",
     1656printk("\n[%s] load mapper from device for node <%s> in path %s\n",
    16171657__FUNCTION__ , name, pathname );
    16181658#endif
     
    16281668#if (DEBUG_VFS_LOOKUP & 1)
    16291669if( DEBUG_VFS_LOOKUP < cycle )
    1630 printk("\n[DBG] %s : found <%s> / inode %x in cluster %x\n",
     1670printk("\n[%s] found <%s> / inode %x in cluster %x\n",
    16311671__FUNCTION__ , name , GET_PTR(child_xp) , GET_CXY(child_xp) );
    16321672#endif
     
    16701710cycle = (uint32_t)hal_get_cycles();
    16711711if( DEBUG_VFS_LOOKUP < cycle )
    1672 printk("\n[DBG] %s : thread %x in process %x exit for <%s>\n"
     1712printk("\n[%s] thread[%x,%x] exit for <%s>\n"
    16731713"     parent %x in cluster %x / child %x in cluster %x / cycle %d\n",
    1674 __FUNCTION__ , this->trdid, process->pid, pathname,
     1714__FUNCTION__ , process->pid, this->trdid, pathname,
    16751715parent_ptr, parent_cxy, child_ptr, child_cxy, cycle );
    16761716#endif
     
    17771817thread_t * this = CURRENT_THREAD;
    17781818if( DEBUG_VFS_ADD_CHILD < cycle )
    1779 printk("\n[DBG] %s : thread %x in process %x enter for <%s>\n"
    1780 "      child_cxy = %x / parent_cxy = %x / cycle %d\n",
    1781 __FUNCTION__, this->trdid, this->process->pid, name,
     1819printk("\n[%s] thread[%x,%x] enter for <%s> / child_cxy %x / parent_cxy %x / cycle %d\n",
     1820__FUNCTION__, this->process->pid, this->trdid, name,
    17821821child_cxy, parent_cxy, (uint32_t)hal_get_cycles() );
    17831822#endif
     
    18101849#if(DEBUG_VFS_ADD_CHILD & 1)
    18111850if( DEBUG_VFS_ADD_CHILD < cycle )
    1812 printk("\n[DBG] %s : thread %x in process %x / dentry <%s> created in cluster %x\n",
    1813 __FUNCTION__, this->trdid, this->process->pid, name, parent_cxy );
     1851printk("\n[%s] thread[%x,%x] / dentry <%s> created in cluster %x\n",
     1852__FUNCTION__, this->process->pid, this->trdid, name, parent_cxy );
    18141853#endif
    18151854
     
    18601899#if(DEBUG_VFS_ADD_CHILD & 1)
    18611900if( DEBUG_VFS_ADD_CHILD < cycle )
    1862 printk("\n[DBG] %s : thread %x in process %x / inode <%s> created in cluster %x\n",
    1863 __FUNCTION__ , this->trdid, this->process->pid, name , child_cxy );
     1901printk("\n[%s] thread[%x,%x] / inode <%s> created in cluster %x\n",
     1902__FUNCTION__ , this->process->pid, this->trdid, name , child_cxy );
    18641903#endif
    18651904
     
    18721911cycle = (uint32_t)hal_get_cycles();
    18731912if( DEBUG_VFS_ADD_CHILD < cycle )
    1874 printk("\n[DBG] %s : thread %x in process %x exit for <%s> / cycle %d\n",
    1875 __FUNCTION__, this->trdid, this->process->pid, name, (uint32_t)hal_get_cycles() );
     1913printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n",
     1914__FUNCTION__, this->process->pid, this->trdid, name, (uint32_t)hal_get_cycles() );
    18761915#endif
    18771916
     
    19521991
    19531992#if DEBUG_VFS_MAPPER_MOVE
    1954 uint32_t cycle = (uint32_t)hal_get_cycles();
     1993uint32_t   cycle = (uint32_t)hal_get_cycles();
     1994thread_t * this  = CURRENT_THREAD;
    19551995if( DEBUG_VFS_MAPPER_MOVE < cycle )
    1956 printk("\n[DBG] %s : thread %x enter for page %d / mapper %x / inode %x / cycle %d\n",
    1957 __FUNCTION__, CURRENT_THREAD, page->index, mapper, mapper->inode, cycle );
     1996printk("\n[%s] thread[%x,%x] enter for page %d / mapper %x / inode %x / cycle %d\n",
     1997__FUNCTION__, this->process->pid, this->trdid, page->index, mapper, mapper->inode, cycle );
    19581998#endif
    19591999
     
    19892029cycle = (uint32_t)hal_get_cycles();
    19902030if( DEBUG_VFS_MAPPER_MOVE < cycle )
    1991 printk("\n[DBG] %s : thread %x exit for page %d / mapper %x / inode %x / cycle %d\n",
    1992 __FUNCTION__, CURRENT_THREAD, page->index, mapper, mapper->inode, cycle );
     2031printk("\n[%s] thread[%x,%x] exit for page %d / mapper %x / inode %x / cycle %d\n",
     2032__FUNCTION__, this->process->pid, this->trdid, page->index, mapper, mapper->inode, cycle );
    19932033#endif
    19942034
     
    20082048    uint32_t   size   = inode->size;
    20092049
    2010     assert( (mapper != NULL) , "mapper pointer is NULL\n" );
     2050assert( (mapper != NULL) , "mapper pointer is NULL\n" );
    20112051
    20122052#if DEBUG_VFS_MAPPER_LOAD
    2013 uint32_t cycle = (uint32_t)hal_get_cycles();
     2053uint32_t   cycle = (uint32_t)hal_get_cycles();
     2054thread_t * this  = CURRENT_THREAD;
    20142055if( DEBUG_VFS_MAPPER_MOVE < cycle )
    2015 printk("\n[DBG] %s : thread %x enter for inode %x in cluster %x / cycle %d\n",
    2016 __FUNCTION__, CURRENT_THREAD, inode, local_cxy, cycle );
     2056printk("\n[%s] thread[%x,%x] enter for inode %x in cluster %x / cycle %d\n",
     2057__FUNCTION__, this->process->pid, this->trdid, inode, local_cxy, cycle );
    20172058#endif
    20182059
     
    20342075cycle = (uint32_t)hal_get_cycles();
    20352076if( DEBUG_VFS_MAPPER_MOVE < cycle )
    2036 printk("\n[DBG] %s : thread %x exit for inode %x in cluster %x / cycle %d\n",
    2037 __FUNCTION__, CURRENT_THREAD, inode, local_cxy, cycle );
     2077printk("\n[%s] thread[%x,%x] exit for inode %x in cluster %x / cycle %d\n",
     2078__FUNCTION__, this->process->pid, this->trdid, inode, local_cxy, cycle );
    20382079#endif
    20392080
  • trunk/kernel/fs/vfs.h

    r568 r598  
    7676
    7777/******************************************************************************************
    78  * This define the masks for the POSIX access rights to inodes
    79  *****************************************************************************************/
    80 
    81 #define VFS_ISUID                0x0004000
    82 #define VFS_ISGID                0x0002000
    83 #define VFS_ISVTX                0x0001000
    84 
    85 #define VFS_IRWXU            0x0000700
    86 #define VFS_IRUSR            0x0000400
    87 #define VFS_IWUSR            0x0000200
    88 #define VFS_IXUSR            0x0000100
    89 
    90 #define VFS_IRWXG            0x0000070
    91 #define VFS_IRGRP            0x0000040
    92 #define VFS_IWGRP            0x0000020
    93 #define VFS_IXGRP            0x0000010
    94 
    95 #define VFS_IRWXO            0x0000007
    96 #define VFS_IROTH            0x0000004
    97 #define VFS_IWOTH            0x0000002
    98 #define VFS_IXOTH            0x0000001
    99 
    100 #define VFS_IREAD            VFS_IRUSR
    101 #define VFS_IWRITE           VFS_IWUSR
    102 #define VFS_IEXEC            VFS_IXUSR
    103 
    104 
    105 /******************************************************************************************
    10678 * This structure defines a VFS context, that contains informations common to all inodes
    10779 * and dentries for a given file system. As it is declared as a global variable in the
     
    155127
    156128/* this enum define the VFS inode types values */
     129/* WARNING : this enum must be kept consistent with macros in <shared_stat.h> file */
    157130
    158131typedef enum   
    159132{
    160     INODE_TYPE_FILE  =     0,           /*! file                                         */
     133    INODE_TYPE_FILE  =     0,           /*! regular file                                 */
    161134    INODE_TYPE_DIR   =     1,           /*! directory                                    */
    162135    INODE_TYPE_FIFO  =     2,           /*! POSIX named pipe                             */
    163136    INODE_TYPE_PIPE  =     3,           /*! POSIX anonymous pipe                         */
    164137    INODE_TYPE_SOCK  =     4,           /*! POSIX socket                                 */
    165     INODE_TYPE_DEV   =     5,           /*! device channel                               */
     138    INODE_TYPE_DEV   =     5,           /*! character device                             */
    166139    INODE_TYPE_SYML  =     6,           /*! symbolic link                                */
    167140}
     
    187160        uint32_t           size;             /*! number of bytes                             */
    188161        uint32_t           links;            /*! number of alias dentry                      */
    189         uid_t              uid;              /*! user owner identifier                       */
    190         gid_t              gid;              /*! group owner identifier                      */
     162        uint32_t           uid;              /*! user owner identifier                       */
     163        uint32_t           gid;              /*! group owner identifier                      */
    191164    uint32_t           rights;           /*! access rights                               */
    192165        uint32_t               refcount;         /*! reference counter (all pointers)            */
     
    201174}
    202175vfs_inode_t;
     176
     177/* This define the masks for the inode <rights> field  */
     178
     179#define VFS_ISUID          0x0004000
     180#define VFS_ISGID          0x0002000
     181#define VFS_ISVTX          0x0001000
     182
     183#define VFS_IRWXU      0x0000700
     184#define VFS_IRUSR      0x0000400
     185#define VFS_IWUSR      0x0000200
     186#define VFS_IXUSR      0x0000100
     187
     188#define VFS_IRWXG      0x0000070
     189#define VFS_IRGRP      0x0000040
     190#define VFS_IWGRP      0x0000020
     191#define VFS_IXGRP      0x0000010
     192
     193#define VFS_IRWXO      0x0000007
     194#define VFS_IROTH      0x0000004
     195#define VFS_IWOTH      0x0000002
     196#define VFS_IXOTH      0x0000001
    203197
    204198/******************************************************************************************
     
    514508/******************* Inode-Tree related functions ****************************************/
    515509/*****************************************************************************************/
     510
     511/******************************************************************************************
     512 * This function returns a printable string for the inode type.
     513 *****************************************************************************************/
     514const char * vfs_inode_type_str( vfs_inode_type_t type );
    516515
    517516/******************************************************************************************
     
    712711
    713712/******************************************************************************************
    714  * This function returns, in the structure pointed by the <k_stat> kernel pointer,
    715  * various informations on the file descriptor identified by the <file_xp> argument.
    716  * TODO not implemented yet...
    717  ******************************************************************************************
    718  * @ file_xp    : extended pointer on the file descriptor of the searched directory .
    719  * @ k_stat     : local pointer on the stat structure in kernel space.
     713 * This function returns, in the structure pointed by the <st> pointer,
     714 * various informations on the inode identified by the <inode_xp> argument.
     715 * TODO : only partially implemented yet...
     716 ******************************************************************************************
     717 * @ inode_xp   : extended pointer on the remote inode.
     718 * @ st         : local pointer on the stat structure in kernel space.
    720719 * @ returns 0 if success / -1 if error.
    721720 *****************************************************************************************/
    722 error_t vfs_stat( xptr_t        file_xp,
    723                   struct stat * k_stat );
     721error_t vfs_stat( xptr_t        inode_xp,
     722                  struct stat * st );
    724723
    725724/******************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.