@@ -109,13 +109,14 @@ pinfo_new(PROCESS_INFO *self, char ignore_one_sigstop)
109
109
}
110
110
111
111
void
112
- finfo_new (FILE_INFO * self , char * path , char * abspath , char * hash )
112
+ finfo_new (FILE_INFO * self , char * path , char * abspath , char * hash , size_t sz )
113
113
{
114
114
static int fcount = 0 ;
115
115
116
116
self -> path = path ;
117
117
self -> abspath = abspath ;
118
118
self -> hash = hash ;
119
+ self -> size = sz ;
119
120
sprintf (self -> outname , ":f%d" , fcount ++ );
120
121
}
121
122
@@ -264,6 +265,19 @@ find_in_path(char *path)
264
265
return ret ;
265
266
}
266
267
268
+ static size_t
269
+ get_file_size (char * fname )
270
+ {
271
+ struct stat fstat ;
272
+
273
+ if (stat (fname , & fstat )) {
274
+ error (0 , errno , "getting `%s' size" , fname );
275
+ return -1 ;
276
+ }
277
+
278
+ return fstat .st_size ;
279
+ }
280
+
267
281
static void
268
282
handle_open (pid_t pid , PROCESS_INFO * pi , int fd , int dirfd , void * path ,
269
283
int purpose )
@@ -278,21 +292,23 @@ handle_open(pid_t pid, PROCESS_INFO *pi, int fd, int dirfd, void *path,
278
292
279
293
if ((purpose & O_ACCMODE ) == O_RDONLY ) {
280
294
char * hash = get_file_hash (abspath );
295
+ size_t sz = get_file_size (abspath );
281
296
282
297
f = find_finfo (abspath , hash );
283
298
if (!f ) {
284
299
f = next_finfo ();
285
- finfo_new (f , path , abspath , hash );
300
+ finfo_new (f , path , abspath , hash , sz );
286
301
record_file (f -> outname , path , abspath );
287
302
record_hash (f -> outname , hash );
303
+ record_size (f -> outname , sz );
288
304
} else {
289
305
free (path );
290
306
free (abspath );
291
307
free (hash );
292
308
}
293
309
} else {
294
310
f = pinfo_next_finfo (pi , fd );
295
- finfo_new (f , path , abspath , NULL );
311
+ finfo_new (f , path , abspath , NULL , -1 );
296
312
record_file (f -> outname , path , abspath );
297
313
}
298
314
@@ -319,15 +335,17 @@ handle_execve(pid_t pid, PROCESS_INFO *pi, int dirfd, char *path)
319
335
}
320
336
321
337
char * hash = get_file_hash (abspath );
338
+ size_t sz = get_file_size (abspath );
322
339
323
340
FILE_INFO * f ;
324
341
325
342
if (!(f = find_finfo (abspath , hash ))) {
326
343
f = next_finfo ();
327
344
328
- finfo_new (f , path , abspath , hash );
345
+ finfo_new (f , path , abspath , hash , sz );
329
346
record_file (f -> outname , path , abspath );
330
347
record_hash (f -> outname , f -> hash );
348
+ record_size (f -> outname , sz );
331
349
} else {
332
350
free (abspath );
333
351
free (hash );
@@ -342,14 +360,16 @@ handle_rename_entry(pid_t pid, PROCESS_INFO *pi, int olddirfd, char *oldpath)
342
360
{
343
361
char * abspath = absolutepath (pid , olddirfd , oldpath );
344
362
char * hash = get_file_hash (abspath );
363
+ size_t sz = get_file_size (abspath );
345
364
346
365
FILE_INFO * f = find_finfo (abspath , hash );
347
366
348
367
if (!f ) {
349
368
f = next_finfo ();
350
- finfo_new (f , oldpath , abspath , hash );
369
+ finfo_new (f , oldpath , abspath , hash , sz );
351
370
record_file (f -> outname , oldpath , abspath );
352
371
record_hash (f -> outname , f -> hash );
372
+ record_size (f -> outname , sz );
353
373
} else {
354
374
free (oldpath );
355
375
free (abspath );
@@ -370,9 +390,10 @@ handle_rename_exit(pid_t pid, PROCESS_INFO *pi, int newdirfd, char *newpath)
370
390
371
391
FILE_INFO * to = next_finfo ();
372
392
373
- finfo_new (to , newpath , abspath , from -> hash );
393
+ finfo_new (to , newpath , abspath , from -> hash , from -> size );
374
394
record_file (to -> outname , newpath , abspath );
375
395
record_hash (to -> outname , to -> hash );
396
+ record_size (to -> outname , to -> size );
376
397
377
398
record_rename (pi -> outname , from -> outname , to -> outname );
378
399
}
@@ -479,7 +500,10 @@ handle_syscall_exit(pid_t pid, PROCESS_INFO *pi,
479
500
480
501
if (f != NULL ) {
481
502
f -> hash = get_file_hash (f -> abspath );
503
+ f -> size = get_file_size (f -> abspath );
504
+
482
505
record_hash (f -> outname , f -> hash );
506
+ record_size (f -> outname , f -> size );
483
507
484
508
// Add it to global cache list
485
509
* next_finfo () = * f ;
0 commit comments