diff options
author | Arvin Schnell <aschnell@suse.com> | 2021-08-17 11:05:38 +0000 |
---|---|---|
committer | Brian C. Lane <bcl@redhat.com> | 2021-08-25 15:29:38 -0700 |
commit | 36d16c57d4ff6cf9903bfe65671c7f90879e004f (patch) | |
tree | 477d19d2c463c6011ed357758a86064d59d4c2c5 /parted/jsonwrt.h | |
parent | 72faef8673b5b1d00059608f0729e93cb21a7664 (diff) | |
download | parted-36d16c57d4ff6cf9903bfe65671c7f90879e004f.tar.gz |
parted: Add --json cmdline switch to output JSON
This outputs the disk's details as a JSON object. eg. a disk image with
a single partition from 1M to 100M:
{
"disk": {
"path": "/root/disk1.img",
"size": "2097152s",
"model": "",
"transport": "file",
"logical-sector-size": 512,
"physical-sector-size": 512,
"label": "gpt",
"max-partitions": 128,
"partitions": [
{
"number": 0,
"start": "34s",
"end": "2047s",
"size": "2014s",
"type": "free"
},{
"number": 1,
"start": "2048s",
"end": "200703s",
"size": "198656s",
"type": "primary",
"name": "root"
},{
"number": 0,
"start": "200704s",
"end": "2097118s",
"size": "1896415s",
"type": "free"
}
]
}
}
Signed-off-by: Brian C. Lane <bcl@redhat.com>
Diffstat (limited to 'parted/jsonwrt.h')
-rw-r--r-- | parted/jsonwrt.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/parted/jsonwrt.h b/parted/jsonwrt.h new file mode 100644 index 0000000..4587b60 --- /dev/null +++ b/parted/jsonwrt.h @@ -0,0 +1,46 @@ +#ifndef UTIL_LINUX_JSONWRT_H +#define UTIL_LINUX_JSONWRT_H + +enum { + UL_JSON_OBJECT, + UL_JSON_ARRAY, + UL_JSON_VALUE +}; + +struct ul_jsonwrt { + FILE *out; + int indent; + + unsigned int after_close :1; +}; + +void ul_jsonwrt_init(struct ul_jsonwrt *fmt, FILE *out, int indent); +void ul_jsonwrt_indent(struct ul_jsonwrt *fmt); +void ul_jsonwrt_open(struct ul_jsonwrt *fmt, const char *name, int type); +void ul_jsonwrt_close(struct ul_jsonwrt *fmt, int type); + +#define ul_jsonwrt_root_open(_f) ul_jsonwrt_open(_f, NULL, UL_JSON_OBJECT) +#define ul_jsonwrt_root_close(_f) ul_jsonwrt_close(_f, UL_JSON_OBJECT) + +#define ul_jsonwrt_array_open(_f, _n) ul_jsonwrt_open(_f, _n, UL_JSON_ARRAY) +#define ul_jsonwrt_array_close(_f) ul_jsonwrt_close(_f, UL_JSON_ARRAY) + +#define ul_jsonwrt_object_open(_f, _n) ul_jsonwrt_open(_f, _n, UL_JSON_OBJECT) +#define ul_jsonwrt_object_close(_f) ul_jsonwrt_close(_f, UL_JSON_OBJECT) + +#define ul_jsonwrt_value_open(_f, _n) ul_jsonwrt_open(_f, _n, UL_JSON_VALUE) +#define ul_jsonwrt_value_close(_f) ul_jsonwrt_close(_f, UL_JSON_VALUE) + + +void ul_jsonwrt_value_raw(struct ul_jsonwrt *fmt, + const char *name, const char *data); +void ul_jsonwrt_value_s(struct ul_jsonwrt *fmt, + const char *name, const char *data); +void ul_jsonwrt_value_u64(struct ul_jsonwrt *fmt, + const char *name, uint64_t data); +void ul_jsonwrt_value_boolean(struct ul_jsonwrt *fmt, + const char *name, int data); +void ul_jsonwrt_value_null(struct ul_jsonwrt *fmt, + const char *name); + +#endif /* UTIL_LINUX_JSONWRT_H */ |