@@ -99,8 +99,10 @@ def __init__(self, *args, **kwargs) -> None:
9999class LinuxUtilities (interfaces .configuration .VersionableInterface ):
100100 """Class with multiple useful linux functions."""
101101
102- _version = (2 , 3 , 1 )
102+ _version = (2 , 4 , 0 )
103103 _required_framework_version = (2 , 0 , 0 )
104+ deleted = "(deleted)"
105+ smear = "<potentially smeared>"
104106
105107 framework .require_interface_version (* _required_framework_version )
106108
@@ -168,6 +170,7 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
168170 # vfsmnt can be the vfsmount object itself (>=3.3) or a vfsmount * (<3.3)
169171 return ""
170172
173+ inode = dentry .d_inode
171174 path_reversed = []
172175 smeared = False
173176 while (
@@ -191,6 +194,7 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
191194
192195 parent = dentry .d_parent
193196 dname = dentry .d_name .name_as_str ()
197+
194198 # empty dentry names are most likely
195199 # the result of smearing
196200 if not dname :
@@ -203,7 +207,10 @@ def do_get_path(cls, rdentry, rmnt, dentry, vfsmnt) -> Union[None, str]:
203207 # if there is smear the missing dname will be empty. e.g. if the normal
204208 # path would be /foo/bar/baz, but bar is missing due to smear the results
205209 # 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 } "
207214 return path
208215
209216 @classmethod
@@ -301,7 +308,7 @@ def _get_new_sock_pipe_path(cls, context, task, filp) -> str:
301308 return f"{ pre_name } :[{ inode .i_ino :d} ]"
302309
303310 @classmethod
304- def path_for_file (cls , context , task , filp ) -> str :
311+ def path_for_file (cls , context , task , filp , files_only = False ) -> str :
305312 """Returns a file (or sock pipe) pathname relative to the task's root directory.
306313
307314 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:
340347 except exceptions .InvalidAddressException :
341348 dname_is_valid = False
342349
343- if dname_is_valid :
350+ if dname_is_valid and not files_only :
344351 ret = LinuxUtilities ._get_new_sock_pipe_path (context , task , filp )
345352 else :
346353 ret = LinuxUtilities ._get_path_file (task , filp )
@@ -353,6 +360,7 @@ def files_descriptors_for_process(
353360 context : interfaces .context .ContextInterface ,
354361 symbol_table : str ,
355362 task : interfaces .objects .ObjectInterface ,
363+ files_only : bool = False ,
356364 ):
357365 try :
358366 files = task .files
@@ -376,7 +384,9 @@ def files_descriptors_for_process(
376384
377385 for fd_num , filp in enumerate (fds ):
378386 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+ )
380390
381391 yield fd_num , filp , full_path
382392
0 commit comments