@@ -230,6 +230,22 @@ def create_stat64_struct(ql, info):
230230 return fstat64_buf
231231
232232
233+ def statFamily (ql , path , ptr , name , stat_func , struct_func ):
234+ file = (ql .mem .string (path ))
235+ real_path = ql .os .transform_to_real_path (file )
236+ regreturn = 0
237+ try :
238+ info = stat_func (real_path )
239+ except OSError as e :
240+ ql .log .debug (f'{ name } ("{ file } ", { hex (ptr )} ) read/write fail' )
241+ return - e .errno
242+ else :
243+ buf = struct_func (ql , info )
244+ ql .mem .write (ptr , buf )
245+ ql .log .debug (f'{ name } ("{ file } ", { hex (ptr )} ) write completed' )
246+ return regreturn
247+
248+
233249def ql_syscall_chmod (ql , filename , mode , null1 , null2 , null3 , null4 ):
234250 regreturn = 0
235251 filename = ql .mem .string (filename )
@@ -329,87 +345,22 @@ def ql_syscall_fstat(ql, fstat_fd, fstat_add, *args, **kw):
329345 return regreturn
330346
331347
332- # int stat64(const char *pathname, struct stat64 *buf);
333- def ql_syscall_stat64 (ql , stat64_pathname , stat64_buf_ptr , * args , ** kw ):
334- stat64_file = (ql .mem .string (stat64_pathname ))
335- real_path = ql .os .transform_to_real_path (stat64_file )
336- if os .path .exists (real_path ) == False :
337- regreturn = - 1
338- else :
339- stat64_info = Stat (real_path )
340- stat64_buf = create_stat64_struct (ql , stat64_info )
341- ql .mem .write (stat64_buf_ptr , stat64_buf )
342- regreturn = 0
343-
344- if regreturn == 0 :
345- ql .log .debug ("stat64 write completed" )
346- else :
347- ql .log .debug ("stat64 read/write fail" )
348- return regreturn
349-
350-
351348# int stat(const char *path, struct stat *buf);
352349def ql_syscall_stat (ql , stat_path , stat_buf_ptr , * args , ** kw ):
353- stat_file = (ql . mem . string ( stat_path ) )
350+ return statFamily (ql , stat_path , stat_buf_ptr , "stat" , Stat , create_stat_struct )
354351
355- real_path = ql .os .transform_to_real_path (stat_file )
356- relative_path = ql .os .transform_to_relative_path (stat_file )
357352
358- if os .path .exists (real_path ) == False :
359- regreturn = - 1
360- else :
361- stat_info = Stat (real_path )
362- stat_buf = create_stat_struct (ql , stat_info )
363- regreturn = 0
364- ql .mem .write (stat_buf_ptr , stat_buf )
365-
366- if regreturn == 0 :
367- ql .log .debug ("stat() write completed" )
368- else :
369- ql .log .debug ("stat() read/write fail" )
370- return regreturn
353+ # int stat64(const char *pathname, struct stat64 *buf);
354+ def ql_syscall_stat64 (ql , stat64_pathname , stat64_buf_ptr , * args , ** kw ):
355+ return statFamily (ql , stat64_pathname , stat64_buf_ptr , "stat64" , Stat , create_stat64_struct )
371356
372357
373358def ql_syscall_lstat (ql , lstat_path , lstat_buf_ptr , * args , ** kw ):
374- lstat_file = (ql .mem .string (lstat_path ))
375-
376- real_path = ql .os .transform_to_real_path (lstat_file )
377- relative_path = ql .os .transform_to_relative_path (lstat_file )
378-
379- if os .path .exists (real_path ) == False :
380- regreturn = - 1
381- else :
382- lstat_info = Lstat (real_path )
383- lstat_buf = create_stat_struct (ql , lstat_info )
384- regreturn = 0
385- ql .mem .write (lstat_buf_ptr , lstat_buf )
386-
387- if regreturn == 0 :
388- ql .log .debug ("lstat() write completed" )
389- else :
390- ql .log .debug ("lstat() read/write fail" )
391- return regreturn
359+ return statFamily (ql , lstat_path , lstat_buf_ptr , "lstat" , Lstat , create_stat_struct )
392360
393361
394362def ql_syscall_lstat64 (ql , lstat64_path , lstat64_buf_ptr , * args , ** kw ):
395- lstat_file = (ql .mem .string (lstat64_path ))
396-
397- real_path = ql .os .transform_to_real_path (lstat_file )
398- relative_path = ql .os .transform_to_relative_path (lstat_file )
399-
400- if os .path .exists (real_path ) == False :
401- regreturn = - 1
402- else :
403- lstat_info = Lstat (real_path )
404- lstat64_buf = create_stat64_struct (ql , lstat_info )
405- regreturn = 0
406- ql .mem .write (lstat64_buf_ptr , lstat64_buf )
407-
408- if regreturn == 0 :
409- ql .log .debug ("lstat64() write completed" )
410- else :
411- ql .log .debug ("lstat64() read/write fail" )
412- return regreturn
363+ return statFamily (ql , lstat64_path , lstat64_buf_ptr , "lstat64" , Lstat , create_stat64_struct )
413364
414365
415366def ql_syscall_mknodat (ql , dirfd , pathname , mode , dev , * args , ** kw ):
0 commit comments