Ignore:
Timestamp:
Dec 3, 2018, 12:15:53 PM (5 years ago)
Author:
alain
Message:

Improve the FAT32 file system to support cat, rm, cp commands.

File:
1 edited

Legend:

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

    r598 r602  
    8686
    8787/////////////////////////////////////////////////
    88 void devfs_global_init( xptr_t   parent_inode_xp,
     88void devfs_global_init( xptr_t   root_inode_xp,
    8989                        xptr_t * devfs_dev_inode_xp,
    9090                        xptr_t * devfs_external_inode_xp )
    9191{
    9292    error_t  error;
     93    xptr_t   unused_xp;   // required by vfs_add_child_in_parent()
    9394
    9495    // creates DEVFS "dev" inode in cluster 0
     
    9697                                     INODE_TYPE_DIR,
    9798                                     FS_TYPE_DEVFS,
    98                                      parent_inode_xp,
     99                                     root_inode_xp,
    99100                                     "dev",
    100                                      NULL,
    101                                      devfs_dev_inode_xp ); 
     101                                     &unused_xp,
     102                                     devfs_dev_inode_xp );
    102103
    103104    assert( (error == 0) , "cannot create <dev>\n" );
     
    117118                                     *devfs_dev_inode_xp,
    118119                                     "external",
    119                                      NULL,
    120                                      devfs_external_inode_xp ); 
     120                                     &unused_xp,
     121                                     devfs_external_inode_xp );
    121122
    122123    assert( (error == 0) , "cannot create <external>\n" );
     
    129130#endif
    130131
    131 }
     132}  // end devfs_global_init()
    132133
    133134///////////////////////////////////////////////////
     
    141142    chdev_t     * chdev_ptr;
    142143    xptr_t        inode_xp;
     144    cxy_t         inode_cxy;
     145    vfs_inode_t * inode_ptr;
    143146    uint32_t      channel;
     147    xptr_t        unused_xp;    // required by add_child_in_parent()
    144148
    145149    // create "internal" directory
     
    150154                             devfs_dev_inode_xp,
    151155                             node_name,
    152                              NULL,
     156                             &unused_xp,
    153157                             devfs_internal_inode_xp );
    154158#if DEBUG_DEVFS_INIT
     
    164168    if( chdev_xp != XPTR_NULL)
    165169    {
    166         chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     170        chdev_ptr = GET_PTR( chdev_xp );
    167171        vfs_add_child_in_parent( local_cxy,
    168172                                 INODE_TYPE_DEV,
     
    170174                                 *devfs_internal_inode_xp,
    171175                                 chdev_ptr->name,
    172                                  GET_PTR( chdev_xp ),
     176                                 &unused_xp,
    173177                                 &inode_xp );
     178
     179        // update child inode "extend" field
     180        inode_cxy = GET_CXY( inode_xp );
     181        inode_ptr = GET_PTR( inode_xp );
     182        hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     183       
    174184#if DEBUG_DEVFS_INIT
    175185cycle = (uint32_t)hal_get_cycles();
     
    184194    for( channel = 0 ; channel < LOCAL_CLUSTER->cores_nr ; channel++ )
    185195    {
    186         chdev_xp = chdev_dir.dma[channel];
     196        chdev_xp  = chdev_dir.dma[channel];
    187197        if( chdev_xp != XPTR_NULL)
    188198        {
    189             chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     199            chdev_ptr = GET_PTR( chdev_xp );
    190200            vfs_add_child_in_parent( local_cxy,
    191201                                     INODE_TYPE_DEV,
     
    193203                                     *devfs_internal_inode_xp,
    194204                                     chdev_ptr->name,
    195                                      GET_PTR( chdev_xp ),
     205                                     &unused_xp,
    196206                                     &inode_xp );
     207
     208            // update child inode "extend" field
     209            inode_cxy = GET_CXY( inode_xp );
     210            inode_ptr = GET_PTR( inode_xp );
     211            hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     212       
    197213#if DEBUG_DEVFS_INIT
    198214cycle = (uint32_t)hal_get_cycles();
     
    209225    {
    210226        chdev_cxy = GET_CXY( chdev_xp );
    211         chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     227        chdev_ptr = GET_PTR( chdev_xp );
    212228        if( chdev_cxy == local_cxy )
    213229        {
     
    217233                                     devfs_external_inode_xp,
    218234                                     chdev_ptr->name,
    219                                      GET_PTR( chdev_xp ),
     235                                     &unused_xp,
    220236                                     &inode_xp );
     237
     238            // update child inode "extend" field
     239            inode_cxy = GET_CXY( inode_xp );
     240            inode_ptr = GET_PTR( inode_xp );
     241            hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     242       
    221243#if DEBUG_DEVFS_INIT
    222244cycle = (uint32_t)hal_get_cycles();
     
    233255    {
    234256        chdev_cxy = GET_CXY( chdev_xp );
    235         chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     257        chdev_ptr = GET_PTR( chdev_xp );
    236258        if( chdev_cxy == local_cxy )
    237259        {
     
    241263                                     devfs_external_inode_xp,
    242264                                     chdev_ptr->name,
    243                                      GET_PTR( chdev_xp ),
     265                                     &unused_xp,
    244266                                     &inode_xp );
     267
     268            // update child inode "extend" field
     269            inode_cxy = GET_CXY( inode_xp );
     270            inode_ptr = GET_PTR( inode_xp );
     271            hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     272       
    245273#if DEBUG_DEVFS_INIT
    246274cycle = (uint32_t)hal_get_cycles();
     
    256284    {
    257285        chdev_xp = chdev_dir.txt_rx[channel];
     286        if( chdev_xp != XPTR_NULL )
     287        {
     288            chdev_cxy = GET_CXY( chdev_xp );
     289            chdev_ptr = GET_PTR( chdev_xp );
     290            if( chdev_cxy == local_cxy )
     291            {
     292                vfs_add_child_in_parent( local_cxy,
     293                                         INODE_TYPE_DEV,
     294                                         FS_TYPE_DEVFS,
     295                                         devfs_external_inode_xp,
     296                                         chdev_ptr->name,
     297                                         &unused_xp,
     298                                         &inode_xp );
     299
     300                // update child inode "extend" field
     301                inode_cxy = GET_CXY( inode_xp );
     302                inode_ptr = GET_PTR( inode_xp );
     303                hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     304       
     305#if DEBUG_DEVFS_INIT
     306cycle = (uint32_t)hal_get_cycles();
     307if( DEBUG_DEVFS_INIT < cycle )
     308printk("\n[%s] thread[%x,%x] created <txt_rx[%d]> inode in cluster %x\n",
     309__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
     310#endif
     311            }
     312        }
     313    }
     314
     315    // create a TXT_TX inode in each cluster containing a TXT_TX chdev
     316    for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ )
     317    {
     318        chdev_xp = chdev_dir.txt_tx[channel];
     319        if( chdev_xp != XPTR_NULL )
     320        {
     321            chdev_cxy = GET_CXY( chdev_xp );
     322            chdev_ptr = GET_PTR( chdev_xp );
     323            if( chdev_cxy == local_cxy )
     324            {
     325                vfs_add_child_in_parent( local_cxy,
     326                                         INODE_TYPE_DEV,
     327                                         FS_TYPE_DEVFS,
     328                                         devfs_external_inode_xp,
     329                                         chdev_ptr->name,
     330                                         &unused_xp,
     331                                         &inode_xp );
     332
     333                // update child inode "extend" field
     334                inode_cxy = GET_CXY( inode_xp );
     335                inode_ptr = GET_PTR( inode_xp );
     336                hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     337       
     338#if DEBUG_DEVFS_INIT
     339cycle = (uint32_t)hal_get_cycles();
     340if( DEBUG_DEVFS_INIT < cycle )
     341printk("\n[%s] thread[%x,%x] created <txt_tx[%d]> inode in cluster %x\n",
     342__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
     343#endif
     344            }
     345        }
     346    }
     347
     348    // create an IOC inode in each cluster containing an IOC chdev
     349    for( channel = 0 ; channel < CONFIG_MAX_IOC_CHANNELS ; channel++ )
     350    {
     351        chdev_xp = chdev_dir.ioc[channel];
     352        if( chdev_xp != XPTR_NULL )
     353        {
     354            chdev_cxy = GET_CXY( chdev_xp );
     355            chdev_ptr = GET_PTR( chdev_xp );
     356            if( chdev_cxy == local_cxy )
     357            {
     358                vfs_add_child_in_parent( local_cxy,
     359                                         INODE_TYPE_DEV,
     360                                         FS_TYPE_DEVFS,
     361                                         devfs_external_inode_xp,
     362                                         chdev_ptr->name,
     363                                         &unused_xp,
     364                                         &inode_xp );
     365
     366                // update child inode "extend" field
     367                inode_cxy = GET_CXY( inode_xp );
     368                inode_ptr = GET_PTR( inode_xp );
     369                hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     370       
     371#if DEBUG_DEVFS_INIT
     372cycle = (uint32_t)hal_get_cycles();
     373if( DEBUG_DEVFS_INIT < cycle )
     374printk("\n[%s] thread[%x,%x] created <ioc[%d]> inode in cluster %x\n",
     375__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
     376#endif
     377            }
     378        }
     379    }
     380
     381    // create a FBF inode in each cluster containing a FBF chdev
     382    for( channel = 0 ; channel < CONFIG_MAX_FBF_CHANNELS ; channel++ )
     383    {
     384        chdev_xp = chdev_dir.fbf[channel];
     385        if( chdev_xp != XPTR_NULL )
     386        {
     387            chdev_cxy = GET_CXY( chdev_xp );
     388            chdev_ptr = GET_PTR( chdev_xp );
     389            if( chdev_cxy == local_cxy )
     390            {
     391                vfs_add_child_in_parent( local_cxy,
     392                                         INODE_TYPE_DEV,
     393                                         FS_TYPE_DEVFS,
     394                                         devfs_external_inode_xp,
     395                                         chdev_ptr->name,
     396                                         &unused_xp,
     397                                         &inode_xp );
     398
     399                // update child inode "extend" field
     400                inode_cxy = GET_CXY( inode_xp );
     401                inode_ptr = GET_PTR( inode_xp );
     402                hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     403       
     404#if DEBUG_DEVFS_INIT
     405cycle = (uint32_t)hal_get_cycles();
     406if( DEBUG_DEVFS_INIT < cycle )
     407printk("\n[%s] thread[%x,%x] created <fbf[%d]> inode in cluster %x\n",
     408__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
     409#endif
     410            }
     411        }
     412    }
     413
     414    // create a NIC_RX inode in each cluster containing a NIC_RX chdev
     415    for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ )
     416    {
     417        chdev_xp = chdev_dir.nic_rx[channel];
    258418        if( chdev_xp != XPTR_NULL )
    259419        {
     
    267427                                         devfs_external_inode_xp,
    268428                                         chdev_ptr->name,
    269                                          GET_PTR( chdev_xp ),
     429                                         &unused_xp,
    270430                                         &inode_xp );
    271431#if DEBUG_DEVFS_INIT
    272432cycle = (uint32_t)hal_get_cycles();
    273433if( DEBUG_DEVFS_INIT < cycle )
    274 printk("\n[%s] thread[%x,%x] created <txt_rx[%d]> inode in cluster %x\n",
     434printk("\n[%s] thread[%x,%x] created <nic_rx[%d]> inode in cluster %x\n",
    275435__FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    276436#endif
     
    279439    }
    280440
    281     // create a TXT_TX inode in each cluster containing a TXT_TX chdev
    282     for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ )
    283     {
    284         chdev_xp = chdev_dir.txt_tx[channel];
     441    // create a NIC_TX inode in each cluster containing a NIC_TX chdev
     442    for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ )
     443    {
     444        chdev_xp = chdev_dir.nic_tx[channel];
    285445        if( chdev_xp != XPTR_NULL )
    286446        {
    287447            chdev_cxy = GET_CXY( chdev_xp );
    288             chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     448            chdev_ptr = GET_PTR( chdev_xp );
    289449            if( chdev_cxy == local_cxy )
    290450            {
     
    294454                                         devfs_external_inode_xp,
    295455                                         chdev_ptr->name,
    296                                          GET_PTR( chdev_xp ),
     456                                         &unused_xp,
    297457                                         &inode_xp );
    298 #if DEBUG_DEVFS_INIT
    299 cycle = (uint32_t)hal_get_cycles();
    300 if( DEBUG_DEVFS_INIT < cycle )
    301 printk("\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 );
    303 #endif
    304             }
    305         }
    306     }
    307 
    308     // create an IOC inode in each cluster containing an IOC chdev
    309     for( channel = 0 ; channel < CONFIG_MAX_IOC_CHANNELS ; channel++ )
    310     {
    311         chdev_xp = chdev_dir.ioc[channel];
    312         if( chdev_xp != XPTR_NULL )
    313         {
    314             chdev_cxy = GET_CXY( chdev_xp );
    315             chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
    316             if( chdev_cxy == local_cxy )
    317             {
    318                 vfs_add_child_in_parent( local_cxy,
    319                                          INODE_TYPE_DEV,
    320                                          FS_TYPE_DEVFS,
    321                                          devfs_external_inode_xp,
    322                                          chdev_ptr->name,
    323                                          GET_PTR( chdev_xp ),
    324                                          &inode_xp );
    325 #if DEBUG_DEVFS_INIT
    326 cycle = (uint32_t)hal_get_cycles();
    327 if( DEBUG_DEVFS_INIT < cycle )
    328 printk("\n[%s] thread[%x,%x] created <ioc[%d]> inode in cluster %x\n",
    329 __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    330 #endif
    331             }
    332         }
    333     }
    334 
    335     // create a FBF inode in each cluster containing a FBF chdev
    336     for( channel = 0 ; channel < CONFIG_MAX_FBF_CHANNELS ; channel++ )
    337     {
    338         chdev_xp = chdev_dir.fbf[channel];
    339         if( chdev_xp != XPTR_NULL )
    340         {
    341             chdev_cxy = GET_CXY( chdev_xp );
    342             chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
    343             if( chdev_cxy == local_cxy )
    344             {
    345                 vfs_add_child_in_parent( local_cxy,
    346                                          INODE_TYPE_DEV,
    347                                          FS_TYPE_DEVFS,
    348                                          devfs_external_inode_xp,
    349                                          chdev_ptr->name,
    350                                          GET_PTR( chdev_xp ),
    351                                          &inode_xp );
    352 #if DEBUG_DEVFS_INIT
    353 cycle = (uint32_t)hal_get_cycles();
    354 if( DEBUG_DEVFS_INIT < cycle )
    355 printk("\n[%s] thread[%x,%x] created <fbf[%d]> inode in cluster %x\n",
    356 __FUNCTION__, this->process->pid, this->trdid, channel, local_cxy, cycle );
    357 #endif
    358             }
    359         }
    360     }
    361 
    362     // create a NIC_RX inode in each cluster containing a NIC_RX chdev
    363     for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ )
    364     {
    365         chdev_xp = chdev_dir.nic_rx[channel];
    366         if( chdev_xp != XPTR_NULL )
    367         {
    368             chdev_cxy = GET_CXY( chdev_xp );
    369             chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
    370             if( chdev_cxy == local_cxy )
    371             {
    372                 vfs_add_child_in_parent( local_cxy,
    373                                          INODE_TYPE_DEV,
    374                                          FS_TYPE_DEVFS,
    375                                          devfs_external_inode_xp,
    376                                          chdev_ptr->name,
    377                                          GET_PTR( chdev_xp ),
    378                                          &inode_xp );
    379 #if DEBUG_DEVFS_INIT
    380 cycle = (uint32_t)hal_get_cycles();
    381 if( DEBUG_DEVFS_INIT < cycle )
    382 printk("\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 );
    384 #endif
    385             }
    386         }
    387     }
    388 
    389     // create a NIC_TX inode in each cluster containing a NIC_TX chdev
    390     for( channel = 0 ; channel < CONFIG_MAX_NIC_CHANNELS ; channel++ )
    391     {
    392         chdev_xp = chdev_dir.nic_tx[channel];
    393         if( chdev_xp != XPTR_NULL )
    394         {
    395             chdev_cxy = GET_CXY( chdev_xp );
    396             chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
    397             if( chdev_cxy == local_cxy )
    398             {
    399                 vfs_add_child_in_parent( local_cxy,
    400                                          INODE_TYPE_DEV,
    401                                          FS_TYPE_DEVFS,
    402                                          devfs_external_inode_xp,
    403                                          chdev_ptr->name,
    404                                          GET_PTR( chdev_xp ),
    405                                          &inode_xp );
     458
     459                // update child inode "extend" field
     460                inode_cxy = GET_CXY( inode_xp );
     461                inode_ptr = GET_PTR( inode_xp );
     462                hal_remote_spt( XPTR( inode_cxy , &inode_ptr->extend ) , chdev_ptr );
     463       
    406464#if DEBUG_DEVFS_INIT
    407465cycle = (uint32_t)hal_get_cycles();
     
    462520    channel = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->channel ) );
    463521
     522// Only TXT devices are associated to a pseudo-file
    464523assert( ( func == DEV_FUNC_TXT ) , __FUNCTION__, "illegal device func_type");
    465524
Note: See TracChangeset for help on using the changeset viewer.