Beispiel #1
0
int split_create_1(split_info_t *s, char *fname,
		u64 split_size, u64 total_size, bool overwrite)
{
	int i;
	int fd;
	char sname[1024];
	int error = 0;
	split_init(s, fname);
	s->create_mode = 1;
	// check if any file already exists
	for (i=-1; i<s->max_split; i++) {
		split_get_fname(s, i, sname);
		if (overwrite) {
			remove(sname);
		} else {
			fd = open(sname, O_RDONLY);
			if (fd >= 0) {
				fprintf(stderr, "Error: file already exists: %s\n", sname);
				close(fd);
				error = 1;
			}
		}
	}
	if (error) {
		split_init(s, "");
		return -1;
	}
	split_set_size(s, split_size, total_size);
	return 0;
}
Beispiel #2
0
// Reallocate split array to `newsize`. If larger than the old splitcount, new
// splits are initialized to NULL account and zero amount.
void
transaction_resize_splits(Transaction *txn, unsigned int newsize)
{
    if (newsize == txn->splitcount) {
        return;
    }
    txn->splits = realloc(txn->splits, sizeof(Split) * newsize);
    for (unsigned int i=txn->splitcount; i<newsize; i++) {
        split_init(&txn->splits[i], NULL, amount_zero(), i);
    }
    txn->splitcount = newsize;
}
Beispiel #3
0
int split_open_1(split_info_t *s, char *fname)
{
	int i;
	u64 size = 0;
	u64 total_size = 0;
	u64 split_size = 0;
	int fd;
	split_init(s, fname);
	for (i=0; i<s->max_split; i++) {
		fd = split_open_file(s, i);
		if (fd<0) {
			if (i==0) goto err;
			break;
		}
		// check previous size - all splits except last must be same size
		if (i > 0 && size != split_size) {
			fprintf(stderr, "split %d: invalid size "FMT_lld"", i, size);
			goto err;
		}
		// get size
		//fseeko(f, 0, SEEK_END);
		//size = ftello(f);
		size = lseek(fd, 0, SEEK_END);
		// check sector alignment
		if (size % 512) {
			fprintf(stderr, "split %d: size ("FMT_lld") not sector (512) aligned!",
					i, size);
		}
		// first sets split size
		if (i==0) {
			split_size = size;
		}
		total_size += size;
	}
	split_set_size(s, split_size, total_size);
	return 0;
err:
	split_close_1(s);
	return -1;
}