drgn/contrib/fs_inodes.py
Martin Liska c710ea7713 fs_inodes: catch proper exception for None path
When inode_path returns None and it's passed to fsdecode,
I get TypeError exception:

```
  File "/usr/lib64/python3.10/os.py", line 823, in fsdecode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not NoneType
```

Thus catch both exception types.

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-26 08:43:16 -08:00

33 lines
746 B
Python
Executable File

#!/usr/bin/env drgn
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later
"""List the paths of all inodes cached in a given filesystem"""
import os
import sys
from drgn.helpers.linux.fs import for_each_mount, inode_path
from drgn.helpers.linux.list import list_for_each_entry
if len(sys.argv) == 1:
path = "/"
else:
path = sys.argv[1]
mnt = None
for mnt in for_each_mount(prog, dst=path):
pass
if mnt is None:
sys.exit(f"No filesystem mounted at {path}")
sb = mnt.mnt.mnt_sb
for inode in list_for_each_entry(
"struct inode", sb.s_inodes.address_of_(), "i_sb_list"
):
try:
print(os.fsdecode(inode_path(inode)))
except (TypeError, ValueError):
continue