/* * pmemlog_nbyte -- return usable size of a log memory pool */ size_t pmemlog_nbyte(PMEMlogpool *plp) { LOG(3, "plp %p", plp); if ((errno = pthread_rwlock_rdlock(plp->rwlockp))) { ERR("!pthread_rwlock_rdlock"); return (size_t)-1; } size_t size = le64toh(plp->end_offset) - le64toh(plp->start_offset); LOG(4, "plp %p nbyte %zu", plp, size); if ((errno = pthread_rwlock_unlock(plp->rwlockp))) ERR("!pthread_rwlock_unlock"); return size; }
/* Read a variable length of chars dependant on how big the chunk was */ static inline i64 read_vchars(rzip_control *control, void *ss, int stream, int length) { i64 s = 0; if (unlikely(read_stream(control, ss, stream, (uchar *)&s, length) != length)) fatal_return(("Stream read of %d bytes failed\n", length), -1); s = le64toh(s); return s; }
Rand_event::Rand_event(const char* buf, const Format_description_event* description_event) :Binary_log_event(&buf, description_event->binlog_version, description_event->server_version) { //buf is advanced in Binary_log_event constructor to point to //beginning of post-header /* We step to the post-header despite it being empty because it could later be filled with something and we have to support that case. The Variable Data part begins immediately. */ buf+= description_event->post_header_len[RAND_EVENT - 1]; memcpy(&seed1, buf + RAND_SEED1_OFFSET, 8); seed1= le64toh(seed1); memcpy(&seed2, buf + RAND_SEED2_OFFSET, 8); seed2= le64toh(seed2); }
static int udf_read(struct vop_read_args *ap) { struct vnode *vp = ap->a_vp; struct uio *uio = ap->a_uio; struct udf_node *node = VTON(vp); struct udf_mnt *udfmp; struct file_entry *fentry; struct buf *bp; uint8_t *data; daddr_t lbn, rablock; off_t diff, fsize; int error = 0; long size, n, on; if (uio->uio_resid == 0) return (0); if (uio->uio_offset < 0) return (EINVAL); if (is_data_in_fentry(node)) { fentry = node->fentry; data = &fentry->data[le32toh(fentry->l_ea)]; fsize = le32toh(fentry->l_ad); n = uio->uio_resid; diff = fsize - uio->uio_offset; if (diff <= 0) return (0); if (diff < n) n = diff; error = uiomove(data + uio->uio_offset, (int)n, uio); return (error); } fsize = le64toh(node->fentry->inf_len); udfmp = node->udfmp; do { lbn = lblkno(udfmp, uio->uio_offset); on = blkoff(udfmp, uio->uio_offset); n = min((u_int)(udfmp->bsize - on), uio->uio_resid); diff = fsize - uio->uio_offset; if (diff <= 0) return (0); if (diff < n) n = diff; size = udfmp->bsize; rablock = lbn + 1; if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) { if (lblktosize(udfmp, rablock) < fsize) { error = cluster_read(vp, fsize, lbn, size, NOCRED, uio->uio_resid, (ap->a_ioflag >> 16), &bp); } else { error = bread(vp, lbn, size, NOCRED, &bp); } } else {
static int udf_open(struct vop_open_args *ap) { struct udf_node *np = VTON(ap->a_vp); off_t fsize; fsize = le64toh(np->fentry->inf_len); vnode_create_vobject(ap->a_vp, fsize, ap->a_td); return 0; }
/* * pmemlog_tell -- return current write point in a log memory pool */ off_t pmemlog_tell(PMEMlogpool *plp) { LOG(3, "plp %p", plp); if ((errno = pthread_rwlock_rdlock(plp->rwlockp))) { ERR("!pthread_rwlock_rdlock"); return (off_t)-1; } off_t wp = le64toh(plp->write_offset) - le64toh(plp->start_offset); LOG(4, "write offset %lld", (long long)wp); if ((errno = pthread_rwlock_unlock(plp->rwlockp))) ERR("!pthread_rwlock_unlock"); return wp; }
static inline uint64_t get_le64(uint8_t **bufferp) { uint64_t tmp; memcpy(&tmp, *bufferp, sizeof (tmp)); *bufferp += sizeof (tmp); return le64toh(tmp); }
FCITX_EXPORT_API size_t fcitx_utils_read_uint64(FILE *fp, uint64_t *p) { uint64_t res = 0; size_t size; size = fread(&res, sizeof(uint64_t), 1, fp); *p = le64toh(res); return size; }
int mb_get_int64le(struct mbdata *mbp, int64_t *x) { int64_t v; int error; error = mb_get_int64(mbp, &v); *x = le64toh(v); return error; }
static inline bool readUInt64 (FILE * file, kdb_unsigned_long_long_t * valuePtr, Key * errorKey) { if (fread (valuePtr, sizeof (kdb_unsigned_long_long_t), 1, file) < 1) { ELEKTRA_SET_ERROR (ELEKTRA_ERROR_READ_FAILED, errorKey, ""); return false; } *valuePtr = le64toh (*valuePtr); return true; }
int md_get_int64le(struct mdchain *mdp, int64_t *x) { int64_t v; int error; error = md_get_int64(mdp, &v); *x = le64toh(v); return error; }
void ble_sm_master_id_parse(void *payload, int len, struct ble_sm_master_id *cmd) { uint8_t *u8ptr; u8ptr = payload; cmd->ediv = le16toh(u8ptr); cmd->rand_val = le64toh(u8ptr + 2); }
static uint64_t journal_file_tag_seqnum(JournalFile *f) { uint64_t r; assert(f); r = le64toh(f->header->n_tags) + 1; f->header->n_tags = htole64(r); return r; }
static void patch_realtime( const char *dir, const char *fn, const struct stat *st, unsigned long long *realtime) { usec_t x; #ifdef HAVE_XATTR uint64_t crtime; _cleanup_free_ const char *path = NULL; #endif /* The timestamp was determined by the file name, but let's * see if the file might actually be older than the file name * suggested... */ assert(dir); assert(fn); assert(st); assert(realtime); x = timespec_load(&st->st_ctim); if (x > 0 && x != (usec_t) -1 && x < *realtime) *realtime = x; x = timespec_load(&st->st_atim); if (x > 0 && x != (usec_t) -1 && x < *realtime) *realtime = x; x = timespec_load(&st->st_mtim); if (x > 0 && x != (usec_t) -1 && x < *realtime) *realtime = x; #ifdef HAVE_XATTR /* Let's read the original creation time, if possible. Ideally * we'd just query the creation time the FS might provide, but * unfortunately there's currently no sane API to query * it. Hence let's implement this manually... */ /* Unfortunately there is is not fgetxattrat(), so we need to * go via path here. :-( */ path = strjoin(dir, "/", fn, NULL); if (!path) return; if (getxattr(path, "user.crtime_usec", &crtime, sizeof(crtime)) == sizeof(crtime)) { crtime = le64toh(crtime); if (crtime > 0 && crtime != (uint64_t) -1 && crtime < *realtime) *realtime = crtime; } #endif }
/* * pmemlog_walk -- walk through all data in a log memory pool * * chunksize of 0 means process_chunk gets called once for all data * as a single chunk. */ void pmemlog_walk(PMEMlogpool *plp, size_t chunksize, int (*process_chunk)(const void *buf, size_t len, void *arg), void *arg) { LOG(3, "plp %p chunksize %zu", plp, chunksize); /* * We are assuming that the walker doesn't change the data it's reading * in place. We prevent everyone from changing the data behind our back * until we are done with processing it. */ if ((errno = pthread_rwlock_rdlock(plp->rwlockp))) { ERR("!pthread_rwlock_rdlock"); return; } char *data = plp->addr; uint64_t write_offset = le64toh(plp->write_offset); uint64_t data_offset = le64toh(plp->start_offset); size_t len; if (chunksize == 0) { /* most common case: process everything at once */ len = write_offset - data_offset; LOG(3, "length %zu", len); (*process_chunk)(&data[data_offset], len, arg); } else { /* * Walk through the complete record, chunk by chunk. * The callback returns 0 to terminate the walk. */ while (data_offset < write_offset) { len = MIN(chunksize, write_offset - data_offset); if (!(*process_chunk)(&data[data_offset], len, arg)) break; data_offset += chunksize; } } if ((errno = pthread_rwlock_unlock(plp->rwlockp))) ERR("!pthread_rwlock_unlock"); }
static int print_iface_handler(struct nl_msg *msg, void *arg) { struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); struct nlattr *tb_msg[NL802154_ATTR_MAX + 1]; unsigned int *wpan_phy = arg; const char *indent = ""; nla_parse(tb_msg, NL802154_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); if (wpan_phy && tb_msg[NL802154_ATTR_WPAN_PHY]) { unsigned int thiswpan_phy = nla_get_u32(tb_msg[NL802154_ATTR_WPAN_PHY]); indent = "\t"; if (*wpan_phy != thiswpan_phy) printf("phy#%d\n", thiswpan_phy); *wpan_phy = thiswpan_phy; } if (tb_msg[NL802154_ATTR_IFNAME]) printf("%sInterface %s\n", indent, nla_get_string(tb_msg[NL802154_ATTR_IFNAME])); else printf("%sUnnamed/non-netdev interface\n", indent); if (tb_msg[NL802154_ATTR_IFINDEX]) printf("%s\tifindex %d\n", indent, nla_get_u32(tb_msg[NL802154_ATTR_IFINDEX])); if (tb_msg[NL802154_ATTR_WPAN_DEV]) printf("%s\twpan_dev 0x%llx\n", indent, (unsigned long long)nla_get_u64(tb_msg[NL802154_ATTR_WPAN_DEV])); if (tb_msg[NL802154_ATTR_EXTENDED_ADDR]) printf("%s\textended_addr 0x%016" PRIx64 "\n", indent, le64toh(nla_get_u64(tb_msg[NL802154_ATTR_EXTENDED_ADDR]))); if (tb_msg[NL802154_ATTR_SHORT_ADDR]) printf("%s\tshort_addr 0x%04x\n", indent, le16toh(nla_get_u16(tb_msg[NL802154_ATTR_SHORT_ADDR]))); if (tb_msg[NL802154_ATTR_PAN_ID]) printf("%s\tpan_id 0x%04x\n", indent, le16toh(nla_get_u16(tb_msg[NL802154_ATTR_PAN_ID]))); if (tb_msg[NL802154_ATTR_IFTYPE]) printf("%s\ttype %s\n", indent, iftype_name(nla_get_u32(tb_msg[NL802154_ATTR_IFTYPE]))); if (tb_msg[NL802154_ATTR_MAX_FRAME_RETRIES]) printf("%s\tmax_frame_retries %d\n", indent, nla_get_s8(tb_msg[NL802154_ATTR_MAX_FRAME_RETRIES])); if (tb_msg[NL802154_ATTR_MIN_BE]) printf("%s\tmin_be %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_MIN_BE])); if (tb_msg[NL802154_ATTR_MAX_BE]) printf("%s\tmax_be %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_MAX_BE])); if (tb_msg[NL802154_ATTR_MAX_CSMA_BACKOFFS]) printf("%s\tmax_csma_backoffs %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_MAX_CSMA_BACKOFFS])); if (tb_msg[NL802154_ATTR_LBT_MODE]) printf("%s\tlbt %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_LBT_MODE])); if (tb_msg[NL802154_ATTR_ACKREQ_DEFAULT]) printf("%s\tackreq_default %d\n", indent, nla_get_u8(tb_msg[NL802154_ATTR_ACKREQ_DEFAULT])); return NL_SKIP; }
/* * pmemlog_tell -- return current write point in a log memory pool */ long long pmemlog_tell(PMEMlogpool *plp) { LOG(3, "plp %p", plp); if ((errno = pthread_rwlock_rdlock(plp->rwlockp))) { ERR("!pthread_rwlock_rdlock"); return (off_t)-1; } ASSERT(le64toh(plp->write_offset) >= le64toh(plp->start_offset)); long long wp = (long long)(le64toh(plp->write_offset) - le64toh(plp->start_offset)); LOG(4, "write offset %lld", wp); util_rwlock_unlock(plp->rwlockp); return wp; }
int md_get_int64le(struct mdchain *mdp, int64_t *x) { int64_t v; int error; error = md_get_int64(mdp, &v); if (x != NULL) *x = le64toh(v); return (error); }
static const struct trie_node_f *node_lookup_f(sd_hwdb *hwdb, const struct trie_node_f *node, uint8_t c) { struct trie_child_entry_f *child; struct trie_child_entry_f search; search.c = c; child = bsearch(&search, trie_node_children(hwdb, node), node->children_count, le64toh(hwdb->head->child_entry_size), trie_children_cmp_f); if (child) return trie_node_from_off(hwdb, child->child_off); return NULL; }
/* * out_get_checksum -- return checksum string with result */ const char * out_get_checksum(void *addr, size_t len, uint64_t *csump) { static char str_buff[STR_MAX] = {0, }; int ret = 0; /* * The memory range can be mapped with PROT_READ, so allocate a new * buffer for the checksum and calculate there. */ void *buf = Malloc(len); if (buf == NULL) { ret = snprintf(str_buff, STR_MAX, "failed"); if (ret < 0 || ret >= STR_MAX) return ""; return str_buff; } memcpy(buf, addr, len); uint64_t *ncsump = (uint64_t *) ((char *)buf + ((char *)csump - (char *)addr)); uint64_t csum = *csump; /* validate checksum and get correct one */ int valid = util_validate_checksum(buf, len, ncsump); if (valid) ret = snprintf(str_buff, STR_MAX, "0x%" PRIx64" [OK]", le64toh(csum)); else ret = snprintf(str_buff, STR_MAX, "0x%" PRIx64 " [wrong! should be: 0x%" PRIx64 "]", le64toh(csum), le64toh(*ncsump)); Free(buf); if (ret < 0 || ret >= STR_MAX) return ""; return str_buff; }
int bdgaddif2(char *s, u_int bdg_idx, u_int dst) { struct nm_route_ent *ht = rt[bdg_idx].ht; uint32_t sh = nm_bridge_rthash(s); uint64_t smac; smac = le64toh(*(uint64_t *)(s)) & 0xffffffffffff; ht[sh].mac = (uint64_t) smac; ht[sh].ports = dst; pr_warn("src %02x:%02x:%02x:%02x:%02x:%02x -> %d [addr %ld sh %d]\n", s[0], s[1], s[2], s[3], s[4], s[5], dst, ht[sh].mac, sh); return 0; }
/* * Intercept management frames to collect beacon rssi data * and to do ibss merges. */ void ath_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m, int subtype, int rssi, int nf) { struct ieee80211vap *vap = ni->ni_vap; struct ath_softc *sc = vap->iv_ic->ic_ifp->if_softc; /* * Call up first so subsequent work can use information * potentially stored in the node (e.g. for ibss merge). */ ATH_VAP(vap)->av_recv_mgmt(ni, m, subtype, rssi, nf); switch (subtype) { case IEEE80211_FC0_SUBTYPE_BEACON: /* update rssi statistics for use by the hal */ /* XXX unlocked check against vap->iv_bss? */ ATH_RSSI_LPF(sc->sc_halstats.ns_avgbrssi, rssi); if (sc->sc_syncbeacon && ni == vap->iv_bss && vap->iv_state == IEEE80211_S_RUN) { /* * Resync beacon timers using the tsf of the beacon * frame we just received. */ ath_beacon_config(sc, vap); } /* fall thru... */ case IEEE80211_FC0_SUBTYPE_PROBE_RESP: if (vap->iv_opmode == IEEE80211_M_IBSS && vap->iv_state == IEEE80211_S_RUN) { uint32_t rstamp = sc->sc_lastrs->rs_tstamp; uint64_t tsf = ath_extend_tsf(sc, rstamp, ath_hal_gettsf64(sc->sc_ah)); /* * Handle ibss merge as needed; check the tsf on the * frame before attempting the merge. The 802.11 spec * says the station should change it's bssid to match * the oldest station with the same ssid, where oldest * is determined by the tsf. Note that hardware * reconfiguration happens through callback to * ath_newstate as the state machine will go from * RUN -> RUN when this happens. */ if (le64toh(ni->ni_tstamp.tsf) >= tsf) { DPRINTF(sc, ATH_DEBUG_STATE, "ibss merge, rstamp %u tsf %ju " "tstamp %ju\n", rstamp, (uintmax_t)tsf, (uintmax_t)ni->ni_tstamp.tsf); (void) ieee80211_ibss_merge(ni); } } break; } }
/** Constructor receives a packet from the MySQL master or the binary log and decodes it to create an Intvar_event. Written every time a statement uses an AUTO_INCREMENT column or the LAST_INSERT_ID() function; precedes other events for the statement. This is written only before a QUERY_EVENT and is not used with row-based logging. An INTVAR_EVENT is written with a "subtype" in the event data part: * INSERT_ID_EVENT indicates the value to use for an AUTO_INCREMENT column in the next statement. * LAST_INSERT_ID_EVENT indicates the value to use for the LAST_INSERT_ID() function in the next statement. */ Intvar_event::Intvar_event(const char* buf, const Format_description_event* description_event) : Binary_log_event(&buf, description_event->binlog_version, description_event->server_version) { //buf is advanced in Binary_log_event constructor to point to //beginning of post-header /* The Post-Header is empty. The Varible Data part begins immediately. */ buf+= description_event->post_header_len[INTVAR_EVENT - 1]; type= buf[I_TYPE_OFFSET]; memcpy(&val, buf + I_VAL_OFFSET, 8); val= le64toh(val); }
/* Windows Registry HKLM\SYSTEM\MountedDevices uses a blob of data * to store partitions. This blob is described here: * http://www.goodells.net/multiboot/partsigs.shtml * The following function maps this blob to a libguestfs partition * name, if possible. */ static char * map_registry_disk_blob (guestfs_h *g, const void *blob) { CLEANUP_FREE_STRING_LIST char **devices = NULL; CLEANUP_FREE_PARTITION_LIST struct guestfs_partition_list *partitions = NULL; size_t i, j, len; uint64_t part_offset; /* First 4 bytes are the disk ID. Search all devices to find the * disk with this disk ID. */ devices = guestfs_list_devices (g); if (devices == NULL) return NULL; for (i = 0; devices[i] != NULL; ++i) { /* Read the disk ID. */ CLEANUP_FREE char *diskid = guestfs_pread_device (g, devices[i], 4, 0x01b8, &len); if (diskid == NULL) continue; if (len < 4) continue; if (memcmp (diskid, blob, 4) == 0) /* found it */ goto found_disk; } return NULL; found_disk: /* Next 8 bytes are the offset of the partition in bytes(!) given as * a 64 bit little endian number. Luckily it's easy to get the * partition byte offset from guestfs_part_list. */ memcpy (&part_offset, (char *) blob + 4, sizeof (part_offset)); part_offset = le64toh (part_offset); partitions = guestfs_part_list (g, devices[i]); if (partitions == NULL) return NULL; for (j = 0; j < partitions->len; ++j) { if (partitions->val[j].part_start == part_offset) /* found it */ goto found_partition; } return NULL; found_partition: /* Construct the full device name. */ return safe_asprintf (g, "%s%d", devices[i], partitions->val[j].part_num); }
uint32_t ProtoDeserializerVisitor::decodeVarInt(istream &in, uint64_t &value) { value = 0; uint8_t size = 0; while (in.good()) { char c = in.get(); value |= static_cast<unsigned int>( (c & 0x7f) << (0x7 * size++) ); if ( !(c & 0x80) ) break; } // Protobuf's VarInt is based on little endian. value = le64toh(value); return size; }
int journal_file_append_first_tag(JournalFile *f) { int r; uint64_t p; if (!f->seal) return 0; log_debug("Calculating first tag..."); r = journal_file_hmac_put_header(f); if (r < 0) return r; p = le64toh(f->header->field_hash_table_offset); if (p < offsetof(Object, hash_table.items)) return -EINVAL; p -= offsetof(Object, hash_table.items); r = journal_file_hmac_put_object(f, OBJECT_FIELD_HASH_TABLE, NULL, p); if (r < 0) return r; p = le64toh(f->header->data_hash_table_offset); if (p < offsetof(Object, hash_table.items)) return -EINVAL; p -= offsetof(Object, hash_table.items); r = journal_file_hmac_put_object(f, OBJECT_DATA_HASH_TABLE, NULL, p); if (r < 0) return r; r = journal_file_append_tag(f); if (r < 0) return r; return 0; }
static uint64_t isf_read_reg64(struct isf_softc *sc, uint16_t reg) { uint64_t val; uint16_t *val16 = (uint16_t *)&val; if (isf_debug) device_printf(sc->isf_dev, "isf_read_reg64(0x%02x)\n", reg); val16[0] = bus_read_2(sc->isf_res, reg * 2); val16[1] = bus_read_2(sc->isf_res, (reg+1) * 2); val16[2] = bus_read_2(sc->isf_res, (reg+2) * 2); val16[3] = bus_read_2(sc->isf_res, (reg+3) * 2); return(le64toh(val)); }
/** * mpr_config_get_volume_wwid - returns wwid given the volume handle * @sc: per adapter object * @volume_handle: volume handle * @wwid: volume wwid * Context: sleep. * * Returns 0 for success, non-zero for failure. */ int mpr_config_get_volume_wwid(struct mpr_softc *sc, u16 volume_handle, u64 *wwid) { Mpi2ConfigReply_t mpi_reply; Mpi2RaidVolPage1_t raid_vol_pg1; *wwid = 0; if (!(mpr_config_get_raid_volume_pg1(sc, &mpi_reply, &raid_vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, volume_handle))) { *wwid = le64toh((u64)raid_vol_pg1.WWID.High << 32 | raid_vol_pg1.WWID.Low); return 0; } else return -1; }
static int data_object_in_hash_table(JournalFile *f, uint64_t hash, uint64_t p) { uint64_t n, h, q; int r; assert(f); n = le64toh(f->header->data_hash_table_size) / sizeof(HashItem); h = hash % n; q = le64toh(f->data_hash_table[h].head_hash_offset); while (q != 0) { Object *o; if (p == q) return 1; r = journal_file_move_to_object(f, OBJECT_DATA, q, &o); if (r < 0) return r; q = le64toh(o->data.next_hash_offset); } return 0; }
//Read len bits and save on datum int bitio_read(bitio* f, uint64_t* datum, int len) { int offset, readable, noffset; uint64_t* pointer; uint64_t tmp, tmp2; int res; //check all the parameters if((f == NULL) || (len < 1) || (len > sizeof(datum)*8)) { errno = EINVAL; fprintf(stderr, "Error1 %i\n", len); if(f == NULL) fprintf(stderr, "NULL\n"); return -1; } //check if we do the right operation if(f->writing) { errno = EINVAL; fprintf(stderr, "Error2\n"); return -1; } readable = (f->end - f->next); if(readable < 0) { //check if there are bits to read errno = EINVAL; fprintf(stderr, "Error4\n"); return -1; } if(readable < len) { //Check if refill the structure res=read(f->fd, f->buf, (MAX_SIZE * 8)); if(res<0) fprintf(stderr, "ERROR\n"); f->next = 0; f->end = f->size; readable = MAX_SIZE * 64; } pointer = f->buf + (f->next / 64); offset = f->next % 64; noffset = 64 - offset; if(len <= noffset) { //Reading on only one element of buf tmp = le64toh(*pointer); tmp >>= offset; tmp &= (((uint64_t)1 << (len)) - 1); f->next += len; }else { //Reading ALSO on the next element of buf