Changeset 266 for trunk/kernel/vfs/vfs.c


Ignore:
Timestamp:
Jul 21, 2017, 1:51:24 PM (7 years ago)
Author:
alain
Message:

Implement vfs_lseek() function.

File:
1 edited

Legend:

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

    r265 r266  
    718718                   uint32_t * new_offset )
    719719{
    720     printk("\n[PANIC] %s non implemented\n", __FUNCTION__ );
    721     hal_core_sleep();
    722     return 0;
    723 
    724     assert( ( file_xp != XPTR_NULL ) , __FUNCTION__ , "file_xp == XPTR_NULL" );
     720    xptr_t         offset_xp;
     721    xptr_t         lock_xp;
     722    cxy_t          file_cxy;
     723    vfs_file_t  *  file_ptr;
     724    vfs_inode_t *  inode_ptr;
     725    uint32_t       new;
     726
     727    assert( (file_xp != XPTR_NULL) , __FUNCTION__ , "file_xp == XPTR_NULL" );
     728
     729    // get cluster and local pointer on remote file descriptor
     730    file_cxy = GET_CXY( file_xp );
     731    file_ptr = (vfs_file_t *)GET_PTR( file_xp );
     732
     733    // build extended pointers on lock and offset
     734    offset_xp = XPTR( file_cxy , &file_ptr->offset );
     735    lock_xp   = XPTR( file_cxy , &file_ptr->lock );
     736
     737    // take file descriptor lock
     738    remote_rwlock_wr_lock( lock_xp );
     739
     740    if      ( whence == SEEK_CUR )   // new = current + offset
     741    {
     742        new = hal_remote_lw( offset_xp ) + offset;
     743    }
     744    else if ( whence == SEEK_SET )   // new = offset
     745    {
     746        new = offset;
     747    }
     748    else if ( whence == SEEK_END )   // new = size + offset
     749    {
     750        // get local pointer on remote inode
     751        inode_ptr = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
     752
     753        new = hal_remote_lw( XPTR( file_cxy , &inode_ptr->size ) ) + offset;
     754    }
     755    else
     756    {
     757        printk("\n[ERROR] in %s : illegal whence value\n", __FUNCTION__ );
     758        remote_rwlock_wr_unlock( lock_xp );
     759        return -1;
     760    }
     761
     762    // set new offset
     763    hal_remote_sw( offset_xp , new );
     764
     765    // release file descriptor lock
     766    remote_rwlock_wr_unlock( lock_xp );
     767
     768    // success
     769    *new_offset = new;
     770    return 0;
    725771
    726772}  // vfs_lseek()
Note: See TracChangeset for help on using the changeset viewer.