static
rc_t CC KBufWriteFileSetSize ( KBufWriteFile *self, uint64_t size )
{
    if ( self -> pos + self -> num_valid > size )
    {
        if ( self -> pos < size )
        {
            size_t total, num_writ, to_write = ( size_t ) ( size - self -> pos );
            for ( total = 0; total < to_write; total += num_writ )
            {
                rc_t rc = KFileWrite ( self -> f, self -> pos + total,
                    & self -> buff [ total ], to_write - total, & num_writ );
                if ( rc != 0 )
                    return rc;
                if ( num_writ == 0 )
                    return RC ( rcFS, rcFile, rcReading, rcTransfer, rcIncomplete );
            }
        }

        self -> pos = 0;
        self -> num_valid = 0;
    }

    return KFileSetSize ( self -> f, size );
}
static rc_t SaveToFile( struct KFile * f, const VNamelist * nl, const char * delim )
{
    uint32_t count;
    rc_t rc = VNameListCount ( nl, &count );
    if ( rc == 0 && count > 0 )
    {
        uint32_t idx;
        uint64_t pos = 0;
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char * s;
            rc = VNameListGet ( nl, idx, &s );
            if ( rc == 0 && s != NULL )
            {
                size_t num_writ;
                rc = KFileWriteAll ( f, pos, s, string_size ( s ), &num_writ );
                if ( rc == 0 )
                {
                    pos += num_writ;
                    rc = KFileWriteAll ( f, pos, delim, string_size ( delim ), &num_writ );
                    if ( rc == 0 )
                        pos += num_writ;
                }
            }
        }
        if ( rc == 0 )
            rc = KFileSetSize ( f, pos );
    }
    return rc;
}
Exemple #3
0
static rc_t LogFileSetSize_timed ( LogFile *self, uint64_t size )
{
    KTimeMs_t ms = KTimeMsStamp ();
    rc_t rc = KFileSetSize ( self -> wrapped, size );
    ms = KTimeMsStamp () - ms;
    WriteToRecorder ( self -> rec, "T\t%lu\t%lu\n", size, ms );
    return rc;
}
Exemple #4
0
/* ----------------------------------------------------------------------
 * SetSize
 *  sets size in bytes of file
 *
 *  "size" [ IN ] - new file size
 */
static
rc_t CC KCounterFileSetSize (KCounterFile *self, uint64_t size)
{
    rc_t rc;

    rc = KFileSetSize (self->original, size);
    if (rc == 0)
	self->max_position = size;
    return rc;
}
Exemple #5
0
rc_t MMArrayGet(struct MMArray *const self, void **const value, uint64_t const element)
{
    unsigned const bin_no = element >> 32;
    unsigned const subbin = ((uint32_t)element) >> MMA_NUM_CHUNKS_BITS;
    unsigned const in_bin = (uint32_t)element & (MMA_SUBCHUNK_SIZE - 1);

    if (bin_no >= sizeof(self->map)/sizeof(self->map[0]))
        return RC(rcExe, rcMemMap, rcConstructing, rcId, rcExcessive);
    
    if (self->map[bin_no].submap[subbin].base == NULL) {
        size_t const chunk = MMA_SUBCHUNK_SIZE * self->elemSize;
        size_t const fsize = self->fsize + chunk;
        rc_t rc = KFileSetSize(self->fp, fsize);
        
        if (rc == 0) {
            KMMap *mmap;
            
            self->fsize = fsize;
            rc = KMMapMakeRgnUpdate(&mmap, self->fp, self->fsize, chunk);
            if (rc == 0) {
                void *base;
                
                rc = KMMapAddrUpdate(mmap, &base);
                if (rc == 0) {
#if PERF
                    static unsigned mapcount = 0;

                    (void)PLOGMSG(klogInfo, (klogInfo, "Number of mmaps: $(cnt)", "cnt=%u", ++mapcount));
#endif
                    self->map[bin_no].submap[subbin].mmap = mmap;
                    self->map[bin_no].submap[subbin].base = base;

                    goto GET_MAP;
                }
                KMMapRelease(mmap);
            }
        }
        return rc;
    }
GET_MAP:
    *value = &self->map[bin_no].submap[subbin].base[(size_t)in_bin * self->elemSize];
    return 0;
}
Exemple #6
0
static
rc_t CC KHttpUndyingFileSetSize(KHttpUndyingFile *self, uint64_t size)
{
    return KFileSetSize(GetUnderlyingFile(self), size);
}
Exemple #7
0
/* ----------------------------------------------------------------------
 * SetSize
 *  sets size in bytes of file
 *
 *  "size" [ IN ] - new file size
 */
static
rc_t CC CCFileSetSize (CCFile *self, uint64_t size)
{
    return KFileSetSize (self->original, size);
}
Exemple #8
0
static rc_t LogFileSetSize ( LogFile *self, uint64_t size )
{
    rc_t rc = KFileSetSize ( self -> wrapped, size );
    WriteToRecorder ( self -> rec, "T\t%lu\n", size );
    return rc;
}