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_display.c

    r594 r611  
    3131#include <string.h>
    3232#include <shared_syscalls.h>
     33#include <vfs.h>
     34#include <mapper.h>
    3335
    3436#include <syscalls.h>
     
    5658int sys_display( reg_t  type,
    5759                 reg_t  arg0,
    58                  reg_t  arg1 )
     60                 reg_t  arg1,
     61                 reg_t  arg2 )
    5962{
    6063
     
    278281        thread_display_busylocks( thread_xp );
    279282    }
     283    /////////////////////////////////
     284    else if( type == DISPLAY_MAPPER )
     285    {
     286        xptr_t        root_inode_xp;
     287        xptr_t        inode_xp;
     288        cxy_t         inode_cxy;
     289        vfs_inode_t * inode_ptr;
     290        xptr_t        mapper_xp;
     291        mapper_t    * mapper_ptr;
     292
     293        char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     294
     295        char     * path    = (char *)arg0;
     296        uint32_t   page_id = (uint32_t)arg1;
     297        uint32_t   nbytes  = (uint32_t)arg2;
     298
     299        // check pathname length
     300        if( hal_strlen_from_uspace( path ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     301        {
     302
     303#if DEBUG_SYSCALLS_ERROR
     304printk("\n[ERROR] in %s for MAPPER : pathname too long\n",
     305 __FUNCTION__ );
     306#endif
     307            this->errno = ENFILE;
     308            return -1;
     309        }
     310
     311        // copy pathname in kernel space
     312        hal_strcpy_from_uspace( kbuf , path , CONFIG_VFS_MAX_PATH_LENGTH );
     313
     314        // compute root inode for pathname
     315        if( kbuf[0] == '/' )                        // absolute path
     316        {
     317            // use extended pointer on VFS root inode
     318            root_inode_xp = process->vfs_root_xp;
     319        }
     320        else                                        // relative path
     321        {
     322            // get cluster and local pointer on reference process
     323            xptr_t      ref_xp  = process->ref_xp;
     324            process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     325            cxy_t       ref_cxy = GET_CXY( ref_xp );
     326
     327            // use extended pointer on CWD inode
     328            root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
     329        }
     330
     331        // get extended pointer on target inode
     332        error = vfs_lookup( root_inode_xp,
     333                            kbuf,
     334                            0,
     335                            &inode_xp,
     336                            NULL );
     337        if( error )
     338            {
     339
     340#if DEBUG_SYSCALLS_ERROR
     341printk("\n[ERROR] in %s for MAPPER : cannot found inode <%s>\n",
     342__FUNCTION__ , kbuf );
     343#endif
     344                    this->errno = ENFILE;
     345                    return -1;
     346            }
     347   
     348        // get target inode cluster and local pointer
     349        inode_cxy = GET_CXY( inode_xp );
     350        inode_ptr = GET_PTR( inode_xp );
     351
     352        // get extended pointer on target mapper
     353        mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     354        mapper_xp  = XPTR( inode_cxy , mapper_ptr );
     355
     356        // display mapper
     357        error = mapper_display_page( mapper_xp , page_id , nbytes , kbuf );
     358
     359        if( error )
     360            {
     361
     362#if DEBUG_SYSCALLS_ERROR
     363printk("\n[ERROR] in %s for MAPPER : cannot display page %d\n",
     364__FUNCTION__ , page_id );
     365#endif
     366                    this->errno = ENFILE;
     367                    return -1;
     368            }
     369    }
    280370    ////
    281371    else
Note: See TracChangeset for help on using the changeset viewer.