示例#1
0
int main(int argc, char **argv)
{
	int	i = 0;
	ext2_refcount_t refcount;
	size_t		size;
	ea_key_t	ea_key;
	ea_value_t	arg;
	errcode_t	retval;

	while (1) {
		switch (bcode_program[i++]) {
		case BCODE_END:
			exit(0);
		case BCODE_CREATE:
			size = bcode_program[i++];
			retval = ea_refcount_create(size, &refcount);
			if (retval) {
				com_err("ea_refcount_create", retval,
					"while creating size %zu", size);
				exit(1);
			} else
				printf("Creating refcount with size %zu\n",
				       size);
			break;
		case BCODE_FREE:
			ea_refcount_free(refcount);
			refcount = 0;
			printf("Freeing refcount\n");
			break;
		case BCODE_STORE:
			ea_key = (size_t) bcode_program[i++];
			arg = bcode_program[i++];
			printf("Storing ea_key %llu with value %llu\n", ea_key,
			       arg);
			retval = ea_refcount_store(refcount, ea_key, arg);
			if (retval)
				com_err("ea_refcount_store", retval,
					"while storing ea_key %llu", ea_key);
			break;
		case BCODE_FETCH:
			ea_key = (size_t) bcode_program[i++];
			retval = ea_refcount_fetch(refcount, ea_key, &arg);
			if (retval)
				com_err("ea_refcount_fetch", retval,
					"while fetching ea_key %llu", ea_key);
			else
				printf("bcode_fetch(%llu) returns %llu\n",
				       ea_key, arg);
			break;
		case BCODE_INCR:
			ea_key = (size_t) bcode_program[i++];
			retval = ea_refcount_increment(refcount, ea_key, &arg);
			if (retval)
				com_err("ea_refcount_increment", retval,
					"while incrementing ea_key %llu",
					ea_key);
			else
				printf("bcode_increment(%llu) returns %llu\n",
				       ea_key, arg);
			break;
		case BCODE_DECR:
			ea_key = (size_t) bcode_program[i++];
			retval = ea_refcount_decrement(refcount, ea_key, &arg);
			if (retval)
				com_err("ea_refcount_decrement", retval,
					"while decrementing ea_key %llu",
					ea_key);
			else
				printf("bcode_decrement(%llu) returns %llu\n",
				       ea_key, arg);
			break;
		case BCODE_VALIDATE:
			retval = ea_refcount_validate(refcount, stderr);
			if (retval)
				com_err("ea_refcount_validate", retval,
					"while validating");
			else
				printf("Refcount validation OK.\n");
			break;
		case BCODE_LIST:
			ea_refcount_intr_begin(refcount);
			while (1) {
				ea_key = ea_refcount_intr_next(refcount, &arg);
				if (!ea_key)
					break;
				printf("\tea_key=%llu, count=%llu\n", ea_key,
				       arg);
			}
			break;
		case BCODE_COLLAPSE:
			refcount_collapse(refcount);
			break;
		}

	}
}
示例#2
0
int main(int argc, char **argv)
{
	int	i = 0;
	ext2_refcount_t refcount;
	int		size, arg;
	blk_t		blk;
	errcode_t	retval;

	while (1) {
		switch (bcode_program[i++]) {
		case BCODE_END:
			exit(0);
		case BCODE_CREATE:
			size = bcode_program[i++];
			retval = ea_refcount_create(size, &refcount);
			if (retval) {
				com_err("ea_refcount_create",
					retval, "");
				exit(1);
			} else
				printf("Creating refcount with size %d\n",
				       size);
			break;
		case BCODE_FREE:
			ea_refcount_free(refcount);
			refcount = 0;
			printf("Freeing refcount\n");
			break;
		case BCODE_STORE:
			blk = (blk_t) bcode_program[i++];
			arg = bcode_program[i++];
			retval = ea_refcount_store(refcount, blk, arg);
			printf("Storing blk %u with value %d\n", blk, arg);
			if (retval)
				com_err("ea_refcount_store", retval, "");
			break;
		case BCODE_FETCH:
			blk = (blk_t) bcode_program[i++];
			retval = ea_refcount_fetch(refcount, blk, &arg);
			if (retval)
				com_err("ea_refcount_fetch", retval, "");
			else
				printf("bcode_fetch(%u) returns %d\n",
				       blk, arg);
			break;
		case BCODE_INCR:
			blk = (blk_t) bcode_program[i++];
			retval = ea_refcount_increment(refcount, blk,
							   &arg);
			if (retval)
				com_err("ea_refcount_increment", retval,
					"");
			else
				printf("bcode_increment(%u) returns %d\n",
				       blk, arg);
			break;
		case BCODE_DECR:
			blk = (blk_t) bcode_program[i++];
			retval = ea_refcount_decrement(refcount, blk,
							   &arg);
			if (retval)
				com_err("ea_refcount_decrement", retval,
					"while decrementing blk %u", blk);
			else
				printf("bcode_decrement(%u) returns %d\n",
				       blk, arg);
			break;
		case BCODE_VALIDATE:
			retval = ea_refcount_validate(refcount, stderr);
			if (retval)
				com_err("ea_refcount_validate",
					retval, "");
			else
				printf("Refcount validation OK.\n");
			break;
		case BCODE_LIST:
			ea_refcount_intr_begin(refcount);
			while (1) {
				blk = ea_refcount_intr_next(refcount, 
								&arg);
				if (!blk)
					break;
				printf("\tblk=%u, count=%d\n", blk,
				       arg);
			}
			break;
		case BCODE_COLLAPSE:
			refcount_collapse(refcount);
			break;
		}
		
	}
}