* Modified to indicate that the format of the file is
* no longer compatible with that of previous sysstat versions.
*/
-#define FORMAT_MAGIC 0x2171
+#define FORMAT_MAGIC 0x2172
/* Structure for file magic header data */
struct file_magic {
+ /*
+ * Size of file's header (size of file_header structure used by file).
+ */
+ unsigned int header_size;
/*
* This field identifies the file as a file created by sysstat.
*/
* Timestamp in seconds since the epoch.
*/
unsigned long sa_ust_time __attribute__ ((aligned (8)));
+ /*
+ * Number of CPU items (1 .. CPU_NR + 1) for the last sample in file.
+ */
+ unsigned int last_cpu_nr;
/*
* Number of activities saved in the file
*/
int i, j, n, p;
unsigned int a_cpu = FALSE;
struct file_activity *fal;
+ void *buffer = NULL;
/* Open sa data file */
if ((*ifd = open(dfile, O_RDONLY)) < 0) {
}
}
+ SREALLOC(buffer, char, file_magic->header_size);
+
/* Read sa data file standard header and allocate activity list */
- sa_fread(*ifd, file_hdr, FILE_HEADER_SIZE, HARD_SIZE);
-
+ sa_fread(*ifd, buffer, file_magic->header_size, HARD_SIZE);
+ memcpy(file_hdr, buffer, MINIMUM(file_magic->header_size, FILE_HEADER_SIZE));
+ free(buffer);
+
SREALLOC(*file_actlst, struct file_activity, FILE_ACTIVITY_SIZE * file_hdr->sa_nr_act);
fal = *file_actlst;
memset(file_magic, 0, FILE_MAGIC_SIZE);
+ file_magic->header_size = FILE_HEADER_SIZE;
+
file_magic->sysstat_magic = SYSSTAT_MAGIC;
file_magic->format_magic = FORMAT_MAGIC;
file_magic->sysstat_extraversion = 0;
struct file_magic file_magic;
struct file_activity file_act[NR_ACT];
struct tm rectime;
- ssize_t sz;
+ void *buffer = NULL;
+ ssize_t sz, n;
int i, p;
if (ofile[0]) {
handle_invalid_sa_file(ofd, &file_magic, ofile, sz);
}
+ SREALLOC(buffer, char, file_magic.header_size);
+
/* Read file standard header */
- if (read(*ofd, &file_hdr, FILE_HEADER_SIZE) != FILE_HEADER_SIZE) {
+ n = read(*ofd, buffer, file_magic.header_size);
+ memcpy(&file_hdr, buffer, MINIMUM(file_magic.header_size, FILE_HEADER_SIZE));
+ free(buffer);
+
+ if (n != file_magic.header_size) {
/* Display error message and exit */
handle_invalid_sa_file(ofd, &file_magic, ofile, 0);
}
exit(3);
}
- /* Read header data */
+ /*
+ * Read header data.
+ * No need to take into account file_magic.header_size. We are sure that
+ * sadc and sar are from the same version (we have checked FORMAT_MAGIC
+ * but also VERSION above) and thus the size of file_header is FILE_HEADER_SIZE.
+ */
if (sa_read(&file_hdr, FILE_HEADER_SIZE)) {
print_read_error();
}