Пример #1
0
static
rc_t KLoaderFile_Open(KLoaderFile* self)
{
    rc_t rc = 0;

    DBG(("%s opening %s\n", __func__, self->realname));
    if( (rc = KDirectoryOpenFileRead(self->dir, &self->kfile, "%s", self->realname)) == 0 ) {
        if( self->has_md5 ) {
            const KFile *md5File = NULL;
            DBG(("%s opening as md5 wrapped %s\n", __func__, self->realname));
            if( (rc = KFileMakeMD5Read(&md5File, self->file, self->md5_digest)) == 0) {
                self->file = md5File;
            }
        }
        if( rc == 0 ) {
            const KFile *z = NULL;
            switch(self->compress_type) {
                case compress_none:
                    break;
                case compress_gzip:
                    DBG(("%s opening as gzip wrapped %s\n", __func__, self->realname));
                    if( (rc = KFileMakeGzipForRead(&z, self->file)) == 0 ) {
                        KFileRelease(self->file);
                        self->file = z;
                    }
                    break;
                case compress_bzip2:
                    DBG(("%s opening as bzip2 wrapped %s\n", __func__, self->realname));
                    if( (rc = KFileMakeBzip2ForRead(&z, self->file)) == 0 ) {
                        KFileRelease(self->file);
                        self->file = z;
                    }
                    break;
                default:
                    rc = RC(rcApp, rcFile, rcOpening, rcType, rcUnexpected);
                    break;
            }
#if ! WINDOWS
            if( rc == 0 && self->ahead ) {
                const KFile *z = NULL;
                if( (rc = KQueueFileMakeRead(&z, self->pos, self->file,
                                             self->buffer_size * 10,  self->buffer_size, 0)) == 0 ) {
                    KFileRelease(self->file);
                    self->file = z;
                }
            }
#endif
        }
    }
    if( rc != 0 ) {
        PLOGERR(klogErr, (klogErr, rc, "opening $(file)", PLOG_S(file), self->filename));
        KFileRelease(self->file);
    }
    return rc;
}
Пример #2
0
static rc_t perform_qtest( const KFile *f, const char * filename,
                           const uint64_t pos, const uint64_t count,
                           const size_t queue_size, const size_t block_size,
                           const size_t chunk_size )
{
    const KFile * qf;
    rc_t rc = KQueueFileMakeRead ( &qf, pos, f, queue_size, block_size, 0 );
    if ( rc != 0 )
    {
        OUTMSG(( "KQueueFileMakeRead( '%s' ) failed: %R\n", filename, rc ));
    }
    else
    {
        uint8_t digest [ 16 ];
        rc = read_loop( qf, pos, count, chunk_size, digest );
        KFileRelease( qf );
        print_digest( digest );
    }
    return rc;
}