client/src/unifycr.c
int unifycr_fid_truncate(int fid, off_t length)
{
    /* get meta data for this file */
    unifycr_filemeta_t* meta = unifycr_get_meta_from_fid(fid);

    /* get current size of file */
    off_t size = meta->size;

    /* drop data if length is less than current size,
     * allocate new space and zero fill it if bigger */
    if (length < size) {
        /* determine the number of chunks to leave after truncating */
        int shrink_rc = unifycr_fid_shrink(fid, length);
        if (shrink_rc != UNIFYCR_SUCCESS) {
            return shrink_rc;
        }
    } else if (length > size) {
        /* file size has been extended, allocate space */
        int extend_rc = unifycr_fid_extend(fid, length);
        if (extend_rc != UNIFYCR_SUCCESS) {
            return UNIFYCR_ERR_NOSPC;
        }

        /* write zero values to new bytes */
        off_t gap_size = length - size;
        int zero_rc = unifycr_fid_write_zero(fid, size, gap_size);
        if (zero_rc != UNIFYCR_SUCCESS) {
            return UNIFYCR_ERR_IO;
        }
    }

    /* set the new size */
    meta->size = length;

    return UNIFYCR_SUCCESS;
}
/* truncate file id to given length, frees resources if length is
 * less than size and allocates and zero-fills new bytes if length
 * is more than size */
truncate file id to given length, frees resources if length is
less than size and allocates and zero-fills new bytes if length
is more than size
truncate file id to given length frees resources if length is less than size and allocates and zero - fills new bytes if length is more than size
int unifycr_fid_truncate(int fid, off_t length)
{
    unifycr_filemeta_t* meta = unifycr_get_meta_from_fid(fid);
    off_t size = meta->size;
    if (length < size) {
        int shrink_rc = unifycr_fid_shrink(fid, length);
        if (shrink_rc != UNIFYCR_SUCCESS) {
            return shrink_rc;
        }
    } else if (length > size) {
        int extend_rc = unifycr_fid_extend(fid, length);
        if (extend_rc != UNIFYCR_SUCCESS) {
            return UNIFYCR_ERR_NOSPC;
        }
        off_t gap_size = length - size;
        int zero_rc = unifycr_fid_write_zero(fid, size, gap_size);
        if (zero_rc != UNIFYCR_SUCCESS) {
            return UNIFYCR_ERR_IO;
        }
    }
    meta->size = length;
    return UNIFYCR_SUCCESS;
}
int unifycr_fid_truncate ( int fid , off_t length ) { unifycr_filemeta_t * meta = unifycr_get_meta_from_fid ( fid ) ; off_t size = meta -> size ; if ( length < size ) { int shrink_rc = unifycr_fid_shrink ( fid , length ) ; if ( shrink_rc != UNIFYCR_SUCCESS ) { return shrink_rc ; } } else if ( length > size ) { int extend_rc = unifycr_fid_extend ( fid , length ) ; if ( extend_rc != UNIFYCR_SUCCESS ) { return UNIFYCR_ERR_NOSPC ; } off_t gap_size = length - size ; int zero_rc = unifycr_fid_write_zero ( fid , size , gap_size ) ; if ( zero_rc != UNIFYCR_SUCCESS ) { return UNIFYCR_ERR_IO ; } } meta -> size = length ; return UNIFYCR_SUCCESS ; }
truncate file id to given length, frees resources if length is
 less than size and allocates and zero-fills new bytes if length
 is more than size
truncate file id to given length frees resources if length is less than size and allocates and zero - fills new bytes if length is more than size
/* get meta data for this file */ /* get current size of file */ /* drop data if length is less than current size,
     * allocate new space and zero fill it if bigger */ /* determine the number of chunks to leave after truncating */ /* file size has been extended, allocate space */ /* write zero values to new bytes */ /* set the new size */