示例#1
0
 def test_inode_paths(self):
     with tempfile.TemporaryDirectory(prefix="drgn-tests-") as dir:
         path1 = os.fsencode(os.path.abspath(os.path.join(dir, "a")))
         path2 = os.fsencode(os.path.abspath(os.path.join(dir, "b")))
         with open(path1, "w") as f:
             os.link(path1, path2)
             with open(path2, "r") as f:
                 inode = path_lookup(self.prog, path1).dentry.d_inode
                 paths = list(inode_paths(inode))
                 self.assertEqual(len(paths), 2)
                 self.assertTrue(
                     (path1.endswith(paths[0]) and path2.endswith(paths[1]))
                     or (path1.endswith(paths[1]) and path2.endswith(paths[0]))
                 )
                 self.assertIn(inode_path(inode), paths)
示例#2
0
# Copyright (c) Facebook, Inc. and its affiliates.
# SPDX-License-Identifier: GPL-3.0+
"""List the paths of all inodes cached in a given filesystem"""

from drgn.helpers.linux.fs import for_each_mount, inode_path
from drgn.helpers.linux.list import list_for_each_entry
import os
import sys
import time

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 ValueError:
        continue