Skip to content

Commit

Permalink
define mode, uid, and gid format specifiers
Browse files Browse the repository at this point in the history
cleaned up some spacing
moved printits to gufi_treesummary
  • Loading branch information
calccrypto committed Dec 1, 2023
1 parent e2ce941 commit ebb0ec6
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 105 deletions.
7 changes: 4 additions & 3 deletions contrib/verifytraceintree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ OF SUCH DAMAGE.
#include <sqlite3.h>

#include "QueuePerThreadPool.h"
#include "config.h"
#include "trace.h"

// Data stored during first pass of input file
Expand Down Expand Up @@ -111,9 +112,9 @@ static int callback(void *arg, int, char **data, char **) {
ca->count++;

// assume no errors
sscanf(data[mode_col], "%d", &ca->st.st_mode);
sscanf(data[uid_col], "%d", &ca->st.st_uid);
sscanf(data[gid_col], "%d", &ca->st.st_gid);
sscanf(data[mode_col], "%" STAT_mode, &ca->st.st_mode);
sscanf(data[uid_col], "%" STAT_uid, &ca->st.st_uid);
sscanf(data[gid_col], "%" STAT_gid, &ca->st.st_gid);

return 0;
}
Expand Down
9 changes: 9 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ See LICENSE.txt in top-level directory for license terms.
// members of struct stat have sizes that vary between OSX/Linux
#if defined(__APPLE__)
# define STAT_ino "llu"
# define STAT_mode "hd"
# define STAT_nlink "hu"
# define STAT_uid "u"
# define STAT_gid "u"
# define STAT_size "lld"
# define STAT_bsize "d"
# define STAT_blocks "lld"
Expand All @@ -30,7 +33,10 @@ See LICENSE.txt in top-level directory for license terms.

#elif defined(__linux__)
# define STAT_ino "lu"
# define STAT_mode "u"
# define STAT_nlink "lu"
# define STAT_uid "u"
# define STAT_gid "u"
# define STAT_size "ld"
# define STAT_bsize "ld"
# define STAT_blocks "ld"
Expand All @@ -41,7 +47,10 @@ See LICENSE.txt in top-level directory for license terms.
#elif defined(__CYGWIN__)

# define STAT_ino "lu"
# define STAT_mode "u"
# define STAT_nlink "hu"
# define STAT_uid "u"
# define STAT_gid "u"
# define STAT_size "ld"
# define STAT_bsize "d"
# define STAT_blocks "ld"
Expand Down
2 changes: 0 additions & 2 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ int SNPRINTF(char *str, size_t size, const char *format, ...);
to size_t or weird bugs may occur */
size_t SNFORMAT_S(char *dst, const size_t dst_len, size_t count, ...);

int printits(struct input *in, struct work *pwork, struct entry_data *data, FILE *out);

int zeroit(struct sum *summary);

