iov.iov_base = rq;
iov.iov_len = sizeof(struct clog_request) + rq->u_rq.data_size;
- rq->u.version[0] = xlate64(CLOG_TFR_VERSION);
+ rq->u.version[0] = htole64(CLOG_TFR_VERSION);
rq->u.version[1] = CLOG_TFR_VERSION;
r = clog_request_to_network(rq);
case DM_ULOG_GET_REGION_SIZE:
case DM_ULOG_GET_SYNC_COUNT:
pu64 = (uint64_t *)rq->u_rq.data;
- *pu64 = xlate64(*pu64);
+ *pu64 = htole64(*pu64);
break;
case DM_ULOG_IS_CLEAN:
case DM_ULOG_IN_SYNC:
pi64 = (int64_t *)rq->u_rq.data;
- *pi64 = xlate64(*pi64);
+ *pi64 = htole64(*pi64);
break;
case DM_ULOG_GET_RESYNC_WORK:
case DM_ULOG_IS_REMOTE_RECOVERING:
pi64 = (int64_t *)rq->u_rq.data;
pu64 = ((uint64_t *)rq->u_rq.data) + 1;
- *pi64 = xlate64(*pi64);
- *pu64 = xlate64(*pu64);
+ *pi64 = htole64(*pi64);
+ *pu64 = htole64(*pu64);
break;
default:
LOG_ERROR("Unknown request type, %u", rq_type);
case DM_ULOG_IN_SYNC:
case DM_ULOG_IS_REMOTE_RECOVERING:
pu64 = (uint64_t *)rq->u_rq.data;
- *pu64 = xlate64(*pu64);
+ *pu64 = htole64(*pu64);
break;
case DM_ULOG_MARK_REGION:
case DM_ULOG_CLEAR_REGION:
pu64 = (uint64_t *)rq->u_rq.data;
for (i = 0; i < end; i++)
- pu64[i] = xlate64(pu64[i]);
+ pu64[i] = htole64(pu64[i]);
break;
case DM_ULOG_SET_REGION_SYNC:
pu64 = (uint64_t *)rq->u_rq.data;
pi64 = ((int64_t *)rq->u_rq.data) + 1;
- *pu64 = xlate64(*pu64);
- *pi64 = xlate64(*pi64);
+ *pu64 = htole64(*pu64);
+ *pi64 = htole64(*pi64);
break;
default:
LOG_ERROR("Unknown request type, %u", rq_type);
size = sizeof(*rq) + u_rq->data_size;
- u_rq->error = xlate32(u_rq->error);
- u_rq->seq = xlate32(u_rq->seq);
+ u_rq->error = htole32(u_rq->error);
+ u_rq->seq = htole32(u_rq->seq);
- rq->originator = xlate32(rq->originator);
+ rq->originator = htole32(rq->originator);
v5_data_endian_switch(rq, 1);
- u_rq->request_type = xlate32(u_rq->request_type);
- u_rq->data_size = xlate32(u_rq->data_size);
+ u_rq->request_type = htole32(u_rq->request_type);
+ u_rq->data_size = htole32(u_rq->data_size);
return size;
}
int r;
/* FIXME: Remove this safety check */
- if (rq->u.version[0] != xlate64(rq->u.version[1])) {
+ if (rq->u.version[0] != htole64(rq->u.version[1])) {
LOG_ERROR("Programmer error: version[0] must be LE");
exit(EXIT_FAILURE);
}
int size;
struct dm_ulog_request *u_rq = &rq->u_rq;
- u_rq->error = xlate32(u_rq->error);
- u_rq->seq = xlate32(u_rq->seq);
- u_rq->request_type = xlate32(u_rq->request_type);
- u_rq->data_size = xlate32(u_rq->data_size);
+ u_rq->error = htole32(u_rq->error);
+ u_rq->seq = htole32(u_rq->seq);
+ u_rq->request_type = htole32(u_rq->request_type);
+ u_rq->data_size = htole32(u_rq->data_size);
- rq->originator = xlate32(rq->originator);
+ rq->originator = htole32(rq->originator);
size = sizeof(*rq) + u_rq->data_size;
int clog_request_from_network(void *data, size_t data_len)
{
uint64_t *vp = data;
- uint64_t version = xlate64(vp[0]);
+ uint64_t version = htole64(vp[0]);
struct clog_request *rq = data;
switch (version) {
if (daemon_test) {
if (rdd->vb) {
- vb_out->version = le16_to_cpu(rdd->vb->version);
- vb_out->flags = le16_to_cpu(rdd->vb->flags);
- vb_out->r_version = le32_to_cpu(rdd->vb->r_version);
+ vb_out->version = le16toh(rdd->vb->version);
+ vb_out->flags = le16toh(rdd->vb->flags);
+ vb_out->r_version = le32toh(rdd->vb->r_version);
}
return 0;
}
memcpy(&vb, lksb->sb_lvbptr, sizeof(struct val_blk));
memcpy(rdd->vb, &vb, sizeof(vb));
- vb_out->version = le16_to_cpu(vb.version);
- vb_out->flags = le16_to_cpu(vb.flags);
- vb_out->r_version = le32_to_cpu(vb.r_version);
+ vb_out->version = le16toh(vb.version);
+ vb_out->flags = le16toh(vb.flags);
+ vb_out->r_version = le32toh(vb.r_version);
}
out:
return 0;
if (rdd->vb && r_version && (r->mode == LD_LK_EX)) {
if (!rdd->vb->version) {
/* first time vb has been written */
- rdd->vb->version = cpu_to_le16(VAL_BLK_VERSION);
+ rdd->vb->version = htole16(VAL_BLK_VERSION);
}
- rdd->vb->r_version = cpu_to_le32(r_version);
+ rdd->vb->r_version = htole32(r_version);
memcpy(lksb->sb_lvbptr, rdd->vb, sizeof(struct val_blk));
log_debug("%s:%s convert_dlm set r_version %u",
memcpy(&vb_next, rdd->vb, sizeof(struct val_blk));
if (!vb_prev.version) {
- vb_next.version = cpu_to_le16(VAL_BLK_VERSION);
+ vb_next.version = htole16(VAL_BLK_VERSION);
new_vb = 1;
}
if ((lmu_flags & LMUF_FREE_VG) && (r->type == LD_RT_VG)) {
- vb_next.flags = cpu_to_le16(VBF_REMOVED);
+ vb_next.flags = htole16(VBF_REMOVED);
new_vb = 1;
}
if (r_version) {
- vb_next.r_version = cpu_to_le32(r_version);
+ vb_next.r_version = htole32(r_version);
new_vb = 1;
}
log_debug("%s:%s unlock_dlm vb old %x %x %u new %x %x %u",
ls->name, r->name,
- le16_to_cpu(vb_prev.version),
- le16_to_cpu(vb_prev.flags),
- le32_to_cpu(vb_prev.r_version),
- le16_to_cpu(vb_next.version),
- le16_to_cpu(vb_next.flags),
- le32_to_cpu(vb_next.r_version));
+ le16toh(vb_prev.version),
+ le16toh(vb_prev.flags),
+ le32toh(vb_prev.r_version),
+ le16toh(vb_next.version),
+ le16toh(vb_next.flags),
+ le32toh(vb_next.r_version));
} else {
log_debug("%s:%s unlock_dlm vb unchanged", ls->name, r->name);
}
if (daemon_test) {
if (rdi->vb) {
- vb_out->version = le16_to_cpu(rdi->vb->version);
- vb_out->flags = le16_to_cpu(rdi->vb->flags);
- vb_out->r_version = le32_to_cpu(rdi->vb->r_version);
+ vb_out->version = le16toh(rdi->vb->version);
+ vb_out->flags = le16toh(rdi->vb->flags);
+ vb_out->r_version = le32toh(rdi->vb->r_version);
}
return 0;
}
if (daemon_test) {
if (rds->vb) {
- vb_out->version = le16_to_cpu(rds->vb->version);
- vb_out->flags = le16_to_cpu(rds->vb->flags);
- vb_out->r_version = le32_to_cpu(rds->vb->r_version);
+ vb_out->version = le16toh(rds->vb->version);
+ vb_out->flags = le16toh(rds->vb->flags);
+ vb_out->r_version = le32toh(rds->vb->r_version);
}
return 0;
}
memcpy(rds->vb, &vb, sizeof(vb));
- vb_out->version = le16_to_cpu(vb.version);
- vb_out->flags = le16_to_cpu(vb.flags);
- vb_out->r_version = le32_to_cpu(vb.r_version);
+ vb_out->version = le16toh(vb.version);
+ vb_out->flags = le16toh(vb.flags);
+ vb_out->r_version = le32toh(vb.r_version);
}
out:
return rv;
if (rds->vb && r_version && (r->mode == LD_LK_EX)) {
if (!rds->vb->version) {
/* first time vb has been written */
- rds->vb->version = cpu_to_le16(VAL_BLK_VERSION);
+ rds->vb->version = htole16(VAL_BLK_VERSION);
}
if (r_version)
- rds->vb->r_version = cpu_to_le32(r_version);
+ rds->vb->r_version = htole32(r_version);
memcpy(&vb, rds->vb, sizeof(vb));
log_debug("%s:%s convert_san set r_version %u",
if (daemon_test) {
if (rds->vb && r_version && (r->mode == LD_LK_EX)) {
if (!rds->vb->version)
- rds->vb->version = cpu_to_le16(VAL_BLK_VERSION);
+ rds->vb->version = htole16(VAL_BLK_VERSION);
if (r_version)
- rds->vb->r_version = cpu_to_le32(r_version);
+ rds->vb->r_version = htole32(r_version);
}
return 0;
}
if (rds->vb && r_version && (r->mode == LD_LK_EX)) {
if (!rds->vb->version) {
/* first time vb has been written */
- rds->vb->version = cpu_to_le16(VAL_BLK_VERSION);
+ rds->vb->version = htole16(VAL_BLK_VERSION);
}
if (r_version)
- rds->vb->r_version = cpu_to_le32(r_version);
+ rds->vb->r_version = htole32(r_version);
memcpy(&vb, rds->vb, sizeof(vb));
log_debug("%s:%s unlock_san set r_version %u",
static size_t _get_sb_size(const struct dm_raid_superblock *sb)
{
- return (FEATURE_FLAG_SUPPORTS_V190 & le32_to_cpu(sb->compat_features)) ?
+ return (FEATURE_FLAG_SUPPORTS_V190 & le32toh(sb->compat_features)) ?
sizeof(*sb) : ((char *) &sb->flags - (char *) sb);
}
}
/* FIXME: big endian??? */
- if (sb->magic != cpu_to_be32(DM_RAID_SB_MAGIC)) {
+ if (sb->magic != htobe32(DM_RAID_SB_MAGIC)) {
log_error("No RAID signature on %s.", dev_path);
goto out;
}
#include "target.h"
#include "lib/mm/xlate.h"
-//#include "linux/byteorder/big_endian.h"
-//#include "linux/byteorder/little_endian.h"
-//#define le32_to_cpu __le32_to_cpu
-//#define le64_to_cpu __le64_to_cpu
-
#include <errno.h>
#include <fcntl.h>
static void _vdo_decode_version(struct vdo_version_number *v)
{
- v->major_version = le32_to_cpu(v->major_version);
- v->minor_version = le32_to_cpu(v->minor_version);
+ v->major_version = le32toh(v->major_version);
+ v->minor_version = le32toh(v->minor_version);
}
static void _vdo_decode_header(struct vdo_header *h)
{
- h->id = le32_to_cpu(h->id);
+ h->id = le32toh(h->id);
_vdo_decode_version(&h->version);
- h->size = le64_to_cpu(h->size);
+ h->size = le64toh(h->size);
}
static void _vdo_decode_geometry_region(struct vdo_volume_region *vr)
{
- vr->id = (enum vdo_volume_region_id) le32_to_cpu(vr->id);
- vr->start_block = le64_to_cpu(vr->start_block);
+ vr->id = (enum vdo_volume_region_id) le32toh(vr->id);
+ vr->start_block = le64toh(vr->start_block);
}
static void _vdo_decode_volume_geometry(struct vdo_volume_geometry *vg)
{
- vg->release_version = le32_to_cpu(vg->release_version);
- vg->nonce = le64_to_cpu(vg->nonce);
- vg->bio_offset = le64_to_cpu(vg->bio_offset);
+ vg->release_version = le32toh(vg->release_version);
+ vg->nonce = le64toh(vg->nonce);
+ vg->bio_offset = le64toh(vg->bio_offset);
_vdo_decode_geometry_region(&vg->regions[VDO_DATA_REGION]);
}
static void _vdo_decode_volume_geometry_4(struct vdo_volume_geometry *vg,
struct vdo_volume_geometry_4 *vg_4)
{
- vg->release_version = le32_to_cpu(vg_4->release_version);
- vg->nonce = le64_to_cpu(vg_4->nonce);
+ vg->release_version = le32toh(vg_4->release_version);
+ vg->nonce = le64toh(vg_4->nonce);
vg->bio_offset = 0;
vg->regions[VDO_DATA_REGION] = vg_4->regions[VDO_DATA_REGION];
_vdo_decode_geometry_region(&vg->regions[VDO_DATA_REGION]);
static void _vdo_decode_config(struct vdo_config *vc)
{
- vc->logical_blocks = le64_to_cpu(vc->logical_blocks);
- vc->physical_blocks = le64_to_cpu(vc->physical_blocks);
- vc->slab_size = le64_to_cpu(vc->slab_size);
- vc->recovery_journal_size = le64_to_cpu(vc->recovery_journal_size);
- vc->slab_journal_blocks = le64_to_cpu(vc->slab_journal_blocks);
+ vc->logical_blocks = le64toh(vc->logical_blocks);
+ vc->physical_blocks = le64toh(vc->physical_blocks);
+ vc->slab_size = le64toh(vc->slab_size);
+ vc->recovery_journal_size = le64toh(vc->recovery_journal_size);
+ vc->slab_journal_blocks = le64toh(vc->slab_journal_blocks);
}
static void _vdo_decode_pvc(struct vdo_component_41_0 *pvc)
{
_vdo_decode_config(&pvc->config);
- pvc->nonce = le64_to_cpu(pvc->nonce);
+ pvc->nonce = le64toh(pvc->nonce);
}
bool dm_vdo_parse_logical_size(const char *vdo_path, uint64_t *logical_blocks)
/* Change bit ordering for devno to generate more compact bTree */
static inline uint32_t _shuffle_devno(dev_t d)
{
- return cpu_to_be32(d);
+ return htobe32(d);
//return (d & 0xff) << 24 | (d & 0xff00) << 8 | (d & 0xff0000) >> 8 | (d & 0xff000000) >> 24;
//return (d & 0xff000000) >> 24 | (d & 0xffff00) | ((d & 0xff) << 24);
//return (uint32_t) d;
uint32_t version;
int ret;
- version = xlate16(pvd->version);
+ version = htole16(pvd->version);
if (pvd->id[0] == 'H' && pvd->id[1] == 'M' &&
(version == 1 || version == 2))
};
#define CPIN_8(x, y, z) {memcpy((x), (y), (z));}
-#define CPIN_16(x, y) {(x) = xlate16_be((y));}
-#define CPIN_32(x, y) {(x) = xlate32_be((y));}
-#define CPIN_64(x, y) {(x) = xlate64_be((y));}
+#define CPIN_16(x, y) {(x) = htobe16((y));}
+#define CPIN_32(x, y) {(x) = htobe32((y));}
+#define CPIN_64(x, y) {(x) = htobe64((y));}
static void pool_label_in(struct pool_disk *pl, void *buf)
{
if ((md_magic == MD_SB_MAGIC) ||
/* coverity[result_independent_of_operands] */
- ((MD_SB_MAGIC != xlate32(MD_SB_MAGIC)) && (md_magic == xlate32(MD_SB_MAGIC))))
+ ((MD_SB_MAGIC != htole32(MD_SB_MAGIC)) && (md_magic == htole32(MD_SB_MAGIC))))
return 1;
return 0;
if (!dev_read_bytes(dev, off, 512, &hdr))
return_0;
- if ((hdr.magic == cpu_to_be32(DDF_MAGIC)) ||
- (hdr.magic == cpu_to_le32(DDF_MAGIC))) {
+ if ((hdr.magic == htobe32(DDF_MAGIC)) ||
+ (hdr.magic == htole32(DDF_MAGIC))) {
crc = hdr.crc;
hdr.crc = 0xffffffff;
our_crc = calc_crc(0, (const uint8_t *)&hdr, 512);
- if ((cpu_to_be32(our_crc) == crc) ||
- (cpu_to_le32(our_crc) == crc)) {
+ if ((htobe32(our_crc) == crc) ||
+ (htole32(our_crc) == crc)) {
*sb_offset = off;
return 1;
} else {
if (!dev_read_bytes(dev, off, 512, &hdr))
return_0;
- if ((hdr.magic == cpu_to_be32(DDF_MAGIC)) ||
- (hdr.magic == cpu_to_le32(DDF_MAGIC))) {
+ if ((hdr.magic == htobe32(DDF_MAGIC)) ||
+ (hdr.magic == htole32(DDF_MAGIC))) {
crc = hdr.crc;
hdr.crc = 0xffffffff;
our_crc = calc_crc(0, (const uint8_t *)&hdr, 512);
- if ((cpu_to_be32(our_crc) == crc) ||
- (cpu_to_le32(our_crc) == crc)) {
+ if ((htobe32(our_crc) == crc) ||
+ (htole32(our_crc) == crc)) {
*sb_offset = off;
return 1;
} else {
/* the gpt table is always written using LE on disk */
- if (le64_to_cpu(gpt_header.magic) != PART_GPT_MAGIC)
+ if (le64toh(gpt_header.magic) != PART_GPT_MAGIC)
return 0;
- entries_start = le64_to_cpu(gpt_header.part_entries_lba) * lbs;
- nr_entries = le32_to_cpu(gpt_header.nr_part_entries);
- sz_entry = le32_to_cpu(gpt_header.sz_part_entry);
+ entries_start = le64toh(gpt_header.part_entries_lba) * lbs;
+ nr_entries = le32toh(gpt_header.nr_part_entries);
+ sz_entry = le32toh(gpt_header.sz_part_entry);
for (i = 0; i < nr_entries; i++) {
if (!dev_read_bytes(dev, entries_start + (uint64_t)i * sz_entry,
sizeof(gpt_part_entry), &gpt_part_entry))
return_0;
- /* just check if the guid is nonzero, no need to call le64_to_cpu here */
+ /* just check if the guid is nonzero, no need to call le64toh here */
if (gpt_part_entry.part_type_guid)
return 1;
}
/* FIXME Check for other types of partition table too */
/* Check for msdos partition table */
- if (buf.magic == xlate16(PART_MSDOS_MAGIC)) {
+ if (buf.magic == htole16(PART_MSDOS_MAGIC)) {
for (p = 0; p < 4; ++p) {
/* Table is invalid if boot indicator not 0 or 0x80 */
if (buf.part[p].boot_ind & 0x7f) {
/* Avoid using nvme_identify_ns_descs before ver 1.3. */
if (!nvme_identify_ctrl(fd, ctrl_id)) {
- if (le32_to_cpu(ctrl_id->ver) < 0x10300)
+ if (le32toh(ctrl_id->ver) < 0x10300)
goto_out;
}
for (i = 0; i < regctl; i++) {
if (status->regctl_eds[i].rcsts) {
- rkey = le64_to_cpu(status->regctl_eds[i].rkey);
+ rkey = le64toh(status->regctl_eds[i].rkey);
*holder_ret = rkey;
break;
}
}
for (i = 0; i < num_keys; i++) {
- key = le64_to_cpu(status->regctl_eds[i].rkey);
+ key = le64toh(status->regctl_eds[i].rkey);
log_debug("dev_find_key %s 0x%llx", devname, (unsigned long long)key);
memcpy(&pr_gen_be, response_buf + 0, 4);
memcpy(&add_len_be, response_buf + 4, 4);
- pr_gen = be32_to_cpu(pr_gen_be);
- add_len = be32_to_cpu(add_len_be);
+ pr_gen = be32toh(pr_gen_be);
+ add_len = be32toh(add_len_be);
num = add_len / 16;
log_debug("dev_read_reservation %s pr_gen %u add_len %u num %d", devname, pr_gen, add_len, num);
if (num > 0) {
memcpy(&key_be, response_buf + 8, 8);
- key = be64_to_cpu(key_be);
+ key = be64toh(key_be);
pr_type_byte = response_buf[21];
pr_type_scsi = pr_type_byte & 0xf; /* top half of byte is scope */
memcpy(&pr_gen_be, response_buf + 0, 4);
memcpy(&add_len_be, response_buf + 4, 4);
- pr_gen = be32_to_cpu(pr_gen_be);
- add_len = be32_to_cpu(add_len_be);
+ pr_gen = be32toh(pr_gen_be);
+ add_len = be32toh(add_len_be);
num_keys = add_len / 8;
log_debug("dev_find_key %s pr_gen %u num %d", devname, pr_gen, num_keys);
unsigned char *p = response_buf + 8 + (i * 8);
memcpy(&key_be, p, 8);
- key = be64_to_cpu(key_be);
+ key = be64toh(key_be);
log_debug("dev_find_key %s 0x%llx", devname, (unsigned long long)key);
{
struct raw_locn *rl;
- mdah->version = xlate32(mdah->version);
- mdah->start = xlate64(mdah->start);
- mdah->size = xlate64(mdah->size);
+ mdah->version = htole32(mdah->version);
+ mdah->start = htole64(mdah->start);
+ mdah->size = htole64(mdah->size);
rl = &mdah->raw_locns[0];
while (rl->offset) {
- rl->checksum = xlate32(rl->checksum);
- rl->offset = xlate64(rl->offset);
- rl->size = xlate64(rl->size);
+ rl->checksum = htole32(rl->checksum);
+ rl->offset = htole64(rl->offset);
+ rl->size = htole64(rl->size);
rl++;
}
}
return 0;
}
- if (mdah->checksum_xl != xlate32(calc_crc(INITIAL_CRC, (uint8_t *)mdah->magic,
+ if (mdah->checksum_xl != htole32(calc_crc(INITIAL_CRC, (uint8_t *)mdah->magic,
MDA_HEADER_SIZE -
sizeof(mdah->checksum_xl)))) {
log_warn("WARNING: wrong checksum %x in mda header on %s at %llu",
mdah->start = start_byte;
_xlate_mdah(mdah);
- mdah->checksum_xl = xlate32(calc_crc(INITIAL_CRC, (uint8_t *)mdah->magic,
+ mdah->checksum_xl = htole32(calc_crc(INITIAL_CRC, (uint8_t *)mdah->magic,
MDA_HEADER_SIZE -
sizeof(mdah->checksum_xl)));
static int _da_setup(struct disk_locn *da, void *baton)
{
struct _dl_setup_baton *p = baton;
- p->pvh_dlocn_xl->offset = xlate64(da->offset);
- p->pvh_dlocn_xl->size = xlate64(da->size);
+ p->pvh_dlocn_xl->offset = htole64(da->offset);
+ p->pvh_dlocn_xl->size = htole64(da->size);
p->pvh_dlocn_xl++;
return 1;
}
if (mdac->area.dev != p->dev)
return 1;
- p->pvh_dlocn_xl->offset = xlate64(mdac->area.start);
- p->pvh_dlocn_xl->size = xlate64(mdac->area.size);
+ p->pvh_dlocn_xl->offset = htole64(mdac->area.start);
+ p->pvh_dlocn_xl->size = htole64(mdac->area.size);
p->pvh_dlocn_xl++;
return 1;
{
struct _dl_setup_baton *p = baton;
- p->pvh_dlocn_xl->offset = xlate64(UINT64_C(0));
- p->pvh_dlocn_xl->size = xlate64(UINT64_C(0));
+ p->pvh_dlocn_xl->offset = htole64(UINT64_C(0));
+ p->pvh_dlocn_xl->size = htole64(UINT64_C(0));
p->pvh_dlocn_xl++;
return 1;
memcpy(lh->type, LVM2_LABEL, sizeof(lh->type));
- pvhdr = (struct pv_header *) ((char *) buf + xlate32(lh->offset_xl));
+ pvhdr = (struct pv_header *) ((char *) buf + htole32(lh->offset_xl));
info = (struct lvmcache_info *) label->info;
- pvhdr->device_size_xl = xlate64(lvmcache_device_size(info));
+ pvhdr->device_size_xl = htole64(lvmcache_device_size(info));
memcpy(pvhdr->pv_uuid, &lvmcache_device(info)->pvid, sizeof(struct id));
if (!id_write_format((const struct id *)pvhdr->pv_uuid, buffer,
sizeof(buffer))) {
* PV header extension
*/
pvhdr_ext = (struct pv_header_extension *) ((char *) baton.pvh_dlocn_xl);
- pvhdr_ext->version = xlate32(PV_HEADER_EXTENSION_VSN);
- pvhdr_ext->flags = xlate32(lvmcache_ext_flags(info));
+ pvhdr_ext->version = htole32(PV_HEADER_EXTENSION_VSN);
+ pvhdr_ext->flags = htole32(lvmcache_ext_flags(info));
/* List of bootloader area locations */
baton.pvh_dlocn_xl = &pvhdr_ext->bootloader_areas_xl[0];
_dl_null_termination(&baton);
/* Create debug message with ba, da and mda locations */
- ba1 = (xlate64(pvhdr_ext->bootloader_areas_xl[0].offset) ||
- xlate64(pvhdr_ext->bootloader_areas_xl[0].size)) ? 0 : -1;
+ ba1 = (htole64(pvhdr_ext->bootloader_areas_xl[0].offset) ||
+ htole64(pvhdr_ext->bootloader_areas_xl[0].size)) ? 0 : -1;
- da1 = (xlate64(pvhdr->disk_areas_xl[0].offset) ||
- xlate64(pvhdr->disk_areas_xl[0].size)) ? 0 : -1;
+ da1 = (htole64(pvhdr->disk_areas_xl[0].offset) ||
+ htole64(pvhdr->disk_areas_xl[0].size)) ? 0 : -1;
mda1 = da1 + 2;
mda2 = mda1 + 1;
- if (!xlate64(pvhdr->disk_areas_xl[mda1].offset) &&
- !xlate64(pvhdr->disk_areas_xl[mda1].size))
+ if (!htole64(pvhdr->disk_areas_xl[mda1].offset) &&
+ !htole64(pvhdr->disk_areas_xl[mda1].size))
mda1 = mda2 = 0;
- else if (!xlate64(pvhdr->disk_areas_xl[mda2].offset) &&
- !xlate64(pvhdr->disk_areas_xl[mda2].size))
+ else if (!htole64(pvhdr->disk_areas_xl[mda2].offset) &&
+ !htole64(pvhdr->disk_areas_xl[mda2].size))
mda2 = 0;
log_debug_metadata("%s: Preparing PV label header %s size " FMTu64 " with"
dev_name(lvmcache_device(info)), buffer, lvmcache_device_size(info),
(ba1 > -1) ? " ba1 (" : "",
(ba1 > -1) ? 1 : 0,
- (ba1 > -1) ? xlate64(pvhdr_ext->bootloader_areas_xl[ba1].offset) >> SECTOR_SHIFT : 0,
+ (ba1 > -1) ? htole64(pvhdr_ext->bootloader_areas_xl[ba1].offset) >> SECTOR_SHIFT : 0,
(ba1 > -1) ? "s, " : "",
(ba1 > -1) ? 1 : 0,
- (ba1 > -1) ? xlate64(pvhdr_ext->bootloader_areas_xl[ba1].size) >> SECTOR_SHIFT : 0,
+ (ba1 > -1) ? htole64(pvhdr_ext->bootloader_areas_xl[ba1].size) >> SECTOR_SHIFT : 0,
(ba1 > -1) ? "s)" : "",
(da1 > -1) ? " da1 (" : "",
(da1 > -1) ? 1 : 0,
- (da1 > -1) ? xlate64(pvhdr->disk_areas_xl[da1].offset) >> SECTOR_SHIFT : 0,
+ (da1 > -1) ? htole64(pvhdr->disk_areas_xl[da1].offset) >> SECTOR_SHIFT : 0,
(da1 > -1) ? "s, " : "",
(da1 > -1) ? 1 : 0,
- (da1 > -1) ? xlate64(pvhdr->disk_areas_xl[da1].size) >> SECTOR_SHIFT : 0,
+ (da1 > -1) ? htole64(pvhdr->disk_areas_xl[da1].size) >> SECTOR_SHIFT : 0,
(da1 > -1) ? "s)" : "",
mda1 ? " mda1 (" : "",
mda1 ? 1 : 0,
- mda1 ? xlate64(pvhdr->disk_areas_xl[mda1].offset) >> SECTOR_SHIFT : 0,
+ mda1 ? htole64(pvhdr->disk_areas_xl[mda1].offset) >> SECTOR_SHIFT : 0,
mda1 ? "s, " : "",
mda1 ? 1 : 0,
- mda1 ? xlate64(pvhdr->disk_areas_xl[mda1].size) >> SECTOR_SHIFT : 0,
+ mda1 ? htole64(pvhdr->disk_areas_xl[mda1].size) >> SECTOR_SHIFT : 0,
mda1 ? "s)" : "",
mda2 ? " mda2 (" : "",
mda2 ? 1 : 0,
- mda2 ? xlate64(pvhdr->disk_areas_xl[mda2].offset) >> SECTOR_SHIFT : 0,
+ mda2 ? htole64(pvhdr->disk_areas_xl[mda2].offset) >> SECTOR_SHIFT : 0,
mda2 ? "s, " : "",
mda2 ? 1 : 0,
- mda2 ? xlate64(pvhdr->disk_areas_xl[mda2].size) >> SECTOR_SHIFT : 0,
+ mda2 ? htole64(pvhdr->disk_areas_xl[mda2].size) >> SECTOR_SHIFT : 0,
mda2 ? "s)" : "");
if (da1 < 0) {
/*
* PV header base
*/
- pvhdr = (struct pv_header *) ((char *) label_buf + xlate32(lh->offset_xl));
+ pvhdr = (struct pv_header *) ((char *) label_buf + htole32(lh->offset_xl));
memcpy(pvid, &pvhdr->pv_uuid, ID_LEN);
strncpy(vgid, FMT_TEXT_ORPHAN_VG_NAME, ID_LEN);
vgid, 0, is_duplicate)))
return_0;
- lvmcache_set_device_size(info, xlate64(pvhdr->device_size_xl));
+ lvmcache_set_device_size(info, htole64(pvhdr->device_size_xl));
lvmcache_del_das(info);
lvmcache_del_mdas(info);
/* Data areas holding the PEs */
dlocn_xl = pvhdr->disk_areas_xl;
- while ((offset = xlate64(dlocn_xl->offset))) {
- lvmcache_add_da(info, offset, xlate64(dlocn_xl->size));
+ while ((offset = htole64(dlocn_xl->offset))) {
+ lvmcache_add_da(info, offset, htole64(dlocn_xl->size));
dlocn_xl++;
}
dlocn_xl++;
/* Metadata areas */
- while ((offset = xlate64(dlocn_xl->offset))) {
+ while ((offset = htole64(dlocn_xl->offset))) {
/*
* This just calls add_mda() above, replacing info with info->mdas.
*/
- lvmcache_add_mda(info, dev, offset, xlate64(dlocn_xl->size), 0, &mda);
+ lvmcache_add_mda(info, dev, offset, htole64(dlocn_xl->size), 0, &mda);
dlocn_xl++;
mda_count++;
* PV header extension
*/
pvhdr_ext = (struct pv_header_extension *) ((char *) dlocn_xl);
- if (!(ext_version = xlate32(pvhdr_ext->version)))
+ if (!(ext_version = htole32(pvhdr_ext->version)))
goto scan_mdas;
if (ext_version != PV_HEADER_EXTENSION_VSN)
ext_version, dev_name(dev));
/* Extension version */
- lvmcache_set_ext_version(info, xlate32(pvhdr_ext->version));
+ lvmcache_set_ext_version(info, htole32(pvhdr_ext->version));
/* Extension flags */
- lvmcache_set_ext_flags(info, xlate32(pvhdr_ext->flags));
+ lvmcache_set_ext_flags(info, htole32(pvhdr_ext->flags));
/* Bootloader areas */
dlocn_xl = pvhdr_ext->bootloader_areas_xl;
- while ((offset = xlate64(dlocn_xl->offset))) {
- lvmcache_add_ba(info, offset, xlate64(dlocn_xl->size));
+ while ((offset = htole64(dlocn_xl->offset))) {
+ lvmcache_add_ba(info, offset, htole64(dlocn_xl->size));
dlocn_xl++;
}
wipe = 0;
if (!memcmp(lh->id, LABEL_ID, sizeof(lh->id))) {
- if (xlate64(lh->sector_xl) == sector)
+ if (htole64(lh->sector_xl) == sector)
wipe = 1;
} else {
dm_list_iterate_items(li, &_labellers) {
memset(buf, 0, LABEL_SIZE);
memcpy(lh->id, LABEL_ID, sizeof(lh->id));
- lh->sector_xl = xlate64(label->sector);
- lh->offset_xl = xlate32(sizeof(*lh));
+ lh->sector_xl = htole64(label->sector);
+ lh->offset_xl = htole32(sizeof(*lh));
if (!(label->labeller->ops->write)(label, buf))
return_0;
- lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl, LABEL_SIZE -
+ lh->crc_xl = htole32(calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl, LABEL_SIZE -
((uint8_t *) &lh->offset_xl - (uint8_t *) lh)));
log_very_verbose("%s: Writing label to sector %" PRIu64 " with stored offset %"
PRIu32 ".", dev_name(dev), label->sector,
- xlate32(lh->offset_xl));
+ htole32(lh->offset_xl));
if (!label_scan_open(dev)) {
log_error("Failed to open device %s", dev_name(dev));
log_error("Ignoring additional label on %s at sector %llu",
dev_name(dev), (unsigned long long)(block_sector + sector));
}
- if (xlate64(lh->sector_xl) != sector) {
+ if (htole64(lh->sector_xl) != sector) {
log_warn("%s: Label for sector %llu found at sector %llu - ignoring.",
dev_name(dev),
- (unsigned long long)xlate64(lh->sector_xl),
+ (unsigned long long)htole64(lh->sector_xl),
(unsigned long long)(block_sector + sector));
continue;
}
if (calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl,
- LABEL_SIZE - ((uint8_t *) &lh->offset_xl - (uint8_t *) lh)) != xlate32(lh->crc_xl)) {
+ LABEL_SIZE - ((uint8_t *) &lh->offset_xl - (uint8_t *) lh)) != htole32(lh->crc_xl)) {
log_very_verbose("Label checksum incorrect on %s - ignoring", dev_name(dev));
continue;
}
uint64_t nr_regions;
} log_header;
- log_header.magic = xlate32(MIRROR_MAGIC);
- log_header.version = xlate32(MIRROR_DISK_VERSION);
- log_header.nr_regions = xlate64((uint64_t)-1);
+ log_header.magic = htole32(MIRROR_MAGIC);
+ log_header.version = htole32(MIRROR_DISK_VERSION);
+ log_header.nr_regions = htole64((uint64_t)-1);
if (dm_snprintf(name, sizeof(name), "%s%s/%s", cmd->dev_dir,
lv->vg->name, lv->name) < 0) {
_initialise_crc32();
for (;size >= 16; size -= 16) {
- a = xlate32(*ptr++) ^ crc;
- b = xlate32(*ptr++);
- c = xlate32(*ptr++);
- d = xlate32(*ptr++);
+ a = htole32(*ptr++) ^ crc;
+ b = htole32(*ptr++);
+ c = htole32(*ptr++);
+ d = htole32(*ptr++);
crc = _crc32_lookup[ 0][(d >> 24) & 0xff] ^
_crc32_lookup[ 1][(d >> 16) & 0xff] ^
/* Process 4 bytes per iteration */
while (start < end) {
- crc = crc ^ xlate32(*start++);
+ crc = crc ^ htole32(*start++);
crc = _crctab[crc & 0xff] ^ crc >> 8;
crc = _crctab[crc & 0xff] ^ crc >> 8;
crc = _crctab[crc & 0xff] ^ crc >> 8;
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2025 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/*
+ * This header provides backward compatibility for endian conversion macros.
+ * Modern systems have these macros in <endian.h>, but this file ensures
+ * compatibility with older glibc versions (< 2.9) and non-glibc systems.
+ */
+
#ifndef _LVM_XLATE_H
#define _LVM_XLATE_H
((x) & 0x000000ff00000000ULL) >> 8)
#endif
-#if BYTE_ORDER == LITTLE_ENDIAN
-/* New clearer variants. */
-#define le16_to_cpu(x) (x)
-#define le32_to_cpu(x) (x)
-#define le64_to_cpu(x) (x)
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#define cpu_to_le64(x) (x)
-#define be16_to_cpu(x) bswap_16(x)
-#define be32_to_cpu(x) bswap_32(x)
-#define be64_to_cpu(x) bswap_64(x)
-#define cpu_to_be16(x) bswap_16(x)
-#define cpu_to_be32(x) bswap_32(x)
-#define cpu_to_be64(x) bswap_64(x)
-/* Old alternative variants. */
-#define xlate16(x) (x)
-#define xlate32(x) (x)
-#define xlate64(x) (x)
-#define xlate16_be(x) bswap_16(x)
-#define xlate32_be(x) bswap_32(x)
-#define xlate64_be(x) bswap_64(x)
-
-#elif BYTE_ORDER == BIG_ENDIAN
-/* New clearer variants. */
-#define le16_to_cpu(x) bswap_16(x)
-#define le32_to_cpu(x) bswap_32(x)
-#define le64_to_cpu(x) bswap_64(x)
-#define cpu_to_le16(x) bswap_16(x)
-#define cpu_to_le32(x) bswap_32(x)
-#define cpu_to_le64(x) bswap_64(x)
-#define be16_to_cpu(x) (x)
-#define be32_to_cpu(x) (x)
-#define be64_to_cpu(x) (x)
-#define cpu_to_be16(x) (x)
-#define cpu_to_be32(x) (x)
-#define cpu_to_be64(x) (x)
-/* Old alternative variants. */
-#define xlate16(x) bswap_16(x)
-#define xlate32(x) bswap_32(x)
-#define xlate64(x) bswap_64(x)
-#define xlate16_be(x) (x)
-#define xlate32_be(x) (x)
-#define xlate64_be(x) (x)
+/*
+ * NOTE: This file may appear unused to static analysis tools like Coverity
+ * on modern systems, but it is essential for backward compatibility.
+ *
+ * So to make it look as 'used' header file, for Coverity scan
+ * lets redefine those macros.
+ *
+ * TODO: is there any better trick how to avoid HFA warnings and add
+ * annotation comment before every inclusion of this header file ??
+ */
+
+#ifdef __COVERITY__
+
+# undef htobe16
+# undef htole16
+# undef be16toh
+# undef le16toh
+
+# undef htobe32
+# undef htole32
+# undef be32toh
+# undef le32toh
+
+# undef htobe64
+# undef htole64
+# undef be64toh
+# undef le64toh
+
+#endif
+
+
+#ifndef htobe16
+
+# if BYTE_ORDER == LITTLE_ENDIAN
+
+# define htobe16(x) bswap_16 (x)
+# define htole16(x) (uint16_t) (x)
+# define be16toh(x) bswap_16 (x)
+# define le16toh(x) (uint16_t) (x)
+
+# define htobe32(x) bswap_32 (x)
+# define htole32(x) (uint32_t) (x)
+# define be32toh(x) bswap_32 (x)
+# define le32toh(x) (uint32_t) (x)
+
+# define htobe64(x) bswap_64 (x)
+# define htole64(x) (uint64_t) (x)
+# define be64toh(x) bswap_64 (x)
+# define le64toh(x) (uint64_t) (x)
+
+# else
+
+# define htobe16(x) (uint16_t) (x)
+# define htole16(x) bswap_16 (x)
+# define be16toh(x) (uint16_t) (x)
+# define le16toh(x) bswap_16 (x)
+
+# define htobe32(x) (uint32_t) (x)
+# define htole32(x) bswap_32 (x)
+# define be32toh(x) (uint32_t) (x)
+# define le32toh(x) bswap_32 (x)
+
+# define htobe64(x) (uint64_t) (x)
+# define htole64(x) bswap_64 (x)
+# define be64toh(x) (uint64_t) (x)
+# define le64toh(x) bswap_64 (x)
+
+# endif
-#else
-#include <asm/byteorder.h>
-/* New clearer variants. */
-#define le16_to_cpu(x) __le16_to_cpu(x)
-#define le32_to_cpu(x) __le32_to_cpu(x)
-#define le64_to_cpu(x) __le64_to_cpu(x)
-#define cpu_to_le16(x) __cpu_to_le16(x)
-#define cpu_to_le32(x) __cpu_to_le32(x)
-#define cpu_to_le64(x) __cpu_to_le64(x)
-#define be16_to_cpu(x) __be16_to_cpu(x)
-#define be32_to_cpu(x) __be32_to_cpu(x)
-#define be64_to_cpu(x) __be64_to_cpu(x)
-#define cpu_to_be16(x) __cpu_to_be16(x)
-#define cpu_to_be32(x) __cpu_to_be32(x)
-#define cpu_to_be64(x) __cpu_to_be64(x)
-/* Old alternative variants. */
-#define xlate16(x) __cpu_to_le16(x)
-#define xlate32(x) __cpu_to_le32(x)
-#define xlate64(x) __cpu_to_le64(x)
-#define xlate16_be(x) __cpu_to_be16(x)
-#define xlate32_be(x) __cpu_to_be32(x)
-#define xlate64_be(x) __cpu_to_be64(x)
#endif
#endif
bad++;
}
- if (xlate64(lh->sector_xl) != labelsector) {
+ if (htole64(lh->sector_xl) != labelsector) {
log_print("CHECK: label_header.sector expected %d", (int)labelsector);
bad++;
}
crc = calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl,
LABEL_SIZE - ((uint8_t *) &lh->offset_xl - (uint8_t *) lh));
- if (crc != xlate32(lh->crc_xl)) {
+ if (crc != htole32(lh->crc_xl)) {
log_print("CHECK: label_header.crc expected 0x%x", crc);
bad++;
}
- if (xlate32(lh->offset_xl) != 32) {
+ if (htole32(lh->offset_xl) != 32) {
log_print("CHECK: label_header.offset expected 32");
bad++;
}
crc = calc_crc(INITIAL_CRC, (uint8_t *)mh->magic,
MDA_HEADER_SIZE - sizeof(mh->checksum_xl));
- if (crc != xlate32(mh->checksum_xl)) {
+ if (crc != htole32(mh->checksum_xl)) {
log_print("CHECK: mda_header_%d.checksum expected 0x%x", mda_num, crc);
bad++;
}
bad++;
}
- if (xlate32(mh->version) != FMTT_VERSION) {
+ if (htole32(mh->version) != FMTT_VERSION) {
log_print("CHECK: mda_header_%d.version expected %u", mda_num, FMTT_VERSION);
bad++;
}
- if (xlate64(mh->start) != mda_offset) {
+ if (htole64(mh->start) != mda_offset) {
log_print("CHECK: mda_header_%d.start does not match pv_header.disk_locn.offset %llu", mda_num, (unsigned long long)mda_offset);
bad++;
}
- if (xlate64(mh->size) != mda_size) {
+ if (htole64(mh->size) != mda_size) {
log_print("CHECK: mda_header_%d.size does not match pv_header.disk_locn.size %llu", mda_num, (unsigned long long)mda_size);
bad++;
}
int ri = rlocn_index; /* 0 or 1 */
int wrapped = 0;
- meta_offset = xlate64(rlocn->offset);
- meta_size = xlate64(rlocn->size);
- meta_checksum = xlate32(rlocn->checksum);
- meta_flags = xlate32(rlocn->flags);
+ meta_offset = htole64(rlocn->offset);
+ meta_size = htole64(rlocn->size);
+ meta_checksum = htole32(rlocn->checksum);
+ meta_flags = htole32(rlocn->flags);
if (meta_offset + meta_size > mda_size)
wrapped = 1;
if (print_fields) {
log_print("label_header at %llu", (unsigned long long)lh_offset);
log_print("label_header.id %s", _chars_to_str(lh->id, str, 8, 256, "label_header.id"));
- log_print("label_header.sector %llu", (unsigned long long)xlate64(lh->sector_xl));
- log_print("label_header.crc 0x%x", xlate32(lh->crc_xl));
- log_print("label_header.offset %u", xlate32(lh->offset_xl));
+ log_print("label_header.sector %llu", (unsigned long long)htole64(lh->sector_xl));
+ log_print("label_header.crc 0x%x", htole32(lh->crc_xl));
+ log_print("label_header.offset %u", htole32(lh->offset_xl));
log_print("label_header.type %s", _chars_to_str(lh->type, str, 8, 256, "label_header.type"));
}
if (print_fields) {
log_print("pv_header at %llu", (unsigned long long)pvh_offset);
log_print("pv_header.pv_uuid %s", _chars_to_str(pvh->pv_uuid, str, ID_LEN, 256, "pv_header.pv_uuid"));
- log_print("pv_header.device_size %llu", (unsigned long long)xlate64(pvh->device_size_xl));
+ log_print("pv_header.device_size %llu", (unsigned long long)htole64(pvh->device_size_xl));
}
if (!_check_pv_header(pvh))
dlocn = pvh->disk_areas_xl;
dlocn_offset = pvh_offset + 40; /* from start of disk */
- while (xlate64(dlocn->offset)) {
+ while (htole64(dlocn->offset)) {
if (print_fields) {
log_print("pv_header.disk_locn[%d] at %llu # location of data area", di,
(unsigned long long)dlocn_offset);
log_print("pv_header.disk_locn[%d].offset %llu", di,
- (unsigned long long)xlate64(dlocn->offset));
+ (unsigned long long)htole64(dlocn->offset));
log_print("pv_header.disk_locn[%d].size %llu", di,
- (unsigned long long)xlate64(dlocn->size));
+ (unsigned long long)htole64(dlocn->size));
}
di++;
dlocn++;
log_print("pv_header.disk_locn[%d] at %llu # location list end", di,
(unsigned long long) dlocn_offset);
log_print("pv_header.disk_locn[%d].offset %llu", di,
- (unsigned long long)xlate64(dlocn->offset));
+ (unsigned long long)htole64(dlocn->offset));
log_print("pv_header.disk_locn[%d].size %llu", di,
- (unsigned long long)xlate64(dlocn->size));
+ (unsigned long long)htole64(dlocn->size));
}
/* advance past the all-zero dlocn struct */
if ((void *)dlocn != (void *)(buf + dlocn_offset - lh_offset))
log_print("CHECK: problem with pv_header.disk_locn[%d] offset calculation", di);
- while (xlate64(dlocn->offset)) {
+ while (htole64(dlocn->offset)) {
if (print_fields) {
log_print("pv_header.disk_locn[%d] at %llu # location of metadata area", di,
(unsigned long long)dlocn_offset);
log_print("pv_header.disk_locn[%d].offset %llu", di,
- (unsigned long long)xlate64(dlocn->offset));
+ (unsigned long long)htole64(dlocn->offset));
log_print("pv_header.disk_locn[%d].size %llu", di,
- (unsigned long long)xlate64(dlocn->size));
+ (unsigned long long)htole64(dlocn->size));
}
if (!mda_count) {
- *mda1_offset = xlate64(dlocn->offset);
- *mda1_size = xlate64(dlocn->size);
+ *mda1_offset = htole64(dlocn->offset);
+ *mda1_size = htole64(dlocn->size);
/*
* mda1 offset is page size from machine that created it,
di, (unsigned long long)*mda1_offset);
}
} else {
- *mda2_offset = xlate64(dlocn->offset);
- *mda2_size = xlate64(dlocn->size);
+ *mda2_offset = htole64(dlocn->offset);
+ *mda2_size = htole64(dlocn->size);
/*
* No fixed location for second mda, so we have to look for
log_print("pv_header.disk_locn[%d] at %llu # location list end", di,
(unsigned long long) dlocn_offset);
log_print("pv_header.disk_locn[%d].offset %llu", di,
- (unsigned long long)xlate64(dlocn->offset));
+ (unsigned long long)htole64(dlocn->offset));
log_print("pv_header.disk_locn[%d].size %llu", di,
- (unsigned long long)xlate64(dlocn->size));
+ (unsigned long long)htole64(dlocn->size));
}
/* advance past the all-zero dlocn struct */
if (print_fields) {
log_print("pv_header_extension at %llu", (unsigned long long)pvhe_offset);
- log_print("pv_header_extension.version %u", xlate32(pvhe->version));
- log_print("pv_header_extension.flags %u", xlate32(pvhe->flags));
+ log_print("pv_header_extension.version %u", htole32(pvhe->version));
+ log_print("pv_header_extension.flags %u", htole32(pvhe->flags));
}
/*
dlocn = pvhe->bootloader_areas_xl;
dlocn_offset = pvhe_offset + 8;
- while (xlate64(dlocn->offset)) {
+ while (htole64(dlocn->offset)) {
if (print_fields) {
log_print("pv_header_extension.disk_locn[%d] at %llu # bootloader area", di,
(unsigned long long)dlocn_offset);
log_print("pv_header_extension.disk_locn[%d].offset %llu", di,
- (unsigned long long)xlate64(dlocn->offset));
+ (unsigned long long)htole64(dlocn->offset));
log_print("pv_header_extension.disk_locn[%d].size %llu", di,
- (unsigned long long)xlate64(dlocn->size));
+ (unsigned long long)htole64(dlocn->size));
}
di++;
log_print("pv_header_extension.disk_locn[%d] at %llu # location list end", di,
(unsigned long long) dlocn_offset);
log_print("pv_header_extension.disk_locn[%d].offset %llu", di,
- (unsigned long long)xlate64(dlocn->offset));
+ (unsigned long long)htole64(dlocn->offset));
log_print("pv_header_extension.disk_locn[%d].size %llu", di,
- (unsigned long long)xlate64(dlocn->size));
+ (unsigned long long)htole64(dlocn->size));
}
if (bad)
if (print_fields) {
log_print("mda_header_%d at %llu # metadata area", mda_num, (unsigned long long)mda_offset);
- log_print("mda_header_%d.checksum 0x%x", mda_num, xlate32(mh->checksum_xl));
+ log_print("mda_header_%d.checksum 0x%x", mda_num, htole32(mh->checksum_xl));
log_print("mda_header_%d.magic 0x%s", mda_num, _chars_to_hexstr(mh->magic, str, 16, 256, "mda_header.magic"));
- log_print("mda_header_%d.version %u", mda_num, xlate32(mh->version));
- log_print("mda_header_%d.start %llu", mda_num, (unsigned long long)xlate64(mh->start));
- log_print("mda_header_%d.size %llu", mda_num, (unsigned long long)xlate64(mh->size));
+ log_print("mda_header_%d.version %u", mda_num, htole32(mh->version));
+ log_print("mda_header_%d.start %llu", mda_num, (unsigned long long)htole64(mh->start));
+ log_print("mda_header_%d.size %llu", mda_num, (unsigned long long)htole64(mh->size));
}
if (!_check_mda_header(mh, mda_num, mda_offset, mda_size, found_header))
memcpy(lh->id, LABEL_ID, sizeof(lh->id));
memcpy(lh->type, LVM2_LABEL, sizeof(lh->type));
- lh->sector_xl = xlate64(labelsector);
- lh->offset_xl = xlate32(32);
+ lh->sector_xl = htole64(labelsector);
+ lh->offset_xl = htole32(32);
crc = calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl,
LABEL_SIZE - ((uint8_t *) &lh->offset_xl - (uint8_t *) lh));
- lh->crc_xl = xlate32(crc);
+ lh->crc_xl = htole32(crc);
log_print("Writing label_header.crc 0x%08x", crc);
if (memcmp(mh->magic, FMTT_MAGIC, sizeof(mh->magic)))
goto fail;
- if (xlate32(mh->version) != FMTT_VERSION) {
+ if (htole32(mh->version) != FMTT_VERSION) {
log_print("Skipping mda2 (wrong mda_header.version)");
goto fail;
}
- if (xlate64(mh->start) != mda_offset) {
+ if (htole64(mh->start) != mda_offset) {
log_print("Skipping mda2 (wrong mda_header.start)");
goto fail;
}
/* set label_header (except crc) */
memcpy(lh->id, LABEL_ID, sizeof(lh->id));
memcpy(lh->type, LVM2_LABEL, sizeof(lh->type));
- lh->sector_xl = xlate64(labelsector);
- lh->offset_xl = xlate32(32);
+ lh->sector_xl = htole64(labelsector);
+ lh->offset_xl = htole32(32);
/* set pv_header */
memcpy(pvh->pv_uuid, &pvid, ID_LEN);
- pvh->device_size_xl = xlate64(device_size);
+ pvh->device_size_xl = htole64(device_size);
/* set data area location */
data_offset = (pe_start_sectors << SECTOR_SHIFT);
- pvh->disk_areas_xl[0].offset = xlate64(data_offset);
+ pvh->disk_areas_xl[0].offset = htole64(data_offset);
pvh->disk_areas_xl[0].size = 0;
/* set end of data areas */
if (mda_count > 0) {
mda1_offset = 4096;
mda1_size = (pe_start_sectors << SECTOR_SHIFT) - 4096;
- pvh->disk_areas_xl[di].offset = xlate64(mda1_offset);
- pvh->disk_areas_xl[di].size = xlate64(mda1_size);
+ pvh->disk_areas_xl[di].offset = htole64(mda1_offset);
+ pvh->disk_areas_xl[di].size = htole64(mda1_size);
di++;
}
/* set second metadata area location */
if (mda_count > 1) {
- pvh->disk_areas_xl[di].offset = xlate64(mda2_offset);
- pvh->disk_areas_xl[di].size = xlate64(mda2_size);
+ pvh->disk_areas_xl[di].offset = htole64(mda2_offset);
+ pvh->disk_areas_xl[di].size = htole64(mda2_size);
di++;
}
/* set pv_header_extension */
pvhe = (struct pv_header_extension *)((char *)pvh + sizeof(struct pv_header) + (di * sizeof(struct disk_locn)));
- pvhe->version = xlate32(PV_HEADER_EXTENSION_VSN);
- pvhe->flags = xlate32(PV_EXT_USED);
+ pvhe->version = htole32(PV_HEADER_EXTENSION_VSN);
+ pvhe->flags = htole32(PV_EXT_USED);
pvhe->bootloader_areas_xl[0].offset = 0;
pvhe->bootloader_areas_xl[0].size = 0;
LABEL_SIZE - ((uint8_t *) &lh->offset_xl - (uint8_t *) lh));
/* set label_header crc (last) */
- lh->crc_xl = xlate32(head_crc);
+ lh->crc_xl = htole32(head_crc);
/*
* Write the updated header sector.
mh = (struct mda_header *)buf;
memcpy(mh->magic, FMTT_MAGIC, sizeof(mh->magic));
- mh->version = xlate32(FMTT_VERSION);
- mh->start = xlate64(mda_offset);
- mh->size = xlate64(mda_size);
+ mh->version = htole32(FMTT_VERSION);
+ mh->start = htole64(mda_offset);
+ mh->size = htole64(mda_size);
rlocn0 = mh->raw_locns;
rlocn0->flags = 0;
- rlocn0->offset = xlate64(512); /* text begins 512 from start of mda_header */
- rlocn0->size = xlate64(mf->text_size);
- rlocn0->checksum = xlate32(mf->text_crc);
+ rlocn0->offset = htole64(512); /* text begins 512 from start of mda_header */
+ rlocn0->size = htole64(mf->text_size);
+ rlocn0->checksum = htole32(mf->text_crc);
rlocn1 = (struct raw_locn *)((char *)mh->raw_locns + 24);
rlocn1->flags = 0;
crc = calc_crc(INITIAL_CRC, (uint8_t *)mh->magic,
MDA_HEADER_SIZE - sizeof(mh->checksum_xl));
- mh->checksum_xl = xlate32(crc);
+ mh->checksum_xl = htole32(crc);
log_print("Writing metadata at %llu length %llu crc 0x%08x mda%d",
(unsigned long long)(mda_offset + 512),