#define obj_add_array json_object_add_value_array
#define obj_add_int json_object_add_value_int
#define obj_add_obj json_object_add_value_object
-#define obj_add_str json_object_add_value_string
#define obj_add_uint json_object_add_value_uint
#define obj_add_uint128 json_object_add_value_uint128
#define obj_add_uint64 json_object_add_value_uint64
obj_add_str(o, k, str);
}
-static void obj_add_uint_0x(struct json_object *o, const char *k, __u32 v)
+void obj_add_uint_0x(struct json_object *o, const char *k, __u32 v)
{
char str[STR_LEN];
obj_add_str(o, k, str);
}
-static void obj_add_uint_0nx(struct json_object *o, const char *k, __u32 v, int width)
+void obj_add_uint_0nx(struct json_object *o, const char *k, __u32 v, int width)
{
char str[STR_LEN];
- sprintf(str, "0x%02x", v);
+ sprintf(str, "0x%0*x", width, v);
obj_add_str(o, k, str);
}
-static void obj_add_uint_02x(struct json_object *o, const char *k, __u32 v)
+void obj_add_uint_02x(struct json_object *o, const char *k, __u32 v)
{
obj_add_uint_0nx(o, k, v, 2);
}
obj_add_str(o, k, str);
}
-static void obj_add_nprix64(struct json_object *o, const char *k, uint64_t v)
+void obj_add_nprix64(struct json_object *o, const char *k, uint64_t v)
{
char str[STR_LEN];
va_end(ap);
}
-static struct json_object *obj_create_array_obj(struct json_object *o, const char *k)
+struct json_object *obj_create_array_obj(struct json_object *o, const char *k)
{
struct json_object *array = json_create_array();
struct json_object *obj = json_create_object();
return obj;
}
-static void json_print(struct json_object *r)
+void json_print(struct json_object *r)
{
json_print_object(r, NULL);
printf("\n");
json_print_ops.flags = flags;
return &json_print_ops;
}
+
+void obj_add_byte_array(struct json_object *o, const char *k, unsigned char *buf, int len)
+{
+ int i;
+
+ _cleanup_free_ char *value = NULL;
+
+ if (!buf || !len) {
+ obj_add_str(o, k, "No information provided");
+ return;
+ }
+
+ value = calloc(1, (len + 1) * 2 + 1);
+
+ if (!value) {
+ obj_add_str(o, k, "Could not allocate string");
+ return;
+ }
+
+ sprintf(value, "0x");
+ for (i = 1; i <= len; i++)
+ sprintf(&value[i * 2], "%02x", buf[len - i]);
+
+ obj_add_str(o, k, value);
+}
+
+void obj_add_0nprix64(struct json_object *o, const char *k, uint64_t v, int width)
+{
+ char str[STR_LEN];
+
+ sprintf(str, "0x%0*"PRIx64"", width, v);
+ obj_add_str(o, k, str);
+}
#define STR_LEN 100
+#define obj_add_str json_object_add_value_string
+
void d(unsigned char *buf, int len, int width, int group);
void d_raw(unsigned char *buf, unsigned len);
bool nvme_registers_pmrctl_ready(__u32 pmrctl);
const char *nvme_degrees_string(long t);
void print_array(char *name, __u8 *data, int size);
+void obj_add_uint_02x(struct json_object *o, const char *k, __u32 v);
+void json_print(struct json_object *r);
+void obj_add_uint_0x(struct json_object *o, const char *k, __u32 v);
+void obj_add_byte_array(struct json_object *o, const char *k, unsigned char *buf, int len);
+void obj_add_nprix64(struct json_object *o, const char *k, uint64_t v);
+struct json_object *obj_create_array_obj(struct json_object *o, const char *k);
+void obj_add_uint_0nx(struct json_object *o, const char *k, __u32 v, int width);
+void obj_add_0nprix64(struct json_object *o, const char *k, uint64_t v, int width);
#endif /* NVME_PRINT_H */