Changeset 625 for trunk/kernel/fs


Ignore:
Timestamp:
Apr 10, 2019, 10:09:39 AM (3 years ago)
Author:
alain
Message:

Fix a bug in the vmm_remove_vseg() function: the physical pages
associated to an user DATA vseg were released to the kernel when
the target process descriptor was in the reference cluster.
This physical pages release should be done only when the page
forks counter value is zero.
All other modifications are cosmetic.

Location:
trunk/kernel/fs
Files:
4 edited

Legend:

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

    r623 r625  
    22 * fatfs.c - FATFS file system API implementation.
    33 *
    4  * Author    Alain Greiner (2016,2017,2018)
     4 * Author    Alain Greiner (2016,2017,2018,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    374374
    375375//////////////////////////////////////////////////////////////////////////////////////////
    376 // This static function - atomically - decrements "free_clusters", and updates
    377 // the "free_cluster_hint" shared variables in the FATFS context in the FAT cluster.
    378 // It scan the FAT to find the first free slot larger than the <cluster> argument,
    379 // and set "free_cluster_hint" <= (free - 1).
     376// This static function decrements the  "free_clusters" variable, and updates the
     377// "free_cluster_hint" variable in the FATFS context, identified by the <fat_ctx_cxy>
     378// and <fat_ctx_ptr> arguments (cluster containing the FAT mapper).
     379// It scan all slots in the FAT mapper seen as an array of 32 bits words, looking for the
     380// first free slot larger than the <cluster> argument, to update "free_cluster_hint".
    380381//
    381382// WARNING : The free_lock protecting exclusive access to these variables
    382383//           must be taken by the calling function.
    383384//////////////////////////////////////////////////////////////////////////////////////////
    384 // @ cluster     : recently allocated cluster index in FAT.
    385 //////////////////////////////////////////////////////////////////////////////////////////
    386 static error_t fatfs_free_clusters_decrement( uint32_t  cluster )
    387 {
    388     fatfs_ctx_t * loc_ctx;      // local pointer on local FATFS context
    389     fatfs_ctx_t * fat_ctx;      // local pointer on FATFS in cluster containing FAT mapper
    390     cxy_t         mapper_cxy;   // cluster identifier for cluster containing FAT mapper
     385// @ fat_ctx_cxy  : FAT mapper cluster identifier.
     386// @ fat_ctx_ptr  : local pointer on FATFS context.
     387// @ cluster      : recently allocated cluster index in FAT.
     388//////////////////////////////////////////////////////////////////////////////////////////
     389static error_t fatfs_free_clusters_decrement( cxy_t         fat_ctx_cxy,
     390                                              fatfs_ctx_t * fat_ctx_ptr,
     391                                              uint32_t      cluster )
     392{
    391393    xptr_t        mapper_xp;    // extended pointer on FAT mapper
    392394    xptr_t        hint_xp;      // extended pointer on "free_cluster_hint" shared variable
     
    397399    uint32_t      page_max;     // max number of pages in FAT mapper
    398400    xptr_t        page_xp;      // extended pointer on current page in FAT mapper
     401    xptr_t        base_xp;      // extended pointer on current page base
    399402    xptr_t        slot_xp;      // extended pointer on current slot in FAT mapper
    400403
     
    407410#endif
    408411
    409     // get local pointer on local FATFS context
    410     loc_ctx = fs_context[FS_TYPE_FATFS].extend;
    411 
    412     // get cluster containing FAT mapper
    413     mapper_xp  = loc_ctx->fat_mapper_xp;
    414     mapper_cxy = GET_CXY( mapper_xp );
    415 
    416     // get local pointer on FATFS context in FAT cluster
    417     fat_ctx = hal_remote_lpt( XPTR( mapper_cxy , &fs_context[FS_TYPE_FATFS].extend ) );
    418 
    419412    // build extended pointers on free_clusters, and free_cluster_hint
    420     hint_xp = XPTR( mapper_cxy , &fat_ctx->free_cluster_hint );
    421     numb_xp = XPTR( mapper_cxy , &fat_ctx->free_clusters );
     413    hint_xp = XPTR( fat_ctx_cxy , &fat_ctx_ptr->free_cluster_hint );
     414    numb_xp = XPTR( fat_ctx_cxy , &fat_ctx_ptr->free_clusters );
    422415
    423416    // update "free_clusters"
     
    425418    hal_remote_s32( numb_xp , numb - 1 );
    426419
    427     // scan FAT mapper to find the first free slot > cluster
    428     // and update "free_cluster_hint" as (free - 1)
     420    // get extended pointer on FAT mapper
     421    mapper_xp = hal_remote_l64( XPTR( fat_ctx_cxy , &fat_ctx_ptr->fat_mapper_xp ) );
     422
     423    // initialise variables to scan the FAT mapper
     424    // and find the first free slot > cluster
    429425    page_id  = (cluster + 1) >> 10;
    430426    slot_id  = (cluster + 1) & 0x3FF;
    431     page_max = (loc_ctx->fat_sectors_count >> 3);
     427    page_max = hal_remote_l32( XPTR( fat_ctx_cxy, &fat_ctx_ptr->fat_sectors_count ) ) >> 3;
    432428
    433429    // scan FAT mapper / loop on pages
     
    443439        }
    444440
     441        // get extended pointer on page
     442        base_xp = ppm_page2base( page_xp );
     443
    445444        // scan FAT mapper / loop on slots
    446445        while ( slot_id < 1024 )
    447446        {
    448447            // get extended pointer on current slot
    449             slot_xp = ppm_page2base( page_xp ) + (slot_id << 2);
    450 
    451             // test FAT slot value
     448            slot_xp = base_xp + (slot_id << 2);
     449
     450            // test slot value
    452451            if ( hal_remote_l32( slot_xp ) == FREE_CLUSTER )
    453452            {
    454                 // update "free_cluster_hint" <= (free - 1)
     453                // update "free_cluster_hint"
    455454                hal_remote_s32( hint_xp , (page_id << 10) + slot_id - 1 );
    456455
     
    465464            }
    466465
    467             // increment slot_id
    468             slot_id++;
     466            // update slot_id
     467            slot_id = 0;
    469468
    470469        }  // end loop on slots
    471470
    472         // update loop variables
     471        // update (page_id,slot_id) variables
    473472        page_id++;
    474473        slot_id = 0;
     
    483482
    484483//////////////////////////////////////////////////////////////////////////////////////////
    485 // This static function atomically increments <free_clusters>, and updates
    486 // the <free_cluster_hint> shared variables in the FATFS context in the FAT cluster.
    487 // If the released cluster index is smaller than the current (hint + 1) value,
    488 // it set "free_cluster_hint" <= cluster - 1.
     484// This static function increments the "free_clusters" variable, and updates the
     485// "free_cluster_hint" variables in the FATFS context, identified by the <fat_ctx_cxy>
     486// and <fat_ctx_ptr> argument (cluster containing the FAT mapper).
     487// If the released cluster index is smaller than the current (hint) value,
     488// it set "free_cluster_hint" <= cluster.
    489489//
    490490// WARNING : The free_lock protecting exclusive access to these variables
    491491//           must be taken by the calling function.
    492492//////////////////////////////////////////////////////////////////////////////////////////
     493// @ fat_ctx_cxy  : FAT mapper cluster identifier.
     494// @ fat_ctx_ptr  : local pointer on FATFS context.
    493495// @ cluster     : recently released cluster index in FAT.
    494496//////////////////////////////////////////////////////////////////////////////////////////
    495 static void fatfs_free_clusters_increment( uint32_t  cluster )
    496 {
    497     fatfs_ctx_t * loc_ctx;      // local pointer on local FATFS context
    498     fatfs_ctx_t * fat_ctx;      // local pointer on FATFS in cluster containing FAT mapper
    499     cxy_t         fat_cxy;      // cluster identifier for cluster containing FAT mapper
     497static void fatfs_free_clusters_increment( cxy_t         fat_ctx_cxy,
     498                                           fatfs_ctx_t * fat_ctx_ptr,
     499                                           uint32_t      cluster )
     500{
    500501    xptr_t        hint_xp;      // extended pointer on "free_cluster_hint" shared variable
    501502    xptr_t        numb_xp;      // extended pointer on "free_clusters" shared variable
     
    503504    uint32_t      numb;         // "free_clusters" variable current value
    504505
    505     // get local pointer on local FATFS context
    506     loc_ctx = fs_context[FS_TYPE_FATFS].extend;
    507 
    508     // get cluster containing FAT mapper
    509     fat_cxy = GET_CXY( loc_ctx->fat_mapper_xp );
    510 
    511     // get local pointer on FATFS context in FAT cluster
    512     fat_ctx = hal_remote_lpt( XPTR( fat_cxy , &fs_context[FS_TYPE_FATFS].extend ) );
    513 
    514     // build extended pointers free_lock, free_clusters, and free_cluster_hint
    515     hint_xp = XPTR( fat_cxy , &fat_ctx->free_cluster_hint );
    516     numb_xp = XPTR( fat_cxy , &fat_ctx->free_clusters );
     506    // build extended pointers on free_clusters, and free_cluster_hint
     507    hint_xp = XPTR( fat_ctx_cxy , &fat_ctx_ptr->free_cluster_hint );
     508    numb_xp = XPTR( fat_ctx_cxy , &fat_ctx_ptr->free_clusters );
    517509
    518510    // get current value of free_cluster_hint and free_clusters
     
    521513
    522514    // update free_cluster_hint if required
    523     if ( cluster < (hint + 1) ) hal_remote_s32( hint_xp , (cluster - 1) );
     515    if ( (cluster - 1) < hint ) hal_remote_s32( hint_xp , (cluster - 1) );
    524516
    525517    // update free_clusters
     
    542534// It does NOT update the FS on the IOC device.
    543535//////////////////////////////////////////////////////////////////////////////////////////
    544 // @ fat_mapper_xp : extended pointer on FAT mapper.
    545 // @ cluster       : cluster index in FAT.
     536// @ mapper_cxy : FAT mapper cluster identifier.
     537// @ mapper_ptr : local pointer on FAT mapper.
     538// @ fatfs_ctx  : local pointer on FATFS context in FAT cluster.
     539// @ cluster    : index of cluster to be released from FAT mapper.
    546540// @ return 0 if success / return -1 if error (cannot access FAT)
    547541//////////////////////////////////////////////////////////////////////////////////////////
    548 static error_t fatfs_recursive_release( xptr_t    fat_mapper_xp,
    549                                         uint32_t  cluster )
     542static error_t fatfs_recursive_release( cxy_t         mapper_cxy,
     543                                        mapper_t    * mapper_ptr,
     544                                        fatfs_ctx_t * fatfs_ctx,
     545                                        uint32_t      cluster )
    550546{
    551547    uint32_t next;
    552548
    553     // get next cluster from FAT mapper
    554     if ( mapper_remote_get_32( fat_mapper_xp , cluster , &next ) ) return -1;
     549    // build extended pointer on FAT mapper
     550    xptr_t mapper_xp = XPTR( mapper_cxy , mapper_ptr );
     551
     552    // get next cluster index from FAT mapper
     553    if ( mapper_remote_get_32( mapper_xp,
     554                               cluster,
     555                               &next ) ) return -1;
    555556
    556557#if (DEBUG_FATFS_RELEASE_INODE & 1)
     
    564565    {
    565566        // call fatfs_recursive_release() on next cluster
    566         if ( fatfs_recursive_release( fat_mapper_xp , next ) ) return -1;
     567        if ( fatfs_recursive_release( mapper_cxy,
     568                                      mapper_ptr,
     569                                      fatfs_ctx,
     570                                      next ) ) return -1;
    567571    }       
    568572
    569573    // update current cluster in FAT mapper
    570     if ( mapper_remote_set_32( fat_mapper_xp, cluster , FREE_CLUSTER ) ) return -1;
     574    if ( mapper_remote_set_32( mapper_xp,
     575                               cluster,
     576                               FREE_CLUSTER ) ) return -1;
    571577
    572578    // Update free_cluster_hint and free_clusters in FAT context
    573     fatfs_free_clusters_increment( cluster );
     579    fatfs_free_clusters_increment( mapper_cxy,
     580                                   fatfs_ctx,
     581                                   cluster );
    574582
    575583    return 0;
     
    582590//////////////////////////////////////////////////////////////////////////////////////////
    583591
    584 //////////////////////////////
    585 void fatfs_ctx_display( void )
    586 {
    587     // get pointer on local FATFS context
    588     vfs_ctx_t   * vfs_ctx   = &fs_context[FS_TYPE_FATFS];
    589     fatfs_ctx_t * fatfs_ctx = (fatfs_ctx_t *)vfs_ctx->extend;
    590 
     592///////////////////////////////////////////
     593void fatfs_ctx_display( fatfs_ctx_t * ctx )
     594{
    591595    printk("\n*** FAT context ***\n"
    592596           "- fat_sectors       = %d\n"
     
    599603           "- free_cluster_hint = %d\n"
    600604           "- fat_mapper_xp     = %l\n",
    601            fatfs_ctx->fat_sectors_count,
    602            fatfs_ctx->bytes_per_sector,
    603            fatfs_ctx->sectors_per_cluster * fatfs_ctx->bytes_per_sector,
    604            fatfs_ctx->fat_begin_lba,
    605            fatfs_ctx->cluster_begin_lba,
    606            fatfs_ctx->root_dir_cluster,
    607            fatfs_ctx->free_clusters,
    608            fatfs_ctx->free_cluster_hint,
    609            fatfs_ctx->fat_mapper_xp );
    610 
    611 }  // end fatfs_ctx_display()
     605           ctx->fat_sectors_count,
     606           ctx->bytes_per_sector,
     607           ctx->sectors_per_cluster * ctx->bytes_per_sector,
     608           ctx->fat_begin_lba,
     609           ctx->cluster_begin_lba,
     610           ctx->root_dir_cluster,
     611           ctx->free_clusters,
     612           ctx->free_cluster_hint,
     613           ctx->fat_mapper_xp );
     614
     615}  // end ctx_display()
    612616
    613617//////////////////////////////////////////
     
    659663    uint32_t * buffer;                 // pointer on current page (array of uint32_t)
    660664    uint32_t   current_page_index;     // index of current page in FAT
    661     uint32_t   current_page_offset;    // offset of slot in current page
     665    uint32_t   current_slot_index;     // index of slot in current page
    662666    uint32_t   page_count_in_file;     // index of page in file (index in linked list)
    663667    uint32_t   next_cluster_id;        // content of current FAT slot
     
    670674thread_t * this  = CURRENT_THREAD;
    671675if( DEBUG_FATFS_GET_CLUSTER < cycle )
    672 printk("\n[%s] thread[%x,%x] enter / first_cluster_id %d / searched_index / cycle %d\n",
     676printk("\n[%s] thread[%x,%x] enter / first_cluster_id %d / searched_index %d / cycle %d\n",
    673677__FUNCTION__, this->process->pid, this->trdid, first_cluster_id, searched_page_index, cycle );
    674678#endif
     
    678682
    679683    // get extended pointer and cluster on FAT mapper
    680     xptr_t mapper_xp  = ctx->fat_mapper_xp;
    681     cxy_t  mapper_cxy = GET_CXY( mapper_xp );
     684    xptr_t fat_mapper_xp  = ctx->fat_mapper_xp;
     685    cxy_t  fat_mapper_cxy = GET_CXY( fat_mapper_xp );
    682686
    683687    // initialize loop variable (1024 slots per page)
    684688    current_page_index  = first_cluster_id >> 10;
    685     current_page_offset = first_cluster_id & 0x3FF;
     689    current_slot_index = first_cluster_id & 0x3FF;
    686690    page_count_in_file  = 0;
    687691    next_cluster_id     = 0xFFFFFFFF;
    688692
    689     // scan FAT (i.e. traverse FAT linked list)
     693    // scan FAT mapper (i.e. traverse FAT linked list)
    690694    while( page_count_in_file < searched_page_index )
    691695    {
    692         // get pointer on current page descriptor
    693         current_page_xp = mapper_remote_get_page( mapper_xp , current_page_index );
     696        // get pointer on current page descriptor in FAT mapper
     697        current_page_xp = mapper_remote_get_page( fat_mapper_xp , current_page_index );
    694698
    695699        if( current_page_xp == XPTR_NULL )
    696700        {
    697             // TODO
     701            printk("\n[ERROR] in %s : cannot get next page from FAT mapper\n", __FUNCTION__);
    698702            return -1;
    699703        }
     
    704708
    705709        // get FAT slot content
    706         next_cluster_id = hal_remote_l32( XPTR( mapper_cxy , &buffer[current_page_offset] ) );
     710        next_cluster_id = hal_remote_l32( XPTR( fat_mapper_cxy,
     711                                                &buffer[current_slot_index] ) );
    707712
    708713#if (DEBUG_FATFS_GET_CLUSTER & 1)
    709714if( DEBUG_FATFS_GET_CLUSTER < cycle )
    710715printk("\n[%s] traverse FAT / current_page_index = %d\n"
    711 "current_page_offset = %d / next_cluster_id = %d\n",
    712 __FUNCTION__, current_page_index, current_page_offset , next_cluster_id );
     716"current_slot_index = %d / next_cluster_id = %d\n",
     717__FUNCTION__, current_page_index, current_slot_index , next_cluster_id );
    713718#endif
    714719
    715720        // update loop variables
    716         current_page_index  = next_cluster_id >> 10;
    717         current_page_offset = next_cluster_id & 0x3FF;
     721        current_page_index = next_cluster_id >> 10;
     722        current_slot_index = next_cluster_id & 0x3FF;
    718723        page_count_in_file++;
    719724    }
    720725
    721     if( next_cluster_id == 0xFFFFFFFF ) return -1;
     726    if( next_cluster_id == 0xFFFFFFFF )
     727    {
     728        printk("\n[ERROR] in %s : searched_cluster_id not found in FAT\n", __FUNCTION__ );
     729        return -1;
     730    }
    722731   
    723732#if DEBUG_FATFS_GET_CLUSTER
     
    759768
    760769#if DEBUG_FATFS_CTX_INIT
    761 uint32_t cycle = (uint32_t)hal_get_cycles();
     770uint32_t   cycle = (uint32_t)hal_get_cycles();
     771thread_t * this  = CURRENT_THREAD;
    762772if( DEBUG_FATFS_CTX_INIT < cycle )
    763773printk("\n[%s] thread[%x,%x] enter for fatfs_ctx = %x / cycle %d\n",
     
    766776
    767777// check argument
    768 assert( (fatfs_ctx != NULL) , "pointer on FATFS context is NULL\n" );
     778assert( (fatfs_ctx != NULL) , "pointer on FATFS context is NULL" );
    769779
    770780// check only cluster 0 does FATFS init
    771 assert( (local_cxy == 0) , "only cluster 0 can initialize FATFS\n");
     781assert( (local_cxy == 0) , "only cluster 0 can initialize FATFS");
    772782
    773783    // allocate a 512 bytes buffer to store the boot record
     
    882892    // WARNING : the inode field MUST be NULL for the FAT mapper
    883893    fat_mapper->inode = NULL;
     894
    884895
    885896    // initialize the FATFS context
     
    895906
    896907    remote_queuelock_init( XPTR( local_cxy , &fatfs_ctx->free_lock ) , LOCK_FATFS_FREE );
     908
     909#if (DEBUG_FATFS_CTX_INIT & 0x1)
     910if( DEBUG_FATFS_CTX_INIT < cycle )
     911fatfs_ctx_display( fatfs_ctx );
     912#endif
    897913
    898914#if DEBUG_FATFS_CTX_INIT
     
    15251541                          xptr_t        child_inode_xp )
    15261542{
    1527     uint8_t  * entry;    // pointer on FAT32 directory entry (array of 32 bytes)
    1528     uint32_t   index;    // index of FAT32 directory entry in mapper
    1529     mapper_t * mapper;   // pointer on directory mapper
    1530     uint32_t   cluster;  // directory entry cluster
    1531     uint32_t   size;     // directory entry size
    1532     bool_t     is_dir;   // directory entry type (file/dir)
    1533     error_t    error;
     1543    uint8_t      * entry;            // pointer on FAT32 directory entry (array of 32 bytes)
     1544    uint32_t       index;            // index of FAT32 directory entry in mapper
     1545    mapper_t     * mapper;           // pointer on directory mapper
     1546    uint32_t       cluster;          // directory entry cluster
     1547    uint32_t       size;             // directory entry size
     1548    bool_t         is_dir;           // directory entry type (file/dir)
     1549    xptr_t         root_xp;          // extended pointer on root of parent dentries
     1550    xptr_t         iter_xp;          // iterator for this list
     1551    cxy_t          child_inode_cxy;  // child inode cluster 
     1552    vfs_inode_t  * child_inode_ptr;  // child inode local pointer
     1553    xptr_t         dentry_xp;        // extended pointer on searched dentry descriptor
     1554    cxy_t          dentry_cxy;       // cluster identifier of dentry (must be local_cxy)
     1555    vfs_dentry_t * dentry_ptr;       // local pointer
     1556    error_t        error;
     1557
     1558    char       dir_name[CONFIG_VFS_MAX_NAME_LENGTH];
    15341559
    15351560// check arguments
     
    15391564
    15401565#if DEBUG_FATFS_GET_DENTRY
    1541 char       parent_name[CONFIG_VFS_MAX_NAME_LENGTH];
    15421566uint32_t   cycle = (uint32_t)hal_get_cycles();
    15431567thread_t * this  = CURRENT_THREAD;
    1544 vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , parent_name );
     1568vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , dir_name );
    15451569if( DEBUG_FATFS_GET_DENTRY < cycle )
    15461570printk("\n[%s]  thread[%x,%x] enter for child <%s> in parent <%s> / cycle %d\n",
    1547 __FUNCTION__, this->process->pid, this->trdid, name , parent_name , cycle );
    1548 #endif
    1549 
    1550     // get pointer and index of searched directory entry in mapper
     1571__FUNCTION__, this->process->pid, this->trdid, name , dir_name , cycle );
     1572#endif
     1573
     1574    // get local pointer on parent mapper
    15511575    mapper = parent_inode->mapper;
     1576
     1577    // get pointer and index in mapper for searched directory entry
    15521578    error  = fatfs_scan_directory( mapper, name , &entry , &index );
    15531579
    1554     // update child inode and dentry descriptors if sucess
    1555     if( error == 0 )
     1580    if( error )
    15561581    {
     1582        vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , dir_name );
     1583        printk("\n[ERROR] in %s : cannot find <%s> in parent mapper <%s>\n",
     1584        __FUNCTION__, name , dir_name );
     1585        return -1;
     1586    }
     1587
     1588    // get relevant infos from FAT32 directory entry
     1589    cluster = (fatfs_get_record( DIR_FST_CLUS_HI , entry , 1 ) << 16) |
     1590              (fatfs_get_record( DIR_FST_CLUS_LO , entry , 1 )      ) ;
     1591    is_dir  = (fatfs_get_record( DIR_ATTR        , entry , 1 ) & ATTR_DIRECTORY);
     1592    size    =  fatfs_get_record( DIR_FILE_SIZE   , entry , 1 );
     1593
     1594    // get child inode cluster and local pointer
     1595    child_inode_cxy = GET_CXY( child_inode_xp );
     1596    child_inode_ptr = GET_PTR( child_inode_xp );
     1597
     1598    // build extended pointer on root of list of parent dentries
     1599    root_xp = XPTR( child_inode_cxy , &child_inode_ptr->parents );
     1600
     1601// check child inode has at least one parent
     1602assert( (xlist_is_empty( root_xp ) == false ), "child inode must have one parent\n");
     1603
     1604    // scan list of parent dentries to search the parent_inode
     1605    bool_t found = false;
     1606    XLIST_FOREACH( root_xp , iter_xp )
     1607    {
     1608        // get pointers on dentry
     1609        dentry_xp  = XLIST_ELEMENT( iter_xp , vfs_dentry_t , parents );
     1610        dentry_cxy = GET_CXY( dentry_xp );
     1611        dentry_ptr = GET_PTR( dentry_xp );
     1612
     1613        // get local pointer on current parent directory inode
     1614        vfs_inode_t * current = hal_remote_lpt( XPTR( dentry_cxy , &dentry_ptr->parent ) );
     1615
     1616        // check if current parent is the searched parent
     1617        if( XPTR( dentry_cxy , current ) == XPTR( local_cxy , parent_inode ) )
     1618        {
     1619            found = true;
     1620            break;
     1621        }
     1622    }
     1623
     1624    if( found == false )
     1625    {
     1626        vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , dir_name );
     1627        printk("\n[ERROR] in %s : cannot find <%s> directory in list of parents for <%s>\n",
     1628        __FUNCTION__, dir_name, name );
     1629        return -1;
     1630    }
     1631
     1632    // update the child inode "type", "size", and "extend" fields
     1633    vfs_inode_type_t type = (is_dir) ? INODE_TYPE_DIR : INODE_TYPE_FILE;
     1634
     1635    hal_remote_s32( XPTR( child_inode_cxy , &child_inode_ptr->type   ) , type );
     1636    hal_remote_s32( XPTR( child_inode_cxy , &child_inode_ptr->size   ) , size );
     1637    hal_remote_s32( XPTR( child_inode_cxy , &child_inode_ptr->extend ) , cluster );
     1638
     1639    // update the dentry "extend" field
     1640    dentry_ptr->extend = (void *)(intptr_t)index;
    15571641
    15581642#if DEBUG_FATFS_GET_DENTRY
    15591643cycle = (uint32_t)hal_get_cycles();
    15601644if( DEBUG_FATFS_GET_DENTRY < cycle )
    1561 printk("\n[%s]  thread[%x,%x] exit / intialised child <%s> in %s / cycle %d\n",
    1562 __FUNCTION__, this->process->pid, this->trdid, name, parent_name, cycle );
    1563 #endif
    1564         // get relevant infos from FAT32 directory entry
    1565         cluster = (fatfs_get_record( DIR_FST_CLUS_HI , entry , 1 ) << 16) |
    1566                   (fatfs_get_record( DIR_FST_CLUS_LO , entry , 1 )      ) ;
    1567         is_dir  = (fatfs_get_record( DIR_ATTR        , entry , 1 ) & ATTR_DIRECTORY);
    1568         size    =  fatfs_get_record( DIR_FILE_SIZE   , entry , 1 );
    1569 
    1570         // get child inode cluster and local pointer
    1571         cxy_t          inode_cxy = GET_CXY( child_inode_xp );
    1572         vfs_inode_t  * inode_ptr = GET_PTR( child_inode_xp );
    1573 
    1574         // build extended pointer on root of list of prent dentries
    1575         xptr_t parents_root_xp = XPTR( inode_cxy , &inode_ptr->parents );
    1576 
    1577 // check child inode has at least one parent
    1578 assert( (xlist_is_empty( parents_root_xp ) == false ), "child inode must have one parent\n");
    1579 
    1580         // get dentry pointers and cluster
    1581         xptr_t         dentry_xp  = XLIST_FIRST( parents_root_xp , vfs_dentry_t , parents );
    1582         vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp );
    1583         cxy_t          dentry_cxy = GET_CXY( dentry_xp );
    1584 
    1585 // check dentry descriptor in same cluster as parent inode
    1586 assert( (dentry_cxy == local_cxy) , "illegal dentry cluster\n" );
    1587 
    1588         // update the child inode "type", "size", and "extend" fields
    1589         vfs_inode_type_t type = (is_dir) ? INODE_TYPE_DIR : INODE_TYPE_FILE;
    1590 
    1591         hal_remote_s32( XPTR( inode_cxy , &inode_ptr->type   ) , type );
    1592         hal_remote_s32( XPTR( inode_cxy , &inode_ptr->size   ) , size );
    1593         hal_remote_s32( XPTR( inode_cxy , &inode_ptr->extend ) , cluster );
    1594 
    1595         // update the dentry "extend" field
    1596         dentry_ptr->extend = (void *)(intptr_t)index;
    1597 
    1598         return 0;
    1599     }
    1600     else
    1601     {
    1602         return -1;
    1603     }
     1645printk("\n[%s]  thread[%x,%x] exit / intialised inode & dentry for <%s> in <%s> / cycle %d\n",
     1646__FUNCTION__, this->process->pid, this->trdid, name, dir_name, cycle );
     1647#endif
     1648
     1649    return 0;
    16041650
    16051651}  // end fatfs_new_dentry()
     
    16151661    error_t    error;
    16161662
     1663    char       dir_name[CONFIG_VFS_MAX_NAME_LENGTH];
     1664
    16171665// check arguments
    16181666assert( (inode  != NULL) , "inode is NULL\n" );
     
    16211669
    16221670#if DEBUG_FATFS_UPDATE_DENTRY
    1623 char       dir_name[CONFIG_VFS_MAX_NAME_LENGTH];
    16241671uint32_t   cycle = (uint32_t)hal_get_cycles();
    16251672thread_t * this  = CURRENT_THREAD;
    16261673vfs_inode_get_name( XPTR( local_cxy , inode ) , dir_name );
    16271674if( DEBUG_FATFS_UPDATE_DENTRY < cycle )
    1628 printk("\n[%s]  thread[%x,%x] enter for entry <%s> in dir <%s> / cycle %d\n",
    1629 __FUNCTION__, this->process->pid, this->trdid, dentry->name , dir_name , cycle );
    1630 #endif
    1631 
    1632     // get pointer and index of searched directory entry in mapper
     1675printk("\n[%s]  thread[%x,%x] enter for <%s/%s> / size %d / cycle %d\n",
     1676__FUNCTION__, this->process->pid, this->trdid, dir_name, dentry->name, size, cycle );
     1677#endif
     1678
     1679    // get local pointer on mapper
    16331680    mapper = inode->mapper;
     1681
     1682    // get pointer and index in mapper for searched directory entry
    16341683    error  = fatfs_scan_directory( mapper, dentry->name , &entry , &index );
    16351684
    1636     // update size in mapper if found
    1637     if( error == 0 )
     1685    if( error )
    16381686    {
     1687        vfs_inode_get_name( XPTR( local_cxy , inode ) , dir_name );
     1688        printk("\n[ERROR] in %s : cannot find <%s> in parent mapper <%s>\n",
     1689        __FUNCTION__, dentry->name, dir_name );
     1690        return -1;
     1691    }
     1692
     1693    // set size in FAT32 directory entry
     1694    fatfs_set_record( DIR_FILE_SIZE , entry , 1 , size );
     1695
     1696    // get local pointer on modified page base
     1697    void * base = (void *)((intptr_t)entry & (~CONFIG_PPM_PAGE_MASK));
     1698
     1699    // get extended pointer on modified page descriptor
     1700    xptr_t page_xp = ppm_base2page( XPTR( local_cxy , base ) );
     1701
     1702    // synchronously update the modified page on device
     1703    error = fatfs_move_page( page_xp , IOC_SYNC_WRITE );
     1704
     1705    if( error )
     1706    {
     1707        vfs_inode_get_name( XPTR( local_cxy , inode ) , dir_name );
     1708        printk("\n[ERROR] in %s : cannot update parent directory <%s> on device\n",
     1709        __FUNCTION__, dir_name );
     1710        return -1;
     1711    }
    16391712
    16401713#if DEBUG_FATFS_UPDATE_DENTRY
    16411714cycle = (uint32_t)hal_get_cycles();
    16421715if( DEBUG_FATFS_UPDATE_DENTRY < cycle )
    1643 printk("\n[%s]  thread[%x,%x] exit / found entry <%s> in <%s> / cycle %d\n",
    1644 __FUNCTION__, this->process->pid, this->trdid, dentry->name, dir_name, cycle );
    1645 #endif
    1646         // set size in FAT32 directory entry
    1647         fatfs_set_record( DIR_FILE_SIZE , entry , 1 , size );
    1648 
    1649         // get local pointer on modified page base
    1650         void * base = (void *)((intptr_t)entry & (~CONFIG_PPM_PAGE_MASK));
    1651 
    1652         // get extended pointer on modified page descriptor
    1653         xptr_t    page_xp = ppm_base2page( XPTR( local_cxy , base ) );
    1654 
    1655         // mark page as dirty
    1656         ppm_page_do_dirty( page_xp );
    1657 
    1658         return 0;
    1659     }
    1660     else
    1661     {
    1662         return -1;
    1663     }
     1716printk("\n[%s]  thread[%x,%x] exit / updated size for <%s/%s> / cycle %d\n",
     1717__FUNCTION__, this->process->pid, this->trdid, dir_name, dentry->name, cycle );
     1718#endif
     1719
     1720    return 0;
    16641721
    16651722}  // end fatfs_update_dentry()
     
    20442101error_t fatfs_cluster_alloc( uint32_t * searched_cluster )
    20452102{
    2046     uint32_t      page_id;        // page index in mapper
     2103    uint32_t      page_id;        // page index in FAT mapper
    20472104    uint32_t      slot_id;        // slot index in page (1024 slots per page)
    2048     uint32_t      hint;           // first free cluster index in FAT
     2105    uint32_t      cluster;        // first free cluster index in FAT
    20492106    uint32_t      free_clusters;  // total number of free clusters
    20502107    vfs_ctx_t   * vfs_ctx;        // local pointer on VFS context (same in all clusters)
     
    20802137    fat_fatfs_ctx = hal_remote_lpt( XPTR( mapper_cxy , &vfs_ctx->extend ) );
    20812138
    2082     // build relevant extended pointers in on free clusters info in FAT cluster
     2139    // build relevant extended pointers on free clusters info in mapper cluster
    20832140    lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->free_lock );
    20842141    hint_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->free_cluster_hint );
     
    20892146
    20902147    // get hint and free_clusters values from FATFS context
    2091     hint          = hal_remote_l32( hint_xp );
     2148    cluster       = hal_remote_l32( hint_xp ) + 1;
    20922149    free_clusters = hal_remote_l32( numb_xp );
    20932150       
    2094     // get page index & slot index for the first free cluster
    2095     page_id  = (hint + 1) >> 10;
    2096     slot_id  = (hint + 1) & 0x3FF;
    2097 
    2098     // get relevant page from mapper
    2099     page_xp = mapper_remote_get_page( mapper_xp , page_id );
    2100 
    2101     if( page_xp == XPTR_NULL )
    2102     {
    2103         printk("\n[ERROR] in %s : cannot acces FAT mapper\n", __FUNCTION__ );
    2104         return -1;
    2105     }
    2106 
    2107     // build extended pointer on free cluster slot
    2108     slot_xp = ppm_page2base( page_xp ) + (slot_id<<2);
    2109          
    21102151#if (DEBUG_FATFS_CLUSTER_ALLOC & 1)
    21112152if( DEBUG_FATFS_CLUSTER_ALLOC < cycle )
    2112 printk("\n[%s] thread[%x,%x] get free info / hint %x / free_clusters %x\n",
    2113 __FUNCTION__, this->process->pid, this->trdid, hint, free_clusters );
     2153printk("\n[%s] thread[%x,%x] get free info : hint %x / free_clusters %x\n",
     2154__FUNCTION__, this->process->pid, this->trdid, (cluster - 1), free_clusters );
    21142155#endif
    21152156
     
    21272168    }
    21282169
    2129     // check "hint"
     2170
     2171
     2172    // get page index & slot index for selected cluster
     2173    page_id  = cluster >> 10;
     2174    slot_id  = cluster & 0x3FF;
     2175
     2176    // get relevant page descriptor from mapper
     2177    page_xp = mapper_remote_get_page( mapper_xp , page_id );
     2178
     2179    if( page_xp == XPTR_NULL )
     2180    {
     2181        printk("\n[ERROR] in %s : cannot acces FAT mapper\n", __FUNCTION__ );
     2182        return -1;
     2183    }
     2184
     2185    // build extended pointer on selected cluster slot in FAT mapper
     2186    slot_xp = ppm_page2base( page_xp ) + (slot_id << 2);
     2187         
     2188    // check selected cluster actually free
    21302189    if( hal_remote_l32( slot_xp ) != FREE_CLUSTER )
    21312190    {
    2132         printk("\n[ERROR] in %s : illegal hint cluster\n", __FUNCTION__ );
     2191        printk("\n[ERROR] in %s : selected cluster %x not free\n", __FUNCTION__, cluster );
    21332192        remote_queuelock_acquire( lock_xp );
    21342193        return -1;
    21352194    }
    21362195
    2137     // update allocated cluster in FAT mapper
    2138     hal_remote_s32( slot_xp , END_OF_CHAIN_CLUSTER_MAX );
    2139 
    2140     // update free cluster info
    2141     fatfs_free_clusters_decrement( hint + 1 );
     2196    // update free cluster info in FATFS context
     2197    fatfs_free_clusters_decrement( mapper_cxy , fat_fatfs_ctx , cluster );
    21422198
    21432199    // release free clusters busylock
    21442200    remote_queuelock_release( lock_xp );
     2201
     2202    // update FAT mapper
     2203    hal_remote_s32( slot_xp , END_OF_CHAIN_CLUSTER_MAX );
     2204
     2205    // synchronously update FAT on device
     2206    fatfs_move_page( page_xp , IOC_SYNC_WRITE );
    21452207
    21462208#if DEBUG_FATFS_CLUSTER_ALLOC
    21472209cycle = (uint32_t)hal_get_cycles();
    21482210if( DEBUG_FATFS_CLUSTER_ALLOC < cycle )
    2149 printk("\n[%s] thread[%x,%x] exit / cluster %x / cycle %d\n",
    2150 __FUNCTION__, this->process->pid, this->trdid, hint + 1, cycle );
    2151 #endif
    2152 
    2153     *searched_cluster = hint + 1;
     2211printk("\n[%s] thread[%x,%x] exit / updated cluster %x in FAT / cycle %d\n",
     2212__FUNCTION__, this->process->pid, this->trdid, cluster, cycle );
     2213#endif
     2214
     2215    *searched_cluster = cluster;
    21542216    return 0;
    21552217
     
    21642226    xptr_t        mapper_xp;      // extended pointer on FAT mapper
    21652227    cxy_t         mapper_cxy;     // Fat mapper cluster identifier
     2228    mapper_t    * mapper_ptr;     // local pointer on FAT mapper
    21662229    xptr_t        lock_xp;        // extended pointer on lock protecting free clusters info.
    21672230    xptr_t        first_xp;       // extended pointer on inode extension
     
    22042267    loc_fatfs_ctx = vfs_ctx->extend;
    22052268
    2206     // get extended pointer and cluster on FAT mapper
     2269    // get pointers and cluster on FAT mapper
    22072270    mapper_xp  = loc_fatfs_ctx->fat_mapper_xp;
    22082271    mapper_cxy = GET_CXY( mapper_xp );
     2272    mapper_ptr = GET_PTR( mapper_xp );
    22092273   
    22102274    // get local pointer on FATFS context in FAT cluster
     
    22182282
    22192283    // call the recursive function to release all clusters from FAT mapper
    2220     if ( fatfs_recursive_release( mapper_xp , first_cluster ) )
     2284    if ( fatfs_recursive_release( mapper_cxy,
     2285                                  mapper_ptr,
     2286                                  fat_fatfs_ctx,
     2287                                  first_cluster ) )
    22212288    {
    22222289        printk("\n[ERROR] in %s : cannot update FAT mapper\n", __FUNCTION__ );
     
    23002367    {
    23012368        // get lba from FATFS context and page_id
    2302         uint32_t      lba        = fatfs_ctx->fat_begin_lba + (page_id << 3);
     2369        uint32_t      lba = fatfs_ctx->fat_begin_lba + (page_id << 3);
    23032370 
    23042371        // access device
     
    23112378        if( error ) return EIO;
    23122379
    2313 #if (DEBUG_FATFS_MOVE_PAGE & 0x1)
    2314 if( DEBUG_FATFS_MOVE_PAGE < cycle )
    2315 mapper_display_page( XPTR(page_cxy , mapper_ptr) , page_id );
    2316 #endif
    2317 
    23182380#if DEBUG_FATFS_MOVE_PAGE
    2319 cycle = (uint32_t)hal_get_cycles();
    23202381if( DEBUG_FATFS_MOVE_PAGE < cycle )
    23212382{
     
    23572418                                       page_id,
    23582419                                       &searched_cluster );
    2359             if( error )  return EIO;
     2420            if( error )
     2421            {
     2422                printk("\n[ERROR] in %s : cannot access FAT mapper\n", __FUNCTION__ );
     2423                return -1;
     2424            }
    23602425        }
    23612426
    23622427        // get lba from searched_cluster
    23632428        uint32_t lba = fatfs_lba_from_cluster( fatfs_ctx , searched_cluster );
     2429
     2430#if DEBUG_FATFS_MOVE_PAGE
     2431if( DEBUG_FATFS_MOVE_PAGE < cycle )
     2432{
     2433    if ( (cmd_type == IOC_READ) || (cmd_type == IOC_SYNC_READ) )
     2434    printk("\n[%s] thread[%x,%x] load page %d of <%s> / cluster_id %x / cycle %d\n",
     2435    __FUNCTION__, this->process->pid, this->trdid, page_id, name, searched_cluster, cycle );
     2436    else
     2437    printk("\n[%s] thread[%x,%x] sync page %d of <%s> / cluster_id %x / cycle %d\n",
     2438    __FUNCTION__, this->process->pid, this->trdid, page_id, name, searched_cluster, cycle );
     2439}
     2440#endif
    23642441
    23652442        // access device
     
    23702447        else                                  error = -1;
    23712448
    2372         if( error ) return EIO;
    2373 
    2374 #if (DEBUG_FATFS_MOVE_PAGE & 0x1)
    2375 if( DEBUG_FATFS_MOVE_PAGE < cycle )
    2376 mapper_display_page( XPTR(page_cxy , mapper_ptr) , page_id );
    2377 #endif
    2378 
    2379 #if DEBUG_FATFS_MOVE_PAGE
    2380 cycle = (uint32_t)hal_get_cycles();
    2381 if(DEBUG_FATFS_MOVE_PAGE < cycle)
    2382 {
    2383     if ( (cmd_type == IOC_READ) || (cmd_type == IOC_SYNC_READ) )
    2384         printk("\n[%s] thread[%x,%x] load page %d of <%s> inode / cycle %d\n",
    2385         __FUNCTION__, this->process->pid, this->trdid, page_id, name, cycle );
    2386     else
    2387         printk("\n[%s] thread[%x,%x] sync page %d of <%s> inode / cycle %d\n",
    2388         __FUNCTION__, this->process->pid, this->trdid, page_id, name, cycle );
    2389 }
    2390 #endif
    2391 
     2449        if( error )
     2450        {
     2451            printk("\n[ERROR] in %s : cannot access device\n", __FUNCTION__ );
     2452            return -1;
     2453        }
    23922454    }
    23932455
  • trunk/kernel/fs/fatfs.h

    r623 r625  
    3535// The FATFS File System implements a FAT32 read/write file system.
    3636//
    37 // The FATFS extensions to the generic VFS are the following:
     37// The FATFS specific extensions to the generic VFS are the following:
    3838//
    3939// 1) The vfs_ctx_t "extend" field is a void* pointing on the fatfs_ctx_t structure.
     
    190190    uint32_t            root_dir_cluster;      /*! cluster index for  root directory    */
    191191    xptr_t              fat_mapper_xp;         /*! extended pointer on FAT mapper       */
    192     uint32_t            free_cluster_hint;     /*! start point to search free cluster   */
     192    uint32_t            free_cluster_hint;     /*! cluster[hint+1] is the first free    */
    193193    uint32_t            free_clusters;         /*! free clusters number                 */
    194194    remote_queuelock_t  free_lock;             /*! exclusive access to hint & number    */
     
    224224
    225225/*****************************************************************************************
    226  * This function display the content of the FATFS context.
    227  ****************************************************************************************/
    228 void fatfs_ctx_display( void );
     226 * This function display the content of the local FATFS context.
     227 *****************************************************************************************
     228 * @ ctx  : local pointer on the context.
     229 ****************************************************************************************/
     230void fatfs_ctx_display( fatfs_ctx_t * ctx );
    229231
    230232/*****************************************************************************************
     
    312314 *****************************************************************************************
    313315 * It initializes a new inode/dentry couple in Inode Tree, attached to the directory
    314  * identified by the <parent_inode> argument. The new directory entry is identified
    315  * by the <name> argument. The child inode descriptor identified by the <child_inode_xp>
    316  * argument, and the dentry descriptor must have been previously allocated.
     316 * identified by the <parent_inode> argument. The directory entry is identified
     317 * by the <name> argument. The child inode descriptor, identified by the <child_inode_xp>
     318 * argument, and the associated dentry descriptor must have been previously allocated.
    317319 * It scan the parent mapper to find the <name> argument.
    318  * It set the "type", "size", and "extend" fields in inode descriptor.
    319  * It set the " extend" field in dentry descriptor.
     320 * It set the "type", "size", and "extend" fields in the child inode descriptor.
     321 * It set the " extend" field in the dentry descriptor.
    320322 * It must be called by a thread running in the cluster containing the parent inode.
    321323 *****************************************************************************************
     
    333335 *****************************************************************************************
    334336 * It update the size of a directory entry identified by the <dentry> argument in
    335  * the mapper of a directory identified by the <inode> argument, as defined by the <size>
    336  * argument.
     337 * the mapper of a directory identified by the <inode> argument, as defined by the
     338 * <size> argument.
    337339 * It scan the mapper to find the entry identified by the dentry "name" field.
    338340 * It set the "size" field in the in the directory mapper AND marks the page as DIRTY.
     
    427429 * in <searched_cluster> the FATFS cluster index of a free cluster.
    428430 * It can be called by a thread running in any cluster, as it uses remote access
    429  * primitives when the FAT mapper is remote. It takes the "free_lock" stored in the
    430  * FATFS context located in the same cluster as the FAT mapper itself, to get exclusive
    431  * access to the FAT. It uses (and updates) the <free_cluster_hint> and <free_clusters>
    432  * shared variables in this FATFS context.
    433  * It updates the FAT mapper, and synchronously updates the FAT region on IOC device.
    434  * The FAT mapper being a cache, this function updates the FAT mapper from informations
    435  * stored on IOC device in case of miss.
     431 * primitives when the FAT mapper is remote. It takes the queuelock stored in the FATFS
     432 * context (located in the same cluster as the FAT mapper itself), to get exclusive
     433 * access to the FAT. It uses the <free_cluster_hint> and <free_clusters> variables
     434 * stored in this FATFS context.
     435 * - it updates the <free_cluster_hint> and <free_clusters> variables in FATFS context.
     436 * - it updates the FAT mapper (handling miss from IOC device if required).
     437 * - it synchronously updates the FAT region on IOC device.
     438 * - it returns the allocated cluster index.
    436439 *****************************************************************************************
    437440 * @ searched_cluster    : [out] found FATFS cluster index.
     
    461464 * This function moves a page from/to the mapper to/from the FATFS file system on device.
    462465 * The page must have been previously allocated and registered in the mapper.   
    463  * The page - and the mapper - can be located in another cluster than the calling thread.
    464466 * The pointer on the mapper and the page index in file are found in the page descriptor.
    465467 * It is used for both a regular file/directory mapper, and the FAT mapper.
  • trunk/kernel/fs/vfs.c

    r623 r625  
    175175    else
    176176    {
    177         ctx = NULL;
    178                 assert( false , "illegal file system type = %d\n" , fs_type );
     177        printk("\n[ERROR] in %s : illegal FS type\n", __FUNCTION__ );
     178        return -1;
    179179    }
    180180
     
    185185    {
    186186        printk("\n[ERROR] in %s : cannot allocate inum\n", __FUNCTION__ );
    187         return ENOMEM;
     187        return -1;
    188188    }
    189189
     
    378378{
    379379
    380 assert( (inode != NULL) , "inode pointer is NULL\n" );
     380assert( (inode != NULL) , "inode pointer is NULL" );
    381381
    382382    uint32_t   page_id;
     
    386386    uint32_t   size   = inode->size;
    387387
    388 assert( (mapper != NULL) , "mapper pointer is NULL\n" );
     388assert( (mapper != NULL) , "mapper pointer is NULL" );
    389389
    390390#if DEBUG_VFS_INODE_LOAD_ALL
     
    560560void vfs_file_destroy( vfs_file_t *  file )
    561561{
    562 
    563 // check refcount
    564 // assert( (file->refcount == 0) , "refcount non zero\n" );
    565 
    566562        kmem_req_t req;
    567563        req.ptr   = file;
     
    766762
    767763// check argument
    768 assert( (file_xp != XPTR_NULL), "file_xp == XPTR_NULL\n" );
     764assert( (file_xp != XPTR_NULL), "file_xp == XPTR_NULL" );
    769765
    770766    // get cluster and local pointer on remote file descriptor
     
    776772   
    777773// check inode type
    778 assert( (inode_type == INODE_TYPE_FILE), "inode type is not INODE_TYPE_FILE" );
     774assert( (inode_type == INODE_TYPE_FILE), "bad inode type" );
    779775
    780776    // get mapper pointer and file offset from file descriptor
    781777    file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
    782     mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
     778    mapper      = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
    783779
    784780    // move data between mapper and buffer
     
    788784                              buffer,
    789785                              size );
     786    if( error )
     787    {
     788        printk("\n[ERROR] in %s : cannot move data", __FUNCTION__ );
     789        return -1;
     790    }
    790791
    791792    // update file offset in file descriptor
    792793    hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->offset ) , size );
    793794
    794     if( error )
    795     {
    796         return -1;
    797     }
     795#if DEBUG_VFS_USER_MOVE
     796char          name[CONFIG_VFS_MAX_NAME_LENGTH];
     797uint32_t      cycle      = (uint32_t)hal_get_cycles();
     798thread_t    * this       = CURRENT_THREAD;
     799vfs_inode_t * inode      = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
     800vfs_inode_get_name( XPTR( file_cxy , inode ) , name );
     801if( cycle > DEBUG_VFS_USER_MOVE )
     802{
     803    if( to_buffer )
     804    printk("\n[%s] thread[%x,%x] moves %d bytes from <%s> mapper to buffer (%x) / cycle %d\n",
     805    __FUNCTION__ , this->process->pid, this->trdid, size, name, buffer );
     806    else           
     807    printk("\n[%s] thread[%x,%x] moves %d bytes from buffer (%x) to <%s> mapper / cycle %d\n",
     808    __FUNCTION__ , this->process->pid, this->trdid, size, buffer, name );
     809}
     810#endif
    798811
    799812    return size;
     
    816829
    817830// check argument
    818 assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL\n" );
     831assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL" );
    819832
    820833    // get cluster and local pointer on remote file descriptor
     
    825838    inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type   ) );
    826839
    827     // action depends on inode type
    828     if( inode_type == INODE_TYPE_FILE )
    829     {
    830         // get mapper pointers and file offset from file descriptor
    831         file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
    832         mapper_ptr  = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
    833         mapper_xp   = XPTR( file_cxy , mapper_ptr );
    834 
    835         // move data between mapper and buffer
    836         error = mapper_move_kernel( mapper_xp,
    837                                     to_buffer,
    838                                     file_offset,
    839                                     buffer_xp,
    840                                     size );
    841         if( error ) return -1;
    842     }
    843     else
    844     {
    845         printk("\n[ERROR] in %s : inode is not a file", __FUNCTION__ );
     840// check inode type
     841assert( (inode_type == INODE_TYPE_FILE), "bad file type" );
     842
     843    // get mapper pointers and file offset from file descriptor
     844    file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
     845    mapper_ptr  = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
     846    mapper_xp   = XPTR( file_cxy , mapper_ptr );
     847
     848    // move data between mapper and buffer
     849    error = mapper_move_kernel( mapper_xp,
     850                                to_buffer,
     851                                file_offset,
     852                                buffer_xp,
     853                                size );
     854    if( error )
     855    {
     856        printk("\n[ERROR] in %s : cannot move data", __FUNCTION__ );
    846857        return -1;
    847858    }
     859
     860#if DEBUG_VFS_KERNEL_MOVE
     861char          name[CONFIG_VFS_MAX_NAME_LENGTH];
     862uint32_t      cycle      = (uint32_t)hal_get_cycles();
     863thread_t    * this       = CURRENT_THREAD;
     864cxy_t         buffer_cxy = GET_CXY( buffer_xp );
     865void        * buffer_ptr = GET_PTR( buffer_xp );
     866vfs_inode_t * inode      = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
     867vfs_inode_get_name( XPTR( file_cxy , inode ) , name );
     868if( cycle > DEBUG_VFS_KERNEL_MOVE )
     869{
     870    if( to_buffer )
     871    printk("\n[%s] thread[%x,%x] moves %d bytes from <%s> mapper to buffer(%x,%x) / cycle %d\n",
     872    __FUNCTION__ , this->process->pid, this->trdid, size, name, buffer_cxy, buffer_ptr );
     873    else           
     874    printk("\n[%s] thread[%x,%x] moves %d bytes from buffer(%x,%x) to <%s> mapper / cycle %d\n",
     875    __FUNCTION__ , this->process->pid, this->trdid, size, buffer_cxy, buffer_ptr, name );
     876}
     877#endif
    848878
    849879    return 0;
     
    866896
    867897// check argument
    868 assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL\n" );
     898assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL" );
    869899
    870900    // get cluster and local pointer on remote file descriptor
     
    946976
    947977// check argument
    948 assert( (file_xp != XPTR_NULL) , "file_xp is XPTR_NULL\n" );
     978assert( (file_xp != XPTR_NULL) , "file_xp is XPTR_NULL" );
    949979
    950980    thread_t  * this    = CURRENT_THREAD;
     
    9971027#endif
    9981028
    999     //////// 2) update file size in all parent directory mapper(s) and on device
     1029    //////// 2) update file size in all parent directory mapper(s) and update device
    10001030
    10011031    // get pointers on remote inode
     
    10521082vfs_inode_get_name( XPTR( parent_cxy , parent_inode_ptr ) , parent_name );
    10531083if( DEBUG_VFS_CLOSE < cycle )
    1054 printk("\n[%s] thread[%x,%x] updated size of <%s> in parent <%s>\n",
    1055 __FUNCTION__, process->pid, this->trdid, name, parent_name );
     1084printk("\n[%s] thread[%x,%x] updated <%s> in <%s> / size = %d bytes\n",
     1085__FUNCTION__, process->pid, this->trdid, name, parent_name, size );
    10561086#endif
    10571087
     
    11141144#if DEBUG_VFS_CLOSE
    11151145if( DEBUG_VFS_CLOSE < cycle )
    1116 printk("\n[%s] thread[%x,%x] reset all fd-array copies for <%x>\n",
     1146printk("\n[%s] thread[%x,%x] reset all fd-array copies for <%s>\n",
    11171147__FUNCTION__, process->pid, this->trdid, name );
    11181148#endif
     
    11321162cycle = (uint32_t)hal_get_cycles();
    11331163if( DEBUG_VFS_CLOSE < cycle )
    1134 printk("\n[%s] thread[%x,%x] exit / <%s> closed / cycle %d\n",
    1135 __FUNCTION__, process->pid, this->trdid, name, cycle );
     1164printk("\n[%s] thread[%x,%x] exit / closed <%s> in process %x / cycle %d\n",
     1165__FUNCTION__, process->pid, this->trdid, name, process->pid, cycle );
    11361166#endif
    11371167
     
    20292059    vfs_inode_type_t  inode_type;   // target inode type
    20302060
    2031     // set lookup working mode
    2032     assert( (rights == 0), __FUNCTION__,
    2033     "access rights non implemented yet\n" );
     2061// check lookup working mode
     2062assert( (rights == 0), "access rights non implemented yet" );
    20342063 
    20352064    // get extended pointer on target inode
     
    20512080    // TODO implement this function
    20522081
    2053 assert( false , "not implemented\n" );
     2082assert( false , "not implemented" );
    20542083
    20552084    return 0;
     
    20612090                    uint32_t rights )
    20622091{
    2063     assert( false , "not implemented cwd_xp: %x, path <%s>, rights %x\n",
    2064       cwd_xp, path, rights );
     2092    assert( false , "not implemented %l %x %x", cwd_xp, path, rights );
    20652093    return 0;
    20662094}
     
    20842112    vfs_inode_type_t   inode_type;
    20852113    uint32_t           inode_size;
    2086     uint32_t           inode_inum;
    20872114    uint32_t           inode_attr;
    20882115    uint32_t           inode_dirty;
     2116    void             * inode_extd;
     2117
    20892118    xptr_t             children_xp;    // extended pointer on children xhtab
    20902119
     
    21152144                                        "                              " };  // level 15
    21162145
    2117 assert( (inode_xp != XPTR_NULL) , "inode_xp cannot be NULL\n" );
    2118 assert( (name_xp  != XPTR_NULL) , "name_xp cannot be NULL\n" );
    2119 assert( (indent < 16)           , "depth cannot be larger than 15\n" );
     2146assert( (inode_xp != XPTR_NULL) , "inode_xp cannot be NULL" );
     2147assert( (name_xp  != XPTR_NULL) , "name_xp cannot be NULL" );
     2148assert( (indent < 16)           , "depth cannot be larger than 15" );
    21202149   
    21212150    // get current inode cluster and local pointer
     
    21262155    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type   ) );
    21272156    inode_size = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->size   ) );
    2128     inode_inum = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->inum   ) );
    21292157    inode_attr = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->attr   ) );
     2158    inode_extd = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->extend ) );
    21302159    mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
    21312160
     
    21372166
    21382167    // display inode
    2139     nolock_printk("%s<%s> : %s / inum %d / %d bytes / dirty %d / cxy %x / inode %x / mapper %x\n",
    2140                   indent_str[indent], name, vfs_inode_type_str( inode_type ),
    2141                   inode_inum, inode_size, inode_dirty, inode_cxy, inode_ptr, mapper_ptr );
     2168    nolock_printk("%s<%s> : %s / extd %d / %d bytes / dirty %d / cxy %x / inode %x / mapper %x\n",
     2169    indent_str[indent], name, vfs_inode_type_str( inode_type ), (uint32_t)inode_extd,
     2170    inode_size, inode_dirty, inode_cxy, inode_ptr, mapper_ptr );
    21422171
    21432172    // scan directory entries when current inode is a directory
     
    24052434// check pathname / root_xp consistency
    24062435assert( ((pathname[0] != '/') || (root_xp == process->vfs_root_xp)),
    2407 "root inode must be VFS root for path <%s>\n", pathname );
     2436"root inode must be VFS root for path <%s>", pathname );
    24082437
    24092438#if DEBUG_VFS_LOOKUP
     
    25502579                if ( error )   // child not found in parent mapper
    25512580                {
    2552                     if ( last && create )  // add a brand new dentry in parent
     2581                    if ( last && create )  // add a brand new dentry in parent directory
    25532582                    {
    25542583                        error = vfs_new_dentry_init( parent_xp,               
     
    27052734    uint32_t    child_size;
    27062735
    2707 #if DEBUG_VFS_NEW_CHILD_INIT
     2736#if DEBUG_VFS_NEW_DENTRY_INIT
    27082737char parent_name[CONFIG_VFS_MAX_NAME_LENGTH];
    27092738char child_name[CONFIG_VFS_MAX_NAME_LENGTH];
     
    27122741uint32_t   cycle = (uint32_t)hal_get_cycles();
    27132742thread_t * this  = CURRENT_THREAD;
    2714 if( DEBUG_VFS_NEW_CHILD_INIT < cycle )
     2743if( DEBUG_VFS_NEW_DENTRY_INIT < cycle )
    27152744printk("\n[%s] thread[%x,%x] enter / parent <%s> / child <%s> / cycle %d\n",
    27162745__FUNCTION__ , this->process->pid, this->trdid, parent_name, child_name, cycle );
     
    27412770    }
    27422771
    2743 #if( DEBUG_VFS_NEW_CHILD_INIT & 1)
    2744 if( DEBUG_VFS_NEW_CHILD_INIT < cycle )
    2745 printk("\n[%s] thread[%x,%x] allocated one FAT cluster to <%s>\n",
    2746 __FUNCTION__ , this->process->pid, this->trdid, child_name );
     2772#if( DEBUG_VFS_NEW_DENTRY_INIT & 1)
     2773if( DEBUG_VFS_NEW_DENTRY_INIT < cycle )
     2774printk("\n[%s] thread[%x,%x] allocated FAT cluster %x to <%s>\n",
     2775__FUNCTION__ , this->process->pid, this->trdid, cluster, child_name );
    27472776#endif
    27482777
     
    27752804    }
    27762805
    2777 #if DEBUG_VFS_NEW_CHILD_INIT
     2806#if DEBUG_VFS_NEW_DENTRY_INIT
    27782807cycle = (uint32_t)hal_get_cycles();
    2779 if( DEBUG_VFS_NEW_CHILD_INIT < cycle )
     2808if( DEBUG_VFS_NEW_DENTRY_INIT < cycle )
    27802809printk("\n[%s] thread[%x,%x] exit / parent <%s> / child <%s> / cycle %d\n",
    27812810__FUNCTION__ , this->process->pid, this->trdid, parent_name, child_name, cycle );
     
    30853114
    30863115// check buffer overflow
    3087 assert( (index >= 0) , "kernel buffer too small\n" );
     3116assert( (index >= 0) , "kernel buffer too small" );
    30883117
    30893118            }
     
    31113140
    31123141// check buffer overflow
    3113 assert( (index >= 0) , "kernel buffer too small\n" );
     3142assert( (index >= 0) , "kernel buffer too small" );
    31143143
    31153144            // update pathname
     
    33793408    error_t error = 0;
    33803409
    3381 assert( (page_xp != XPTR_NULL) , "page pointer is NULL\n" );
     3410assert( (page_xp != XPTR_NULL) , "page pointer is NULL" );
    33823411
    33833412    page_t * page_ptr = GET_PTR( page_xp );
     
    33873416    mapper_t * mapper = hal_remote_lpt( XPTR( page_cxy , &page_ptr->mapper ) );
    33883417
    3389 assert( (mapper != NULL) , "no mapper for page\n" );
     3418assert( (mapper != NULL) , "no mapper for page" );
    33903419
    33913420    // get FS type
     
    34073436    else
    34083437    {
    3409         assert( false , "undefined file system type\n" );
     3438        assert( false , "undefined file system type" );
    34103439    }
    34113440
     
    34203449    error_t error = 0;
    34213450
    3422 assert( (inode  != NULL) , "inode  pointer is NULL\n" );
    3423 assert( (dentry != NULL) , "dentry pointer is NULL\n" );
     3451assert( (inode  != NULL) , "inode  pointer is NULL" );
     3452assert( (dentry != NULL) , "dentry pointer is NULL" );
    34243453
    34253454    mapper_t * mapper = inode->mapper;
    34263455
    3427 assert( (mapper != NULL) , "mapper pointer is NULL\n" );
     3456assert( (mapper != NULL) , "mapper pointer is NULL" );
    34283457
    34293458    // get FS type
     
    34453474    else
    34463475    {
    3447         assert( false , "undefined file system type\n" );
     3476        assert( false , "undefined file system type" );
    34483477    }
    34493478
     
    34583487    error_t error = 0;
    34593488
    3460 assert( (inode  != NULL) , "inode  pointer is NULL\n" );
    3461 assert( (dentry != NULL) , "dentry pointer is NULL\n" );
     3489assert( (inode  != NULL) , "inode  pointer is NULL" );
     3490assert( (dentry != NULL) , "dentry pointer is NULL" );
    34623491
    34633492    mapper_t * mapper = inode->mapper;
    34643493
    3465 assert( (mapper != NULL) , "mapper pointer is NULL\n" );
     3494assert( (mapper != NULL) , "mapper pointer is NULL" );
    34663495
    34673496    // get FS type
     
    34833512    else
    34843513    {
    3485         assert( false , "undefined file system type\n" );
     3514        assert( false , "undefined file system type" );
    34863515    }
    34873516
     
    34983527
    34993528// check arguments
    3500 assert( (parent != NULL) , "parent pointer is NULL\n");
    3501 assert( (child_xp != XPTR_NULL) , "child pointer is NULL\n");
     3529assert( (parent != NULL) , "parent pointer is NULL");
     3530assert( (child_xp != XPTR_NULL) , "child pointer is NULL");
    35023531
    35033532    // get parent inode FS type
     
    35113540    else if( fs_type == FS_TYPE_RAMFS )
    35123541    {
    3513         assert( false , "should not be called for RAMFS\n" );
     3542        assert( false , "should not be called for RAMFS" );
    35143543    }
    35153544    else if( fs_type == FS_TYPE_DEVFS )
    35163545    {
    3517         assert( false , "should not be called for DEVFS\n" );
     3546        assert( false , "should not be called for DEVFS" );
    35183547    }
    35193548    else
    35203549    {
    3521         assert( false , "undefined file system type\n" );
     3550        assert( false , "undefined file system type" );
    35223551    }
    35233552
     
    35343563
    35353564// check arguments
    3536 assert( (inode  != NULL) , "inode  pointer is NULL\n");
    3537 assert( (dentry != NULL) , "dentry pointer is NULL\n");
     3565assert( (inode  != NULL) , "inode  pointer is NULL");
     3566assert( (dentry != NULL) , "dentry pointer is NULL");
    35383567
    35393568    // get parent inode FS type
     
    35473576    else if( fs_type == FS_TYPE_RAMFS )
    35483577    {
    3549         assert( false , "should not be called for RAMFS\n" );
     3578        assert( false , "should not be called for RAMFS" );
    35503579    }
    35513580    else if( fs_type == FS_TYPE_DEVFS )
    35523581    {
    3553         assert( false , "should not be called for DEVFS\n" );
     3582        assert( false , "should not be called for DEVFS" );
    35543583    }
    35553584    else
    35563585    {
    3557         assert( false , "undefined file system type\n" );
     3586        assert( false , "undefined file system type" );
    35583587    }
    35593588
     
    35743603
    35753604// check arguments
    3576 assert( (inode != NULL) , "parent pointer is NULL\n");
    3577 assert( (array != NULL) , "child pointer is NULL\n");
     3605assert( (inode != NULL) , "parent pointer is NULL");
     3606assert( (array != NULL) , "child pointer is NULL");
    35783607assert( (detailed == false) , "detailed argument not supported\n");
    35793608
     
    36023631    else if( fs_type == FS_TYPE_RAMFS )
    36033632    {
    3604         assert( false , "should not be called for RAMFS\n" );
     3633        assert( false , "should not be called for RAMFS" );
    36053634    }
    36063635    else if( fs_type == FS_TYPE_DEVFS )
     
    36163645    else
    36173646    {
    3618         assert( false , "undefined file system type\n" );
     3647        assert( false , "undefined file system type" );
    36193648    }
    36203649
     
    36293658
    36303659// check arguments
    3631 assert( (inode != NULL) , "inode pointer is NULL\n");
     3660assert( (inode != NULL) , "inode pointer is NULL");
    36323661
    36333662    // get inode FS type
     
    36413670    else if( fs_type == FS_TYPE_RAMFS )
    36423671    {
    3643         assert( false , "should not be called for RAMFS\n" );
     3672        assert( false , "should not be called for RAMFS" );
    36443673    }
    36453674    else if( fs_type == FS_TYPE_DEVFS )
    36463675    {
    3647         assert( false , "should not be called for DEVFS\n" );
     3676        assert( false , "should not be called for DEVFS" );
    36483677    }
    36493678    else
    36503679    {
    3651         assert( false , "undefined file system type\n" );
     3680        assert( false , "undefined file system type" );
    36523681    }
    36533682
     
    36683697    else if( fs_type == FS_TYPE_RAMFS )
    36693698    {
    3670         assert( false , "should not be called for RAMFS\n" );
     3699        assert( false , "should not be called for RAMFS" );
    36713700    }
    36723701    else if( fs_type == FS_TYPE_DEVFS )
    36733702    {
    3674         assert( false , "should not be called for DEVFS\n" );
     3703        assert( false , "should not be called for DEVFS" );
    36753704    }
    36763705    else
    36773706    {
    3678         assert( false , "undefined file system type\n" );
     3707        assert( false , "undefined file system type" );
    36793708    }
    36803709
     
    36953724    else if( fs_type == FS_TYPE_RAMFS )
    36963725    {
    3697         assert( false , "should not be called for RAMFS\n" );
     3726        assert( false , "should not be called for RAMFS" );
    36983727    }
    36993728    else if( fs_type == FS_TYPE_DEVFS )
    37003729    {
    3701         assert( false , "should not be called for DEVFS\n" );
     3730        assert( false , "should not be called for DEVFS" );
    37023731    }
    37033732    else
    37043733    {
    3705         assert( false , "undefined file system type\n" );
     3734        assert( false , "undefined file system type" );
    37063735    }
    37073736
     
    37233752    else if( fs_type == FS_TYPE_RAMFS )
    37243753    {
    3725         assert( false , "should not be called for RAMFS\n" );
     3754        assert( false , "should not be called for RAMFS" );
    37263755    }
    37273756    else if( fs_type == FS_TYPE_DEVFS )
    37283757    {
    3729         assert( false , "should not be called for DEVFS\n" );
     3758        assert( false , "should not be called for DEVFS" );
    37303759    }
    37313760    else
    37323761    {
    3733         assert( false , "undefined file system type\n" );
     3762        assert( false , "undefined file system type" );
    37343763    }
    37353764
     
    37433772    error_t error = 0;
    37443773
    3745 assert( (inode_xp  != XPTR_NULL) , "inode pointer is NULL\n")       
     3774assert( (inode_xp  != XPTR_NULL) , "inode pointer is NULL")       
    37463775
    37473776    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     
    37513780    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
    37523781
    3753 assert( (mapper != NULL) , "mapper pointer is NULL\n")       
     3782assert( (mapper != NULL) , "mapper pointer is NULL")       
    37543783
    37553784    // get FS type from mapper
     
    37633792    else if( fs_type == FS_TYPE_RAMFS )
    37643793    {
    3765         assert( false , "should not be called for RAMFS\n" );
     3794        assert( false , "should not be called for RAMFS" );
    37663795    }
    37673796    else if( fs_type == FS_TYPE_DEVFS )
    37683797    {
    3769         assert( false , "should not be called for DEVFS\n" );
     3798        assert( false , "should not be called for DEVFS" );
    37703799    }
    37713800    else
    37723801    {
    3773         assert( false , "undefined file system type\n" );
     3802        assert( false , "undefined file system type" );
    37743803    }
    37753804
  • trunk/kernel/fs/vfs.h

    r623 r625  
    593593 * This function is called by the vfs_lookup() function when a new dentry/inode must
    594594 * be created from scratch and introduced in both the Inode Tree and the IOC device.
    595  * The dentry and inode descriptors have been created by the caller:
     595 * The dentry and inode descriptors have been created by the caller.
    596596 * - It allocates one cluster from the relevant FS, and updates the File Allocation
    597597 *   Table (both the FAT mapper, and the IOC device).
     
    966966 * the <inode> argument, to find a directory entry identified by the <dentry> argument,
    967967 * and update the size for this directory entry in mapper, as defined by <size>.
    968  * The searched "name" is defined in the <dentry> argument, that must be in the same
    969  * cluster as the parent inode. It is called by the vfs_close() function.
     968 * The parent directory on device is synchronously updated.
     969 * It is called by the vfs_close() function.
    970970 *
    971971 * Depending on the file system type, it calls the relevant, FS specific function.
Note: See TracChangeset for help on using the changeset viewer.