int sumit(struct sum *summary, struct entry_data *data);
Expand Down
4 changes: 2 additions & 2 deletions src/bf.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ void show_input(struct input* in, int retval) {
printf("in.nameto = '%s'\n", in->nameto.data);
printf("in.andor = %d\n", (int) in->andor);
printf("in.external_enabled = %d\n", in->external_enabled);
printf("in.nobody.uid = %d\n", (int) in->nobody.uid);
printf("in.nobody.gid = %d\n", (int) in->nobody.gid);
printf("in.nobody.uid = %" STAT_uid "\n", in->nobody.uid);
printf("in.nobody.gid = %" STAT_gid "\n", in->nobody.gid);
printf("in.sql.init = '%s'\n", in->sql.init.data);
printf("in.sql.tsum = '%s'\n", in->sql.tsum.data);
printf("in.sql.sum = '%s'\n", in->sql.sum.data);
Expand Down
54 changes: 27 additions & 27 deletions src/dfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ static int printit(const char *name, const struct stat *status, char *type, char
printf("%s ", name);
if (!strncmp(type,"l",1)) printf("-> %s ",linkname);

printf("%"STAT_ino" ", status->st_ino);
printf("%lld ", pinode);
printf("%d ", status->st_mode);
printf("%"STAT_nlink" ", status->st_nlink);
printf("%d ", status->st_uid);
printf("%d ", status->st_gid);
printf("%"STAT_size" ", status->st_size);
printf("%"STAT_bsize" ", status->st_blksize);
printf("%"STAT_blocks" ", status->st_blocks);
printf("%ld ", status->st_atime);
printf("%ld ", status->st_mtime);
printf("%ld ", status->st_ctime);
printf("%" STAT_ino" ", status->st_ino);
printf("%lld ", pinode);
printf("%" STAT_mode " ", status->st_mode);
printf("%" STAT_nlink " ", status->st_nlink);
printf("%" STAT_uid " ", status->st_uid);
printf("%" STAT_gid " ", status->st_gid);
printf("%" STAT_size " ", status->st_size);
printf("%" STAT_bsize " ", status->st_blksize);
printf("%" STAT_blocks" ", status->st_blocks);
printf("%ld ", status->st_atime);
printf("%ld ", status->st_mtime);
printf("%ld ", status->st_ctime);

if (xattrs->count) {
printf("xattr:");
Expand All @@ -112,21 +112,21 @@ static int printload(struct input *in, const char *name, const struct stat *stat
char *type, char *linkname, struct xattrs *xattrs, long long pinode,
char *sortf, FILE *of) {
(void) pinode;
fprintf(of,"%s%c", name,in->delim);
fprintf(of,"%c%c", type[0],in->delim);
fprintf(of,"%"STAT_ino"%c", status->st_ino,in->delim);
fprintf(of,"%s%c", name,in->delim);
fprintf(of,"%c%c", type[0],in->delim);
fprintf(of,"%" STAT_ino "%c", status->st_ino,in->delim);
//fprintf(of,"%lld%c", pinode,in->delim);
fprintf(of,"%d%c", status->st_mode,in->delim);
fprintf(of,"%"STAT_nlink"%c", status->st_nlink,in->delim);
fprintf(of,"%d%c", status->st_uid,in->delim);
fprintf(of,"%d%c", status->st_gid,in->delim);
fprintf(of,"%"STAT_size"%c", status->st_size,in->delim);
fprintf(of,"%"STAT_bsize"%c", status->st_blksize,in->delim);
fprintf(of,"%"STAT_blocks"%c", status->st_blocks,in->delim);
fprintf(of,"%ld%c", status->st_atime,in->delim);
fprintf(of,"%ld%c", status->st_mtime,in->delim);
fprintf(of,"%ld%c", status->st_ctime,in->delim);
fprintf(of,"%s%c", linkname,in->delim);
fprintf(of,"%" STAT_mode "%c", status->st_mode,in->delim);
fprintf(of,"%" STAT_nlink "%c", status->st_nlink,in->delim);
fprintf(of,"%" STAT_uid "%c", status->st_uid,in->delim);
fprintf(of,"%" STAT_gid "%c", status->st_gid,in->delim);
fprintf(of,"%" STAT_size "%c", status->st_size,in->delim);
fprintf(of,"%" STAT_bsize "%c", status->st_blksize,in->delim);
fprintf(of,"%" STAT_blocks"%c", status->st_blocks,in->delim);
fprintf(of,"%ld%c", status->st_atime,in->delim);
fprintf(of,"%ld%c", status->st_mtime,in->delim);
fprintf(of,"%ld%c", status->st_ctime,in->delim);
fprintf(of,"%s%c", linkname,in->delim);
for(size_t i = 0; i < xattrs->count; i++) {
fprintf(of, "%s\\0", xattrs->pairs[i].name);
}
Expand Down Expand Up @@ -261,7 +261,7 @@ void listdir(struct input *in, const char *name, long long int level,
printit(path,&st,type,lpath,&xattrs,1,pin);
}
} else {
printf("%s %s %"STAT_ino" %lld\n",type, path, entry->d_ino,pin);
printf("%s %s %" STAT_ino " %lld\n",type, path, entry->d_ino,pin);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/gufi_rollup.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ static int rollup_xattr_dbs_callback(void *args, int count, char **data, char **
uid_t uid;
gid_t gid;

sscanf(uid_str, "%d", &uid); /* skip checking for failure */
sscanf(gid_str, "%d", &gid); /* skip checking for failure */
sscanf(uid_str, "%" STAT_uid, &uid); /* skip checking for failure */
sscanf(gid_str, "%" STAT_gid, &gid); /* skip checking for failure */

/* parent xattr db filename */
char xattr_db_name[MAXPATH];
Expand Down
42 changes: 42 additions & 0 deletions src/gufi_treesummary.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,48 @@ OF SUCH DAMAGE.
#include "dbutils.h"
#include "QueuePerThreadPool.h"

static int printits(struct input *in, struct work *pwork, struct entry_data *ed, FILE *out) {
fprintf(out, "%s%c", pwork->name, in->delim);
fprintf(out, "%c%c", ed->type, in->delim);
fprintf(out, "%" STAT_ino "%c", ed->statuso.st_ino, in->delim);
fprintf(out, "%" STAT_mode "%c", ed->statuso.st_mode, in->delim);
fprintf(out, "%" STAT_nlink "%c", ed->statuso.st_nlink, in->delim);
fprintf(out, "%" STAT_uid "%c", ed->statuso.st_uid, in->delim);
fprintf(out, "%" STAT_gid "%c", ed->statuso.st_gid, in->delim);
fprintf(out, "%" STAT_size "%c", ed->statuso.st_size, in->delim);
fprintf(out, "%" STAT_bsize "%c", ed->statuso.st_blksize, in->delim);
fprintf(out, "%" STAT_blocks"%c", ed->statuso.st_blocks, in->delim);
fprintf(out, "%ld%c", ed->statuso.st_atime, in->delim);
fprintf(out, "%ld%c", ed->statuso.st_mtime, in->delim);
fprintf(out, "%ld%c", ed->statuso.st_ctime, in->delim);

/* we need this field even if its not populated for gufi_trace2index */
/*
if (!strncmp(pwork->type,"l",1)) {
fprintf(out, "%s%c", ed->linkname,in->delim);
}
*/
fprintf(out, "%s%c", ed->linkname,in->delim);

/* we need this field even if its not populated for gufi_trace2index */
/*
if (ed->xattrs > 0) {
//printf("xattr: ");
fprintf(out,"%s%c",ed->xattr,in->delim);
}
*/
/* fwrite(ed->xattrs, sizeof(char), ed->xattrs_len, out); */
fprintf(out,"%c",in->delim);

/* this one is for create time which posix doesnt have */
fprintf(out,"%c", in->delim);
/* moved this to end because we would like to use this for input to gufi_trace2index load from file */
fprintf(out, "%lld%c", pwork->pinode, in->delim);
fprintf(out, "%d%c", ed->suspect, in->delim);
fprintf(out,"\n");
return 0;
}

struct PoolArgs {
struct input in;
trie_t *skip; /* paths to skip during descent (only . and ..) */
Expand Down
52 changes: 25 additions & 27 deletions src/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,29 @@ int worktofile(FILE *file, const char delim, const size_t prefix_len, struct wor

count += fwrite(work->name + prefix_len, 1, work->name_len - prefix_len, file);
count += fwrite(&delim, 1, 1, file);
count += fprintf(file, "%c%c", ed->type, delim);
count += fprintf(file, "%" STAT_ino "%c", ed->statuso.st_ino, delim);
count += fprintf(file, "%d%c", ed->statuso.st_mode, delim);
count += fprintf(file, "%" STAT_nlink "%c", ed->statuso.st_nlink, delim);
count += fprintf(file, "%" PRId64 "%c", (int64_t) ed->statuso.st_uid, delim);
count += fprintf(file, "%" PRId64 "%c", (int64_t) ed->statuso.st_gid, delim);
count += fprintf(file, "%" STAT_size "%c", ed->statuso.st_size, delim);
count += fprintf(file, "%" STAT_bsize "%c", ed->statuso.st_blksize, delim);
count += fprintf(file, "%" STAT_blocks "%c", ed->statuso.st_blocks, delim);
count += fprintf(file, "%ld%c", ed->statuso.st_atime, delim);
count += fprintf(file, "%ld%c", ed->statuso.st_mtime, delim);
count += fprintf(file, "%ld%c", ed->statuso.st_ctime, delim);
count += fprintf(file, "%s%c", ed->linkname, delim);
count += fprintf(file, "%c%c", ed->type, delim);
count += fprintf(file, "%" STAT_ino "%c", ed->statuso.st_ino, delim);
count += fprintf(file, "%" STAT_mode "%c", ed->statuso.st_mode, delim);
count += fprintf(file, "%" STAT_nlink "%c", ed->statuso.st_nlink, delim);
count += fprintf(file, "%" STAT_uid "%c", ed->statuso.st_uid, delim);
count += fprintf(file, "%" STAT_gid "%c", ed->statuso.st_gid, delim);
count += fprintf(file, "%" STAT_size "%c", ed->statuso.st_size, delim);
count += fprintf(file, "%" STAT_bsize "%c", ed->statuso.st_blksize, delim);
count += fprintf(file, "%" STAT_blocks "%c", ed->statuso.st_blocks, delim);
count += fprintf(file, "%ld%c", ed->statuso.st_atime, delim);
count += fprintf(file, "%ld%c", ed->statuso.st_mtime, delim);
count += fprintf(file, "%ld%c", ed->statuso.st_ctime, delim);
count += fprintf(file, "%s%c", ed->linkname, delim);
count += xattrs_to_file(file, &ed->xattrs, XATTRDELIM);
count += fprintf(file, "%c", delim);
count += fprintf(file, "%d%c", ed->crtime, delim);
count += fprintf(file, "%d%c", ed->ossint1, delim);
count += fprintf(file, "%d%c", ed->ossint2, delim);
count += fprintf(file, "%d%c", ed->ossint3, delim);
count += fprintf(file, "%d%c", ed->ossint4, delim);
count += fprintf(file, "%s%c", ed->osstext1, delim);
count += fprintf(file, "%s%c", ed->osstext2, delim);
count += fprintf(file, "%lld%c", work->pinode, delim);
count += fprintf(file, "%c", delim);
count += fprintf(file, "%d%c", ed->crtime, delim);
count += fprintf(file, "%d%c", ed->ossint1, delim);
count += fprintf(file, "%d%c", ed->ossint2, delim);
count += fprintf(file, "%d%c", ed->ossint3, delim);
count += fprintf(file, "%d%c", ed->ossint4, delim);
count += fprintf(file, "%s%c", ed->osstext1, delim);
count += fprintf(file, "%s%c", ed->osstext2, delim);
count += fprintf(file, "%lld%c", work->pinode, delim);
count += fprintf(file, "\n");

return count;
Expand All @@ -117,16 +117,14 @@ int linetowork(char *line, const size_t len, const char delim, struct work *work

char *p;
char *q;
int64_t uid = -1;
int64_t gid = -1;

p=line; q = split(p, &delim, 1, end); work->name_len = SNPRINTF(work->name, MAXPATH, "%s", p);
p = q; q = split(p, &delim, 1, end); ed->type = *p;
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_ino, &ed->statuso.st_ino);
p = q; q = split(p, &delim, 1, end); ed->statuso.st_mode = atol(p);
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_mode, &ed->statuso.st_mode);
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_nlink, &ed->statuso.st_nlink);
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" PRId64, &uid); ed->statuso.st_uid = uid;
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" PRId64, &gid); ed->statuso.st_gid = gid;
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_uid, &ed->statuso.st_uid);
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_gid, &ed->statuso.st_gid);
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_size, &ed->statuso.st_size);
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_bsize, &ed->statuso.st_blksize);
p = q; q = split(p, &delim, 1, end); sscanf(p, "%" STAT_blocks, &ed->statuso.st_blocks);
Expand Down
42 changes: 0 additions & 42 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,48 +74,6 @@ OF SUCH DAMAGE.

#include "utils.h"

int printits(struct input *in, struct work *pwork, struct entry_data *ed, FILE *out) {
fprintf(out, "%s%c", pwork->name, in->delim);
fprintf(out, "%c%c", ed->type, in->delim);
fprintf(out, "%"STAT_ino"%c", ed->statuso.st_ino, in->delim);
fprintf(out, "%d%c", ed->statuso.st_mode, in->delim);
fprintf(out, "%"STAT_nlink"%c", ed->statuso.st_nlink, in->delim);
fprintf(out, "%d%c", ed->statuso.st_uid, in->delim);
fprintf(out, "%d%c", ed->statuso.st_gid, in->delim);
fprintf(out, "%"STAT_size"%c", ed->statuso.st_size, in->delim);
fprintf(out, "%"STAT_bsize"%c", ed->statuso.st_blksize, in->delim);
fprintf(out, "%"STAT_blocks"%c", ed->statuso.st_blocks, in->delim);
fprintf(out, "%ld%c", ed->statuso.st_atime, in->delim);
fprintf(out, "%ld%c", ed->statuso.st_mtime, in->delim);
fprintf(out, "%ld%c", ed->statuso.st_ctime, in->delim);

/* we need this field even if its not populated for gufi_trace2index */
/*
if (!strncmp(pwork->type,"l",1)) {
fprintf(out, "%s%c", ed->linkname,in->delim);
}
*/
fprintf(out, "%s%c", ed->linkname,in->delim);

/* we need this field even if its not populated for gufi_trace2index */
/*
if (ed->xattrs > 0) {
//printf("xattr: ");
fprintf(out,"%s%c",ed->xattr,in->delim);
}
*/
/* fwrite(ed->xattrs, sizeof(char), ed->xattrs_len, out); */
fprintf(out,"%c",in->delim);

/* this one is for create time which posix doesnt have */
fprintf(out,"%c", in->delim);
/* moved this to end because we would like to use this for input to gufi_trace2index load from file */
fprintf(out, "%lld%c", pwork->pinode, in->delim);
fprintf(out, "%d%c", ed->suspect, in->delim);
fprintf(out,"\n");
return 0;
}

int zeroit(struct sum *summary)
{
summary->totfiles=0;
Expand Down

0 comments on commit ebb0ec6

Please sign in to comment.