Skip to content

Commit 6f34c0f

Browse files
committed
crash.subsystem.filesystems: add is_fstype_super and is_fstype_inode
These two helpers will take a generic superblock or inode and determine whether it belongs to the given file system. It's a naive implementation that uses a string comparison. This is intentional so the comparison can be made without symbol resolution that may require module loading. Signed-off-by: Jeff Mahoney <jeffm@suse.com>
1 parent 096a337 commit 6f34c0f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎crash/subsystem/filesystem/__init__.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,35 @@ def get_super_block(desc: AddressSpecifier, force: bool=False) -> gdb.Value:
142142
raise gdb.NotAvailableError(f"no superblock available at `{desc}'")
143143

144144
return sb
145+
146+
def is_fstype_super(super_block: gdb.Value, name: str) -> bool:
147+
"""
148+
Tests whether the super_block belongs to a particular file system type.
149+
150+
This uses a naive string comparison so modules are not required.
151+
152+
Args:
153+
super_block (gdb.Value<struct super_block>):
154+
The struct super_block to test
155+
name (str): The name of the file system type
156+
157+
Returns:
158+
bool: whether the super_block belongs to the specified file system
159+
"""
160+
return super_fstype(super_block) == name
161+
162+
def is_fstype_inode(inode: gdb.Value, name: str) -> bool:
163+
"""
164+
Tests whether the inode belongs to a particular file system type.
165+
166+
Args:
167+
inode (gdb.Value<struct inode>): The struct inode to test
168+
name (str): The name of the file system type
169+
170+
Returns:
171+
bool: whether the inode belongs to the specified file system
172+
173+
Raises:
174+
gdb.NotAvailableError: The target value was not available.
175+
"""
176+
return is_fstype_super(inode['i_sb'], name)

0 commit comments

Comments
 (0)