From 52d98a1157ba99392ee059addc8ce6997923c4de Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 19 Sep 2022 20:32:26 -0700 Subject: [PATCH] doc update and schema update --- docs/parsers/proc_pid_mountinfo.md | 137 +++++++++++++++++---------- jc/parsers/proc_pid_mountinfo.py | 144 ++++++++++++++++++----------- 2 files changed, 177 insertions(+), 104 deletions(-) diff --git a/docs/parsers/proc_pid_mountinfo.md b/docs/parsers/proc_pid_mountinfo.md index 58ecc4d3..33463209 100644 --- a/docs/parsers/proc_pid_mountinfo.md +++ b/docs/parsers/proc_pid_mountinfo.md @@ -31,46 +31,81 @@ Schema: [ { - "module": string, - "size": integer, - "used": integer, - "used_by": [ + "mount_id": integer, + "parent_id": integer, + "maj": integer, + "min": integer, + "root": string, + "mount_point": string, + "mount_options": [ string ], - "status": string, - "location": string + "optional_fields": { # [0] + "": integer + }, + "fs_type": string, + "mount_source": string, + "super_options": [ + string + ], + "super_options_fields": { + "": string + } } ] + [0] if empty, then unbindable + Examples: $ cat /proc/1/mountinfo | jc --proc -p [ { - "module": "binfmt_misc", - "size": 24576, - "used": 1, - "used_by": [], - "status": "Live", - "location": "0xffffffffc0ab4000" - }, - { - "module": "vsock_loopback", - "size": 16384, - "used": 0, - "used_by": [], - "status": "Live", - "location": "0xffffffffc0a14000" - }, - { - "module": "vmw_vsock_virtio_transport_common", - "size": 36864, - "used": 1, - "used_by": [ - "vsock_loopback" + "mount_id": 24, + "parent_id": 30, + "maj": 0, + "min": 22, + "root": "/", + "mount_point": "/sys", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" ], - "status": "Live", - "location": "0xffffffffc0a03000" + "optional_fields": { + "master": 1, + "shared": 7 + }, + "fs_type": "sysfs", + "mount_source": "sysfs", + "super_options": [ + "rw" + ] + }, + { + "mount_id": 25, + "parent_id": 30, + "maj": 0, + "min": 23, + "root": "/", + "mount_point": "/proc", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ], + "optional_fields": { + "shared": 14 + }, + "fs_type": "proc", + "mount_source": "proc", + "super_options": [ + "rw" + ] }, ... ] @@ -78,30 +113,30 @@ Examples: $ cat /proc/1/mountinfo | jc --proc_pid-mountinfo -p -r [ { - "module": "binfmt_misc", - "size": "24576", - "used": "1", - "used_by": [], - "status": "Live", - "location": "0xffffffffc0ab4000" + "mount_id": "24", + "parent_id": "30", + "maj": "0", + "min": "22", + "root": "/", + "mount_point": "/sys", + "mount_options": "rw,nosuid,nodev,noexec,relatime", + "optional_fields": "master:1 shared:7 ", + "fs_type": "sysfs", + "mount_source": "sysfs", + "super_options": "rw" }, { - "module": "vsock_loopback", - "size": "16384", - "used": "0", - "used_by": [], - "status": "Live", - "location": "0xffffffffc0a14000" - }, - { - "module": "vmw_vsock_virtio_transport_common", - "size": "36864", - "used": "1", - "used_by": [ - "vsock_loopback" - ], - "status": "Live", - "location": "0xffffffffc0a03000" + "mount_id": "25", + "parent_id": "30", + "maj": "0", + "min": "23", + "root": "/", + "mount_point": "/proc", + "mount_options": "rw,nosuid,nodev,noexec,relatime", + "optional_fields": "shared:14 ", + "fs_type": "proc", + "mount_source": "proc", + "super_options": "rw" }, ... ] diff --git a/jc/parsers/proc_pid_mountinfo.py b/jc/parsers/proc_pid_mountinfo.py index 0e11ee94..55329b7a 100644 --- a/jc/parsers/proc_pid_mountinfo.py +++ b/jc/parsers/proc_pid_mountinfo.py @@ -26,46 +26,81 @@ Schema: [ { - "module": string, - "size": integer, - "used": integer, - "used_by": [ + "mount_id": integer, + "parent_id": integer, + "maj": integer, + "min": integer, + "root": string, + "mount_point": string, + "mount_options": [ string ], - "status": string, - "location": string + "optional_fields": { # [0] + "": integer + }, + "fs_type": string, + "mount_source": string, + "super_options": [ + string + ], + "super_options_fields": { + "": string + } } ] + [0] if empty, then unbindable + Examples: $ cat /proc/1/mountinfo | jc --proc -p [ { - "module": "binfmt_misc", - "size": 24576, - "used": 1, - "used_by": [], - "status": "Live", - "location": "0xffffffffc0ab4000" - }, - { - "module": "vsock_loopback", - "size": 16384, - "used": 0, - "used_by": [], - "status": "Live", - "location": "0xffffffffc0a14000" - }, - { - "module": "vmw_vsock_virtio_transport_common", - "size": 36864, - "used": 1, - "used_by": [ - "vsock_loopback" + "mount_id": 24, + "parent_id": 30, + "maj": 0, + "min": 22, + "root": "/", + "mount_point": "/sys", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" ], - "status": "Live", - "location": "0xffffffffc0a03000" + "optional_fields": { + "master": 1, + "shared": 7 + }, + "fs_type": "sysfs", + "mount_source": "sysfs", + "super_options": [ + "rw" + ] + }, + { + "mount_id": 25, + "parent_id": 30, + "maj": 0, + "min": 23, + "root": "/", + "mount_point": "/proc", + "mount_options": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ], + "optional_fields": { + "shared": 14 + }, + "fs_type": "proc", + "mount_source": "proc", + "super_options": [ + "rw" + ] }, ... ] @@ -73,30 +108,30 @@ Examples: $ cat /proc/1/mountinfo | jc --proc_pid-mountinfo -p -r [ { - "module": "binfmt_misc", - "size": "24576", - "used": "1", - "used_by": [], - "status": "Live", - "location": "0xffffffffc0ab4000" + "mount_id": "24", + "parent_id": "30", + "maj": "0", + "min": "22", + "root": "/", + "mount_point": "/sys", + "mount_options": "rw,nosuid,nodev,noexec,relatime", + "optional_fields": "master:1 shared:7 ", + "fs_type": "sysfs", + "mount_source": "sysfs", + "super_options": "rw" }, { - "module": "vsock_loopback", - "size": "16384", - "used": "0", - "used_by": [], - "status": "Live", - "location": "0xffffffffc0a14000" - }, - { - "module": "vmw_vsock_virtio_transport_common", - "size": "36864", - "used": "1", - "used_by": [ - "vsock_loopback" - ], - "status": "Live", - "location": "0xffffffffc0a03000" + "mount_id": "25", + "parent_id": "30", + "maj": "0", + "min": "23", + "root": "/", + "mount_point": "/proc", + "mount_options": "rw,nosuid,nodev,noexec,relatime", + "optional_fields": "shared:14 ", + "fs_type": "proc", + "mount_source": "proc", + "super_options": "rw" }, ... ] @@ -131,7 +166,7 @@ def _process(proc_data: List[Dict]) -> List[Dict]: List of Dictionaries. Structured to conform to the schema. """ - int_list = {'size', 'used'} + int_list = {'mount_id', 'parent_id', 'maj', 'min'} for entry in proc_data: for key in entry: @@ -142,7 +177,7 @@ def _process(proc_data: List[Dict]) -> List[Dict]: entry['mount_options'] = entry['mount_options'].split(',') if 'optional_fields' in entry: - entry['optional_fields'] = {x.split(':')[0]: x.split(':')[1] for x in entry['optional_fields'].split()} + entry['optional_fields'] = {x.split(':')[0]: int(x.split(':')[1]) for x in entry['optional_fields'].split()} if 'super_options' in entry: if entry['super_options']: @@ -163,6 +198,9 @@ def _process(proc_data: List[Dict]) -> List[Dict]: key, val = field.split('=') entry['super_options_fields'][key] = val + else: + del entry['super_options'] + return proc_data