2 * sa_conv.c: Convert an old format sa file to the up-to-date format.
3 * (C) 1999-2020 by Sebastien GODARD (sysstat <at> orange.fr)
5 ***************************************************************************
6 * This program is free software; you can redistribute it and/or modify it *
7 * under the terms of the GNU General Public License as published by the *
8 * Free Software Foundation; either version 2 of the License, or (at your *
9 * option) any later version. *
11 * This program is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without the implied warranty of MERCHANTABILITY *
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
16 * You should have received a copy of the GNU General Public License along *
17 * with this program; if not, write to the Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *
19 ***************************************************************************
35 # define _(string) gettext(string)
37 # define _(string) (string)
40 extern int endian_mismatch;
41 extern unsigned int user_hz;
42 extern unsigned int act_types_nr[];
43 extern unsigned int rec_types_nr[];
44 extern unsigned int hdr_types_nr[];
46 unsigned int oact_types_nr[] = {OLD_FILE_ACTIVITY_ULL_NR, OLD_FILE_ACTIVITY_UL_NR, OLD_FILE_ACTIVITY_U_NR};
49 ***************************************************************************
50 * Read and upgrade file's magic data section.
53 * @dfile System activity data file name.
54 * @stdfd File descriptor for STDOUT.
57 * @fd File descriptor for sa datafile to convert.
58 * @file_magic File's magic structure.
59 * @hdr_size Size of header structure read from file.
61 * Format magic number of file to convert, converted to
64 * TRUE if data read from file don't match current machine's
68 * -1 on error, 0 otherwise.
69 ***************************************************************************
71 int upgrade_magic_section(char dfile[], int *fd, int stdfd, struct file_magic *file_magic,
72 unsigned int *hdr_size, int *previous_format, int *endian_mismatch)
75 unsigned int fm_types_nr[] = {FILE_MAGIC_ULL_NR, FILE_MAGIC_UL_NR, FILE_MAGIC_U_NR};
77 /* Open and read sa magic structure */
78 sa_open_read_magic(fd, dfile, file_magic, TRUE, endian_mismatch, FALSE);
80 switch (file_magic->format_magic) {
83 case FORMAT_MAGIC_SWAPPED:
84 *previous_format = FORMAT_MAGIC;
88 case FORMAT_MAGIC_2171:
89 case FORMAT_MAGIC_2171_SWAPPED:
90 *previous_format = FORMAT_MAGIC_2171;
93 case FORMAT_MAGIC_2173:
94 case FORMAT_MAGIC_2173_SWAPPED:
95 *previous_format = FORMAT_MAGIC_2173;
99 fprintf(stderr, _("Cannot convert the format of this file\n"));
104 fprintf(stderr, "file_magic: ");
105 if (*previous_format == FORMAT_MAGIC_2171) {
107 * We have read too many bytes: file_magic structure
108 * was smaller with previous sysstat versions.
109 * Go back 4 (unsigned int header_size) + 64 (char pad[64]) bytes.
111 if (lseek(*fd, -68, SEEK_CUR) < 0) {
112 fprintf(stderr, "\nlseek: %s\n", strerror(errno));
117 /* Set format magic number to that of current version */
118 file_magic->format_magic = (*endian_mismatch ? FORMAT_MAGIC_SWAPPED
121 /* Save original header structure's size */
122 *hdr_size = file_magic->header_size;
124 /* Fill new structure members */
125 file_magic->header_size = FILE_HEADER_SIZE;
126 file_magic->hdr_types_nr[0] = FILE_HEADER_ULL_NR;
127 file_magic->hdr_types_nr[1] = FILE_HEADER_UL_NR;
128 file_magic->hdr_types_nr[2] = FILE_HEADER_U_NR;
129 memset(file_magic->pad, 0, sizeof(unsigned char) * FILE_MAGIC_PADDING);
131 /* Indicate that file has been upgraded */
132 enum_version_nr(&fm);
133 file_magic->upgraded = (fm.sysstat_patchlevel << 8) +
134 fm.sysstat_sublevel + 1;
136 memcpy(&fm, file_magic, FILE_MAGIC_SIZE);
137 /* Restore endianness before writing */
138 if (*endian_mismatch) {
139 /* Start swapping at field "header_size" position */
140 swap_struct(fm_types_nr, &(fm.header_size), 0);
143 /* Write file's magic structure */
144 if (write_all(stdfd, &fm, FILE_MAGIC_SIZE) != FILE_MAGIC_SIZE) {
145 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
148 fprintf(stderr, "OK\n");
154 ***************************************************************************
155 * Upgrade file_header structure (from 0x2171 format to current format).
158 * @buffer File's header structure (as read from file).
160 * Format magic number of file to convert.
162 * TRUE if data read from file don't match current
163 * machine's endianness.
166 * @file_hdr File's header structure (up-to-date format).
167 * @arch_64 TRUE if file's data come from a 64-bit machine.
168 * @vol_act_nr Number of volatile activity structures following a restart
169 * record for 0x2173 file format.
170 ***************************************************************************
172 void upgrade_file_header(void *buffer, struct file_header *file_hdr, int previous_format,
173 int endian_mismatch, int *arch_64, unsigned int *vol_act_nr)
175 struct file_header_2171 *f_hdr_2171 = (struct file_header_2171 *) buffer;
176 struct file_header_2173 *f_hdr_2173 = (struct file_header_2173 *) buffer;
177 unsigned int hdr_2171_types_nr[] = {FILE_HEADER_2171_ULL_NR, FILE_HEADER_2171_UL_NR, FILE_HEADER_2171_U_NR};
178 unsigned int hdr_2173_types_nr[] = {FILE_HEADER_2173_ULL_NR, FILE_HEADER_2173_UL_NR, FILE_HEADER_2173_U_NR};
181 memset(file_hdr, 0, FILE_HEADER_SIZE);
182 file_hdr->sa_hz = HZ;
184 if (previous_format == FORMAT_MAGIC_2171) {
185 *arch_64 = (f_hdr_2171->sa_sizeof_long == SIZEOF_LONG_64BIT);
187 /* Normalize endianness for f_hdr_2171 structure */
188 if (endian_mismatch) {
189 swap_struct(hdr_2171_types_nr, f_hdr_2171, *arch_64);
192 file_hdr->sa_ust_time = (unsigned long long) f_hdr_2171->sa_ust_time;
193 /* sa_cpu_nr field will be updated later */
194 file_hdr->sa_act_nr = f_hdr_2171->sa_act_nr;
195 file_hdr->sa_year = (int) f_hdr_2171->sa_year;
196 file_hdr->sa_day = f_hdr_2171->sa_day;
197 file_hdr->sa_month = f_hdr_2171->sa_month;
198 file_hdr->sa_sizeof_long = f_hdr_2171->sa_sizeof_long;
199 strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, sizeof(file_hdr->sa_sysname));
200 file_hdr->sa_sysname[sizeof(file_hdr->sa_sysname) - 1] = '\0';
201 strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, sizeof(file_hdr->sa_nodename));
202 file_hdr->sa_nodename[sizeof(file_hdr->sa_nodename) - 1] = '\0';
203 strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, sizeof(file_hdr->sa_release));
204 file_hdr->sa_release[sizeof(file_hdr->sa_release) - 1] = '\0';
205 strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, sizeof(file_hdr->sa_machine));
206 file_hdr->sa_machine[sizeof(file_hdr->sa_machine) - 1] = '\0';
209 else if (previous_format == FORMAT_MAGIC_2173) {
210 *arch_64 = (f_hdr_2173->sa_sizeof_long == SIZEOF_LONG_64BIT);
212 /* Normalize endianness for f_hdr_2171 structure */
213 if (endian_mismatch) {
214 swap_struct(hdr_2173_types_nr, f_hdr_2173, *arch_64);
217 file_hdr->sa_ust_time = (unsigned long long) f_hdr_2173->sa_ust_time;
218 /* sa_cpu_nr field will be updated later */
219 file_hdr->sa_act_nr = f_hdr_2173->sa_act_nr;
220 file_hdr->sa_year = (int) f_hdr_2173->sa_year;
221 file_hdr->sa_day = f_hdr_2173->sa_day;
222 file_hdr->sa_month = f_hdr_2173->sa_month;
223 file_hdr->sa_sizeof_long = f_hdr_2173->sa_sizeof_long;
224 strncpy(file_hdr->sa_sysname, f_hdr_2173->sa_sysname, UTSNAME_LEN);
225 file_hdr->sa_sysname[UTSNAME_LEN - 1] = '\0';
226 strncpy(file_hdr->sa_nodename, f_hdr_2173->sa_nodename, UTSNAME_LEN);
227 file_hdr->sa_nodename[UTSNAME_LEN - 1] = '\0';
228 strncpy(file_hdr->sa_release, f_hdr_2173->sa_release, UTSNAME_LEN);
229 file_hdr->sa_release[UTSNAME_LEN - 1] = '\0';
230 strncpy(file_hdr->sa_machine, f_hdr_2173->sa_machine, UTSNAME_LEN);
231 file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
233 *vol_act_nr = f_hdr_2173->sa_vol_act_nr;
236 for (i = 0; i < 3; i++) {
237 file_hdr->act_types_nr[i] = act_types_nr[i];
238 file_hdr->rec_types_nr[i] = rec_types_nr[i];
240 file_hdr->act_size = FILE_ACTIVITY_SIZE;
241 file_hdr->rec_size = RECORD_HEADER_SIZE;
244 * Note: @extra_next and @sa_tzname[] members are set to zero
245 * because file_hdr has been memset'd to zero.
250 ***************************************************************************
251 * Read and upgrade file's header section.
254 * @dfile System activity data file name.
255 * @fd File descriptor for sa datafile to convert.
256 * @stdfd File descriptor for STDOUT.
257 * @act Array of activities.
258 * @file_magic File's magic structure.
259 * @hdr_size Size of header structure read from file.
261 * Format magic number of file to convert.
263 * TRUE if data read from file don't match current machine's
267 * @file_hdr File's header structure (up-to-date format).
268 * @arch_64 TRUE if file's data come from a 64-bit machine.
269 * @vol_act_nr Number of volatile activity structures following a restart
270 * record for 0x2173 file format.
272 * Activity list in file.
275 * -1 on error, 0 otherwise.
276 ***************************************************************************
278 int upgrade_header_section(char dfile[], int fd, int stdfd, struct activity *act[],
279 struct file_magic *file_magic, struct file_header *file_hdr,
280 unsigned int hdr_size, int previous_format, int *arch_64,
281 int endian_mismatch, unsigned int *vol_act_nr,
282 struct old_file_activity **ofile_actlst)
284 struct old_file_activity *ofal;
285 struct file_header fh;
287 unsigned int a_cpu = FALSE;
290 fprintf(stderr, "file_header: ");
292 /* Read file header structure */
293 n = (previous_format == FORMAT_MAGIC_2171 ? FILE_HEADER_SIZE_2171
295 SREALLOC(buffer, char, n);
296 sa_fread(fd, buffer, (size_t) n, HARD_SIZE, UEOF_STOP);
298 /* Upgrade file_header structure */
299 upgrade_file_header(buffer, file_hdr, previous_format,
300 endian_mismatch, arch_64, vol_act_nr);
305 if (file_hdr->sa_act_nr > MAX_NR_ACT)
308 /* Read file activity list */
309 SREALLOC(*ofile_actlst, struct old_file_activity, OLD_FILE_ACTIVITY_SIZE * file_hdr->sa_act_nr);
310 ofal = *ofile_actlst;
312 for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++) {
314 sa_fread(fd, ofal, OLD_FILE_ACTIVITY_SIZE, HARD_SIZE, UEOF_STOP);
316 /* Normalize endianness for file_activity structures */
317 if (endian_mismatch) {
318 swap_struct(oact_types_nr, ofal, *arch_64);
321 if ((ofal->nr < 1) || (ofal->nr2 < 1))
323 * Every activity, known or unknown,
324 * should have at least one item and sub-item.
328 if ((p = get_activity_position(act, ofal->id, RESUME_IF_NOT_FOUND)) >= 0) {
329 /* This is a known activity, maybe with an unknown format */
331 if ((ofal->id == A_CPU) && !a_cpu) {
333 * We have found the CPU activity: Set sa_cpu_nr field
334 * in file_header structure that should contains the
335 * number of CPU when the file was created.
337 file_hdr->sa_cpu_nr = ofal->nr;
342 if (!ofal->size || (ofal->size > MAX_ITEM_STRUCT_SIZE))
345 /* Size of activity in file is larger than up-to-date activity size */
346 if (ofal->size > act[p]->msize) {
347 act[p]->msize = ofal->size;
351 * When upgrading a file:
352 * ofal->size : Size of an item for current activity, as
353 * read from the file.
354 * act[p]->msize: Size of the buffer in memory where an item
355 * for current activity, as read from the file,
356 * will be saved. We have:
357 * act[p]->msize >= {ofal->size ; act[p]->fsize}
358 * act[p]->fsize: Size of an item for current activity with
361 act[p]->nr_ini = ofal->nr;
362 act[p]->nr2 = ofal->nr2;
364 * Don't set act[p]->fsize! Should retain the size of an item
365 * for up-to-date format!
372 * CPU activity should always be in file for versions older than 11.7.1
373 * and have a known format (expected magical number).
375 fprintf(stderr, _("\nCPU activity not found in file. Aborting...\n"));
379 memcpy(&fh, file_hdr, FILE_HEADER_SIZE);
380 /* Restore endianness before writing */
381 if (endian_mismatch) {
382 /* Start swapping at field "header_size" position */
383 swap_struct(hdr_types_nr, &fh, *arch_64);
386 /* Write file_header structure */
387 if ((n = write_all(stdfd, &fh, FILE_HEADER_SIZE)) != FILE_HEADER_SIZE) {
388 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
392 fprintf(stderr, "OK\n");
398 fprintf(stderr, _("\nInvalid data found. Aborting...\n"));
405 ***************************************************************************
406 * Convert a long integer value to a long long integer value.
407 * The long integer value may be 32 or 64-bit wide and come from a 32 or
408 * 64-bit architecture.
410 * Note: Consider the value 0x01020304 read on a 32-bit machine.
411 * Big-endian, saved as: 01 02 03 04
412 * Lille-endian, saved as: 04 03 02 01
413 * The value should be saved as a 64-bit value and endianness should be
415 * Big-endian: 00 00 00 00 01 02 03 04
416 * Little-endian: 04 03 02 01 00 00 00 00
419 * @buffer Address of value to convert.
421 * TRUE if data read from file don't match current machine's
423 * @arch_64 TRUE if file's data come from a 64-bit machine.
424 ***************************************************************************
426 unsigned long long moveto_long_long(void *buffer, int endian_mismatch, int arch_64)
429 unsigned long long *ull_int, ull_i;
432 ull_int = (unsigned long long *) buffer;
436 u_int = (unsigned int *) buffer;
437 if (endian_mismatch) {
438 ull_i = (unsigned long long) *u_int;
439 return (ull_i >> 32) | (ull_i << 32);
442 return (unsigned long long) *u_int;
447 ***************************************************************************
448 * Upgrade stats_cpu structure (from ACTIVITY_MAGIC_BASE format to
449 * ACTIVITY_MAGIC_BASE + 1 format).
452 * @act Array of activities.
453 * @p Position of activity in array.
454 * @st_size Size of the structure read from file.
455 ***************************************************************************
457 void upgrade_stats_cpu(struct activity *act[], int p, int st_size)
460 struct stats_cpu *scc;
461 struct stats_cpu_8a *scp;
463 for (i = 0; i < act[p]->nr_ini; i++) {
465 * For previous structure's format: Use msize (which has possibly been set to
466 * the size of the structure read from disk if it's greater than that of
467 * current format: See upgrade_header_section()).
468 * For current structure format: Use fsize. This is the normal size of
469 * structure's up-to-date format that will be written to file.
471 scp = (struct stats_cpu_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
472 scc = (struct stats_cpu *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
474 scc->cpu_user = scp->cpu_user;
475 scc->cpu_nice = scp->cpu_nice;
476 scc->cpu_sys = scp->cpu_sys;
477 scc->cpu_idle = scp->cpu_idle;
478 scc->cpu_iowait = scp->cpu_iowait;
479 scc->cpu_steal = scp->cpu_steal;
480 scc->cpu_hardirq = scp->cpu_hardirq;
481 scc->cpu_softirq = scp->cpu_softirq;
482 scc->cpu_guest = scp->cpu_guest;
484 if (st_size >= STATS_CPU_8A_SIZE) {
485 /* guest_nice field has been added without a structure format change */
486 scc->cpu_guest_nice = scp->cpu_guest_nice;
492 ***************************************************************************
493 * Upgrade stats_pcsw structure (from ACTIVITY_MAGIC_BASE format to
494 * ACTIVITY_MAGIC_BASE + 1 format).
497 * @act Array of activities.
498 * @p Position of activity in array.
499 ***************************************************************************
501 void upgrade_stats_pcsw(struct activity *act[], int p)
503 struct stats_pcsw *spc = (struct stats_pcsw *) act[p]->buf[1];
504 struct stats_pcsw_8a *spp = (struct stats_pcsw_8a *) act[p]->buf[0];
506 spc->context_switch = spp->context_switch;
508 * Copy a long into a long. Take into account that file may have been
509 * created on a 64-bit machine and we may be converting on a 32-bit machine.
511 memcpy(&spc->processes, &spp->processes, 8);
515 ***************************************************************************
516 * Upgrade stats_irq structure (from ACTIVITY_MAGIC_BASE format to
517 * ACTIVITY_MAGIC_BASE + 1 format).
520 * @act Array of activities.
521 * @p Position of activity in array.
522 ***************************************************************************
524 void upgrade_stats_irq(struct activity *act[], int p)
527 struct stats_irq *sic;
528 struct stats_irq_8a *sip;
530 for (i = 0; i < act[p]->nr_ini; i++) {
531 sip = (struct stats_irq_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
532 sic = (struct stats_irq *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
534 sic->irq_nr = sip->irq_nr;
539 ***************************************************************************
540 * Upgrade stats_io structure (from ACTIVITY_MAGIC_BASE format to
541 * ACTIVITY_MAGIC_BASE + 1 format).
544 * @act Array of activities.
545 * @p Position of activity in array.
547 * TRUE if data read from file don't match current machine's
549 ***************************************************************************
551 void upgrade_stats_io(struct activity *act[], int p, int endian_mismatch)
553 struct stats_io *sic = (struct stats_io *) act[p]->buf[1];
554 struct stats_io_8a *sip = (struct stats_io_8a *) act[p]->buf[0];
556 sic->dk_drive = moveto_long_long(&sip->dk_drive, endian_mismatch, FALSE);
557 sic->dk_drive_rio = moveto_long_long(&sip->dk_drive_rio, endian_mismatch, FALSE);
558 sic->dk_drive_wio = moveto_long_long(&sip->dk_drive_wio, endian_mismatch, FALSE);
559 sic->dk_drive_rblk = moveto_long_long(&sip->dk_drive_rblk, endian_mismatch, FALSE);
560 sic->dk_drive_wblk = moveto_long_long(&sip->dk_drive_wblk, endian_mismatch, FALSE);
564 ***************************************************************************
565 * Upgrade stats_memory structure (from ACTIVITY_MAGIC_BASE format to
566 * ACTIVITY_MAGIC_BASE + 1 format).
569 * @act Array of activities.
570 * @p Position of activity in array.
571 * @st_size Size of the structure read from file.
573 * TRUE if data read from file don't match current machine's
575 * @arch_64 TRUE if file's data come from a 64-bit machine.
576 ***************************************************************************
578 void upgrade_stats_memory(struct activity *act[], int p, int st_size,
579 int endian_mismatch, int arch_64)
581 struct stats_memory *smc = (struct stats_memory *) act[p]->buf[1];
582 struct stats_memory_8a *smp = (struct stats_memory_8a *) act[p]->buf[0];
584 smc->frmkb = moveto_long_long(&smp->frmkb, endian_mismatch, arch_64);
585 smc->bufkb = moveto_long_long(&smp->bufkb, endian_mismatch, arch_64);
586 smc->camkb = moveto_long_long(&smp->camkb, endian_mismatch, arch_64);
587 smc->tlmkb = moveto_long_long(&smp->tlmkb, endian_mismatch, arch_64);
588 smc->frskb = moveto_long_long(&smp->frskb, endian_mismatch, arch_64);
589 smc->tlskb = moveto_long_long(&smp->tlskb, endian_mismatch, arch_64);
590 smc->caskb = moveto_long_long(&smp->caskb, endian_mismatch, arch_64);
591 smc->comkb = moveto_long_long(&smp->comkb, endian_mismatch, arch_64);
592 smc->activekb = moveto_long_long(&smp->activekb, endian_mismatch, arch_64);
593 smc->inactkb = moveto_long_long(&smp->inactkb, endian_mismatch, arch_64);
595 /* Some fields have been added without a structure format change */
596 if (st_size >= STATS_MEMORY_8A_1_SIZE) {
597 smc->dirtykb = moveto_long_long(&smp->dirtykb, endian_mismatch, arch_64);
599 if (st_size >= STATS_MEMORY_8A_2_SIZE) {
600 smc->anonpgkb = moveto_long_long(&smp->anonpgkb, endian_mismatch, arch_64);
601 smc->slabkb = moveto_long_long(&smp->slabkb, endian_mismatch, arch_64);
602 smc->kstackkb = moveto_long_long(&smp->kstackkb, endian_mismatch, arch_64);
603 smc->pgtblkb = moveto_long_long(&smp->pgtblkb, endian_mismatch, arch_64);
604 smc->vmusedkb = moveto_long_long(&smp->vmusedkb, endian_mismatch, arch_64);
606 if (st_size >= STATS_MEMORY_8A_SIZE) {
607 smc->availablekb = moveto_long_long(&(smp->availablekb), endian_mismatch, arch_64);;
612 ***************************************************************************
613 * Upgrade stats_ktables structure (from ACTIVITY_MAGIC_BASE format to
614 * ACTIVITY_MAGIC_BASE + 1 format).
617 * @act Array of activities.
618 * @p Position of activity in array.
620 * TRUE if data read from file don't match current machine's
622 ***************************************************************************
624 void upgrade_stats_ktables(struct activity *act[], int p, int endian_mismatch)
626 struct stats_ktables *skc = (struct stats_ktables *) act[p]->buf[1];
627 struct stats_ktables_8a *skp = (struct stats_ktables_8a *) act[p]->buf[0];
629 skc->file_used = moveto_long_long(&skp->file_used, endian_mismatch, FALSE);
630 skc->inode_used = moveto_long_long(&skp->inode_used, endian_mismatch, FALSE);
631 skc->dentry_stat = moveto_long_long(&skp->dentry_stat, endian_mismatch, FALSE);
632 skc->pty_nr = moveto_long_long(&skp->pty_nr, endian_mismatch, FALSE);
636 ***************************************************************************
637 * Upgrade stats_queue structure (from ACTIVITY_MAGIC_BASE or
638 * ACTIVITY_MAGIC_BASE + 1 format to ACTIVITY_MAGIC_BASE + 2 format).
641 * @act Array of activities.
642 * @p Position of activity in array.
643 * @magic Structure format magic value.
645 * TRUE if data read from file don't match current machine's
647 * @arch_64 TRUE if file's data come from a 64-bit machine.
648 ***************************************************************************
650 void upgrade_stats_queue(struct activity *act[], int p, unsigned int magic,
651 int endian_mismatch, int arch_64)
653 struct stats_queue *sqc = (struct stats_queue *) act[p]->buf[1];
655 if (magic == ACTIVITY_MAGIC_BASE) {
656 struct stats_queue_8a *sqp = (struct stats_queue_8a *) act[p]->buf[0];
658 sqc->nr_running = moveto_long_long(&sqp->nr_running, endian_mismatch, arch_64);
659 sqc->procs_blocked = 0ULL; /* New field */
660 sqc->nr_threads = moveto_long_long(&sqp->nr_threads, endian_mismatch, FALSE);
661 sqc->load_avg_1 = sqp->load_avg_1;
662 sqc->load_avg_5 = sqp->load_avg_5;
663 sqc->load_avg_15 = sqp->load_avg_15;
666 struct stats_queue_8b *sqp = (struct stats_queue_8b *) act[p]->buf[0];
668 sqc->nr_running = moveto_long_long(&sqp->nr_running, endian_mismatch, arch_64);
669 sqc->procs_blocked = moveto_long_long(&sqp->procs_blocked, endian_mismatch, arch_64);
670 sqc->nr_threads = moveto_long_long(&sqp->nr_threads, endian_mismatch, FALSE);
671 sqc->load_avg_1 = sqp->load_avg_1;
672 sqc->load_avg_5 = sqp->load_avg_5;
673 sqc->load_avg_15 = sqp->load_avg_15;
678 ***************************************************************************
679 * Upgrade stats_serial structure (from ACTIVITY_MAGIC_BASE format to
680 * ACTIVITY_MAGIC_BASE + 1 format).
683 * @act Array of activities.
684 * @p Position of activity in array.
685 * @st_size Size of the structure read from file.
687 * TRUE if data read from file don't match current machine's
691 * Number of serial line structures that actually need to be written to
693 ***************************************************************************
695 int upgrade_stats_serial(struct activity *act[], int p, size_t st_size, int endian_mismatch)
699 struct stats_serial *ssc;
701 /* Copy TTY stats to target structure */
702 memcpy(act[p]->buf[1], act[p]->buf[0], (size_t) act[p]->nr_ini * st_size);
704 for (i = 0; i < act[p]->nr_ini; i++) {
705 ssc = (struct stats_serial *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
707 /* Line number now starts at 0 instead of 1 */
708 line = (endian_mismatch ? __builtin_bswap32(ssc->line) : ssc->line);
712 ssc->line = (endian_mismatch ? __builtin_bswap32(line) : line);
719 ***************************************************************************
720 * Upgrade stats_disk structure (from ACTIVITY_MAGIC_BASE format to
721 * ACTIVITY_MAGIC_BASE + 1 format).
724 * @act Array of activities.
725 * @p Position of activity in array.
726 * @magic Structure format magic value.
728 * TRUE if data read from file don't match current machine's
730 * @arch_64 TRUE if file's data come from a 64-bit machine.
731 ***************************************************************************
733 void upgrade_stats_disk(struct activity *act[], int p, unsigned int magic,
734 int endian_mismatch, int arch_64)
737 struct stats_disk *sdc;
739 if (magic == ACTIVITY_MAGIC_BASE) {
740 struct stats_disk_8a *sdp;
742 for (i = 0; i < act[p]->nr_ini; i++) {
743 sdp = (struct stats_disk_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
744 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
746 sdc->nr_ios = moveto_long_long(&sdp->nr_ios, endian_mismatch, arch_64);
747 sdc->rd_sect = (unsigned long) sdp->rd_sect;
748 sdc->wr_sect = (unsigned long) sdp->wr_sect;
749 sdc->rd_ticks = (unsigned int) sdp->rd_ticks;
750 sdc->wr_ticks = (unsigned int) sdp->wr_ticks;
751 sdc->tot_ticks = (unsigned int) sdp->tot_ticks;
752 sdc->rq_ticks = (unsigned int) sdp->rq_ticks;
753 sdc->major = sdp->major;
754 sdc->minor = sdp->minor;
758 struct stats_disk_8b *sdp;
760 for (i = 0; i < act[p]->nr_ini; i++) {
761 sdp = (struct stats_disk_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
762 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
764 sdc->nr_ios = sdp->nr_ios;
765 memcpy(&sdc->rd_sect, &sdp->rd_sect, 8);
766 memcpy(&sdc->wr_sect, &sdp->wr_sect, 8);
767 sdc->rd_ticks = sdp->rd_ticks;
768 sdc->wr_ticks = sdp->wr_ticks;
769 sdc->tot_ticks = sdp->tot_ticks;
770 sdc->rq_ticks = sdp->rq_ticks;
771 sdc->major = sdp->major;
772 sdc->minor = sdp->minor;
778 ***************************************************************************
779 * Upgrade stats_net_dev structure (from ACTIVITY_MAGIC_BASE or
780 * ACTIVITY_MAGIC_BASE + 1 format to ACTIVITY_MAGIC_BASE + 3 format).
783 * @act Array of activities.
784 * @p Position of activity in array.
785 * @magic Structure format magic value.
787 * TRUE if data read from file don't match current machine's
789 * @arch_64 TRUE if file's data come from a 64-bit machine.
790 ***************************************************************************
792 void upgrade_stats_net_dev(struct activity *act[], int p, unsigned int magic,
793 int endian_mismatch, int arch_64)
796 struct stats_net_dev *sndc;
798 if (magic == ACTIVITY_MAGIC_BASE) {
799 struct stats_net_dev_8a *sndp;
801 for (i = 0; i < act[p]->nr_ini; i++) {
802 sndp = (struct stats_net_dev_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
803 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
805 sndc->rx_packets = moveto_long_long(&sndp->rx_packets, endian_mismatch, arch_64);
806 sndc->tx_packets = moveto_long_long(&sndp->tx_packets, endian_mismatch, arch_64);
807 sndc->rx_bytes = moveto_long_long(&sndp->rx_bytes, endian_mismatch, arch_64);
808 sndc->tx_bytes = moveto_long_long(&sndp->tx_bytes, endian_mismatch, arch_64);
809 sndc->rx_compressed = moveto_long_long(&sndp->rx_compressed, endian_mismatch, arch_64);
810 sndc->tx_compressed = moveto_long_long(&sndp->tx_compressed, endian_mismatch, arch_64);
811 sndc->multicast = moveto_long_long(&sndp->multicast, endian_mismatch, arch_64);
812 sndc->speed = 0; /* New field */
813 strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
814 sndc->interface[sizeof(sndc->interface) - 1] = '\0';
815 sndc->duplex = '\0'; /* New field */
818 else if (magic == ACTIVITY_MAGIC_BASE + 1) {
819 struct stats_net_dev_8b *sndp;
821 for (i = 0; i < act[p]->nr_ini; i++) {
822 sndp = (struct stats_net_dev_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
823 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
825 sndc->rx_packets = sndp->rx_packets;
826 sndc->tx_packets = sndp->tx_packets;
827 sndc->rx_bytes = sndp->rx_bytes;
828 sndc->tx_bytes = sndp->tx_bytes;
829 sndc->rx_compressed = sndp->rx_compressed;
830 sndc->tx_compressed = sndp->tx_compressed;
831 sndc->multicast = sndp->multicast;
832 sndc->speed = 0; /* New field */
833 strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
834 sndc->interface[sizeof(sndc->interface) - 1] = '\0';
835 sndc->duplex = '\0'; /* New field */
839 struct stats_net_dev_8c *sndp;
841 for (i = 0; i < act[p]->nr_ini; i++) {
842 sndp = (struct stats_net_dev_8c *) ((char *) act[p]->buf[0] + i * act[p]->msize);
843 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
845 sndc->rx_packets = sndp->rx_packets;
846 sndc->tx_packets = sndp->tx_packets;
847 sndc->rx_bytes = sndp->rx_bytes;
848 sndc->tx_bytes = sndp->tx_bytes;
849 sndc->rx_compressed = sndp->rx_compressed;
850 sndc->tx_compressed = sndp->tx_compressed;
851 sndc->multicast = sndp->multicast;
852 sndc->speed = sndp->speed;
853 strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
854 sndc->interface[sizeof(sndc->interface) - 1] = '\0';
855 sndc->duplex = sndp->duplex;
861 ***************************************************************************
862 * Upgrade stats_net_edev structure (from ACTIVITY_MAGIC_BASE format to
863 * ACTIVITY_MAGIC_BASE + 1 format).
866 * @act Array of activities.
867 * @p Position of activity in array.
868 * @magic Structure format magic value.
870 * TRUE if data read from file don't match current machine's
872 * @arch_64 TRUE if file's data come from a 64-bit machine.
873 ***************************************************************************
875 void upgrade_stats_net_edev(struct activity *act[], int p, unsigned int magic,
876 int endian_mismatch, int arch_64)
879 struct stats_net_edev *snedc;
881 if (magic == ACTIVITY_MAGIC_BASE) {
882 struct stats_net_edev_8a *snedp;
884 for (i = 0; i < act[p]->nr_ini; i++) {
885 snedp = (struct stats_net_edev_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
886 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
888 snedc->collisions = moveto_long_long(&snedp->collisions, endian_mismatch, arch_64);
889 snedc->rx_errors = moveto_long_long(&snedp->rx_errors, endian_mismatch, arch_64);
890 snedc->tx_errors = moveto_long_long(&snedp->tx_errors, endian_mismatch, arch_64);
891 snedc->rx_dropped = moveto_long_long(&snedp->rx_dropped, endian_mismatch, arch_64);
892 snedc->tx_dropped = moveto_long_long(&snedp->tx_dropped, endian_mismatch, arch_64);
893 snedc->rx_fifo_errors = moveto_long_long(&snedp->rx_fifo_errors, endian_mismatch, arch_64);
894 snedc->tx_fifo_errors = moveto_long_long(&snedp->tx_fifo_errors, endian_mismatch, arch_64);
895 snedc->rx_frame_errors = moveto_long_long(&snedp->rx_frame_errors, endian_mismatch, arch_64);
896 snedc->tx_carrier_errors = moveto_long_long(&snedp->tx_carrier_errors, endian_mismatch, arch_64);
897 strncpy(snedc->interface, snedp->interface, sizeof(snedc->interface));
898 snedc->interface[sizeof(snedc->interface) - 1] = '\0';
902 struct stats_net_edev_8b *snedp;
904 for (i = 0; i < act[p]->nr_ini; i++) {
905 snedp = (struct stats_net_edev_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
906 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
908 snedc->collisions = snedp->collisions;
909 snedc->rx_errors = snedp->rx_errors;
910 snedc->tx_errors = snedp->tx_errors;
911 snedc->rx_dropped = snedp->rx_dropped;
912 snedc->tx_dropped = snedp->tx_dropped;
913 snedc->rx_fifo_errors = snedp->rx_fifo_errors;
914 snedc->tx_fifo_errors = snedp->tx_fifo_errors;
915 snedc->rx_frame_errors = snedp->rx_frame_errors;
916 snedc->tx_carrier_errors = snedp->tx_carrier_errors;
917 strncpy(snedc->interface, snedp->interface, sizeof(snedc->interface));
918 snedc->interface[sizeof(snedc->interface) - 1] = '\0';
924 ***************************************************************************
925 * Upgrade stats_net_ip structure (from ACTIVITY_MAGIC_BASE format to
926 * ACTIVITY_MAGIC_BASE + 1 format).
929 * @act Array of activities.
930 * @p Position of activity in array.
931 * @magic Structure format magic value.
933 * TRUE if data read from file don't match current machine's
935 * @arch_64 TRUE if file's data come from a 64-bit machine.
936 ***************************************************************************
938 void upgrade_stats_net_ip(struct activity *act[], int p, unsigned int magic,
939 int endian_mismatch, int arch_64)
941 struct stats_net_ip *snic = (struct stats_net_ip *) act[p]->buf[1];
943 if (magic == ACTIVITY_MAGIC_BASE) {
944 struct stats_net_ip_8a *snip = (struct stats_net_ip_8a *) act[p]->buf[0];
946 snic->InReceives = moveto_long_long(&snip->InReceives, endian_mismatch, arch_64);
947 snic->ForwDatagrams = moveto_long_long(&snip->ForwDatagrams, endian_mismatch, arch_64);
948 snic->InDelivers = moveto_long_long(&snip->InDelivers, endian_mismatch, arch_64);
949 snic->OutRequests = moveto_long_long(&snip->OutRequests, endian_mismatch, arch_64);
950 snic->ReasmReqds = moveto_long_long(&snip->ReasmReqds, endian_mismatch, arch_64);
951 snic->ReasmOKs = moveto_long_long(&snip->ReasmOKs, endian_mismatch, arch_64);
952 snic->FragOKs = moveto_long_long(&snip->FragOKs, endian_mismatch, arch_64);
953 snic->FragCreates = moveto_long_long(&snip->FragCreates, endian_mismatch, arch_64);
956 struct stats_net_ip_8b *snip = (struct stats_net_ip_8b *) act[p]->buf[0];
958 snic->InReceives = snip->InReceives;
959 snic->ForwDatagrams = snip->ForwDatagrams;
960 snic->InDelivers = snip->InDelivers;
961 snic->OutRequests = snip->OutRequests;
962 snic->ReasmReqds = snip->ReasmReqds;
963 snic->ReasmOKs = snip->ReasmOKs;
964 snic->FragOKs = snip->FragOKs;
965 snic->FragCreates = snip->FragCreates;
970 ***************************************************************************
971 * Upgrade stats_net_eip structure (from ACTIVITY_MAGIC_BASE format to
972 * ACTIVITY_MAGIC_BASE + 1 format).
975 * @act Array of activities.
976 * @p Position of activity in array.
977 * @magic Structure format magic value.
979 * TRUE if data read from file don't match current machine's
981 * @arch_64 TRUE if file's data come from a 64-bit machine.
982 ***************************************************************************
984 void upgrade_stats_net_eip(struct activity *act[], int p, unsigned int magic,
985 int endian_mismatch, int arch_64)
987 struct stats_net_eip *sneic = (struct stats_net_eip *) act[p]->buf[1];
989 if (magic == ACTIVITY_MAGIC_BASE) {
990 struct stats_net_eip_8a *sneip = (struct stats_net_eip_8a *) act[p]->buf[0];
992 sneic->InHdrErrors = moveto_long_long(&sneip->InHdrErrors, endian_mismatch, arch_64);
993 sneic->InAddrErrors = moveto_long_long(&sneip->InAddrErrors, endian_mismatch, arch_64);
994 sneic->InUnknownProtos = moveto_long_long(&sneip->InUnknownProtos, endian_mismatch, arch_64);
995 sneic->InDiscards = moveto_long_long(&sneip->InDiscards, endian_mismatch, arch_64);
996 sneic->OutDiscards = moveto_long_long(&sneip->OutDiscards, endian_mismatch, arch_64);
997 sneic->OutNoRoutes = moveto_long_long(&sneip->OutNoRoutes, endian_mismatch, arch_64);
998 sneic->ReasmFails = moveto_long_long(&sneip->ReasmFails, endian_mismatch, arch_64);
999 sneic->FragFails = moveto_long_long(&sneip->FragFails, endian_mismatch, arch_64);
1002 struct stats_net_eip_8b *sneip = (struct stats_net_eip_8b *) act[p]->buf[0];
1004 sneic->InHdrErrors = sneip->InHdrErrors;
1005 sneic->InAddrErrors = sneip->InAddrErrors;
1006 sneic->InUnknownProtos = sneip->InUnknownProtos;
1007 sneic->InDiscards = sneip->InDiscards;
1008 sneic->OutDiscards = sneip->OutDiscards;
1009 sneic->OutNoRoutes = sneip->OutNoRoutes;
1010 sneic->ReasmFails = sneip->ReasmFails;
1011 sneic->FragFails = sneip->FragFails;
1016 ***************************************************************************
1017 * Upgrade stats_net_ip6 structure (from ACTIVITY_MAGIC_BASE format to
1018 * ACTIVITY_MAGIC_BASE + 1 format).
1021 * @act Array of activities.
1022 * @p Position of activity in array.
1023 * @magic Structure format magic value.
1025 * TRUE if data read from file don't match current machine's
1027 * @arch_64 TRUE if file's data come from a 64-bit machine.
1028 ***************************************************************************
1030 void upgrade_stats_net_ip6(struct activity *act[], int p, unsigned int magic,
1031 int endian_mismatch, int arch_64)
1033 struct stats_net_ip6 *snic6 = (struct stats_net_ip6 *) act[p]->buf[1];
1035 if (magic == ACTIVITY_MAGIC_BASE) {
1036 struct stats_net_ip6_8a *snip6 = (struct stats_net_ip6_8a *) act[p]->buf[0];
1038 snic6->InReceives6 = moveto_long_long(&snip6->InReceives6, endian_mismatch, arch_64);
1039 snic6->OutForwDatagrams6 = moveto_long_long(&snip6->OutForwDatagrams6, endian_mismatch, arch_64);
1040 snic6->InDelivers6 = moveto_long_long(&snip6->InDelivers6, endian_mismatch, arch_64);
1041 snic6->OutRequests6 = moveto_long_long(&snip6->OutRequests6, endian_mismatch, arch_64);
1042 snic6->ReasmReqds6 = moveto_long_long(&snip6->ReasmReqds6, endian_mismatch, arch_64);
1043 snic6->ReasmOKs6 = moveto_long_long(&snip6->ReasmOKs6, endian_mismatch, arch_64);
1044 snic6->InMcastPkts6 = moveto_long_long(&snip6->InMcastPkts6, endian_mismatch, arch_64);
1045 snic6->OutMcastPkts6 = moveto_long_long(&snip6->OutMcastPkts6, endian_mismatch, arch_64);
1046 snic6->FragOKs6 = moveto_long_long(&snip6->FragOKs6, endian_mismatch, arch_64);
1047 snic6->FragCreates6 = moveto_long_long(&snip6->FragCreates6, endian_mismatch, arch_64);
1050 struct stats_net_ip6_8b *snip6 = (struct stats_net_ip6_8b *) act[p]->buf[0];
1052 snic6->InReceives6 = snip6->InReceives6;
1053 snic6->OutForwDatagrams6 = snip6->OutForwDatagrams6;
1054 snic6->InDelivers6 = snip6->InDelivers6;
1055 snic6->OutRequests6 = snip6->OutRequests6;
1056 snic6->ReasmReqds6 = snip6->ReasmReqds6;
1057 snic6->ReasmOKs6 = snip6->ReasmOKs6;
1058 snic6->InMcastPkts6 = snip6->InMcastPkts6;
1059 snic6->OutMcastPkts6 = snip6->OutMcastPkts6;
1060 snic6->FragOKs6 = snip6->FragOKs6;
1061 snic6->FragCreates6 = snip6->FragCreates6;
1066 ***************************************************************************
1067 * Upgrade stats_net_eip6 structure (from ACTIVITY_MAGIC_BASE format to
1068 * ACTIVITY_MAGIC_BASE + 1 format).
1071 * @act Array of activities.
1072 * @p Position of activity in array.
1073 * @magic Structure format magic value.
1075 * TRUE if data read from file don't match current machine's
1077 * @arch_64 TRUE if file's data come from a 64-bit machine.
1078 ***************************************************************************
1080 void upgrade_stats_net_eip6(struct activity *act[], int p, unsigned int magic,
1081 int endian_mismatch, int arch_64)
1083 struct stats_net_eip6 *sneic6 = (struct stats_net_eip6 *) act[p]->buf[1];
1085 if (magic == ACTIVITY_MAGIC_BASE) {
1086 struct stats_net_eip6_8a *sneip6 = (struct stats_net_eip6_8a *) act[p]->buf[0];
1088 sneic6->InHdrErrors6 = moveto_long_long(&sneip6->InHdrErrors6, endian_mismatch, arch_64);
1089 sneic6->InAddrErrors6 = moveto_long_long(&sneip6->InAddrErrors6, endian_mismatch, arch_64);
1090 sneic6->InUnknownProtos6 = moveto_long_long(&sneip6->InUnknownProtos6, endian_mismatch, arch_64);
1091 sneic6->InTooBigErrors6 = moveto_long_long(&sneip6->InTooBigErrors6, endian_mismatch, arch_64);
1092 sneic6->InDiscards6 = moveto_long_long(&sneip6->InDiscards6, endian_mismatch, arch_64);
1093 sneic6->OutDiscards6 = moveto_long_long(&sneip6->OutDiscards6, endian_mismatch, arch_64);
1094 sneic6->InNoRoutes6 = moveto_long_long(&sneip6->InNoRoutes6, endian_mismatch, arch_64);
1095 sneic6->OutNoRoutes6 = moveto_long_long(&sneip6->OutNoRoutes6, endian_mismatch, arch_64);
1096 sneic6->ReasmFails6 = moveto_long_long(&sneip6->ReasmFails6, endian_mismatch, arch_64);
1097 sneic6->FragFails6 = moveto_long_long(&sneip6->FragFails6, endian_mismatch, arch_64);
1098 sneic6->InTruncatedPkts6 = moveto_long_long(&sneip6->InTruncatedPkts6, endian_mismatch, arch_64);
1101 struct stats_net_eip6_8b *sneip6 = (struct stats_net_eip6_8b *) act[p]->buf[0];
1103 sneic6->InHdrErrors6 = sneip6->InHdrErrors6;
1104 sneic6->InAddrErrors6 = sneip6->InAddrErrors6;
1105 sneic6->InUnknownProtos6 = sneip6->InUnknownProtos6;
1106 sneic6->InTooBigErrors6 = sneip6->InTooBigErrors6;
1107 sneic6->InDiscards6 = sneip6->InDiscards6;
1108 sneic6->OutDiscards6 = sneip6->OutDiscards6;
1109 sneic6->InNoRoutes6 = sneip6->InNoRoutes6;
1110 sneic6->OutNoRoutes6 = sneip6->OutNoRoutes6;
1111 sneic6->ReasmFails6 = sneip6->ReasmFails6;
1112 sneic6->FragFails6 = sneip6->FragFails6;
1113 sneic6->InTruncatedPkts6 = sneip6->InTruncatedPkts6;
1118 ***************************************************************************
1119 * Upgrade stats_huge structure (from ACTIVITY_MAGIC_BASE format to
1120 * ACTIVITY_MAGIC_BASE + 1 format).
1123 * @act Array of activities.
1124 * @p Position of activity in array.
1126 * TRUE if data read from file don't match current machine's
1128 * @arch_64 TRUE if file's data come from a 64-bit machine.
1129 ***************************************************************************
1131 void upgrade_stats_huge(struct activity *act[], int p,
1132 int endian_mismatch, int arch_64)
1134 struct stats_huge *shc = (struct stats_huge *) act[p]->buf[1];
1135 struct stats_huge_8a *shp = (struct stats_huge_8a *) act[p]->buf[0];
1137 shc->frhkb = moveto_long_long(&shp->frhkb, endian_mismatch, arch_64);
1138 shc->tlhkb = moveto_long_long(&shp->tlhkb, endian_mismatch, arch_64);
1142 ***************************************************************************
1143 * Upgrade stats_pwr_wghfreq structure (from ACTIVITY_MAGIC_BASE format to
1144 * ACTIVITY_MAGIC_BASE + 1 format).
1147 * @act Array of activities.
1148 * @p Position of activity in array.
1149 ***************************************************************************
1151 void upgrade_stats_pwr_wghfreq(struct activity *act[], int p)
1155 struct stats_pwr_wghfreq *spc, *spc_k;
1156 struct stats_pwr_wghfreq_8a *spp, *spp_k;
1158 for (i = 0; i < act[p]->nr_ini; i++) {
1159 spp = (struct stats_pwr_wghfreq_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize * act[p]->nr2);
1160 spc = (struct stats_pwr_wghfreq *) ((char *) act[p]->buf[1] + i * act[p]->fsize * act[p]->nr2);
1162 for (k = 0; k < act[p]->nr2; k++) {
1163 spp_k = (struct stats_pwr_wghfreq_8a *) ((char *) spp + k * act[p]->msize);
1166 spc_k = (struct stats_pwr_wghfreq *) ((char *) spc + k * act[p]->fsize);
1168 spc_k->time_in_state = spp_k->time_in_state;
1169 memcpy(&spc_k->freq, &spp_k->freq, 8);
1175 ***************************************************************************
1176 * Upgrade stats_filesystem structure (from ACTIVITY_MAGIC_BASE format to
1177 * ACTIVITY_MAGIC_BASE + 1 format).
1180 * @act Array of activities.
1181 * @p Position of activity in array.
1182 * @st_size Size of the structure read from file.
1183 ***************************************************************************
1185 void upgrade_stats_filesystem(struct activity *act[], int p, int st_size)
1188 struct stats_filesystem *sfc;
1189 struct stats_filesystem_8a *sfp;
1191 for (i = 0; i < act[p]->nr_ini; i++) {
1192 sfp = (struct stats_filesystem_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
1193 sfc = (struct stats_filesystem *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1195 sfc->f_blocks = sfp->f_blocks;
1196 sfc->f_bfree = sfp->f_bfree;
1197 sfc->f_bavail = sfp->f_bavail;
1198 sfc->f_files = sfp->f_files;
1199 sfc->f_ffree = sfp->f_ffree;
1200 strncpy(sfc->fs_name, sfp->fs_name, sizeof(sfc->fs_name));
1201 sfc->fs_name[sizeof(sfc->fs_name) - 1] = '\0';
1203 if (st_size <= STATS_FILESYSTEM_8A_1_SIZE) {
1204 /* mountp didn't exist with older versions */
1205 sfc->mountp[0] = '\0';
1208 strncpy(sfc->mountp, sfp->mountp, sizeof(sfc->mountp));
1209 sfc->mountp[sizeof(sfc->mountp) - 1] = '\0';
1215 ***************************************************************************
1216 * Count number of stats_disk structures that need to be written.
1219 * @act Array of activities.
1220 * @p Position of activity in array.
1221 ***************************************************************************
1223 __nr_t count_stats_disk(struct activity *act[], int p)
1227 struct stats_disk *sdc;
1229 for (i = 0; i < act[p]->nr_ini; i++) {
1230 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1231 if (!(sdc->major + sdc->minor))
1241 ***************************************************************************
1242 * Count number of stats_net_dev structures that need to be written.
1245 * @act Array of activities.
1246 * @p Position of activity in array.
1247 ***************************************************************************
1249 __nr_t count_stats_net_dev(struct activity *act[], int p)
1253 struct stats_net_dev *sndc;
1255 for (i = 0; i < act[p]->nr_ini; i++) {
1256 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1257 if (!strcmp(sndc->interface, ""))
1267 ***************************************************************************
1268 * Count number of stats_net_edev structures that need to be written.
1271 * @act Array of activities.
1272 * @p Position of activity in array.
1273 ***************************************************************************
1275 __nr_t count_stats_net_edev(struct activity *act[], int p)
1279 struct stats_net_edev *snedc;
1281 for (i = 0; i < act[p]->nr_ini; i++) {
1282 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1283 if (!strcmp(snedc->interface, ""))
1293 ***************************************************************************
1294 * Count number of stats_pwr_usb structures that need to be written.
1297 * @act Array of activities.
1298 * @p Position of activity in array.
1299 ***************************************************************************
1301 __nr_t count_stats_pwr_usb(struct activity *act[], int p)
1305 struct stats_pwr_usb *suc;
1307 for (i = 0; i < act[p]->nr_ini; i++) {
1308 suc = (struct stats_pwr_usb *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1319 ***************************************************************************
1320 * Count number of stats_filesystem structures that need to be written.
1323 * @act Array of activities.
1324 * @p Position of activity in array.
1325 ***************************************************************************
1327 __nr_t count_stats_filesystem(struct activity *act[], int p)
1331 struct stats_filesystem *sfc;
1333 for (i = 0; i < act[p]->nr_ini; i++) {
1334 sfc = (struct stats_filesystem *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1345 ***************************************************************************
1346 * Count number of stats_fchost structures that need to be written.
1349 * @act Array of activities.
1350 * @p Position of activity in array.
1351 ***************************************************************************
1353 __nr_t count_stats_fchost(struct activity *act[], int p)
1357 struct stats_fchost *sfcc;
1359 for (i = 0; i < act[p]->nr_ini; i++) {
1360 sfcc = (struct stats_fchost *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1361 if (!sfcc->fchost_name[0])
1371 ***************************************************************************
1372 * Upgrade file's activity list section.
1375 * @stdfd File descriptor for STDOUT.
1376 * @act Array of activities.
1377 * @file_hdr Pointer on file_header structure.
1378 * @ofile_actlst Activity list in file.
1380 * TRUE if data read from file don't match current machine's
1382 * @arch_64 TRUE if file's data come from a 64-bit machine.
1385 * @file_actlst Activity list with up-to-date format.
1388 * -1 on error, 0 otherwise.
1389 ***************************************************************************
1391 int upgrade_activity_section(int stdfd, struct activity *act[],
1392 struct file_header *file_hdr,
1393 struct old_file_activity *ofile_actlst,
1394 struct file_activity **file_actlst,
1395 int endian_mismatch, int arch_64)
1398 struct old_file_activity *ofal;
1399 struct file_activity *fal, fa;
1401 fprintf(stderr, "file_activity: ");
1403 SREALLOC(*file_actlst, struct file_activity, FILE_ACTIVITY_SIZE * file_hdr->sa_act_nr);
1405 ofal = ofile_actlst;
1407 for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++, fal++) {
1409 /* Every activity should be known at the moment (may change in the future) */
1410 p = get_activity_position(act, ofal->id, EXIT_IF_NOT_FOUND);
1413 fal->nr2 = ofal->nr2;
1414 fal->magic = act[p]->magic; /* Update activity magic number */
1415 fal->has_nr = HAS_COUNT_FUNCTION(act[p]->options);
1416 /* Also update its size, which may have changed with recent versions */
1417 fal->size = act[p]->fsize;
1418 for (j = 0; j < 3; j++) {
1419 fal->types_nr[j] = act[p]->gtypes_nr[j];
1422 memcpy(&fa, fal, FILE_ACTIVITY_SIZE);
1423 /* Restore endianness before writing */
1424 if (endian_mismatch) {
1425 /* Start swapping at field "header_size" position */
1426 swap_struct(act_types_nr, &fa, arch_64);
1430 * Even unknown activities must be written
1431 * (they are counted in sa_act_nr).
1433 if (write_all(stdfd, &fa, FILE_ACTIVITY_SIZE) != FILE_ACTIVITY_SIZE) {
1434 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1437 fprintf(stderr, "%s ", act[p]->name);
1440 fprintf(stderr, "OK\n");
1446 ***************************************************************************
1447 * Upgrade a record header.
1450 * @fd File descriptor for sa datafile to convert.
1451 * @stdfd File descriptor for STDOUT.
1452 * @orec_hdr Record's header structure to convert.
1454 * TRUE if data read from file don't match current machine's
1456 * @arch_64 TRUE if file's data come from a 64-bit machine.
1459 * -1 on error, 0 otherwise.
1460 ***************************************************************************
1462 int upgrade_record_header(int fd, int stdfd, struct old_record_header *orec_hdr,
1463 int endian_mismatch, int arch_64)
1465 struct record_header rec_hdr;
1467 memset(&rec_hdr, 0, sizeof(struct record_header));
1469 /* Convert current record header */
1470 rec_hdr.uptime_cs = orec_hdr->uptime0 * 100 / HZ; /* Uptime in cs, not jiffies */
1471 rec_hdr.ust_time = (unsigned long long) orec_hdr->ust_time;
1472 rec_hdr.record_type = orec_hdr->record_type;
1473 rec_hdr.hour = orec_hdr->hour;
1474 rec_hdr.minute = orec_hdr->minute;
1475 rec_hdr.second = orec_hdr->second;
1477 /* Restore endianness before writing */
1478 if (endian_mismatch) {
1479 swap_struct(rec_types_nr, &rec_hdr, arch_64);
1482 /* Write record header */
1483 if (write_all(stdfd, &rec_hdr, RECORD_HEADER_SIZE) != RECORD_HEADER_SIZE) {
1484 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1488 fprintf(stderr, "H");
1494 ***************************************************************************
1495 * Upgrade a COMMENT record.
1498 * @fd File descriptor for sa datafile to convert.
1499 * @stdfd File descriptor for STDOUT.
1502 * -1 on error, 0 otherwise.
1503 ***************************************************************************
1505 int upgrade_comment_record(int fd, int stdfd)
1507 char file_comment[MAX_COMMENT_LEN];
1509 /* Read the COMMENT record */
1510 sa_fread(fd, file_comment, sizeof(file_comment), HARD_SIZE, UEOF_STOP);
1511 file_comment[sizeof(file_comment) - 1] = '\0';
1513 /* Then write it. No changes at this time */
1514 if (write_all(stdfd, file_comment, sizeof(file_comment)) != sizeof(file_comment)) {
1515 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1519 fprintf(stderr, "C");
1525 ***************************************************************************
1526 * Upgrade a RESTART record.
1529 * @fd File descriptor for sa datafile to convert.
1530 * @stdfd File descriptor for STDOUT.
1531 * @act Array of activities.
1532 * @file_hdr Pointer on file_header structure.
1534 * TRUE is sa datafile has an old format which is no longer
1535 * compatible with current one.
1537 * TRUE if data read from file don't match current machine's
1539 * @arch_64 TRUE if file's data come from a 64-bit machine.
1540 * @vol_act_nr Number of volatile activity structures.
1543 * -1 on error, 0 otherwise.
1544 ***************************************************************************
1546 int upgrade_restart_record(int fd, int stdfd, struct activity *act[],
1547 struct file_header *file_hdr, int previous_format,
1548 int endian_mismatch, int arch_64, unsigned int vol_act_nr)
1552 struct old_file_activity ofile_act;
1553 /* Number of cpu read in the activity list. See upgrade_header_section() */
1554 __nr_t cpu_nr = file_hdr->sa_cpu_nr;
1556 if (previous_format == FORMAT_MAGIC_2173) {
1558 * For versions from 10.3.1 to 11.6.x,
1559 * the restart record is followed by a list
1560 * of volatile activity structures. Among them is A_CPU activity.
1562 for (i = 0; i < vol_act_nr; i++) {
1563 sa_fread(fd, &ofile_act, OLD_FILE_ACTIVITY_SIZE, HARD_SIZE, UEOF_STOP);
1565 /* Normalize endianness for file_activity structures */
1566 if (endian_mismatch) {
1567 swap_struct(oact_types_nr, &ofile_act, arch_64);
1570 if (ofile_act.id && (ofile_act.nr > 0)) {
1571 p = get_activity_position(act, ofile_act.id, EXIT_IF_NOT_FOUND);
1572 act[p]->nr_ini = ofile_act.nr;
1574 if (ofile_act.id == A_CPU) {
1575 cpu_nr = ofile_act.nr;
1579 /* Reallocate structures */
1580 allocate_structures(act);
1583 /* Restore endianness before writing */
1584 if (endian_mismatch) {
1585 cpu_nr = __builtin_bswap32(cpu_nr);
1588 /* Write new number of CPU following the restart record */
1589 if (write_all(stdfd, &cpu_nr, sizeof(__nr_t)) != sizeof(__nr_t)) {
1590 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1594 fprintf(stderr, "R");
1600 ***************************************************************************
1601 * Upgrade a record which is not a COMMENT or a RESTART one.
1604 * @fd File descriptor for sa datafile to convert.
1605 * @stdfd File descriptor for STDOUT.
1606 * @act Array of activities.
1607 * @file_hdr Pointer on file_header structure (up-to-date format).
1609 * Activity list in file.
1610 * @file_actlst Activity list in file (up-to-date format).
1612 * TRUE if data read from file don't match current machine's
1614 * @arch_64 TRUE if file's data come from a 64-bit machine.
1617 * -1 on error, 0 otherwise.
1618 ***************************************************************************
1620 int upgrade_common_record(int fd, int stdfd, struct activity *act[], struct file_header *file_hdr,
1621 struct old_file_activity *ofile_actlst, struct file_activity *file_actlst,
1622 int endian_mismatch, int arch_64)
1625 __nr_t nr_struct, nr;
1626 struct old_file_activity *ofal = ofile_actlst;
1627 struct file_activity *fal = file_actlst;
1631 * This is not a special record, so read the extra fields,
1632 * even if the format of the activity is unknown.
1634 for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++, fal++) {
1636 /* Every activity should be known at the moment (may change in the future) */
1637 p = get_activity_position(act, fal->id, EXIT_IF_NOT_FOUND);
1639 /* Warning: Stats structures keep their original endianness here */
1640 if ((act[p]->nr_ini > 0) &&
1641 ((act[p]->nr_ini > 1) || (act[p]->nr2 > 1)) &&
1642 (act[p]->msize > ofal->size)) {
1643 for (j = 0; j < act[p]->nr_ini; j++) {
1644 for (k = 0; k < act[p]->nr2; k++) {
1646 (char *) act[p]->buf[0] + (j * act[p]->nr2 + k) * act[p]->msize,
1647 (size_t) ofal->size, HARD_SIZE, UEOF_STOP);
1651 else if (act[p]->nr_ini > 0) {
1652 sa_fread(fd, act[p]->buf[0],
1653 (size_t) ofal->size * (size_t) act[p]->nr_ini * (size_t) act[p]->nr2,
1654 HARD_SIZE, UEOF_STOP);
1657 nr_struct = act[p]->nr_ini;
1659 * NB: Cannot upgrade a stats structure with
1660 * a magic number higher than currently known.
1662 if (ofal->magic < act[p]->magic) {
1665 /* Known activity but old format */
1669 upgrade_stats_cpu(act, p, ofal->size);
1673 upgrade_stats_pcsw(act, p);
1677 upgrade_stats_irq(act, p);
1681 upgrade_stats_io(act, p, endian_mismatch);
1685 upgrade_stats_queue(act, p, ofal->magic,
1686 endian_mismatch, arch_64);
1690 upgrade_stats_memory(act, p, ofal->size,
1691 endian_mismatch, arch_64);
1695 upgrade_stats_ktables(act, p, endian_mismatch);
1699 nr_struct = upgrade_stats_serial(act, p, ofal->size,
1704 upgrade_stats_disk(act, p, ofal->magic,
1705 endian_mismatch, arch_64);
1709 upgrade_stats_net_dev(act, p, ofal->magic,
1710 endian_mismatch, arch_64);
1714 upgrade_stats_net_edev(act, p, ofal->magic,
1715 endian_mismatch, arch_64);
1719 upgrade_stats_net_ip(act, p, ofal->magic,
1720 endian_mismatch, arch_64);
1724 upgrade_stats_net_eip(act, p, ofal->magic,
1725 endian_mismatch, arch_64);
1729 upgrade_stats_net_ip6(act, p, ofal->magic,
1730 endian_mismatch, arch_64);
1734 upgrade_stats_net_eip6(act, p, ofal->magic,
1735 endian_mismatch, arch_64);
1739 upgrade_stats_huge(act, p, endian_mismatch, arch_64);
1743 upgrade_stats_pwr_wghfreq(act, p);
1747 upgrade_stats_filesystem(act, p, ofal->size);
1753 /* Known activity with current up-to-date format */
1754 for (j = 0; j < act[p]->nr_ini; j++) {
1755 for (k = 0; k < act[p]->nr2; k++) {
1756 memcpy((char *) act[p]->buf[1] + (j * act[p]->nr2 + k) * act[p]->msize,
1757 (char *) act[p]->buf[0] + (j * act[p]->nr2 + k) * act[p]->msize,
1768 /* Nothing to do: Already done in upgrade_stats_serial() */
1772 nr_struct = count_stats_disk(act, p);
1776 nr_struct = count_stats_net_dev(act, p);
1780 nr_struct = count_stats_net_edev(act, p);
1784 nr_struct = count_stats_pwr_usb(act, p);
1788 nr_struct = count_stats_filesystem(act, p);
1792 nr_struct = count_stats_fchost(act, p);
1796 /* Restore endianness before writing */
1797 if (endian_mismatch) {
1798 nr = __builtin_bswap32(nr_struct);
1804 /* Write number of structures for current activity */
1805 if (write_all(stdfd, &nr, sizeof(__nr_t)) != sizeof(__nr_t))
1808 fprintf(stderr, "n");
1811 for (j = 0; j < nr_struct; j++) {
1812 for (k = 0; k < act[p]->nr2; k++) {
1813 if (write_all(stdfd,
1814 (char *) act[p]->buf[1] + (j * act[p]->nr2 + k) * act[p]->fsize,
1815 act[p]->fsize) != act[p]->fsize)
1819 fprintf(stderr, "%c", cc);
1826 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1833 ***************************************************************************
1834 * Upgrade statistics records.
1837 * @fd File descriptor for sa datafile to convert.
1838 * @stdfd File descriptor for STDOUT.
1839 * @act Array of activities.
1840 * @file_hdr Pointer on file_header structure.
1842 * Activity list in file.
1843 * @file_actlst Activity list with up-to-date format.
1845 * TRUE is sa datafile has an old format which is no longer * @endian_mismatch
1846 * TRUE if data read from file don't match current machine's
1848 * @arch_64 TRUE if file's data come from a 64-bit machine.
1850 * compatible with current one.
1852 * TRUE if data read from file don't match current machine's
1854 * @arch_64 TRUE if file's data come from a 64-bit machine.
1855 * @vol_act_nr Number of volatile activity structures.
1858 * -1 on error, 0 otherwise.
1859 ***************************************************************************
1861 int upgrade_stat_records(int fd, int stdfd, struct activity *act[], struct file_header *file_hdr,
1862 struct old_file_activity *ofile_actlst, struct file_activity *file_actlst,
1863 int previous_format, int endian_mismatch, int arch_64,
1864 unsigned int vol_act_nr)
1868 struct old_record_header orec_hdr;
1869 unsigned int orec_types_nr[] = {OLD_RECORD_HEADER_ULL_NR, OLD_RECORD_HEADER_UL_NR, OLD_RECORD_HEADER_U_NR};
1871 fprintf(stderr, _("Statistics:\n"));
1874 eosaf = sa_fread(fd, &orec_hdr, OLD_RECORD_HEADER_SIZE, SOFT_SIZE, UEOF_STOP);
1876 /* Normalize endianness */
1877 if (endian_mismatch) {
1878 swap_struct(orec_types_nr, &orec_hdr, arch_64);
1880 rtype = orec_hdr.record_type;
1883 /* Upgrade current record header */
1884 if (upgrade_record_header(fd, stdfd, &orec_hdr,
1885 endian_mismatch, arch_64) < 0)
1888 if (rtype == R_COMMENT) {
1889 /* Upgrade the COMMENT record */
1890 if (upgrade_comment_record(fd, stdfd) < 0)
1893 else if (rtype == R_RESTART) {
1894 /* Upgrade the RESTART record */
1895 if (upgrade_restart_record(fd, stdfd, act, file_hdr,
1896 previous_format, endian_mismatch,
1897 arch_64, vol_act_nr) < 0)
1901 /* Upgrade current statistics record */
1902 if (upgrade_common_record(fd, stdfd, act, file_hdr, ofile_actlst,
1903 file_actlst, endian_mismatch, arch_64) < 0)
1910 fprintf(stderr, "\n");
1916 ***************************************************************************
1917 * Close file descriptors and exit.
1920 * @fd File descriptor for sa datafile to convert.
1921 * @stdfd File descriptor for STDOUT.
1922 * @exit_code Exit code.
1923 ***************************************************************************
1925 void upgrade_exit(int fd, int stdfd, int exit_code)
1939 ***************************************************************************
1940 * Convert a sysstat activity data file from a previous version to the
1941 * up-to-date format. Presently data files from sysstat version 9.1.6 and
1942 * later are converted to current sysstat version format.
1945 * @dfile System activity data file name.
1946 * @act Array of activities.
1947 ***************************************************************************
1949 void convert_file(char dfile[], struct activity *act[])
1951 int fd = 0, stdfd = 0, previous_format = 0;
1953 unsigned int vol_act_nr = 0, hdr_size;
1954 struct file_magic file_magic;
1955 struct file_header file_hdr;
1956 struct file_activity *file_actlst = NULL;
1957 struct old_file_activity *ofile_actlst = NULL;
1960 if ((stdfd = dup(STDOUT_FILENO)) < 0) {
1962 upgrade_exit(0, 0, 2);
1965 /* Upgrade file's magic section */
1966 if (upgrade_magic_section(dfile, &fd, stdfd, &file_magic, &hdr_size,
1967 &previous_format, &endian_mismatch) < 0) {
1968 upgrade_exit(fd, stdfd, 2);
1970 if (previous_format == FORMAT_MAGIC) {
1971 /* Nothing to do at the present time */
1972 fprintf(stderr, _("\nFile format already up-to-date\n"));
1981 /* HZ set on the command line with option -O */
1984 fprintf(stderr, _("HZ: Using current value: %lu\n"), HZ);
1986 /* Upgrade file's header section */
1987 if (upgrade_header_section(dfile, fd, stdfd, act, &file_magic,
1988 &file_hdr, hdr_size, previous_format, &arch_64,
1989 endian_mismatch, &vol_act_nr, &ofile_actlst) < 0) {
1990 upgrade_exit(fd, stdfd, 2);
1993 /* Upgrade file's activity list section */
1994 if (upgrade_activity_section(stdfd, act, &file_hdr,
1995 ofile_actlst, &file_actlst,
1996 endian_mismatch, arch_64) < 0) {
1997 upgrade_exit(fd, stdfd, 2);
2000 /* Perform required allocations */
2001 allocate_structures(act);
2003 /* Upgrade statistics records */
2004 if (upgrade_stat_records(fd, stdfd, act, &file_hdr, ofile_actlst, file_actlst,
2005 previous_format, endian_mismatch, arch_64,
2007 upgrade_exit(fd, stdfd, 2);
2012 free_structures(act);
2015 _("File successfully converted to sysstat format version %s\n"),
2019 upgrade_exit(fd, stdfd, 0);