Ignore:
Timestamp:
Jan 9, 2019, 3:02:51 PM (5 years ago)
Author:
alain
Message:

Introduce sigificant modifs in VFS to support the <ls> command,
and the . and .. directories entries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_opendir.c

    r610 r611  
    11/*
    2  * sys_opendir.c - open a directory.
     2 * sys_opendir.c - Open a VFS directory.
    33 *
    44 * Author        Alain Greiner (2016,2017,2018)
     
    2222 */
    2323
     24#include <kernel_config.h>
    2425#include <hal_kernel_types.h>
    2526#include <hal_uspace.h>
    2627#include <thread.h>
    2728#include <process.h>
     29#include <remote_dir.h>
    2830#include <printk.h>
    2931#include <errno.h>
     32#include <vseg.h>
    3033#include <vfs.h>
    3134#include <syscalls.h>
     
    3639                  DIR  ** dirp )
    3740{
    38     error_t       error;
    39     vseg_t      * vseg;                   // for user space checking
    40     xptr_t        root_inode_xp;          // extended pointer on path root inode
    41 
     41    error_t        error;
     42    xptr_t         root_inode_xp;          // extended pointer on path root inode
     43    xptr_t         inode_xp;               // extended pointer on directory inode
     44    vfs_inode_t  * inode_ptr;              // local pointer on directory inode
     45    cxy_t          inode_cxy;              // directory inode cluster
     46    uint32_t       inode_type;             // to check directory inode type
     47    xptr_t         dir_xp;                 // extended pointer on remote_dir_t
     48    remote_dir_t * dir_ptr;                // local pointer on remote_dir_t
     49    cxy_t          dir_cxy;                // remote_dir_t cluster identifier
     50    vseg_t       * vseg;                   // for user space checking
     51    intptr_t       ident;                  // dirent array pointer in user space                 
    4252    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4353       
    44         thread_t  * this    = CURRENT_THREAD;
    45         process_t * process = this->process;
     54        thread_t     * this    = CURRENT_THREAD;  // client thread
     55        process_t    * process = this->process;   // client process
    4656
    4757#if (DEBUG_SYS_OPENDIR || CONFIG_INSTRUMENTATION_SYSCALLS)
     
    8595#endif
    8696
    87     // compute root inode for path
     97    // compute root inode for pathname
    8898    if( kbuf[0] == '/' )                        // absolute path
    8999    {
     
    102112    }
    103113
    104 /*
    105     // call the relevant VFS function ???
    106     error = vfs_opendir( root_inode_xp,
    107                          kbuf );
     114    // get extended pointer on directory inode
     115    error = vfs_lookup( root_inode_xp,
     116                        kbuf,
     117                        0,
     118                        &inode_xp,
     119                        NULL );
    108120    if( error )
    109121        {
    110122
    111123#if DEBUG_SYSCALLS_ERROR
    112 printk("\n[ERROR] in %s / thread[%x,%x] : cannot open directory <%s>\n",
    113 __FUNCTION__ , process->pid , this->trdid , pathname );
     124printk("\n[ERROR] in %s / thread[%x,%x] : cannot found directory <%s>\n",
     125__FUNCTION__ , process->pid , this->trdid , kbuf );
    114126#endif
    115127                this->errno = ENFILE;
     
    117129        }
    118130   
    119     // copy to user space ???
    120 */
     131    // check inode type
     132    inode_ptr  = GET_PTR( inode_xp );
     133    inode_cxy  = GET_CXY( inode_xp );
     134    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
     135
     136    if( inode_type != INODE_TYPE_DIR )
     137        {
     138
     139#if DEBUG_SYSCALLS_ERROR
     140printk("\n[ERROR] in %s / thread[%x,%x] : cannot found directory <%s>\n",
     141__FUNCTION__ , process->pid , this->trdid , kbuf );
     142#endif
     143                this->errno = ENFILE;
     144                return -1;
     145        }
     146   
     147    // allocate, initialize, and register a new remote_dir_t structure
     148    // in the calling process reference cluster
     149    dir_xp  = remote_dir_create( inode_xp );
     150    dir_ptr = GET_PTR( dir_xp );
     151    dir_cxy = GET_CXY( dir_xp );
     152
     153    if( dir_xp == XPTR_NULL )
     154        {
     155
     156#if DEBUG_SYSCALLS_ERROR
     157printk("\n[ERROR] in %s / thread[%x,%x] : cannot create remote_dir for <%s>\n",
     158__FUNCTION__ , process->pid , this->trdid , kbuf );
     159#endif
     160                this->errno = ENFILE;
     161                return -1;
     162        }
     163   
     164    // get ident from remote_dir structure
     165    ident = (intptr_t)hal_remote_lpt( XPTR( dir_cxy , &dir_ptr->ident ) );
     166
     167    // set ident value in user buffer
     168    hal_copy_to_uspace( dirp , &ident , sizeof(intptr_t) );
    121169
    122170    hal_fence();
Note: See TracChangeset for help on using the changeset viewer.