void zfs_oldace_byteswap(ace_t *ace, int ace_cnt) { int i; for (i = 0; i != ace_cnt; i++, ace++) { ace->a_who = BSWAP_32(ace->a_who); ace->a_access_mask = BSWAP_32(ace->a_access_mask); ace->a_flags = BSWAP_16(ace->a_flags); ace->a_type = BSWAP_16(ace->a_type); } }
/* pcap_sendpacket wrapper, some easiness of use added */ bool TWinPCAP::SendPacket(unsigned char * src_mac, unsigned char * dst_mac, int proto, unsigned char * payload, unsigned int payload_size) { unsigned char pkt_data[PCAP_MAX_PACKET_SIZE]; TEthernetPacket * pkt_header = (TEthernetPacket *)pkt_data; /* if src-mac not specified - use cached mac of opened adapter */ if (src_mac) memcpy(pkt_header->h_source, src_mac, 6); else memcpy(pkt_header->h_source, this->adapter_mac, 6); /* if dst-mac is not specified - broadcast the packet */ if (dst_mac) memcpy(pkt_header->h_dest, dst_mac, 6); else memset(pkt_header->h_dest, 0xff, 6); /* protocol */ pkt_header->h_proto = BSWAP_16(proto); /* payload (if no payload specified - fill with zeroes) */ if (payload) memcpy(pkt_data + sizeof(TEthernetPacket), payload, payload_size); else memset(pkt_data + sizeof(TEthernetPacket), 0x00, payload_size); /* do an actual send */ if (this->pcap_sendpacket(this->adapter, pkt_data, sizeof(TEthernetPacket) + payload_size) != 0) return false; else return true; }
uint8_t MB85RC64_ReadByte(uint16_t pos) { uint8_t data; pos = BSWAP_16(pos); I2C_BurstRead(gInstance, MB85RC64_ADDR, pos, 2, &data, 1); return data; }
void zfs_znode_byteswap(void *buf, size_t size) { znode_phys_t *zp = buf; ASSERT(size >= sizeof (znode_phys_t)); zp->zp_crtime[0] = BSWAP_64(zp->zp_crtime[0]); zp->zp_crtime[1] = BSWAP_64(zp->zp_crtime[1]); zp->zp_atime[0] = BSWAP_64(zp->zp_atime[0]); zp->zp_atime[1] = BSWAP_64(zp->zp_atime[1]); zp->zp_mtime[0] = BSWAP_64(zp->zp_mtime[0]); zp->zp_mtime[1] = BSWAP_64(zp->zp_mtime[1]); zp->zp_ctime[0] = BSWAP_64(zp->zp_ctime[0]); zp->zp_ctime[1] = BSWAP_64(zp->zp_ctime[1]); zp->zp_gen = BSWAP_64(zp->zp_gen); zp->zp_mode = BSWAP_64(zp->zp_mode); zp->zp_size = BSWAP_64(zp->zp_size); zp->zp_parent = BSWAP_64(zp->zp_parent); zp->zp_links = BSWAP_64(zp->zp_links); zp->zp_xattr = BSWAP_64(zp->zp_xattr); zp->zp_rdev = BSWAP_64(zp->zp_rdev); zp->zp_flags = BSWAP_64(zp->zp_flags); zp->zp_uid = BSWAP_64(zp->zp_uid); zp->zp_gid = BSWAP_64(zp->zp_gid); zp->zp_zap = BSWAP_64(zp->zp_zap); zp->zp_s2size = BSWAP_64(zp->zp_s2size); zp->zp_s2ptruncgen = BSWAP_32(zp->zp_s2ptruncgen); zp->zp_s2gen = BSWAP_32(zp->zp_s2gen); zp->zp_s2fid = BSWAP_64(zp->zp_s2fid); zp->zp_acl.z_acl_extern_obj = BSWAP_64(zp->zp_acl.z_acl_extern_obj); zp->zp_acl.z_acl_size = BSWAP_32(zp->zp_acl.z_acl_size); zp->zp_acl.z_acl_version = BSWAP_16(zp->zp_acl.z_acl_version); zp->zp_acl.z_acl_count = BSWAP_16(zp->zp_acl.z_acl_count); if (zp->zp_acl.z_acl_version == ZFS_ACL_VERSION) { zfs_acl_byteswap((void *)&zp->zp_acl.z_ace_data[0], ZFS_ACE_SPACE); } else { zfs_oldace_byteswap((ace_t *)&zp->zp_acl.z_ace_data[0], ACE_SLOT_CNT); } }
void sa_byteswap(sa_handle_t *hdl, sa_buf_type_t buftype) { sa_hdr_phys_t *sa_hdr_phys = SA_GET_HDR(hdl, buftype); dmu_buf_impl_t *db; sa_os_t *sa = hdl->sa_os->os_sa; int num_lengths = 1; int i; ASSERT(MUTEX_HELD(&sa->sa_lock)); if (sa_hdr_phys->sa_magic == SA_MAGIC) return; db = SA_GET_DB(hdl, buftype); if (buftype == SA_SPILL) { arc_release(db->db_buf, NULL); arc_buf_thaw(db->db_buf); } sa_hdr_phys->sa_magic = BSWAP_32(sa_hdr_phys->sa_magic); sa_hdr_phys->sa_layout_info = BSWAP_16(sa_hdr_phys->sa_layout_info); /* * Determine number of variable lenghts in header * The standard 8 byte header has one for free and a * 16 byte header would have 4 + 1; */ if (SA_HDR_SIZE(sa_hdr_phys) > 8) num_lengths += (SA_HDR_SIZE(sa_hdr_phys) - 8) >> 1; for (i = 0; i != num_lengths; i++) sa_hdr_phys->sa_lengths[i] = BSWAP_16(sa_hdr_phys->sa_lengths[i]); sa_attr_iter(hdl->sa_os, sa_hdr_phys, DMU_OT_SA, sa_byteswap_cb, NULL, hdl); if (buftype == SA_SPILL) arc_buf_freeze(((dmu_buf_impl_t *)hdl->sa_spill)->db_buf); }
/* receives an ethernet packet, parses it */ unsigned int TWinPCAP::ReadPacket(unsigned char * src_mac, unsigned char * dst_mac, int * proto, unsigned char * payload , unsigned int buffer_size) { struct pcap_pkthdr * header; TEthernetPacket * pkt_data; if (this->pcap_next_ex(this->adapter, &header, (const u_char **)&pkt_data) == 1) { if (src_mac) memcpy(src_mac, pkt_data->h_source, 6); if (dst_mac) memcpy(dst_mac, pkt_data->h_dest, 6); if (proto) *proto = BSWAP_16(pkt_data->h_proto); if (payload) memcpy(payload, ((u_char *)pkt_data) + sizeof(TEthernetPacket), min(header->caplen - sizeof(TEthernetPacket), buffer_size)); return header->caplen; } else { return 0; } }
void zap_leaf_byteswap(zap_leaf_phys_t *buf, int size) { int i; zap_leaf_t l; l.l_bs = highbit(size)-1; l.l_phys = buf; buf->l_hdr.lh_block_type = BSWAP_64(buf->l_hdr.lh_block_type); buf->l_hdr.lh_prefix = BSWAP_64(buf->l_hdr.lh_prefix); buf->l_hdr.lh_magic = BSWAP_32(buf->l_hdr.lh_magic); buf->l_hdr.lh_nfree = BSWAP_16(buf->l_hdr.lh_nfree); buf->l_hdr.lh_nentries = BSWAP_16(buf->l_hdr.lh_nentries); buf->l_hdr.lh_prefix_len = BSWAP_16(buf->l_hdr.lh_prefix_len); buf->l_hdr.lh_freelist = BSWAP_16(buf->l_hdr.lh_freelist); for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++) buf->l_hash[i] = BSWAP_16(buf->l_hash[i]); for (i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) { zap_leaf_chunk_t *lc = &ZAP_LEAF_CHUNK(&l, i); struct zap_leaf_entry *le; switch (lc->l_free.lf_type) { case ZAP_CHUNK_ENTRY: le = &lc->l_entry; le->le_type = BSWAP_8(le->le_type); le->le_value_intlen = BSWAP_8(le->le_value_intlen); le->le_next = BSWAP_16(le->le_next); le->le_name_chunk = BSWAP_16(le->le_name_chunk); le->le_name_numints = BSWAP_16(le->le_name_numints); le->le_value_chunk = BSWAP_16(le->le_value_chunk); le->le_value_numints = BSWAP_16(le->le_value_numints); le->le_cd = BSWAP_32(le->le_cd); le->le_hash = BSWAP_64(le->le_hash); break; case ZAP_CHUNK_FREE: lc->l_free.lf_type = BSWAP_8(lc->l_free.lf_type); lc->l_free.lf_next = BSWAP_16(lc->l_free.lf_next); break; case ZAP_CHUNK_ARRAY: lc->l_array.la_type = BSWAP_8(lc->l_array.la_type); lc->l_array.la_next = BSWAP_16(lc->l_array.la_next); /* la_array doesn't need swapping */ break; default: ASSERT(!"bad leaf type"); } } }
static int zfs_space_delta_cb(dmu_object_type_t bonustype, void *data, uint64_t *userp, uint64_t *groupp) { /* * Is it a valid type of object to track? */ if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA) return (SET_ERROR(ENOENT)); /* * If we have a NULL data pointer * then assume the id's aren't changing and * return EEXIST to the dmu to let it know to * use the same ids */ if (data == NULL) return (SET_ERROR(EEXIST)); if (bonustype == DMU_OT_ZNODE) { znode_phys_t *znp = data; *userp = znp->zp_uid; *groupp = znp->zp_gid; } else { int hdrsize; sa_hdr_phys_t *sap = data; sa_hdr_phys_t sa = *sap; boolean_t swap = B_FALSE; ASSERT(bonustype == DMU_OT_SA); if (sa.sa_magic == 0) { /* * This should only happen for newly created * files that haven't had the znode data filled * in yet. */ *userp = 0; *groupp = 0; return (0); } if (sa.sa_magic == BSWAP_32(SA_MAGIC)) { sa.sa_magic = SA_MAGIC; sa.sa_layout_info = BSWAP_16(sa.sa_layout_info); swap = B_TRUE; } else { VERIFY3U(sa.sa_magic, ==, SA_MAGIC); } hdrsize = sa_hdrsize(&sa); VERIFY3U(hdrsize, >=, sizeof (sa_hdr_phys_t)); *userp = *((uint64_t *)((uintptr_t)data + hdrsize + SA_UID_OFFSET)); *groupp = *((uint64_t *)((uintptr_t)data + hdrsize + SA_GID_OFFSET)); if (swap) { *userp = BSWAP_64(*userp); *groupp = BSWAP_64(*groupp); } } return (0); }
/* * swap ace_t and ace_oject_t */ void zfs_ace_byteswap(void *buf, size_t size, boolean_t zfs_layout) { #ifdef TODO caddr_t end; caddr_t ptr; zfs_ace_t *zacep; ace_t *acep; uint16_t entry_type; size_t entry_size; int ace_type; end = (caddr_t)buf + size; ptr = buf; while (ptr < end) { if (zfs_layout) { zacep = (zfs_ace_t *)ptr; zacep->z_hdr.z_access_mask = BSWAP_32(zacep->z_hdr.z_access_mask); zacep->z_hdr.z_flags = BSWAP_16(zacep->z_hdr.z_flags); ace_type = zacep->z_hdr.z_type = BSWAP_16(zacep->z_hdr.z_type); entry_type = zacep->z_hdr.z_flags & ACE_TYPE_FLAGS; } else { acep = (ace_t *)ptr; acep->a_access_mask = BSWAP_32(acep->a_access_mask); acep->a_flags = BSWAP_16(acep->a_flags); ace_type = acep->a_type = BSWAP_16(acep->a_type); acep->a_who = BSWAP_32(acep->a_who); entry_type = acep->a_flags & ACE_TYPE_FLAGS; } switch (entry_type) { case ACE_OWNER: case ACE_EVERYONE: case (ACE_IDENTIFIER_GROUP | ACE_GROUP): entry_size = zfs_layout ? sizeof (zfs_ace_hdr_t) : sizeof (ace_t); break; case ACE_IDENTIFIER_GROUP: default: if (zfs_layout) { zacep->z_fuid = BSWAP_64(zacep->z_fuid); } switch (ace_type) { case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE: case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE: case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE: case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE: entry_size = zfs_layout ? sizeof (zfs_object_ace_t) : sizeof (ace_object_t); break; default: entry_size = zfs_layout ? sizeof (zfs_ace_t) : sizeof (ace_t); break; } } ptr = ptr + entry_size; } #else /* TODO */ panic("%s:%u: TODO", __func__, __LINE__); #endif /* TODO */ }
int hpm2_get_capabilities(struct ipmi_intf * intf, struct hpm2_lan_attach_capabilities * caps) { struct ipmi_rq req; struct ipmi_rs * rsp; struct hpmx_cmd_get_capabilities_rq rq; /* reset result */ memset(caps, 0, sizeof(struct hpm2_lan_attach_capabilities)); /* prepare request */ rq.picmg_id = 0; rq.hpmx_id = 2; /* prepare request */ memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPM2_GET_LAN_ATTACH_CAPABILITIES; req.msg.data = (uint8_t *)&rq; req.msg.data_len = sizeof(rq); /* send */ rsp = intf->sendrecv(intf, &req); if (!rsp) { lprintf(LOG_NOTICE, "Error sending request."); return -1; } if (rsp->ccode == 0xC1) { lprintf(LOG_DEBUG, "IPM Controller is not HPM.2 compatible"); return rsp->ccode; } else if (rsp->ccode) { lprintf(LOG_NOTICE, "Get HPM.x Capabilities request failed," " compcode = %x", rsp->ccode); return rsp->ccode; } /* check response length */ if (rsp->data_len < 2 || rsp->data_len > 10) { lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len); return -1; } /* check HPM.x identifier */ if (rsp->data[1] != 2) { lprintf(LOG_NOTICE, "Bad HPM.x ID, id=%d", rsp->data[1]); return rsp->ccode; } /* * this hardly can happen, since completion code is already checked. * but check for safety */ if (rsp->data_len < 4) { lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len); return -1; } /* copy HPM.2 capabilities */ memcpy(caps, rsp->data + 2, rsp->data_len - 2); #if WORDS_BIGENDIAN /* swap bytes to convert from little-endian format */ caps->lan_channel_mask = BSWAP_16(caps->lan_channel_mask); #endif /* check HPM.2 revision */ if (caps->hpm2_revision_id == 0) { lprintf(LOG_NOTICE, "Bad HPM.2 revision, rev=%d", caps->hpm2_revision_id); return -1; } if (!caps->lan_channel_mask) { return -1; } /* check response length */ if (rsp->data_len < 8) { lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len); return -1; } /* check HPM.2 LAN parameters start */ if (caps->hpm2_lan_params_start < 0xC0) { lprintf(LOG_NOTICE, "Bad HPM.2 LAN params start, start=%x", caps->hpm2_lan_params_start); return -1; } /* check HPM.2 LAN parameters revision */ if (caps->hpm2_lan_params_rev != HPM2_LAN_PARAMS_REV) { lprintf(LOG_NOTICE, "Bad HPM.2 LAN params revision, rev=%d", caps->hpm2_lan_params_rev); return -1; } /* check for HPM.2 SOL extension */ if (!(caps->hpm2_caps & HPM2_CAPS_SOL_EXTENSION)) { /* no further checks */ return 0; } /* check response length */ if (rsp->data_len < 10) { lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len); return -1; } /* check HPM.2 SOL parameters start */ if (caps->hpm2_sol_params_start < 0xC0) { lprintf(LOG_NOTICE, "Bad HPM.2 SOL params start, start=%x", caps->hpm2_sol_params_start); return -1; } /* check HPM.2 SOL parameters revision */ if (caps->hpm2_sol_params_rev != HPM2_SOL_PARAMS_REV) { lprintf(LOG_NOTICE, "Bad HPM.2 SOL params revision, rev=%d", caps->hpm2_sol_params_rev); return -1; } return 0; }
int hpm2_get_lan_channel_capabilities(struct ipmi_intf * intf, uint8_t hpm2_lan_params_start, struct hpm2_lan_channel_capabilities * caps) { struct ipmi_rq req; struct ipmi_rs * rsp; uint8_t rq[4]; /* reset result */ memset(caps, 0, sizeof(struct hpm2_lan_channel_capabilities)); /* prepare request */ memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_TRANSPORT; req.msg.cmd = IPMI_LAN_GET_CONFIG; req.msg.data = (uint8_t *)&rq; req.msg.data_len = sizeof(rq); /* prepare request data */ rq[0] = 0xE; /* sending channel */ rq[1] = hpm2_lan_params_start; /* HPM.2 Channel Caps */ rq[2] = rq[3] = 0; /* send */ rsp = intf->sendrecv(intf, &req); if (!rsp) { lprintf(LOG_NOTICE, "Error sending request."); return -1; } if (rsp->ccode == 0x80) { lprintf(LOG_DEBUG, "HPM.2 Channel Caps parameter is not supported"); return rsp->ccode; } else if (rsp->ccode) { lprintf(LOG_NOTICE, "Get LAN Configuration Parameters request failed," " compcode = %x", rsp->ccode); return rsp->ccode; } /* check response length */ if (rsp->data_len != sizeof (struct hpm2_lan_channel_capabilities) + 1) { lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len); return -1; } /* check parameter revision */ if (rsp->data[0] != LAN_PARAM_REV(HPM2_LAN_PARAMS_REV, HPM2_LAN_PARAMS_REV)) { lprintf(LOG_NOTICE, "Bad HPM.2 LAN parameter revision, rev=%d", rsp->data[0]); return -1; } /* copy parameter data */ memcpy(caps, &rsp->data[1], sizeof (struct hpm2_lan_channel_capabilities)); #if WORDS_BIGENDIAN /* swap bytes to convert from little-endian format */ caps->max_inbound_pld_size = BSWAP_16(caps->max_inbound_pld_size); caps->max_outbound_pld_size = BSWAP_16(caps->max_outbound_pld_size); #endif return 0; }
int uconv_u16tou8(const uint16_t *u16s, size_t *utf16len, uchar_t *u8s, size_t *utf8len, int flag) { int inendian; int outendian; size_t u16l; size_t u8l; uint32_t hi; uint32_t lo; boolean_t do_not_ignore_null; if (u16s == NULL || utf16len == NULL) return (EILSEQ); if (u8s == NULL || utf8len == NULL) return (E2BIG); if (check_endian(flag, &inendian, &outendian) != 0) return (EBADF); u16l = u8l = 0; hi = 0; do_not_ignore_null = ((flag & UCONV_IGNORE_NULL) == 0); if ((flag & UCONV_IN_ACCEPT_BOM) && check_bom16(u16s, *utf16len, &inendian)) u16l++; inendian &= UCONV_IN_NAT_ENDIAN; for (; u16l < *utf16len; u16l++) { if (u16s[u16l] == 0 && do_not_ignore_null) break; lo = (uint32_t)((inendian) ? u16s[u16l] : BSWAP_16(u16s[u16l])); if (lo >= UCONV_U16_HI_MIN && lo <= UCONV_U16_HI_MAX) { if (hi) return (EILSEQ); hi = lo; continue; } else if (lo >= UCONV_U16_LO_MIN && lo <= UCONV_U16_LO_MAX) { if (! hi) return (EILSEQ); lo = (((hi - UCONV_U16_HI_MIN) * UCONV_U16_BIT_SHIFT + lo - UCONV_U16_LO_MIN) & UCONV_U16_BIT_MASK) + UCONV_U16_START; hi = 0; } else if (hi) { return (EILSEQ); } /* * Now we convert a UTF-32 character into a UTF-8 character. * Unicode coding space is between U+0000 and U+10FFFF; * anything bigger is an illegal character. */ if (lo <= UCONV_U8_ONE_BYTE) { if (u8l >= *utf8len) return (E2BIG); u8s[u8l++] = (uchar_t)lo; } else if (lo <= UCONV_U8_TWO_BYTES) { if ((u8l + 1) >= *utf8len) return (E2BIG); u8s[u8l++] = (uchar_t)(0xc0 | ((lo & 0x07c0) >> 6)); u8s[u8l++] = (uchar_t)(0x80 | (lo & 0x003f)); } else if (lo <= UCONV_U8_THREE_BYTES) { if ((u8l + 2) >= *utf8len) return (E2BIG); u8s[u8l++] = (uchar_t)(0xe0 | ((lo & 0x0f000) >> 12)); u8s[u8l++] = (uchar_t)(0x80 | ((lo & 0x00fc0) >> 6)); u8s[u8l++] = (uchar_t)(0x80 | (lo & 0x0003f)); } else if (lo <= UCONV_U8_FOUR_BYTES) {
int uconv_u16tou32(const uint16_t *u16s, size_t *utf16len, uint32_t *u32s, size_t *utf32len, int flag) { int inendian; int outendian; size_t u16l; size_t u32l; uint32_t hi; uint32_t lo; boolean_t do_not_ignore_null; /* * Do preliminary validity checks on parameters and collect info on * endians. */ if (u16s == NULL || utf16len == NULL) return (EILSEQ); if (u32s == NULL || utf32len == NULL) return (E2BIG); if (check_endian(flag, &inendian, &outendian) != 0) return (EBADF); /* * Initialize input and output parameter buffer indices and * temporary variables. */ u16l = u32l = 0; hi = 0; do_not_ignore_null = ((flag & UCONV_IGNORE_NULL) == 0); /* * Check on the BOM at the beginning of the input buffer if required * and if there is indeed one, process it. */ if ((flag & UCONV_IN_ACCEPT_BOM) && check_bom16(u16s, *utf16len, &inendian)) u16l++; /* * Reset inendian and outendian so that after this point, those can be * used as condition values. */ inendian &= UCONV_IN_NAT_ENDIAN; outendian &= UCONV_OUT_NAT_ENDIAN; /* * If there is something in the input buffer and if necessary and * requested, save the BOM at the output buffer. */ if (*utf16len > 0 && *utf32len > 0 && (flag & UCONV_OUT_EMIT_BOM)) u32s[u32l++] = (outendian) ? UCONV_BOM_NORMAL : UCONV_BOM_SWAPPED_32; /* * Do conversion; if encounter a surrogate pair, assemble high and * low pair values to form a UTF-32 character. If a half of a pair * exists alone, then, either it is an illegal (EILSEQ) or * invalid (EINVAL) value. */ for (; u16l < *utf16len; u16l++) { if (u16s[u16l] == 0 && do_not_ignore_null) break; lo = (uint32_t)((inendian) ? u16s[u16l] : BSWAP_16(u16s[u16l])); if (lo >= UCONV_U16_HI_MIN && lo <= UCONV_U16_HI_MAX) { if (hi) return (EILSEQ); hi = lo; continue; } else if (lo >= UCONV_U16_LO_MIN && lo <= UCONV_U16_LO_MAX) { if (! hi) return (EILSEQ); lo = (((hi - UCONV_U16_HI_MIN) * UCONV_U16_BIT_SHIFT + lo - UCONV_U16_LO_MIN) & UCONV_U16_BIT_MASK) + UCONV_U16_START; hi = 0; } else if (hi) { return (EILSEQ); } if (u32l >= *utf32len) return (E2BIG); u32s[u32l++] = (outendian) ? lo : BSWAP_32(lo); } /* * If high half didn't see low half, then, it's most likely the input * parameter is incomplete. */ if (hi) return (EINVAL); /* * Save the number of consumed and saved characters. They do not * include terminating NULL character (U+0000) at the end of * the input buffer (even when UCONV_IGNORE_NULL isn't specified and * the input buffer length is big enough to include the terminating * NULL character). */ *utf16len = u16l; *utf32len = u32l; return (0); }
/* * swap ace_t and ace_oject_t */ void zfs_ace_byteswap(void *buf, size_t size, boolean_t zfs_layout) { caddr_t end; caddr_t ptr; zfs_ace_t *zacep; ace_t *acep; uint16_t entry_type; size_t entry_size; int ace_type; end = (caddr_t)buf + size; ptr = buf; while (ptr < end) { if (zfs_layout) { /* * Avoid overrun. Embedded aces can have one * of several sizes. We don't know exactly * how many our present, only the size of the * buffer containing them. That size may be * larger than needed to hold the aces * present. As long as we do not do any * swapping beyond the end of our block we are * okay. It it safe to swap any non-ace data * within the block since it is just zeros. */ if (ptr + sizeof (zfs_ace_hdr_t) > end) { break; } zacep = (zfs_ace_t *)ptr; zacep->z_hdr.z_access_mask = BSWAP_32(zacep->z_hdr.z_access_mask); zacep->z_hdr.z_flags = BSWAP_16(zacep->z_hdr.z_flags); ace_type = zacep->z_hdr.z_type = BSWAP_16(zacep->z_hdr.z_type); entry_type = zacep->z_hdr.z_flags & ACE_TYPE_FLAGS; } else { /* Overrun avoidance */ if (ptr + sizeof (ace_t) > end) { break; } acep = (ace_t *)ptr; acep->a_access_mask = BSWAP_32(acep->a_access_mask); acep->a_flags = BSWAP_16(acep->a_flags); ace_type = acep->a_type = BSWAP_16(acep->a_type); acep->a_who = BSWAP_32(acep->a_who); entry_type = acep->a_flags & ACE_TYPE_FLAGS; } switch (entry_type) { case ACE_OWNER: case ACE_EVERYONE: case (ACE_IDENTIFIER_GROUP | ACE_GROUP): entry_size = zfs_layout ? sizeof (zfs_ace_hdr_t) : sizeof (ace_t); break; case ACE_IDENTIFIER_GROUP: default: /* Overrun avoidance */ if (zfs_layout) { if (ptr + sizeof (zfs_ace_t) <= end) { zacep->z_fuid = BSWAP_64(zacep->z_fuid); } else { entry_size = sizeof (zfs_ace_t); break; } } switch (ace_type) { case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE: case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE: case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE: case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE: entry_size = zfs_layout ? sizeof (zfs_object_ace_t) : sizeof (ace_object_t); break; default: entry_size = zfs_layout ? sizeof (zfs_ace_t) : sizeof (ace_t); break; } } ptr = ptr + entry_size; } }
int MB85RC64_WriteByte(uint16_t pos, uint8_t data) { pos = BSWAP_16(pos); return I2C_BurstWrite(gInstance, MB85RC64_ADDR, pos, 2, &data, 1); }
int MB85RC64_Read(uint16_t pos, uint8_t * buf, uint32_t len) { pos = BSWAP_16(pos); return I2C_BurstRead(gInstance, MB85RC64_ADDR, pos, 2, buf, len); }