* Map the fields of a structure containing statistics read from a file to
* those of the structure known by current sysstat version.
* Each structure (either read from file or from current sysstat version)
- * are described by 3 values: The number of [unsigned] long long integers,
+ * is described by 3 values: The number of [unsigned] long long integers,
* the number of [unsigned] long integers following in the structure, and
* last the number of [unsigned] integers.
* We assume that those numbers will *never* decrease with newer sysstat
* @gtypes_nr Structure description as expected for current sysstat version.
* @ftypes_nr Structure description as read from file.
* @ps Pointer on structure containing statistics.
- * @st_size Size of the structure containing statistics. This is the size
- * of the structure *read from file* (not the size of the
- * structure expected by current sysstat version).
+ * @f_size Size of the structure containing statistics. This is the
+ * size of the structure *read from file*.
+ * @g_size Size of the structure expected by current sysstat version.
***************************************************************************
*/
void remap_struct(unsigned int gtypes_nr[], unsigned int ftypes_nr[],
- void *ps, unsigned int st_size)
+ void *ps, unsigned int f_size, unsigned int g_size)
{
int d;
/* Sanity check */
- if (MAP_SIZE(ftypes_nr) > st_size)
+ if (MAP_SIZE(ftypes_nr) > f_size)
return;
/* Remap [unsigned] long fields */
if (d) {
memmove(((char *) ps) + gtypes_nr[0] * ULL_ALIGNMENT_WIDTH,
((char *) ps) + ftypes_nr[0] * ULL_ALIGNMENT_WIDTH,
- st_size - ftypes_nr[0] * ULL_ALIGNMENT_WIDTH);
+ MINIMUM(f_size - ftypes_nr[0] * ULL_ALIGNMENT_WIDTH,
+ g_size - gtypes_nr[0] * ULL_ALIGNMENT_WIDTH));
if (d > 0) {
memset(((char *) ps) + ftypes_nr[0] * ULL_ALIGNMENT_WIDTH,
0, d * ULL_ALIGNMENT_WIDTH);
+ gtypes_nr[1] * UL_ALIGNMENT_WIDTH,
((char *) ps) + gtypes_nr[0] * ULL_ALIGNMENT_WIDTH
+ ftypes_nr[1] * UL_ALIGNMENT_WIDTH,
- st_size - ftypes_nr[0] * ULL_ALIGNMENT_WIDTH
- - ftypes_nr[1] * UL_ALIGNMENT_WIDTH);
+ MINIMUM(f_size - ftypes_nr[0] * ULL_ALIGNMENT_WIDTH
+ - ftypes_nr[1] * UL_ALIGNMENT_WIDTH,
+ g_size - gtypes_nr[0] * ULL_ALIGNMENT_WIDTH
+ - gtypes_nr[1] * UL_ALIGNMENT_WIDTH));
if (d > 0) {
memset(((char *) ps) + gtypes_nr[0] * ULL_ALIGNMENT_WIDTH
+ ftypes_nr[1] * UL_ALIGNMENT_WIDTH,
((char *) ps) + gtypes_nr[0] * ULL_ALIGNMENT_WIDTH
+ gtypes_nr[1] * UL_ALIGNMENT_WIDTH
+ ftypes_nr[2] * U_ALIGNMENT_WIDTH,
- st_size - ftypes_nr[0] * ULL_ALIGNMENT_WIDTH
- - ftypes_nr[1] * UL_ALIGNMENT_WIDTH
- - ftypes_nr[2] * U_ALIGNMENT_WIDTH);
+ MINIMUM(f_size - ftypes_nr[0] * ULL_ALIGNMENT_WIDTH
+ - ftypes_nr[1] * UL_ALIGNMENT_WIDTH
+ - ftypes_nr[2] * U_ALIGNMENT_WIDTH,
+ g_size - gtypes_nr[0] * ULL_ALIGNMENT_WIDTH
+ - gtypes_nr[1] * UL_ALIGNMENT_WIDTH
+ - gtypes_nr[2] * U_ALIGNMENT_WIDTH));
if (d > 0) {
memset(((char *) ps) + gtypes_nr[0] * ULL_ALIGNMENT_WIDTH
+ gtypes_nr[1] * UL_ALIGNMENT_WIDTH
return 1;
/* Remap record header structure to that expected by current version */
- remap_struct(rec_types_nr, file_hdr->rec_types_nr, buffer, file_hdr->rec_size);
+ remap_struct(rec_types_nr, file_hdr->rec_types_nr, buffer,
+ file_hdr->rec_size, RECORD_HEADER_SIZE);
memcpy(record_hdr, buffer, RECORD_HEADER_SIZE);
/* Normalize endianness */
/* Remap structure's fields to those known by current sysstat version */
for (j = 0; j < (nr_value * act[p]->nr2); j++) {
remap_struct(act[p]->gtypes_nr, act[p]->ftypes_nr,
- (char *) act[p]->buf[curr] + j * act[p]->msize, act[p]->fsize);
+ (char *) act[p]->buf[curr] + j * act[p]->msize,
+ act[p]->fsize, act[p]->msize);
}
}
}
* smaller than FILE_HEADER_SIZE. Remap the fields of the file header
* then copy its contents to the expected structure.
*/
- remap_struct(hdr_types_nr, file_magic->hdr_types_nr, buffer, file_magic->header_size);
+ remap_struct(hdr_types_nr, file_magic->hdr_types_nr, buffer,
+ file_magic->header_size, FILE_HEADER_SIZE);
memcpy(file_hdr, buffer, FILE_HEADER_SIZE);
free(buffer);
buffer = NULL;
* smaller than FILE_ACTIVITY_SIZE. Remap the fields of the file's structure
* then copy its contents to the expected structure.
*/
- remap_struct(act_types_nr, file_hdr->act_types_nr, buffer, file_hdr->act_size);
+ remap_struct(act_types_nr, file_hdr->act_types_nr, buffer,
+ file_hdr->act_size, FILE_ACTIVITY_SIZE);
memcpy(fal, buffer, FILE_ACTIVITY_SIZE);
/* Normalize endianness for file_activity structures */