json_print(root);
}
-static void d_json(unsigned char *buf, int len, int width, int group,
- struct json_object *array)
+static void d_json(unsigned char *buf, int len, int width, int group, struct json_object *array)
{
- int i, line_done = 0;
- char ascii[32 + 1];
+ int i;
+ char ascii[32 + 1] = { 0 };
+
assert(width < sizeof(ascii));
for (i = 0; i < len; i++) {
- line_done = 0;
ascii[i % width] = (buf[i] >= '!' && buf[i] <= '~') ? buf[i] : '.';
- if (((i + 1) % width) == 0) {
- ascii[i % width + 1] = '\0';
+ if (!((i + 1) % width)) {
json_array_add_value_string(array, ascii);
- line_done = 1;
+ memset(ascii, 0, sizeof(ascii));
}
}
- if (!line_done) {
+
+ if (strlen(ascii)) {
ascii[i % width + 1] = '\0';
json_array_add_value_string(array, ascii);
}
}
}
+void json_d(unsigned char *buf, int len, int width, int group)
+{
+ struct json_object *root = json_create_object();
+ struct json_object *data = json_create_array();
+
+ d_json(buf, len, width, group, data);
+ json_object_add_value_array(root, "data", data);
+
+ json_print(root);
+}
+
static void json_nvme_list_ctrl(struct nvme_ctrl_list *ctrl_list)
{
__u16 num = le16_to_cpu(ctrl_list->num);
.id_ctrl_rpmbs = NULL,
.lba_range = NULL,
.lba_status_info = NULL,
+ .d = json_d,
/* libnvme tree print functions */
.list_item = NULL,
printf("\tLBA Status Information Report Interval (LSIRI): %u\n", result & 0xffff);
}
+void stdout_d(unsigned char *buf, int len, int width, int group)
+{
+ int i, offset = 0;
+ char ascii[32 + 1] = { 0 };
+
+ assert(width < sizeof(ascii));
+
+ printf(" ");
+
+ for (i = 0; i <= 15; i++)
+ printf("%3x", i);
+
+ for (i = 0; i < len; i++) {
+ if (!(i % width))
+ printf( "\n%04x:", offset);
+ if (i % group)
+ printf( "%02x", buf[i]);
+ else
+ printf( " %02x", buf[i]);
+ ascii[i % width] = (buf[i] >= '!' && buf[i] <= '~') ? buf[i] : '.';
+ if (!((i + 1) % width)) {
+ printf( " \"%.*s\"", width, ascii);
+ offset += width;
+ memset(ascii, 0, sizeof(ascii));
+ }
+ }
+
+ if (strlen(ascii)) {
+ unsigned b = width - (i % width);
+ printf( " %*s \"%.*s\"", 2 * b + b / group + (b % group ? 1 : 0), "", width, ascii);
+ }
+
+ printf( "\n");
+}
+
static void stdout_plm_config(struct nvme_plm_config *plmcfg)
{
printf("\tEnable Event :%04x\n", le16_to_cpu(plmcfg->ee));
.id_ctrl_rpmbs = stdout_id_ctrl_rpmbs,
.lba_range = stdout_lba_range,
.lba_status_info = stdout_lba_status_info,
+ .d = stdout_d,
/* libnvme tree print functions */
.list_item = stdout_list_item,
void d(unsigned char *buf, int len, int width, int group)
{
- int i, offset = 0;
- char ascii[32 + 1] = { 0 };
-
- assert(width < sizeof(ascii));
- printf(" ");
- for (i = 0; i <= 15; i++)
- printf("%3x", i);
- for (i = 0; i < len; i++) {
- if (i % width == 0)
- printf( "\n%04x:", offset);
- if (i % group == 0)
- printf( " %02x", buf[i]);
- else
- printf( "%02x", buf[i]);
- ascii[i % width] = (buf[i] >= '!' && buf[i] <= '~') ? buf[i] : '.';
- if (((i + 1) % width) == 0) {
- printf( " \"%.*s\"", width, ascii);
- offset += width;
- memset(ascii, 0, sizeof(ascii));
- }
- }
- if (strlen(ascii)) {
- unsigned b = width - (i % width);
- printf( " %*s \"%.*s\"", 2 * b + b / group + (b % group ? 1 : 0), "", width, ascii);
- }
- printf( "\n");
+ nvme_print(d, 0, buf, len, width, group);
}
void d_raw(unsigned char *buf, unsigned len)
void (*id_ctrl_rpmbs)(__le32 ctrl_rpmbs);
void (*lba_range)(struct nvme_lba_range_type *lbrt, int nr_ranges);
void (*lba_status_info)(__u32 result);
+ void (*d)(unsigned char *buf, int len, int width, int group);
/* libnvme tree print functions */
void (*list_item)(nvme_ns_t n);