Ejemplo n.º 1
0
void set_stats(const ino iNode, gstat *pStat) {
    if (iNode < 16) {
        char iNodeDataBlock[BLOCK_SIZE];
        ReadBlock(4, iNodeDataBlock);
        iNodeEntry *iNodes = (iNodeEntry *)iNodeDataBlock;
        assign_stats(iNodes[iNode], pStat);
    } else {
        char iNodeDataBlock[BLOCK_SIZE];
        ReadBlock(5, iNodeDataBlock);
        iNodeEntry *iNodes = (iNodeEntry *)iNodeDataBlock;
        // We remove 16 from the iNode to get back to the beginning of the array
        assign_stats(iNodes[iNode - 16], pStat);
    }
}
Ejemplo n.º 2
0
/*
 * Allocate an array of size 'n'.
 */
array_t *allocate_array P1(int, n)
{
    array_t *p;

    if (n < 0 || n > max_array_size)
	error("Illegal array size.\n");
    if (n == 0) {
	return null_array();
    }
    num_arrays++;
    total_array_size += sizeof(array_t) + sizeof(svalue_t) *
	(n - 1);
    p = ALLOC_ARRAY(n);
    p->ref = 1;
    p->size = n;
#ifdef PACKAGE_MUDLIB_STATS
    if (current_object) {
	assign_stats(&p->stats, current_object);
	add_array_size(&p->stats, n);
    } else {
	null_stats(&p->stats);
    }
#endif
    while (n--)
	p->item[n] = const0;
    return p;
}
Ejemplo n.º 3
0
/*
 * Slice of an array.
 * It now frees the passed array
 */
array_t *slice_array P3(array_t *, p, int, from, int, to)
{
    int cnt;
    svalue_t *sv1, *sv2;

    if (from < 0)
	from = 0;
    if (to >= p->size)
	to = p->size - 1;
    if (from > to) {
	free_array(p);
	return null_array();
    }

    if (!(--p->ref)){
#ifdef PACKAGE_MUDLIB_STATS
	add_array_size(&p->stats, -((int)p->size));
#endif
	total_array_size += (to - from + 1 - p->size) * sizeof(svalue_t);
	if (from) {
	    sv1 = p->item + from;
	    cnt = from;
	    while (cnt--) free_svalue(--sv1, "slice_array:2");
	    cnt = to - from + 1;
	    sv1 = p->item;
	    sv2 = p->item + from;
	    while (cnt--) *sv1++ = *sv2++;
	} else {
	    sv2 = p->item + to + 1;
	}
	cnt = (p->size - 1) - to;
	while (cnt--) free_svalue(sv2++, "slice_array:3");
	p = RESIZE_ARRAY(p, to-from+1);
#ifdef PACKAGE_MUDLIB_STATS
	if (current_object) {
	    assign_stats(&p->stats, current_object);
	    add_array_size(&p->stats, to - from + 1);
	} else null_stats(&p->stats);
#endif
	p->size = to-from+1;
	p->ref = 1;
	return p;
    } else {
	array_t *d;

	d = allocate_empty_array(to - from + 1);
	sv1 = d->item - from;
	sv2 = p->item;
	for (cnt = from; cnt <= to; cnt++)
	  assign_svalue_no_free(sv1 + cnt, sv2 + cnt);
	return d;
    }
}