Esempio n. 1
0
File: ass2.c Progetto: felx/detritus
int
permute(char *stuff, char *temp, int len) {
	int	i;
	int	stuff_len = strlen(stuff);
	int	rtcode = 0;

	struct bnode	*node;

	if (len > 0) {
		for (i = 0; i < stuff_len; i++) {
			/* Check to see if the current character has been
				used */
			if (stuff[i] > 0) {
				/* It hasn't, let's use it */
				temp[0] = stuff[i];
				stuff[i] *= -1;

				/* Recurse for the rest of the string */
				rtcode += permute(stuff, temp + 1, len - 1);

				/* Set things back to the way they were */
				temp[0] = '\0';
				stuff[i] *= -1;
			}
		}

	} else {
		node = bnode_create(scratch);

		if (node) {
			bnode_print(node);
			if ((btree = btree_insert(btree, node)) == NULL) {
				rtcode = 1;
			}
		} else {
			perror("permute: ");
			rtcode = 1;
		}
	}

	return(rtcode);
}
Esempio n. 2
0
static int bucket_create(const char *account, uint32_t account_vid,
			 const char *bucket)
{
	char onode_name[SD_MAX_VDI_LEN];
	char alloc_name[SD_MAX_VDI_LEN];
	struct kv_bnode bnode;
	uint32_t vid;
	int ret;

	snprintf(onode_name, SD_MAX_VDI_LEN, "%s/%s", account, bucket);
	ret = sd_create_hyper_volume(onode_name, &vid);
	if (ret != SD_RES_SUCCESS) {
		sd_err("Failed to create bucket %s onode vid", bucket);
		return ret;
	}
	snprintf(alloc_name, SD_MAX_VDI_LEN, "%s/%s/allocator", account,
		 bucket);
	ret = sd_create_hyper_volume(alloc_name, &vid);
	if (ret != SD_RES_SUCCESS) {
		sd_err("Failed to create bucket %s data vid", bucket);
		sd_delete_vdi(onode_name);
		return ret;
	}
	ret = oalloc_init(vid);
	if (ret != SD_RES_SUCCESS) {
		sd_err("Failed to init allocator for bucket %s", bucket);
		goto err;
	}

	pstrcpy(bnode.name, sizeof(bnode.name), bucket);
	bnode.bytes_used = 0;
	bnode.object_count = 0;
	ret = bnode_create(&bnode, account_vid);
	if (ret != SD_RES_SUCCESS)
		goto err;

	return SD_RES_SUCCESS;
err:
	sd_delete_vdi(onode_name);
	sd_delete_vdi(alloc_name);
	return ret;
}