Skip to content

Commit 3e30a1e

Browse files
committed
In our documentation we claim that the size of each file in bytes
is also recorded, something which wasn't true up until now. This commit aims to correct that. Signed-off-by: Fotios Valasiadis <[email protected]>
1 parent 6c79eb7 commit 3e30a1e

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/record.c

+9
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ record_hash(char *foutname, char *hash)
197197
record_triple(foutname, "b:hash", hash, true);
198198
}
199199

200+
void
201+
record_size(char *foutname, size_t sz)
202+
{
203+
char size[32];
204+
205+
sprintf(size, "%lu", sz);
206+
record_triple(foutname, "b:size", size, false);
207+
}
208+
200209
void
201210
record_process_create(char *p1outname, char *p2outname)
202211
{

src/record.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ void record_rename(char *poutname, char *from_foutname, char *to_foutname);
99
void record_file(char *foutname, char *path, char *abspath);
1010
void record_fileuse(char *poutname, char *foutname, int purpose);
1111
void record_hash(char *foutname, char *hash);
12+
void record_size(char *foutname, size_t sz);
1213
void record_process_create(char *p1outname, char *p2outname);
1314
void record_exec(char *poutname, char *foutname);

src/tracer.c

+30-6
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ pinfo_new(PROCESS_INFO *self, char ignore_one_sigstop)
109109
}
110110

111111
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)
113113
{
114114
static int fcount = 0;
115115

116116
self->path = path;
117117
self->abspath = abspath;
118118
self->hash = hash;
119+
self->size = sz;
119120
sprintf(self->outname, ":f%d", fcount++);
120121
}
121122

@@ -264,6 +265,19 @@ find_in_path(char *path)
264265
return ret;
265266
}
266267

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+
267281
static void
268282
handle_open(pid_t pid, PROCESS_INFO *pi, int fd, int dirfd, void *path,
269283
int purpose)
@@ -278,21 +292,23 @@ handle_open(pid_t pid, PROCESS_INFO *pi, int fd, int dirfd, void *path,
278292

279293
if ((purpose & O_ACCMODE) == O_RDONLY) {
280294
char *hash = get_file_hash(abspath);
295+
size_t sz = get_file_size(abspath);
281296

282297
f = find_finfo(abspath, hash);
283298
if (!f) {
284299
f = next_finfo();
285-
finfo_new(f, path, abspath, hash);
300+
finfo_new(f, path, abspath, hash, sz);
286301
record_file(f->outname, path, abspath);
287302
record_hash(f->outname, hash);
303+
record_size(f->outname, sz);
288304
} else {
289305
free(path);
290306
free(abspath);
291307
free(hash);
292308
}
293309
} else {
294310
f = pinfo_next_finfo(pi, fd);
295-
finfo_new(f, path, abspath, NULL);
311+
finfo_new(f, path, abspath, NULL, -1);
296312
record_file(f->outname, path, abspath);
297313
}
298314

@@ -319,15 +335,17 @@ handle_execve(pid_t pid, PROCESS_INFO *pi, int dirfd, char *path)
319335
}
320336

321337
char *hash = get_file_hash(abspath);
338+
size_t sz = get_file_size(abspath);
322339

323340
FILE_INFO *f;
324341

325342
if (!(f = find_finfo(abspath, hash))) {
326343
f = next_finfo();
327344

328-
finfo_new(f, path, abspath, hash);
345+
finfo_new(f, path, abspath, hash, sz);
329346
record_file(f->outname, path, abspath);
330347
record_hash(f->outname, f->hash);
348+
record_size(f->outname, sz);
331349
} else {
332350
free(abspath);
333351
free(hash);
@@ -342,14 +360,16 @@ handle_rename_entry(pid_t pid, PROCESS_INFO *pi, int olddirfd, char *oldpath)
342360
{
343361
char *abspath = absolutepath(pid, olddirfd, oldpath);
344362
char *hash = get_file_hash(abspath);
363+
size_t sz = get_file_size(abspath);
345364

346365
FILE_INFO *f = find_finfo(abspath, hash);
347366

348367
if (!f) {
349368
f = next_finfo();
350-
finfo_new(f, oldpath, abspath, hash);
369+
finfo_new(f, oldpath, abspath, hash, sz);
351370
record_file(f->outname, oldpath, abspath);
352371
record_hash(f->outname, f->hash);
372+
record_size(f->outname, sz);
353373
} else {
354374
free(oldpath);
355375
free(abspath);
@@ -370,9 +390,10 @@ handle_rename_exit(pid_t pid, PROCESS_INFO *pi, int newdirfd, char *newpath)
370390

371391
FILE_INFO *to = next_finfo();
372392

373-
finfo_new(to, newpath, abspath, from->hash);
393+
finfo_new(to, newpath, abspath, from->hash, from->size);
374394
record_file(to->outname, newpath, abspath);
375395
record_hash(to->outname, to->hash);
396+
record_size(to->outname, to->size);
376397

377398
record_rename(pi->outname, from->outname, to->outname);
378399
}
@@ -479,7 +500,10 @@ handle_syscall_exit(pid_t pid, PROCESS_INFO *pi,
479500

480501
if (f != NULL) {
481502
f->hash = get_file_hash(f->abspath);
503+
f->size = get_file_size(f->abspath);
504+
482505
record_hash(f->outname, f->hash);
506+
record_size(f->outname, f->size);
483507

484508
// Add it to global cache list
485509
*next_finfo() = *f;

src/types.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef struct {
2727
char *path;
2828
char *abspath;
2929
char *hash;
30+
size_t size;
3031
char outname[16];
3132
} FILE_INFO;
3233

0 commit comments

Comments
 (0)