Changeset 407 for trunk/kernel/fs/vfs.c


Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (5 years ago)
Author:
alain
Message:

First implementation of fork/exec.

Location:
trunk/kernel/fs
Files:
1 copied
1 moved

Legend:

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

    r406 r407  
    156156    error_t            error;
    157157
    158     vfs_dmsg("\n[INFO] %s : core[%x,%d] enter / dentry_xp = %l\n",
    159     __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , dentry_xp );
     158vfs_dmsg("\n[DBG] %s : core[%x,%d] enter / dentry = %x in cluster %x\n",
     159__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, GET_PTR(dentry_xp), GET_CXY(dentry_xp) );
    160160 
    161161    // check fs type and get pointer on context
     
    229229    remote_spinlock_init( XPTR( local_cxy , &inode->main_lock ) );
    230230
    231     vfs_dmsg("\n[INFO] %s : core[%x,%d] exit / inode_xp = %l / dentry_xp = %l\n",
    232     __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, XPTR(local_cxy,inode), dentry_xp );
     231vfs_dmsg("\n[DBG] %s : core[%x,%d] exit / inode = %x in cluster %x\n",
     232__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, inode , local_cxy );
    233233 
    234234    // return extended pointer on inode
     
    262262                        xptr_t        child_xp )
    263263{
    264     vfs_dmsg("\n[INFO] %s : core[%x,%d] enter for <%s> / cycle %d\n",
    265     __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , name , hal_time_stamp() );
     264vfs_dmsg("\n[DBG] %s : core[%x,%d] enter for <%s> / cycle %d\n",
     265__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , name , hal_time_stamp() );
    266266
    267267    error_t error = 0;
     
    292292    }
    293293
    294     vfs_dmsg("\n[INFO] %s : core[%x,%d] exit for <%s> / cycle %d\n",
    295     __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , name , hal_time_stamp() );
     294vfs_dmsg("\n[DBG] %s : core[%x,%d] exit for <%s> / cycle %d\n",
     295__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , name , hal_time_stamp() );
    296296
    297297    return error;
     
    413413
    414414    // display inode header
    415     printk("\n*** inode <%s> / inode_xp = %l / dentry_xp = %l ***\n",
    416            name , inode_xp , dentry_xp );
     415    printk("\n***** inode <%s> [%x in cluster %x]\n",
     416           name , GET_PTR(inode_xp) , GET_CXY(inode_xp) );
    417417
    418418    // display children from xhtab
     
    435435        kmem_req_t       req;        // request to kernel memory allocator
    436436
    437     vfs_dmsg("\n[INFO] %s : core[%x,%d] enter for <%s> / parent inode = %x / cycle %d\n",
    438     __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, name, parent, hal_time_stamp() );
     437vfs_dmsg("\n[DBG] %s : core[%x,%d] enter for <%s> / parent inode = %x / cycle %d\n",
     438__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, name, parent, hal_time_stamp() );
    439439
    440440    // get pointer on context
     
    484484    *dentry_xp = XPTR( local_cxy , dentry );
    485485
    486     vfs_dmsg("\n[INFO] %s : core[%x,%d] exit for <%s> / dentry = %l / cycle %d\n",
    487     __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, name, *dentry_xp, hal_time_stamp() );
     486vfs_dmsg("\n[DBG] %s : core[%x,%d] exit for <%s> / dentry = %x in cluster %x / cycle %d\n",
     487__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, name, dentry, local_cxy , hal_time_stamp() );
    488488
    489489    return 0;
     
    586586//////////////////////////////////////////////////////////////////////////////////////////
    587587
    588 ////////////////////////////////////
    589 error_t vfs_open( xptr_t     cwd_xp,
    590                           char     * path,
    591                           uint32_t   flags,
    592                   uint32_t   mode,
    593                           xptr_t   * new_file_xp,
    594                   uint32_t * new_file_id )
     588//////////////////////////////////////
     589error_t vfs_open( process_t * process,
     590                          char      * path,
     591                          uint32_t    flags,
     592                  uint32_t    mode,
     593                          xptr_t    * new_file_xp,
     594                  uint32_t  * new_file_id )
    595595{
    596596    error_t       error;
     
    603603    uint32_t      file_id;      // created file descriptor index in reference fd_array
    604604
    605     vfs_dmsg("\n[INFO] %s : core[%x,%d] enter for <%s> / cycle %d\n",
    606     __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path, (uint32_t)hal_time_stamp() );
     605vfs_dmsg("\n[DBG] %s : core[%x,%d] enter for <%s> / cycle %d\n",
     606__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path, (uint32_t)hal_time_stamp() );
    607607
    608608    // compute lookup working mode
     
    614614    // compute attributes for the created file
    615615    file_attr = 0;
    616     if( (flags & O_RDONLY ) == 0 )  file_attr |= FD_ATTR_READ_ENABLE;
    617     if( (flags & O_WRONLY ) == 0 )  file_attr |= FD_ATTR_WRITE_ENABLE;
     616    if( (flags & O_RDONLY ) == 0 )  file_attr |= FD_ATTR_WRITE_ENABLE;
     617    if( (flags & O_WRONLY ) == 0 )  file_attr |= FD_ATTR_READ_ENABLE;
    618618    if( (flags & O_SYNC   )      )  file_attr |= FD_ATTR_SYNC;
    619619    if( (flags & O_APPEND )      )  file_attr |= FD_ATTR_APPEND;
     
    621621
    622622    // get extended pointer on target inode
    623     error = vfs_lookup( cwd_xp , path , lookup_mode , &inode_xp );
     623    error = vfs_lookup( process->vfs_cwd_xp , path , lookup_mode , &inode_xp );
    624624
    625625    if( error ) return error;
     
    629629    inode_ptr = (vfs_inode_t *)GET_PTR( inode_xp );
    630630   
     631vfs_dmsg("\n[DBG] %s : core[%x,%d] found inode for <%s> in cluster %x / cycle %d\n",
     632__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path, inode_cxy , (uint32_t)hal_time_stamp() );
     633
    631634    // create a new file descriptor in cluster containing inode
    632635    if( inode_cxy == local_cxy )      // target cluster is local
     
    641644    if( error )  return error;
    642645
    643     // allocate and register a new file descriptor index in reference cluster fd_array
    644     error = process_fd_register( file_xp , &file_id );
     646    // allocate and register a new file descriptor index in reference process
     647    error = process_fd_register( process , file_xp , &file_id );
    645648
    646649    if( error ) return error;
    647650
    648     vfs_dmsg("\n[INFO] %s : core[%x,%d] exit for <%s> / file_xp = %l / cycle %d\n",
    649     __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path, file_xp, hal_time_stamp() );
     651vfs_dmsg("\n[DBG] %s : core[%x,%d] exit for <%s> / file = %x in cluster %x / cycle %d\n",
     652__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, path,
     653GET_PTR(file_xp), GET_CXY(file_xp), hal_time_stamp() );
    650654
    651655    // success
     
    656660}  // end vfs_open()
    657661
    658 ////////////////////////////////////////////
    659 error_t vfs_user_move( bool_t   to_buffer,
    660                        xptr_t   file_xp,
    661                        void   * buffer,
    662                        uint32_t size )
    663 {
    664     assert( ( file_xp != XPTR_NULL ) , __FUNCTION__ , "file_xp == XPTR_NULL" );
     662//////////////////////////////////////
     663int vfs_user_move( bool_t   to_buffer,
     664                   xptr_t   file_xp,
     665                   void   * buffer,
     666                   uint32_t size )
     667{
     668    assert( ( file_xp != XPTR_NULL ) , __FUNCTION__ ,
     669    "file_xp == XPTR_NULL" );
    665670
    666671    cxy_t              file_cxy;     // remote file descriptor cluster
     
    678683    inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type   ) );
    679684   
    680     // action depends on inode type
    681     if( inode_type == INODE_TYPE_FILE )
    682     {
    683         // get mapper pointer and file offset from file descriptor
    684         file_offset = hal_remote_lw( XPTR( file_cxy , &file_ptr->offset ) );
    685         mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
    686 
    687         // move data between mapper and buffer
    688         if( file_cxy == local_cxy )
    689         {
    690             error = mapper_move_user( mapper,
    691                                       to_buffer,
    692                                       file_offset,
    693                                       buffer,
    694                                       size );
    695         }
    696         else
    697         {
    698             rpc_mapper_move_buffer_client( file_cxy,
    699                                            mapper,
    700                                            to_buffer,
    701                                            true,          // user buffer
    702                                            file_offset,
    703                                            (uint64_t)(intptr_t)buffer,
    704                                            size,
    705                                            &error );
    706         }
    707 
    708         if( error ) return -1;
    709         else        return 0;
    710     }
    711     else
    712     {
    713         printk("\n[ERROR] in %s : inode is not a file", __FUNCTION__ );
    714         return -1;
    715     }
     685    assert( (inode_type == INODE_TYPE_FILE) , __FUNCTION__ ,
     686    "inode type is not INODE_TYPE_FILE" );
     687
     688    // get mapper pointer and file offset from file descriptor
     689    file_offset = hal_remote_lw( XPTR( file_cxy , &file_ptr->offset ) );
     690    mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
     691
     692    // move data between mapper and buffer
     693    if( file_cxy == local_cxy )
     694    {
     695        error = mapper_move_user( mapper,
     696                                  to_buffer,
     697                                  file_offset,
     698                                  buffer,
     699                                  size );
     700    }
     701    else
     702    {
     703        rpc_mapper_move_buffer_client( file_cxy,
     704                                       mapper,
     705                                       to_buffer,
     706                                       true,          // user buffer
     707                                       file_offset,
     708                                       (uint64_t)(intptr_t)buffer,
     709                                       size,
     710                                       &error );
     711    }
     712
     713    if( error ) return -1;
     714    else        return size;
     715
    716716}  // end vfs_user_move()
    717717
     
    905905    panic("not implemented");
    906906    return 0;
    907 }  // vfs_unlink()
    908 
    909 ///////////////////////////////////////
    910 error_t vfs_stat( xptr_t       file_xp,
    911                   vfs_stat_t * k_stat )
     907}
     908
     909////////////////////////////////////////
     910error_t vfs_stat( xptr_t        file_xp,
     911                  struct stat * k_stat )
    912912{
    913913    panic("not implemented");
     
    915915}
    916916
    917 ////////////////////////////////////////////
    918 error_t vfs_readdir( xptr_t         file_xp,
    919                      vfs_dirent_t * k_dirent )
     917/////////////////////////////////////////////
     918error_t vfs_readdir( xptr_t          file_xp,
     919                     struct dirent * k_dirent )
    920920{
    921921    panic("not implemented");
     
    10941094
    10951095    // display inode
    1096     nolock_printk("%s%s <%s> : inode = %l / mapper = %l / dentry = %l\n",
     1096    nolock_printk("%s%s <%s> : inode = %x / mapper = %x / cluster %x\n",
    10971097                  indent_str[indent], vfs_inode_type_str( inode_type ), name,
    1098                   inode_xp , XPTR( inode_cxy , mapper_ptr ) , dentry_xp );
     1098                  inode_ptr , mapper_ptr , inode_cxy );
    10991099
    11001100    // scan directory entries 
     
    11711171
    11721172    // get pointers on TXT0 chdev
    1173     xptr_t    txt0_xp  = chdev_dir.txt[0];
     1173    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
    11741174    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
    11751175    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
     
    13381338    process = this->process;
    13391339
    1340     vfs_dmsg("\n[INFO] %s : core[%x,%d] enter for <%s> / cycle %d\n",
    1341     __FUNCTION__ , local_cxy , this->core->lid , pathname , hal_time_stamp() );
     1340vfs_dmsg("\n[DBG] %s : core[%x,%d] enter for <%s> / cycle %d\n",
     1341__FUNCTION__ , local_cxy , this->core->lid , pathname , hal_time_stamp() );
    13421342
    13431343    // get extended pointer on first inode to search
     
    13621362        vfs_get_name_from_path( current , name , &next , &last );
    13631363
    1364         vfs_dmsg("\n[INFO] %s : core[%x,%d] look for <%s> / last = %d\n",
    1365         __FUNCTION__ , local_cxy , this->core->lid , name , last );
     1364vfs_dmsg("\n[DBG] %s : core[%x,%d] look for <%s> / last = %d\n",
     1365__FUNCTION__ , local_cxy , this->core->lid , name , last );
    13661366
    13671367        // search a child dentry matching name in parent inode
     
    13801380        if (found == false ) // child node not found in inode tree
    13811381        {
    1382             vfs_dmsg("\n[INFO] %s : core[%x,%d] miss <%s> => load it\n",
    1383             __FUNCTION__ , local_cxy , this->core->lid , name );
     1382
     1383vfs_dmsg("\n[DBG] %s : core[%x,%d] miss <%s> => load it\n",
     1384__FUNCTION__ , local_cxy , this->core->lid , name );
    13841385
    13851386            // release lock on parent inode
     
    14051406            if( error )
    14061407            {
    1407                 printk("\n[ERROR] in %s : no memory for inode %s in path %s\n",
     1408                printk("\n[ERROR] in %s : no memory for inode <%s> in path <%s>\n",
    14081409                __FUNCTION__ , name , pathname );
    14091410                return ENOMEM;
     
    14281429            if ( error )
    14291430            {
    1430                 printk("\n[ERROR] in %s : core[%x,%d] / <%s> not found in parent\n",
    1431                 __FUNCTION__ , local_cxy , this->core->lid , name );
     1431                printk("\n[ERROR] in %s : core[%x,%d] / <%s> node not found in <%s>\n",
     1432                __FUNCTION__ , local_cxy , this->core->lid , name , pathname );
    14321433                return ENOENT;
    14331434            }
     
    14641465            vfs_inode_lock( parent_xp );
    14651466
    1466             vfs_dmsg("\n[INFO] %s : core[%x,%d] created node <%s>\n",
    1467             __FUNCTION__ , local_cxy , this->core->lid , name );
     1467vfs_dmsg("\n[DBG] %s : core[%x,%d] created node <%s>\n",
     1468__FUNCTION__ , local_cxy , this->core->lid , name );
     1469
    14681470        }
    14691471
    1470         vfs_dmsg("\n[INFO] %s : core[%x,%d] found <%s> / parent = %l / child = %l\n",
    1471         __FUNCTION__ , local_cxy , this->core->lid , name , parent_xp , child_xp );
     1472vfs_dmsg("\n[DBG] %s : core[%x,%d] found <%s> / inode = %x in cluster %x\n",
     1473__FUNCTION__ , local_cxy , this->core->lid , name , GET_PTR(child_xp) , GET_CXY(child_xp) );
    14721474
    14731475        // TODO check access rights here [AG]
     
    14941496    vfs_inode_unlock( parent_xp );
    14951497
    1496     vfs_dmsg("\n[INFO] %s : exit <%s> found / inode = %l\n",
    1497                  __FUNCTION__ , pathname , child_xp );
     1498vfs_dmsg("\n[DBG] %s : core[%x,%d] exit for <%s> / inode = %x in cluster %x\n",
     1499__FUNCTION__,local_cxy,this->core->lid,pathname,GET_PTR(child_xp),GET_CXY(child_xp) );
    14981500
    14991501    // return searched pointer
     
    15931595    parent_ptr = (vfs_inode_t *)GET_PTR( parent_xp );
    15941596
    1595     vfs_dmsg("\n[INFO] %s : enter for <%s> / core[%x,%d] / child_cxy = %x / parent_xp = %l\n",
    1596     __FUNCTION__ , name , local_cxy , CURRENT_THREAD->core->lid , child_cxy , parent_xp );
     1597vfs_dmsg("\n[DBG] %s : core[%x,%d] enter for <%s> / child_cxy = %x / parent_cxy = %x\n",
     1598__FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , name , child_cxy , parent_cxy );
    15971599
    15981600    // 1. create dentry
     
    16041606                                   &dentry_xp );
    16051607
    1606         vfs_dmsg("\n[INFO] %s : dentry <%s> created in local cluster %x\n",
    1607         __FUNCTION__ , name , local_cxy );
     1608vfs_dmsg("\n[DBG] %s : dentry <%s> created in local cluster %x\n",
     1609__FUNCTION__ , name , local_cxy );
     1610
    16081611    }
    16091612    else                               // parent cluster is remote
     
    16161619                                      &error );
    16171620
    1618         vfs_dmsg("\n[INFO] %s : dentry <%s> created in remote cluster %x\n",
    1619         __FUNCTION__ , name , parent_cxy );
     1621vfs_dmsg("\n[DBG] %s : dentry <%s> created in remote cluster %x\n",
     1622__FUNCTION__ , name , parent_cxy );
     1623
    16201624    }
    16211625                                     
     
    16231627    {
    16241628        printk("\n[ERROR] in %s : cannot create dentry in cluster %x\n",
    1625                __FUNCTION__ , parent_cxy );
     1629        __FUNCTION__ , parent_cxy );
    16261630        return ENOMEM;
    16271631    }
     
    16451649                                  &inode_xp );
    16461650
    1647         vfs_dmsg("\n[INFO] %s : inode %l created in local cluster %x\n",
    1648                  __FUNCTION__ , inode_xp , local_cxy );
     1651vfs_dmsg("\n[DBG] %s : inode %x created in local cluster %x\n",
     1652__FUNCTION__ , GET_PTR(inode_xp) , local_cxy );
     1653
    16491654    }
    16501655    else                              // child cluster is remote
     
    16621667                                     &error );
    16631668
    1664         vfs_dmsg("\n[INFO] %s : inode %l created in remote cluster %x\n",
    1665                  __FUNCTION__ , inode_xp , child_cxy );
     1669vfs_dmsg("\n[DBG] %s : inode %x created in remote cluster %x\n",
     1670__FUNCTION__ , GET_PTR(inode_xp) , child_cxy );
     1671
    16661672    }
    16671673                                     
     
    16821688    hal_remote_swd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) , inode_xp );
    16831689
    1684     vfs_dmsg("\n[INFO] %s : exit in cluster %x for <%s>\n",
    1685     __FUNCTION__ , local_cxy , name );
     1690vfs_dmsg("\n[DBG] %s : exit in cluster %x for <%s>\n",
     1691__FUNCTION__ , local_cxy , name );
    16861692
    16871693    // success : return extended pointer on child inode
     
    17071713    assert( (mapper != NULL) , __FUNCTION__ , "no mapper for page\n" );
    17081714
    1709     vfs_dmsg("\n[DMSG] %s : enters for page %d / inode_cxy = %x / inode_ptr = %x\n",
    1710     __FUNCTION__ , page->index , local_cxy , mapper->inode );
     1715vfs_dmsg("\n[DBG] %s : core[%x,%d] enters for page %d / mapper = %x / inode = %x\n",
     1716__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid , page->index , mapper, mapper->inode );
    17111717
    17121718    // get FS type
     
    17331739    }
    17341740
    1735     vfs_dmsg("\n[DMSG] %s : exit for page %d / inode_cxy = %x / inode_ptr = %x\n",
    1736     __FUNCTION__ , page->index , local_cxy , mapper->inode );
     1741vfs_dmsg("\n[DBG] %s : core[%x,%d] exit for page %d / mapper = %x / inode = %x\n",
     1742__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, page->index, mapper, mapper->inode );
    17371743
    17381744    return error;
     
    17531759    assert( (mapper != NULL) , __FUNCTION__ , "mapper pointer is NULL\n" );
    17541760
    1755     vfs_dmsg("\n[INFO] %s : core[%x,%d] enter for inode %l / cycle %d\n",
    1756     __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, XPTR(local_cxy , inode) );
     1761vfs_dmsg("\n[DBG] %s : core[%x,%d] enter for inode %x in cluster %x/ cycle %d\n",
     1762__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, inode , local_cxy , hal_time_stamp() );
    17571763
    17581764    // compute number of pages
     
    17701776    }
    17711777
    1772     vfs_dmsg("\n[INFO] %s : core[%x,%d] exit for inode %l / cycle %d\n",
    1773     __FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, XPTR(local_cxy , inode) );
     1778vfs_dmsg("\n[DBG] %s : core[%x,%d] exit for inode %x in cluster %x / cycle %d\n",
     1779__FUNCTION__, local_cxy, CURRENT_THREAD->core->lid, inode , local_cxy , hal_time_stamp() );
    17741780
    17751781    return 0;
Note: See TracChangeset for help on using the changeset viewer.