From c76c48cad5db06c63851add06f4431a5bc7884c3 Mon Sep 17 00:00:00 2001 From: carns Date: Wed, 12 May 2010 15:32:15 +0000 Subject: [PATCH] add magic number, hack up the logutils to handle 2.00 file format git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@244 3b7491f3-a168-0410-bf4b-c445ed680a29 --- darshan-log-format.h | 4 ++++ darshan-logutils.c | 28 ++++++++++++++++++++++++++-- lib/darshan-posix.c | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/darshan-log-format.h b/darshan-log-format.h index 44e12d2..0fe9589 100644 --- a/darshan-log-format.h +++ b/darshan-log-format.h @@ -14,6 +14,9 @@ /* update this on file format changes */ #define CP_VERSION "2.00" +/* magic number for validating output files and checking byte order */ +#define CP_MAGIC_NR 6567223 + /* size (in bytes) of job record */ #define CP_JOB_RECORD_SIZE 1024 @@ -217,6 +220,7 @@ struct darshan_file struct darshan_job { char version_string[8]; + int64_t magic_nr; int64_t uid; int64_t start_time; int64_t end_time; diff --git a/darshan-logutils.c b/darshan-logutils.c index f2965c6..36f9787 100644 --- a/darshan-logutils.c +++ b/darshan-logutils.c @@ -254,6 +254,16 @@ int darshan_log_getjob(darshan_fd file, struct darshan_job *job) perror("darshan_job_init"); return(-1); } + /* TODO: error out on anything except 2.00 in trunk for now, build + * backwards compatibility later + */ + if(strcmp(job->version_string, "2.00") == 0) + return(0); + fprintf(stderr, "Error: incompatible darshan file.\n"); + fprintf(stderr, "Error: expected version %s, but got %s\n", + CP_VERSION, job->version_string); + + return(-1); if(strcmp(job->version_string, "1.21") == 0) return(0); if(strcmp(job->version_string, "1.22") == 0) @@ -337,9 +347,18 @@ int darshan_log_getfile(darshan_fd fd, struct darshan_job *job, struct darshan_f } } else if(strcmp(job->version_string, "1.24") == 0) + { + ret = gzread(fd, file, sizeof(*file)); + if(ret == sizeof(*file)) + { + /* got exactly one, correct size record */ + return(1); + } + } + else if(strcmp(job->version_string, "2.00") == 0) { /* make sure this is the current version */ - assert(strcmp("1.24", CP_VERSION) == 0); + assert(strcmp("2.00", CP_VERSION) == 0); ret = gzread(fd, file, sizeof(*file)); if(ret == sizeof(*file)) @@ -490,9 +509,14 @@ void darshan_log_close(darshan_fd file) */ void darshan_log_print_version_warnings(struct darshan_job *job) { + if(strcmp(job->version_string, "2.00") == 0) + { + /* current version */ + return; + } + if(strcmp(job->version_string, "1.24") == 0) { - /* nothing to do, this is the current version */ return; } diff --git a/lib/darshan-posix.c b/lib/darshan-posix.c index ea45456..ba14d09 100644 --- a/lib/darshan-posix.c +++ b/lib/darshan-posix.c @@ -1028,6 +1028,7 @@ void darshan_initialize(int argc, char** argv, int nprocs, int rank) } strcpy(darshan_global_job->log_job.version_string, CP_VERSION); + darshan_global_job->log_job.magic_nr = CP_MAGIC_NR; darshan_global_job->log_job.uid = getuid(); darshan_global_job->log_job.start_time = time(NULL); darshan_global_job->log_job.nprocs = nprocs; -- 2.26.2