client/src/unifycr.c
int unifycr_fid_write_zero(int fid, off_t pos, off_t count)
{
    int rc = UNIFYCR_SUCCESS;

    /* allocate an aligned chunk of memory */
    size_t buf_size = 1024 * 1024;
    void* buf = (void*) malloc(buf_size);
    if (buf == NULL) {
        return UNIFYCR_ERR_IO;
    }

    /* set values in this buffer to zero */
    memset(buf, 0, buf_size);

    /* write zeros to file */
    off_t written = 0;
    off_t curpos = pos;
    while (written < count) {
        /* compute number of bytes to write on this iteration */
        size_t num = buf_size;
        off_t remaining = count - written;
        if (remaining < (off_t) buf_size) {
            num = (size_t) remaining;
        }

        /* write data to file */
        int write_rc = unifycr_fid_write(fid, curpos, buf, num);
        if (write_rc != UNIFYCR_SUCCESS) {
            rc = UNIFYCR_ERR_IO;
            break;
        }

        /* update the number of bytes written */
        curpos  += (off_t) num;
        written += (off_t) num;
    }

    /* free the buffer */
    free(buf);

    return rc;
}
/* given a file id, write zero bytes to region of specified offset
 * and length, assumes space is already reserved */
given a file id, write zero bytes to region of specified offset
and length, assumes space is already reserved
given a file id write zero bytes to region of specified offset and length assumes space is already reserved
int unifycr_fid_write_zero(int fid, off_t pos, off_t count)
{
    int rc = UNIFYCR_SUCCESS;
    size_t buf_size = 1024 * 1024;
    void* buf = (void*) malloc(buf_size);
    if (buf == NULL) {
        return UNIFYCR_ERR_IO;
    }
    memset(buf, 0, buf_size);
    off_t written = 0;
    off_t curpos = pos;
    while (written < count) {
        size_t num = buf_size;
        off_t remaining = count - written;
        if (remaining < (off_t) buf_size) {
            num = (size_t) remaining;
        }
        int write_rc = unifycr_fid_write(fid, curpos, buf, num);
        if (write_rc != UNIFYCR_SUCCESS) {
            rc = UNIFYCR_ERR_IO;
            break;
        }
        curpos  += (off_t) num;
        written += (off_t) num;
    }
    free(buf);
    return rc;
}
int unifycr_fid_write_zero ( int fid , off_t pos , off_t count ) { int rc = UNIFYCR_SUCCESS ; size_t buf_size = 1024 * 1024 ; void * buf = ( void * ) malloc ( buf_size ) ; if ( buf == NULL ) { return UNIFYCR_ERR_IO ; } memset ( buf , 0 , buf_size ) ; off_t written = 0 ; off_t curpos = pos ; while ( written < count ) { size_t num = buf_size ; off_t remaining = count - written ; if ( remaining < ( off_t ) buf_size ) { num = ( size_t ) remaining ; } int write_rc = unifycr_fid_write ( fid , curpos , buf , num ) ; if ( write_rc != UNIFYCR_SUCCESS ) { rc = UNIFYCR_ERR_IO ; break ; } curpos += ( off_t ) num ; written += ( off_t ) num ; } free ( buf ) ; return rc ; }
given a file id, write zero bytes to region of specified offset
 and length, assumes space is already reserved
given a file id write zero bytes to region of specified offset and length assumes space is already reserved
/* allocate an aligned chunk of memory */ /* set values in this buffer to zero */ /* write zeros to file */ /* compute number of bytes to write on this iteration */ /* write data to file */ /* update the number of bytes written */ /* free the buffer */