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


Ignore:
Timestamp:
Jan 11, 2019, 6:35:07 PM (6 years ago)
Author:
alain
Message:

Fix several bugs in vfs.c, fatfs.c, and devfs.c to support
the <.> and <..> directory entries.

File:
1 edited

Legend:

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

    r611 r612  
    23502350                if( parent_cxy == local_cxy )
    23512351                {
    2352                     error = vfs_fs_child_init( parent_ptr,
     2352                    error = vfs_fs_get_dentry( parent_ptr,
    23532353                                               name,
    23542354                                               child_xp );
     
    23562356                else
    23572357                {
    2358                     rpc_vfs_fs_child_init_client( parent_cxy,
     2358                    rpc_vfs_fs_get_dentry_client( parent_cxy,
    23592359                                                  parent_ptr,
    23602360                                                  name,
     
    23672367                    if ( last && create )  // add a brand new dentry in parent
    23682368                    {
    2369                         error = vfs_new_child_init( parent_xp,               
    2370                                                     dentry_xp,
    2371                                                     child_xp );
     2369                        error = vfs_new_dentry_init( parent_xp,               
     2370                                                     dentry_xp,
     2371                                                     child_xp );
    23722372                        if ( error )
    23732373                        {
     
    25102510}  // end vfs_lookup()
    25112511
    2512 ///////////////////////////////////////////////
    2513 error_t vfs_new_child_init( xptr_t   parent_xp,
    2514                             xptr_t   dentry_xp,
    2515                             xptr_t   child_xp )
     2512////////////////////////////////////////////////
     2513error_t vfs_new_dentry_init( xptr_t   parent_xp,
     2514                             xptr_t   dentry_xp,
     2515                             xptr_t   child_xp )
    25162516{
    25172517    error_t     error;
     
    25992599    return 0;
    26002600
    2601 }  // end vfs_new_child_init()
     2601}  // end vfs_new_dentry_init()
    26022602
    26032603///////////////////////////////////////////////////
     
    26152615    vfs_dentry_t  * dentry_ptr;        // local pointer on dentry (used for . and ..)
    26162616
    2617     xptr_t          parents_root_xp;   // extended pointer on inode "parents" field
    2618     xptr_t          parents_entry_xp;  // extended pointer on dentry "parents" field
     2617    // xptr_t          parents_root_xp;   // extended pointer on inode "parents" field
     2618    // xptr_t          parents_entry_xp;  // extended pointer on dentry "parents" field
    26192619    xptr_t          children_xhtab_xp; // extended pointer on inode "children" field
    26202620    xptr_t          children_entry_xp; // extended pointer on dentry "children" field
     
    26282628vfs_inode_get_name( parent_xp , parent_name );
    26292629if( DEBUG_VFS_ADD_SPECIAL < cycle )
    2630 printk("\n[%s] thread[%x,%x] enter / child <%s> / parent <%s> / cycle %d\n",
     2630printk("\n[%s] thread[%x,%x] enter for child <%s> in parent <%s> / cycle %d\n",
    26312631__FUNCTION__, this->process->pid, this->trdid, child_name, parent_name, cycle );
    26322632#endif
     
    26862686    }
    26872687
    2688     // register <.> dentry in child_inode xlist of parents TODO faut-il ?
    2689     parents_root_xp  = XPTR( child_cxy , &child_ptr->parents );
    2690     parents_entry_xp = XPTR( child_cxy , &dentry_ptr->parents );
    2691     xlist_add_first( parents_root_xp , parents_entry_xp );
    2692     hal_remote_atomic_add( XPTR( child_cxy , &child_ptr->links ) , 1 );
     2688   
     2689    // don't register <.> dentry in child_inode xlist of parents
     2690    // parents_root_xp  = XPTR( child_cxy , &child_ptr->parents );
     2691    // parents_entry_xp = XPTR( child_cxy , &dentry_ptr->parents );
     2692    // xlist_add_first( parents_root_xp , parents_entry_xp );
     2693    // hal_remote_atomic_add( XPTR( child_cxy , &child_ptr->links ) , 1 );
    26932694
    26942695    // update "parent" and "child_xp" fields in <.> dentry
     
    27702771    }
    27712772
    2772     // register <..> dentry in parent_inode xlist of parents TODO faut-il ?
    2773     parents_root_xp  = XPTR( parent_cxy , &parent_ptr->parents );
    2774     parents_entry_xp = XPTR( child_cxy  , &dentry_ptr->parents );
    2775     xlist_add_first( parents_root_xp , parents_entry_xp );
    2776     hal_remote_atomic_add( XPTR( parent_cxy , &parent_ptr->links ) , 1 );
     2773    // don't register <..> dentry in parent_inode xlist of parents
     2774    // parents_root_xp  = XPTR( parent_cxy , &parent_ptr->parents );
     2775    // parents_entry_xp = XPTR( child_cxy  , &dentry_ptr->parents );
     2776    // xlist_add_first( parents_root_xp , parents_entry_xp );
     2777    // hal_remote_atomic_add( XPTR( parent_cxy , &parent_ptr->links ) , 1 );
    27772778
    27782779    // update "parent" and "child_xp" fields in <..> dentry
     
    28152816cycle = (uint32_t)hal_get_cycles();
    28162817if( DEBUG_VFS_ADD_SPECIAL < cycle )
    2817 printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
    2818 __FUNCTION__, this->process->pid, this->trdid, (uint32_t)hal_get_cycles() );
     2818printk("\n[%s] thread[%x,%x] exit for child <%s> in parent <%s> / cycle %d\n",
     2819__FUNCTION__, this->process->pid, this->trdid, child_name, parent_name, cycle );
    28192820#endif
    28202821
     
    31833184}  // end vfs_remove_child_from_parent()
    31843185
     3186
     3187
     3188
    31853189//////////////////////////////////////////////////////////////////////////////////////////
    31863190//    API used by VFS to access a specific FS 
     
    32513255    else if( fs_type == FS_TYPE_RAMFS )
    32523256    {
    3253         assert( false , "should not be called for RAMFS\n" );
     3257        error = 0;     // does nothing for RAMFS
    32543258    }
    32553259    else if( fs_type == FS_TYPE_DEVFS )
    32563260    {
    3257         assert( false , "should not be called for DEVFS\n" );
     3261        error = 0;     // does nothing for DEVFS
    32583262    }
    32593263    else
     
    32893293    else if( fs_type == FS_TYPE_RAMFS )
    32903294    {
    3291         assert( false , "should not be called for RAMFS\n" );
     3295        error = 0;     // does nothing for RAMFS
    32923296    }
    32933297    else if( fs_type == FS_TYPE_DEVFS )
    32943298    {
    3295         assert( false , "should not be called for DEVFS\n" );
     3299        error = 0;     // does nothing for DEVFS
    32963300    }
    32973301    else
     
    33053309
    33063310////////////////////////////////////////////////
    3307 error_t vfs_fs_child_init( vfs_inode_t * parent,
     3311error_t vfs_fs_get_dentry( vfs_inode_t * parent,
    33083312                           char        * name,
    33093313                           xptr_t        child_xp )
     
    33213325    if( fs_type == FS_TYPE_FATFS )
    33223326    {
    3323         error = fatfs_child_init( parent , name , child_xp );
     3327        error = fatfs_get_dentry( parent , name , child_xp );
    33243328    }
    33253329    else if( fs_type == FS_TYPE_RAMFS )
     
    33383342    return error;
    33393343
    3340 } // end vfs_fs_child_init()
    3341 
     3344} // end vfs_fs_get_dentry()
     3345
     3346///////////////////////////////////////////////////
     3347error_t vfs_fs_get_user_dir( vfs_inode_t   * inode,
     3348                             struct dirent * array,
     3349                             uint32_t        max_dirent,
     3350                             uint32_t        min_dentry,
     3351                             bool_t          detailed,
     3352                             uint32_t      * entries,
     3353                             bool_t        * done )
     3354{
     3355    error_t error = 0;
     3356
     3357// check arguments
     3358assert( (inode != NULL) , "parent pointer is NULL\n");
     3359assert( (array != NULL) , "child pointer is NULL\n");
     3360assert( (detailed == false) , "detailed argument not supported\n");
     3361
     3362    // check inode type
     3363    if( inode->type != INODE_TYPE_DIR )
     3364    {
     3365        printk("\n[ERROR] in %s : target inode is not a directory\n",
     3366        __FUNCTION__ );
     3367        return -1;
     3368    }
     3369
     3370    // get parent inode FS type
     3371    vfs_fs_type_t fs_type = inode->ctx->type;
     3372
     3373    // call relevant FS function
     3374    if( fs_type == FS_TYPE_FATFS )
     3375    {
     3376        error = fatfs_get_user_dir( inode,
     3377                                    array,
     3378                                    max_dirent,
     3379                                    min_dentry,
     3380                                    detailed,
     3381                                    entries,
     3382                                    done );
     3383    }
     3384    else if( fs_type == FS_TYPE_RAMFS )
     3385    {
     3386        assert( false , "should not be called for RAMFS\n" );
     3387    }
     3388    else if( fs_type == FS_TYPE_DEVFS )
     3389    {
     3390        error = devfs_get_user_dir( inode,
     3391                                    array,
     3392                                    max_dirent,
     3393                                    min_dentry,
     3394                                    detailed,
     3395                                    entries,
     3396                                    done );
     3397    }
     3398    else
     3399    {
     3400        assert( false , "undefined file system type\n" );
     3401    }
     3402
     3403    return error;
     3404
     3405}  // end vfs_fs_get_user_dir()
     3406 
    33423407////////////////////////////////////////////////
    33433408error_t vfs_fs_sync_inode( vfs_inode_t * inode )
Note: See TracChangeset for help on using the changeset viewer.