コード例 #1
0
ファイル: walb_util.c プロジェクト: herumi/walb
/**
 * Write sector data to the offset.
 *
 * @fd file descriptor to write.
 * @offset offset in sectors.
 * @sect sectors data to be written.
 *
 * RETURN:
 *   true in success, or false.
 */
bool sector_write(int fd, u64 offset, const struct sector_data *sect)
{
	ASSERT(fd > 0);
	ASSERT_SECTOR_DATA(sect);

	return pwrite_all(fd, sect->data, sect->size, offset * sect->size);
}
コード例 #2
0
ファイル: walb_util.c プロジェクト: herumi/walb
/**
 * Write from sector data in units of logical block.
 * Logical block size is 512 bytes.
 *
 * @fd file descriptor to write.
 * @offset_lb offset [logical block].
 * @sect sector data to be partially written.
 * @idx_lb start index [logical block].
 * @n_lb number of logical blocks to write.
 *
 * RETURN:
 *   true in success, or false.
 */
bool sector_write_lb(
	int fd, u64 offset_lb, const struct sector_data *sect,
	unsigned int idx_lb, unsigned int n_lb)
{
	const ssize_t count = n_lb * LOGICAL_BLOCK_SIZE;
	const off_t buf_off = idx_lb * LOGICAL_BLOCK_SIZE;
	const off_t file_off = offset_lb * LOGICAL_BLOCK_SIZE;

	ASSERT(fd > 0);
	ASSERT_SECTOR_DATA(sect);
	ASSERT(capacity_pb(sect->size, idx_lb + n_lb) == 1);

	return pwrite_all(fd, sect->data + buf_off, count, file_off);
}
コード例 #3
0
ファイル: act_storage.c プロジェクト: aerospike/act
//------------------------------------------------
// Do one device write operation.
//
static uint64_t
write_to_device(device* dev, uint64_t offset, uint32_t size, const uint8_t* buf)
{
	int fd = fd_get(dev);

	if (fd == -1) {
		return -1;
	}

	if (! pwrite_all(fd, buf, size, offset)) {
		close(fd);
		fprintf(stdout, "ERROR: writing %s: %d '%s'\n", dev->name, errno,
				act_strerror(errno));
		return -1;
	}

	uint64_t stop_ns = get_ns();

	fd_put(dev, fd);

	return stop_ns;
}