@@ -99,8 +99,10 @@ def __init__(self, *args, **kwargs) -> None:
99
99
class LinuxUtilities (interfaces .configuration .VersionableInterface ):
100
100
"""Class with multiple useful linux functions."""
101
101
102
- _version = (2 , 3 , 1 )
102
+ _version = (2 , 4 , 0 )
103
103
_required_framework_version = (2 , 0 , 0 )
104
+ deleted = "(deleted)"
105
+ smear = "<potentially smeared>"
104
106
105
107
framework .require_interface_version (* _required_framework_version )
106
108
@@ -168,6 +170,7 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
168
170
# vfsmnt can be the vfsmount object itself (>=3.3) or a vfsmount * (<3.3)
169
171
return ""
170
172
173
+ inode = dentry .d_inode
171
174
path_reversed = []
172
175
smeared = False
173
176
while (
@@ -191,6 +194,7 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
191
194
192
195
parent = dentry .d_parent
193
196
dname = dentry .d_name .name_as_str ()
197
+
194
198
# empty dentry names are most likely
195
199
# the result of smearing
196
200
if not dname :
@@ -203,7 +207,10 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
203
207
# if there is smear the missing dname will be empty. e.g. if the normal
204
208
# path would be /foo/bar/baz, but bar is missing due to smear the results
205
209
# returned here will show /foo//baz. Note the // for the missing dname.
206
- return f"<potentially smeared> { path } "
210
+ return f"{ LinuxUtilities .smear } { path } "
211
+
212
+ if inode and inode .is_readable () and inode .is_valid () and inode .i_nlink == 0 :
213
+ path = f" { path } { LinuxUtilities .deleted } "
207
214
return path
208
215
209
216
@classmethod
@@ -301,7 +308,7 @@ def _get_new_sock_pipe_path(cls, context, task, filp) -> str:
301
308
return f"{ pre_name } :[{ inode .i_ino :d} ]"
302
309
303
310
@classmethod
304
- def path_for_file (cls , context , task , filp ) -> str :
311
+ def path_for_file (cls , context , task , filp , files_only = False ) -> str :
305
312
"""Returns a file (or sock pipe) pathname relative to the task's root directory.
306
313
307
314
A 'file' structure doesn't have enough information to properly restore its
@@ -340,7 +347,7 @@ def path_for_file(cls, context, task, filp) -> str:
340
347
except exceptions .InvalidAddressException :
341
348
dname_is_valid = False
342
349
343
- if dname_is_valid :
350
+ if dname_is_valid and not files_only :
344
351
ret = LinuxUtilities ._get_new_sock_pipe_path (context , task , filp )
345
352
else :
346
353
ret = LinuxUtilities ._get_path_file (task , filp )
@@ -353,6 +360,7 @@ def files_descriptors_for_process(
353
360
context : interfaces .context .ContextInterface ,
354
361
symbol_table : str ,
355
362
task : interfaces .objects .ObjectInterface ,
363
+ files_only : bool = False ,
356
364
):
357
365
try :
358
366
files = task .files
@@ -376,7 +384,9 @@ def files_descriptors_for_process(
376
384
377
385
for fd_num , filp in enumerate (fds ):
378
386
if filp and filp .is_readable ():
379
- full_path = LinuxUtilities .path_for_file (context , task , filp )
387
+ full_path = LinuxUtilities .path_for_file (
388
+ context , task , filp , files_only
389
+ )
380
390
381
391
yield fd_num , filp , full_path
382
392
0 commit comments