|
| 1 | +# Copyright (c) 2023, Oracle and/or its affiliates. |
| 2 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ |
| 3 | +import argparse |
| 4 | +from typing import Any |
| 5 | +from typing import List |
| 6 | + |
| 7 | +import drgn.helpers.linux.fs |
| 8 | + |
| 9 | +from drgn_tools.corelens import CorelensModule |
| 10 | +from drgn_tools.table import print_table |
| 11 | + |
| 12 | + |
| 13 | +def get_mountinfo(prog: drgn.Program) -> List[List[Any]]: |
| 14 | + """ |
| 15 | + Get all the mount points from the vmcore |
| 16 | +
|
| 17 | + :param prog: drgn program |
| 18 | + :returns: List of mount points |
| 19 | + """ |
| 20 | + |
| 21 | + mount_table = list() |
| 22 | + |
| 23 | + mounts = prog["init_task"].nsproxy.mnt_ns |
| 24 | + for mnt in drgn.helpers.linux.fs.for_each_mount(mounts): |
| 25 | + devname = mnt.mnt_devname |
| 26 | + fstype = mnt.mnt.mnt_sb.s_type.name |
| 27 | + mntpt = drgn.helpers.linux.fs.d_path( |
| 28 | + mnt.mnt.address_of_(), mnt.mnt_mountpoint |
| 29 | + ) |
| 30 | + |
| 31 | + mount_stats = [ |
| 32 | + devname.string_().decode("utf-8"), |
| 33 | + fstype.string_().decode("utf-8"), |
| 34 | + mntpt.decode("utf-8"), |
| 35 | + ] |
| 36 | + mount_table.append(mount_stats) |
| 37 | + return mount_table |
| 38 | + |
| 39 | + |
| 40 | +def mountinfo(prog: drgn.Program) -> None: |
| 41 | + """ |
| 42 | + Print all the mount points from the vmcore |
| 43 | +
|
| 44 | + :param prog: drgn program |
| 45 | + :returns: None |
| 46 | + """ |
| 47 | + mnt_tbl = get_mountinfo(prog) |
| 48 | + mnt_tbl.insert(0, ["-------", "------", "-------"]) |
| 49 | + mnt_tbl.insert(0, ["DEVNAME", "TYPE", "DIRNAME"]) |
| 50 | + print_table(mnt_tbl) |
| 51 | + |
| 52 | + |
| 53 | +class Mounts(CorelensModule): |
| 54 | + """Print info about all mount points""" |
| 55 | + |
| 56 | + name = "mounts" |
| 57 | + |
| 58 | + def run(self, prog: drgn.Program, args: argparse.Namespace) -> None: |
| 59 | + mountinfo(prog) |
0 commit comments