1320423Simp/*- 2320423Simp * Copyright (c) 2017 Netflix, Inc 3320423Simp * All rights reserved. 4320423Simp * 5320423Simp * Redistribution and use in source and binary forms, with or without 6320423Simp * modification, are permitted provided that the following conditions 7320423Simp * are met: 8320423Simp * 1. Redistributions of source code must retain the above copyright 9320423Simp * notice, this list of conditions and the following disclaimer. 10320423Simp * 2. Redistributions in binary form must reproduce the above copyright 11320423Simp * notice, this list of conditions and the following disclaimer in the 12320423Simp * documentation and/or other materials provided with the distribution. 13320423Simp * 14320423Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15320423Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16320423Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17320423Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18320423Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19320423Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20320423Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21320423Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22320423Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23320423Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24320423Simp * SUCH DAMAGE. 25320423Simp */ 26320423Simp 27320423Simp#include <sys/cdefs.h> 28320423Simp__FBSDID("$FreeBSD: stable/11/sbin/nvmecontrol/util.c 328728 2018-02-01 19:46:41Z mav $"); 29320423Simp 30320423Simp#include <sys/endian.h> 31320423Simp#include "nvmecontrol.h" 32320423Simp 33320423Simpchar * 34320423Simpuint128_to_str(uint128_t u, char *buf, size_t buflen) 35320423Simp{ 36320423Simp char *end = buf + buflen - 1; 37320423Simp 38320423Simp *end-- = '\0'; 39320423Simp if (u == 0) 40320423Simp *end-- = '0'; 41320423Simp while (u && end >= buf) { 42320423Simp *end-- = u % 10 + '0'; 43320423Simp u /= 10; 44320423Simp } 45320423Simp end++; 46320423Simp if (u != 0) 47320423Simp return NULL; 48320423Simp 49320423Simp return end; 50320423Simp} 51320423Simp 52320423Simp/* "Missing" from endian.h */ 53320423Simpuint64_t 54320423Simple48dec(const void *pp) 55320423Simp{ 56320423Simp uint8_t const *p = (uint8_t const *)pp; 57320423Simp 58320423Simp return (((uint64_t)le16dec(p + 4) << 32) | le32dec(p)); 59320423Simp} 60