vfs.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #
  2. # gdb helper commands and functions for Linux kernel debugging
  3. #
  4. # VFS tools
  5. #
  6. # Copyright (c) 2023 Glenn Washburn
  7. # Copyright (c) 2016 Linaro Ltd
  8. #
  9. # Authors:
  10. # Glenn Washburn <development@efficientek.com>
  11. # Kieran Bingham <kieran.bingham@linaro.org>
  12. #
  13. # This work is licensed under the terms of the GNU GPL version 2.
  14. #
  15. import gdb
  16. from linux import utils
  17. def dentry_name(d):
  18. parent = d['d_parent']
  19. if parent == d or parent == 0:
  20. return ""
  21. p = dentry_name(d['d_parent']) + "/"
  22. return p + d['d_name']['name'].string()
  23. class DentryName(gdb.Function):
  24. """Return string of the full path of a dentry.
  25. $lx_dentry_name(PTR): Given PTR to a dentry struct, return a string
  26. of the full path of the dentry."""
  27. def __init__(self):
  28. super(DentryName, self).__init__("lx_dentry_name")
  29. def invoke(self, dentry_ptr):
  30. return dentry_name(dentry_ptr)
  31. DentryName()
  32. dentry_type = utils.CachedType("struct dentry")
  33. class InodeDentry(gdb.Function):
  34. """Return dentry pointer for inode.
  35. $lx_i_dentry(PTR): Given PTR to an inode struct, return a pointer to
  36. the associated dentry struct, if there is one."""
  37. def __init__(self):
  38. super(InodeDentry, self).__init__("lx_i_dentry")
  39. def invoke(self, inode_ptr):
  40. d_u = inode_ptr["i_dentry"]["first"]
  41. if d_u == 0:
  42. return ""
  43. return utils.container_of(d_u, dentry_type.get_type().pointer(), "d_u")
  44. InodeDentry()