Пример #1
0
RetCode ProcessFileSystem::openFile ( const std::string& path, bool, FileHandle& fh )
{
    Entry* e = getEntry ( path );

    if ( e == nullptr )
        return NoSuchPath;

    if ( e->file == nullptr )
        return InvalidFileType;

    assert ( e->file != nullptr );
    assert ( e->dir == nullptr );

    fh.Clear();
    fh.set_hid ( HostId );
    fh.set_fid ( genHandle ( e ) );

    assert ( fh.fid() >= 0 );

    RetCode rc = e->file->open ( fh );

    if ( NotOk ( rc ) )
    {
        releaseHandle ( fh.fid() );
        fh.Clear();
    }

    return rc;
}
Пример #2
0
RetCode ProcessFileSystem::closeFile ( const FileHandle& fh )
{
    if ( fh.hid() != HostId )
        return InvalidFileHandle;

    Entry* e = handles_[fh.fid()];

    if ( e == nullptr )
        return InvalidFileHandle;

    assert ( e->file != nullptr );
    assert ( e->dir == nullptr );

    e->file->close ( fh );

    // we release the file handle regardless of errors (can't really be any)
    releaseHandle ( fh.fid() );

    return Success;
}
Пример #3
0
RetCode ProcessFileSystem::readFile ( const FileHandle& fh, std::vector<char>& data,
                                      off_t offset, size_t& processed ) const
{
    Entry* e = handles_.at ( fh.fid() );

    if ( e == nullptr || e->file == nullptr )
        return InvalidFileHandle;

    assert ( e->dir == nullptr );

    return e->file->read ( fh, data, offset, processed );
}