2 * sa_conv.c: Convert an old format sa file to the up-to-date format.
3 * (C) 1999-2017 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 act_types_nr[];
42 extern unsigned int rec_types_nr[];
43 extern unsigned int hdr_types_nr[];
45 unsigned int oact_types_nr[] = {OLD_FILE_ACTIVITY_ULL_NR, OLD_FILE_ACTIVITY_UL_NR, OLD_FILE_ACTIVITY_U_NR};
48 ***************************************************************************
49 * Read and upgrade file's magic data section.
52 * @dfile System activity data file name.
53 * @stdfd File descriptor for STDOUT.
56 * @fd File descriptor for sa datafile to convert.
57 * @file_magic File's magic structure.
58 * @hdr_size Size of header structure read from file.
60 * Format magic number of file to convert, converted to
63 * TRUE if data read from file don't match current machine's
67 * -1 on error, 0 otherwise.
68 ***************************************************************************
70 int upgrade_magic_section(char dfile[], int *fd, int stdfd, struct file_magic *file_magic,
71 unsigned int *hdr_size, int *previous_format, int *endian_mismatch)
74 unsigned int fm_types_nr[] = {FILE_MAGIC_ULL_NR, FILE_MAGIC_UL_NR, FILE_MAGIC_U_NR};
76 /* Open and read sa magic structure */
77 sa_open_read_magic(fd, dfile, file_magic, TRUE, endian_mismatch, FALSE);
79 switch (file_magic->format_magic) {
82 case FORMAT_MAGIC_SWAPPED:
83 *previous_format = FORMAT_MAGIC;
87 case FORMAT_MAGIC_2171:
88 case FORMAT_MAGIC_2171_SWAPPED:
89 *previous_format = FORMAT_MAGIC_2171;
92 case FORMAT_MAGIC_2173:
93 case FORMAT_MAGIC_2173_SWAPPED:
94 *previous_format = FORMAT_MAGIC_2173;
98 fprintf(stderr, _("Cannot convert the format of this file\n"));
103 fprintf(stderr, "file_magic: ");
104 if (*previous_format == FORMAT_MAGIC_2171) {
106 * We have read too many bytes: file_magic structure
107 * was smaller with previous sysstat versions.
108 * Go back 4 (unsigned int header_size) + 64 (char pad[64]) bytes.
110 if (lseek(*fd, -68, SEEK_CUR) < 0) {
111 fprintf(stderr, "\nlseek: %s\n", strerror(errno));
116 /* Set format magic number to that of current version */
117 file_magic->format_magic = (*endian_mismatch ? FORMAT_MAGIC_SWAPPED
120 /* Save original header structure's size */
121 *hdr_size = file_magic->header_size;
123 /* Fill new structure members */
124 file_magic->header_size = FILE_HEADER_SIZE;
125 file_magic->hdr_types_nr[0] = FILE_HEADER_ULL_NR;
126 file_magic->hdr_types_nr[1] = FILE_HEADER_UL_NR;
127 file_magic->hdr_types_nr[2] = FILE_HEADER_U_NR;
128 memset(file_magic->pad, 0, sizeof(unsigned char) * FILE_MAGIC_PADDING);
130 /* Indicate that file has been upgraded */
131 enum_version_nr(&fm);
132 file_magic->upgraded = (fm.sysstat_patchlevel << 8) +
133 fm.sysstat_sublevel + 1;
135 memcpy(&fm, file_magic, FILE_MAGIC_SIZE);
136 /* Restore endianness before writing */
137 if (*endian_mismatch) {
138 /* Start swapping at field "header_size" position */
139 swap_struct(fm_types_nr, &(fm.header_size), 0);
142 /* Write file's magic structure */
143 if (write(stdfd, &fm, FILE_MAGIC_SIZE) != FILE_MAGIC_SIZE) {
144 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
147 fprintf(stderr, "OK\n");
153 ***************************************************************************
154 * Upgrade file_header structure (from 0x2171 format to current format).
157 * @buffer File's header structure (as read from file).
159 * Format magic number of file to convert.
161 * TRUE if data read from file don't match current
162 * machine's endianness.
165 * @file_hdr File's header structure (up-to-date format).
166 * @arch_64 TRUE if file's data come from a 64-bit machine.
167 * @vol_act_nr Number of volatile activity structures following a restart
168 * record for 0x2173 file format.
169 ***************************************************************************
171 void upgrade_file_header(void *buffer, struct file_header *file_hdr, int previous_format,
172 int endian_mismatch, int *arch_64, unsigned int *vol_act_nr)
174 struct file_header_2171 *f_hdr_2171 = (struct file_header_2171 *) buffer;
175 struct file_header_2173 *f_hdr_2173 = (struct file_header_2173 *) buffer;
176 unsigned int hdr_2171_types_nr[] = {FILE_HEADER_2171_ULL_NR, FILE_HEADER_2171_UL_NR, FILE_HEADER_2171_U_NR};
177 unsigned int hdr_2173_types_nr[] = {FILE_HEADER_2173_ULL_NR, FILE_HEADER_2173_UL_NR, FILE_HEADER_2173_U_NR};
180 memset(file_hdr, 0, FILE_HEADER_SIZE);
181 file_hdr->sa_hz = HZ;
183 if (previous_format == FORMAT_MAGIC_2171) {
184 *arch_64 = (f_hdr_2171->sa_sizeof_long == SIZEOF_LONG_64BIT);
186 /* Normalize endianness for f_hdr_2171 structure */
187 if (endian_mismatch) {
188 swap_struct(hdr_2171_types_nr, f_hdr_2171, *arch_64);
191 file_hdr->sa_ust_time = (unsigned long long) f_hdr_2171->sa_ust_time;
192 /* sa_cpu_nr field will be updated later */
193 file_hdr->sa_act_nr = f_hdr_2171->sa_act_nr;
194 file_hdr->sa_year = (int) f_hdr_2171->sa_year;
195 file_hdr->sa_day = f_hdr_2171->sa_day;
196 file_hdr->sa_month = f_hdr_2171->sa_month;
197 file_hdr->sa_sizeof_long = f_hdr_2171->sa_sizeof_long;
198 strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, UTSNAME_LEN);
199 file_hdr->sa_sysname[UTSNAME_LEN - 1] = '\0';
200 strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, UTSNAME_LEN);
201 file_hdr->sa_nodename[UTSNAME_LEN - 1] = '\0';
202 strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, UTSNAME_LEN);
203 file_hdr->sa_release[UTSNAME_LEN - 1] = '\0';
204 strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, UTSNAME_LEN);
205 file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
208 else if (previous_format == FORMAT_MAGIC_2173) {
209 *arch_64 = (f_hdr_2173->sa_sizeof_long == SIZEOF_LONG_64BIT);
211 /* Normalize endianness for f_hdr_2171 structure */
212 if (endian_mismatch) {
213 swap_struct(hdr_2173_types_nr, f_hdr_2173, *arch_64);
216 file_hdr->sa_ust_time = (unsigned long long) f_hdr_2173->sa_ust_time;
217 /* sa_cpu_nr field will be updated later */
218 file_hdr->sa_act_nr = f_hdr_2173->sa_act_nr;
219 file_hdr->sa_year = (int) f_hdr_2173->sa_year;
220 file_hdr->sa_day = f_hdr_2173->sa_day;
221 file_hdr->sa_month = f_hdr_2173->sa_month;
222 file_hdr->sa_sizeof_long = f_hdr_2173->sa_sizeof_long;
223 strncpy(file_hdr->sa_sysname, f_hdr_2173->sa_sysname, UTSNAME_LEN);
224 file_hdr->sa_sysname[UTSNAME_LEN - 1] = '\0';
225 strncpy(file_hdr->sa_nodename, f_hdr_2173->sa_nodename, UTSNAME_LEN);
226 file_hdr->sa_nodename[UTSNAME_LEN - 1] = '\0';
227 strncpy(file_hdr->sa_release, f_hdr_2173->sa_release, UTSNAME_LEN);
228 file_hdr->sa_release[UTSNAME_LEN - 1] = '\0';
229 strncpy(file_hdr->sa_machine, f_hdr_2173->sa_machine, UTSNAME_LEN);
230 file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
232 *vol_act_nr = f_hdr_2173->sa_vol_act_nr;
235 for (i = 0; i < 3; i++) {
236 file_hdr->act_types_nr[i] = act_types_nr[i];
237 file_hdr->rec_types_nr[i] = rec_types_nr[i];
239 file_hdr->act_size = FILE_ACTIVITY_SIZE;
240 file_hdr->rec_size = RECORD_HEADER_SIZE;
244 ***************************************************************************
245 * Read and upgrade file's header section.
248 * @dfile System activity data file name.
249 * @fd File descriptor for sa datafile to convert.
250 * @stdfd File descriptor for STDOUT.
251 * @act Array of activities.
252 * @file_magic File's magic structure.
253 * @hdr_size Size of header structure read from file.
255 * Format magic number of file to convert.
257 * TRUE if data read from file don't match current machine's
261 * @file_hdr File's header structure (up-to-date format).
262 * @arch_64 TRUE if file's data come from a 64-bit machine.
263 * @vol_act_nr Number of volatile activity structures following a restart
264 * record for 0x2173 file format.
266 * Activity list in file.
269 * -1 on error, 0 otherwise.
270 ***************************************************************************
272 int upgrade_header_section(char dfile[], int fd, int stdfd, struct activity *act[],
273 struct file_magic *file_magic, struct file_header *file_hdr,
274 unsigned int hdr_size, int previous_format, int *arch_64,
275 int endian_mismatch, unsigned int *vol_act_nr,
276 struct old_file_activity **ofile_actlst)
278 struct old_file_activity *ofal;
279 struct file_header fh;
281 unsigned int a_cpu = FALSE;
284 fprintf(stderr, "file_header: ");
286 /* Read file header structure */
287 n = (previous_format == FORMAT_MAGIC_2171 ? FILE_HEADER_SIZE_2171
289 SREALLOC(buffer, char, n);
290 sa_fread(fd, buffer, n, HARD_SIZE);
292 /* Upgrade file_header structure */
293 upgrade_file_header(buffer, file_hdr, previous_format,
294 endian_mismatch, arch_64, vol_act_nr);
299 if (file_hdr->sa_act_nr > MAX_NR_ACT)
302 /* Read file activity list */
303 SREALLOC(*ofile_actlst, struct old_file_activity, OLD_FILE_ACTIVITY_SIZE * file_hdr->sa_act_nr);
304 ofal = *ofile_actlst;
306 for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++) {
308 sa_fread(fd, ofal, OLD_FILE_ACTIVITY_SIZE, HARD_SIZE);
310 /* Normalize endianness for file_activity structures */
311 if (endian_mismatch) {
312 swap_struct(oact_types_nr, ofal, *arch_64);
315 if ((ofal->nr < 1) || (ofal->nr2 < 1))
317 * Every activity, known or unknown,
318 * should have at least one item and sub-item.
322 if ((p = get_activity_position(act, ofal->id, RESUME_IF_NOT_FOUND)) >= 0) {
323 /* This is a known activity, maybe with an unknown format */
325 if ((ofal->id == A_CPU) && !a_cpu) {
327 * We have found the CPU activity: Set sa_cpu_nr field
328 * in file_header structure that should contains the
329 * number of CPU when the file was created.
331 file_hdr->sa_cpu_nr = ofal->nr;
335 /* Size of an activity cannot be zero */
339 /* Size of activity in file is larger than up-to-date activity size */
340 if (ofal->size > act[p]->msize) {
341 act[p]->msize = ofal->size;
345 * When upgrading a file:
346 * ofal->size : Size of an item for current activity, as
347 * read from the file.
348 * act[p]->msize: Size of the buffer in memory where an item
349 * for current activity, as read from the file,
350 * will be saved. We have:
351 * act[p]->msize >= {ofal->size ; act[p]->fsize}
352 * act[p]->fsize: Size of an item for current activity with
355 act[p]->nr_ini = ofal->nr;
356 act[p]->nr2 = ofal->nr2;
358 * Don't set act[p]->fsize! Should retain the size of an item
359 * for up-to-date format!
366 * CPU activity should always be in file for versions older than 11.7.1
367 * and have a known format (expected magical number).
369 fprintf(stderr, _("\nCPU activity not found in file. Aborting...\n"));
373 memcpy(&fh, file_hdr, FILE_HEADER_SIZE);
374 /* Restore endianness before writing */
375 if (endian_mismatch) {
376 /* Start swapping at field "header_size" position */
377 swap_struct(hdr_types_nr, &fh, *arch_64);
380 /* Write file_header structure */
381 if ((n = write(stdfd, &fh, FILE_HEADER_SIZE)) != FILE_HEADER_SIZE) {
382 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
386 fprintf(stderr, "OK\n");
392 fprintf(stderr, _("\nInvalid data found. Aborting...\n"));
399 ***************************************************************************
400 * Convert a long integer value to a long long integer value.
401 * The long integer value may be 32 or 64-bit wide and come from a 32 or
402 * 64-bit architecture.
404 * Note: Consider the value 0x01020304 read on a 32-bit machine.
405 * Big-endian, saved as: 01 02 03 04
406 * Lille-endian, saved as: 04 03 02 01
407 * The value should be saved as an 64-bit value and endianness should be
409 * Big-endian: 00 00 00 00 01 02 03 04
410 * Little-endian: 04 03 02 01 00 00 00 00
413 * @buffer Address of value to convert.
415 * TRUE if data read from file don't match current machine's
417 * @arch_64 TRUE if file's data come from a 64-bit machine.
418 ***************************************************************************
420 unsigned long long moveto_long_long(void *buffer, int endian_mismatch, int arch_64)
423 unsigned long long *ull_int, ull_i;
426 ull_int = (unsigned long long *) buffer;
430 u_int = (unsigned int *) buffer;
431 if (endian_mismatch) {
432 ull_i = (unsigned long long) *u_int;
433 return (ull_i >> 32) | (ull_i << 32);
436 return (unsigned long long) *u_int;
441 ***************************************************************************
442 * Upgrade stats_cpu structure (from ACTIVITY_MAGIC_BASE format to
443 * ACTIVITY_MAGIC_BASE + 1 format).
446 * @act Array of activities.
447 * @p Position of activity in array.
448 * @st_size Size of the structure read from file.
449 ***************************************************************************
451 void upgrade_stats_cpu(struct activity *act[], int p, int st_size)
454 struct stats_cpu *scc;
455 struct stats_cpu_8a *scp;
457 for (i = 0; i < act[p]->nr_ini; i++) {
459 * For previous structure's format: Use msize (which has possibly been set to
460 * the size of the structure read from disk if it's greater than that of
461 * current format: See upgrade_header_section()).
462 * For current structure format: Use fsize. This is the normal size of
463 * structure's up-to-date format that will be written to file.
465 scp = (struct stats_cpu_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
466 scc = (struct stats_cpu *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
468 scc->cpu_user = scp->cpu_user;
469 scc->cpu_nice = scp->cpu_nice;
470 scc->cpu_sys = scp->cpu_sys;
471 scc->cpu_idle = scp->cpu_idle;
472 scc->cpu_iowait = scp->cpu_iowait;
473 scc->cpu_steal = scp->cpu_steal;
474 scc->cpu_hardirq = scp->cpu_hardirq;
475 scc->cpu_softirq = scp->cpu_softirq;
476 scc->cpu_guest = scp->cpu_guest;
478 if (st_size >= STATS_CPU_8A_SIZE) {
479 /* guest_nice field has been added without a structure format change */
480 scc->cpu_guest_nice = scp->cpu_guest_nice;
486 ***************************************************************************
487 * Upgrade stats_pcsw structure (from ACTIVITY_MAGIC_BASE format to
488 * ACTIVITY_MAGIC_BASE + 1 format).
491 * @act Array of activities.
492 * @p Position of activity in array.
493 ***************************************************************************
495 void upgrade_stats_pcsw(struct activity *act[], int p)
497 struct stats_pcsw *spc = (struct stats_pcsw *) act[p]->buf[1];
498 struct stats_pcsw_8a *spp = (struct stats_pcsw_8a *) act[p]->buf[0];
500 spc->context_switch = spp->context_switch;
502 * Copy a long into a long. Take into account that file may have been
503 * created on a 64-bit machine and we may be converting on a 32-bit machine.
505 memcpy(&spc->processes, &spp->processes, 8);
509 ***************************************************************************
510 * Upgrade stats_irq structure (from ACTIVITY_MAGIC_BASE format to
511 * ACTIVITY_MAGIC_BASE + 1 format).
514 * @act Array of activities.
515 * @p Position of activity in array.
516 ***************************************************************************
518 void upgrade_stats_irq(struct activity *act[], int p)
521 struct stats_irq *sic;
522 struct stats_irq_8a *sip;
524 for (i = 0; i < act[p]->nr_ini; i++) {
525 sip = (struct stats_irq_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
526 sic = (struct stats_irq *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
528 sic->irq_nr = sip->irq_nr;
533 ***************************************************************************
534 * Upgrade stats_io structure (from ACTIVITY_MAGIC_BASE format to
535 * ACTIVITY_MAGIC_BASE + 1 format).
538 * @act Array of activities.
539 * @p Position of activity in array.
541 * TRUE if data read from file don't match current machine's
543 ***************************************************************************
545 void upgrade_stats_io(struct activity *act[], int p, int endian_mismatch)
547 struct stats_io *sic = (struct stats_io *) act[p]->buf[1];
548 struct stats_io_8a *sip = (struct stats_io_8a *) act[p]->buf[0];
550 sic->dk_drive = moveto_long_long(&sip->dk_drive, endian_mismatch, FALSE);
551 sic->dk_drive_rio = moveto_long_long(&sip->dk_drive_rio, endian_mismatch, FALSE);
552 sic->dk_drive_wio = moveto_long_long(&sip->dk_drive_wio, endian_mismatch, FALSE);
553 sic->dk_drive_rblk = moveto_long_long(&sip->dk_drive_rblk, endian_mismatch, FALSE);
554 sic->dk_drive_wblk = moveto_long_long(&sip->dk_drive_wblk, endian_mismatch, FALSE);
558 ***************************************************************************
559 * Upgrade stats_memory structure (from ACTIVITY_MAGIC_BASE format to
560 * ACTIVITY_MAGIC_BASE + 1 format).
563 * @act Array of activities.
564 * @p Position of activity in array.
565 * @st_size Size of the structure read from file.
567 * TRUE if data read from file don't match current machine's
569 * @arch_64 TRUE if file's data come from a 64-bit machine.
570 ***************************************************************************
572 void upgrade_stats_memory(struct activity *act[], int p, int st_size,
573 int endian_mismatch, int arch_64)
575 struct stats_memory *smc = (struct stats_memory *) act[p]->buf[1];
576 struct stats_memory_8a *smp = (struct stats_memory_8a *) act[p]->buf[0];
578 smc->frmkb = moveto_long_long(&smp->frmkb, endian_mismatch, arch_64);
579 smc->bufkb = moveto_long_long(&smp->bufkb, endian_mismatch, arch_64);
580 smc->camkb = moveto_long_long(&smp->camkb, endian_mismatch, arch_64);
581 smc->tlmkb = moveto_long_long(&smp->tlmkb, endian_mismatch, arch_64);
582 smc->frskb = moveto_long_long(&smp->frskb, endian_mismatch, arch_64);
583 smc->tlskb = moveto_long_long(&smp->tlskb, endian_mismatch, arch_64);
584 smc->caskb = moveto_long_long(&smp->caskb, endian_mismatch, arch_64);
585 smc->comkb = moveto_long_long(&smp->comkb, endian_mismatch, arch_64);
586 smc->activekb = moveto_long_long(&smp->activekb, endian_mismatch, arch_64);
587 smc->inactkb = moveto_long_long(&smp->inactkb, endian_mismatch, arch_64);
589 /* Some fields have been added without a structure format change */
590 if (st_size >= STATS_MEMORY_8A_1_SIZE) {
591 smc->dirtykb = moveto_long_long(&smp->dirtykb, endian_mismatch, arch_64);
593 if (st_size >= STATS_MEMORY_8A_2_SIZE) {
594 smc->anonpgkb = moveto_long_long(&smp->anonpgkb, endian_mismatch, arch_64);
595 smc->slabkb = moveto_long_long(&smp->slabkb, endian_mismatch, arch_64);
596 smc->kstackkb = moveto_long_long(&smp->kstackkb, endian_mismatch, arch_64);
597 smc->pgtblkb = moveto_long_long(&smp->pgtblkb, endian_mismatch, arch_64);
598 smc->vmusedkb = moveto_long_long(&smp->vmusedkb, endian_mismatch, arch_64);
600 if (st_size >= STATS_MEMORY_8A_SIZE) {
601 smc->availablekb = moveto_long_long(&(smp->availablekb), endian_mismatch, arch_64);;
606 ***************************************************************************
607 * Upgrade stats_ktables structure (from ACTIVITY_MAGIC_BASE format to
608 * ACTIVITY_MAGIC_BASE + 1 format).
611 * @act Array of activities.
612 * @p Position of activity in array.
614 * TRUE if data read from file don't match current machine's
616 ***************************************************************************
618 void upgrade_stats_ktables(struct activity *act[], int p, int endian_mismatch)
620 struct stats_ktables *skc = (struct stats_ktables *) act[p]->buf[1];
621 struct stats_ktables_8a *skp = (struct stats_ktables_8a *) act[p]->buf[0];
623 skc->file_used = moveto_long_long(&skp->file_used, endian_mismatch, FALSE);
624 skc->inode_used = moveto_long_long(&skp->inode_used, endian_mismatch, FALSE);
625 skc->dentry_stat = moveto_long_long(&skp->dentry_stat, endian_mismatch, FALSE);
626 skc->pty_nr = moveto_long_long(&skp->pty_nr, endian_mismatch, FALSE);
630 ***************************************************************************
631 * Upgrade stats_queue structure (from ACTIVITY_MAGIC_BASE or
632 * ACTIVITY_MAGIC_BASE + 1 format to ACTIVITY_MAGIC_BASE + 2 format).
635 * @act Array of activities.
636 * @p Position of activity in array.
637 * @magic Structure format magic value.
639 * TRUE if data read from file don't match current machine's
641 * @arch_64 TRUE if file's data come from a 64-bit machine.
642 ***************************************************************************
644 void upgrade_stats_queue(struct activity *act[], int p, unsigned int magic,
645 int endian_mismatch, int arch_64)
647 struct stats_queue *sqc = (struct stats_queue *) act[p]->buf[1];
649 if (magic == ACTIVITY_MAGIC_BASE) {
650 struct stats_queue_8a *sqp = (struct stats_queue_8a *) act[p]->buf[0];
652 sqc->nr_running = moveto_long_long(&sqp->nr_running, endian_mismatch, arch_64);
653 sqc->procs_blocked = 0ULL; /* New field */
654 sqc->nr_threads = moveto_long_long(&sqp->nr_threads, endian_mismatch, FALSE);
655 sqc->load_avg_1 = sqp->load_avg_1;
656 sqc->load_avg_5 = sqp->load_avg_5;
657 sqc->load_avg_15 = sqp->load_avg_15;
660 struct stats_queue_8b *sqp = (struct stats_queue_8b *) act[p]->buf[0];
662 sqc->nr_running = moveto_long_long(&sqp->nr_running, endian_mismatch, arch_64);
663 sqc->procs_blocked = moveto_long_long(&sqp->procs_blocked, endian_mismatch, arch_64);
664 sqc->nr_threads = moveto_long_long(&sqp->nr_threads, endian_mismatch, FALSE);
665 sqc->load_avg_1 = sqp->load_avg_1;
666 sqc->load_avg_5 = sqp->load_avg_5;
667 sqc->load_avg_15 = sqp->load_avg_15;
672 ***************************************************************************
673 * Upgrade stats_serial structure (from ACTIVITY_MAGIC_BASE format to
674 * ACTIVITY_MAGIC_BASE + 1 format).
677 * @act Array of activities.
678 * @p Position of activity in array.
679 ***************************************************************************
681 void upgrade_stats_serial(struct activity *act[], int p, int endian_mismatch)
685 struct stats_serial *ssc;
687 for (i = 0; i < act[p]->nr_ini; i++) {
688 ssc = (struct stats_serial *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
690 /* Line number now starts at 0 instead of 1 */
691 line = (endian_mismatch ? __builtin_bswap32(ssc->line) : ssc->line);
695 ssc->line = (endian_mismatch ? __builtin_bswap32(line) : line);
699 * Updating @nr_ini is part of the upgrade process so that
700 * only the required number of structures gets written to disk.
701 * Don't do it later as a line number of 0 no longer indicates the
708 ***************************************************************************
709 * Upgrade stats_disk structure (from ACTIVITY_MAGIC_BASE format to
710 * ACTIVITY_MAGIC_BASE + 1 format).
713 * @act Array of activities.
714 * @p Position of activity in array.
715 * @magic Structure format magic value.
717 * TRUE if data read from file don't match current machine's
719 * @arch_64 TRUE if file's data come from a 64-bit machine.
720 ***************************************************************************
722 void upgrade_stats_disk(struct activity *act[], int p, unsigned int magic,
723 int endian_mismatch, int arch_64)
726 struct stats_disk *sdc;
728 if (magic == ACTIVITY_MAGIC_BASE) {
729 struct stats_disk_8a *sdp;
731 for (i = 0; i < act[p]->nr_ini; i++) {
732 sdp = (struct stats_disk_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
733 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
735 sdc->nr_ios = moveto_long_long(&sdp->nr_ios, endian_mismatch, arch_64);
736 sdc->rd_sect = (unsigned long) sdp->rd_sect;
737 sdc->wr_sect = (unsigned long) sdp->wr_sect;
738 sdc->rd_ticks = (unsigned int) sdp->rd_ticks;
739 sdc->wr_ticks = (unsigned int) sdp->wr_ticks;
740 sdc->tot_ticks = (unsigned int) sdp->tot_ticks;
741 sdc->rq_ticks = (unsigned int) sdp->rq_ticks;
742 sdc->major = sdp->major;
743 sdc->minor = sdp->minor;
747 struct stats_disk_8b *sdp;
749 for (i = 0; i < act[p]->nr_ini; i++) {
750 sdp = (struct stats_disk_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
751 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
753 sdc->nr_ios = sdp->nr_ios;
754 memcpy(&sdc->rd_sect, &sdp->rd_sect, 8);
755 memcpy(&sdc->wr_sect, &sdp->wr_sect, 8);
756 sdc->rd_ticks = sdp->rd_ticks;
757 sdc->wr_ticks = sdp->wr_ticks;
758 sdc->tot_ticks = sdp->tot_ticks;
759 sdc->rq_ticks = sdp->rq_ticks;
760 sdc->major = sdp->major;
761 sdc->minor = sdp->minor;
767 ***************************************************************************
768 * Upgrade stats_net_dev structure (from ACTIVITY_MAGIC_BASE or
769 * ACTIVITY_MAGIC_BASE + 1 format to ACTIVITY_MAGIC_BASE + 3 format).
772 * @act Array of activities.
773 * @p Position of activity in array.
774 * @magic Structure format magic value.
776 * TRUE if data read from file don't match current machine's
778 * @arch_64 TRUE if file's data come from a 64-bit machine.
779 ***************************************************************************
781 void upgrade_stats_net_dev(struct activity *act[], int p, unsigned int magic,
782 int endian_mismatch, int arch_64)
785 struct stats_net_dev *sndc;
787 if (magic == ACTIVITY_MAGIC_BASE) {
788 struct stats_net_dev_8a *sndp;
790 for (i = 0; i < act[p]->nr_ini; i++) {
791 sndp = (struct stats_net_dev_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
792 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
794 sndc->rx_packets = moveto_long_long(&sndp->rx_packets, endian_mismatch, arch_64);
795 sndc->tx_packets = moveto_long_long(&sndp->tx_packets, endian_mismatch, arch_64);
796 sndc->rx_bytes = moveto_long_long(&sndp->rx_bytes, endian_mismatch, arch_64);
797 sndc->tx_bytes = moveto_long_long(&sndp->tx_bytes, endian_mismatch, arch_64);
798 sndc->rx_compressed = moveto_long_long(&sndp->rx_compressed, endian_mismatch, arch_64);
799 sndc->tx_compressed = moveto_long_long(&sndp->tx_compressed, endian_mismatch, arch_64);
800 sndc->multicast = moveto_long_long(&sndp->multicast, endian_mismatch, arch_64);
801 sndc->speed = 0; /* New field */
802 strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
803 sndc->interface[MAX_IFACE_LEN - 1] = '\0';
804 sndc->duplex = '\0'; /* New field */
807 else if (magic == ACTIVITY_MAGIC_BASE) {
808 struct stats_net_dev_8b *sndp;
810 for (i = 0; i < act[p]->nr_ini; i++) {
811 sndp = (struct stats_net_dev_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
812 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
814 sndc->rx_packets = sndp->rx_packets;
815 sndc->tx_packets = sndp->tx_packets;
816 sndc->rx_bytes = sndp->rx_bytes;
817 sndc->tx_bytes = sndp->tx_bytes;
818 sndc->rx_compressed = sndp->rx_compressed;
819 sndc->tx_compressed = sndp->tx_compressed;
820 sndc->multicast = sndp->multicast;
821 sndc->speed = 0; /* New field */
822 strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
823 sndc->interface[MAX_IFACE_LEN - 1] = '\0';
824 sndc->duplex = '\0'; /* New field */
828 struct stats_net_dev_8c *sndp;
830 for (i = 0; i < act[p]->nr_ini; i++) {
831 sndp = (struct stats_net_dev_8c *) ((char *) act[p]->buf[0] + i * act[p]->msize);
832 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
834 sndc->rx_packets = sndp->rx_packets;
835 sndc->tx_packets = sndp->tx_packets;
836 sndc->rx_bytes = sndp->rx_bytes;
837 sndc->tx_bytes = sndp->tx_bytes;
838 sndc->rx_compressed = sndp->rx_compressed;
839 sndc->tx_compressed = sndp->tx_compressed;
840 sndc->multicast = sndp->multicast;
841 sndc->speed = sndp->speed;
842 strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
843 sndc->interface[MAX_IFACE_LEN - 1] = '\0';
844 sndc->duplex = sndp->duplex;
850 ***************************************************************************
851 * Upgrade stats_net_edev structure (from ACTIVITY_MAGIC_BASE format to
852 * ACTIVITY_MAGIC_BASE + 1 format).
855 * @act Array of activities.
856 * @p Position of activity in array.
857 * @magic Structure format magic value.
859 * TRUE if data read from file don't match current machine's
861 * @arch_64 TRUE if file's data come from a 64-bit machine.
862 ***************************************************************************
864 void upgrade_stats_net_edev(struct activity *act[], int p, unsigned int magic,
865 int endian_mismatch, int arch_64)
868 struct stats_net_edev *snedc;
870 if (magic == ACTIVITY_MAGIC_BASE) {
871 struct stats_net_edev_8a *snedp;
873 for (i = 0; i < act[p]->nr_ini; i++) {
874 snedp = (struct stats_net_edev_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
875 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
877 snedc->collisions = moveto_long_long(&snedp->collisions, endian_mismatch, arch_64);
878 snedc->rx_errors = moveto_long_long(&snedp->rx_errors, endian_mismatch, arch_64);
879 snedc->tx_errors = moveto_long_long(&snedp->tx_errors, endian_mismatch, arch_64);
880 snedc->rx_dropped = moveto_long_long(&snedp->rx_dropped, endian_mismatch, arch_64);
881 snedc->tx_dropped = moveto_long_long(&snedp->tx_dropped, endian_mismatch, arch_64);
882 snedc->rx_fifo_errors = moveto_long_long(&snedp->rx_fifo_errors, endian_mismatch, arch_64);
883 snedc->tx_fifo_errors = moveto_long_long(&snedp->tx_fifo_errors, endian_mismatch, arch_64);
884 snedc->rx_frame_errors = moveto_long_long(&snedp->rx_frame_errors, endian_mismatch, arch_64);
885 snedc->tx_carrier_errors = moveto_long_long(&snedp->tx_carrier_errors, endian_mismatch, arch_64);
886 strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
887 snedc->interface[MAX_IFACE_LEN - 1] = '\0';
891 struct stats_net_edev_8b *snedp;
893 for (i = 0; i < act[p]->nr_ini; i++) {
894 snedp = (struct stats_net_edev_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
895 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
897 snedc->collisions = snedp->collisions;
898 snedc->rx_errors = snedp->rx_errors;
899 snedc->tx_errors = snedp->tx_errors;
900 snedc->rx_dropped = snedp->rx_dropped;
901 snedc->tx_dropped = snedp->tx_dropped;
902 snedc->rx_fifo_errors = snedp->rx_fifo_errors;
903 snedc->tx_fifo_errors = snedp->tx_fifo_errors;
904 snedc->rx_frame_errors = snedp->rx_frame_errors;
905 snedc->tx_carrier_errors = snedp->tx_carrier_errors;
906 strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
907 snedc->interface[MAX_IFACE_LEN - 1] = '\0';
913 ***************************************************************************
914 * Upgrade stats_net_ip structure (from ACTIVITY_MAGIC_BASE format to
915 * ACTIVITY_MAGIC_BASE + 1 format).
918 * @act Array of activities.
919 * @p Position of activity in array.
920 * @magic Structure format magic value.
922 * TRUE if data read from file don't match current machine's
924 * @arch_64 TRUE if file's data come from a 64-bit machine.
925 ***************************************************************************
927 void upgrade_stats_net_ip(struct activity *act[], int p, unsigned int magic,
928 int endian_mismatch, int arch_64)
930 struct stats_net_ip *snic = (struct stats_net_ip *) act[p]->buf[1];
932 if (magic == ACTIVITY_MAGIC_BASE) {
933 struct stats_net_ip_8a *snip = (struct stats_net_ip_8a *) act[p]->buf[0];
935 snic->InReceives = moveto_long_long(&snip->InReceives, endian_mismatch, arch_64);
936 snic->ForwDatagrams = moveto_long_long(&snip->ForwDatagrams, endian_mismatch, arch_64);
937 snic->InDelivers = moveto_long_long(&snip->InDelivers, endian_mismatch, arch_64);
938 snic->OutRequests = moveto_long_long(&snip->OutRequests, endian_mismatch, arch_64);
939 snic->ReasmReqds = moveto_long_long(&snip->ReasmReqds, endian_mismatch, arch_64);
940 snic->ReasmOKs = moveto_long_long(&snip->ReasmOKs, endian_mismatch, arch_64);
941 snic->FragOKs = moveto_long_long(&snip->FragOKs, endian_mismatch, arch_64);
942 snic->FragCreates = moveto_long_long(&snip->FragCreates, endian_mismatch, arch_64);
945 struct stats_net_ip_8b *snip = (struct stats_net_ip_8b *) act[p]->buf[0];
947 snic->InReceives = snip->InReceives;
948 snic->ForwDatagrams = snip->ForwDatagrams;
949 snic->InDelivers = snip->InDelivers;
950 snic->OutRequests = snip->OutRequests;
951 snic->ReasmReqds = snip->ReasmReqds;
952 snic->ReasmOKs = snip->ReasmOKs;
953 snic->FragOKs = snip->FragOKs;
954 snic->FragCreates = snip->FragCreates;
959 ***************************************************************************
960 * Upgrade stats_net_eip structure (from ACTIVITY_MAGIC_BASE format to
961 * ACTIVITY_MAGIC_BASE + 1 format).
964 * @act Array of activities.
965 * @p Position of activity in array.
966 * @magic Structure format magic value.
968 * TRUE if data read from file don't match current machine's
970 * @arch_64 TRUE if file's data come from a 64-bit machine.
971 ***************************************************************************
973 void upgrade_stats_net_eip(struct activity *act[], int p, unsigned int magic,
974 int endian_mismatch, int arch_64)
976 struct stats_net_eip *sneic = (struct stats_net_eip *) act[p]->buf[1];
978 if (magic == ACTIVITY_MAGIC_BASE) {
979 struct stats_net_eip_8a *sneip = (struct stats_net_eip_8a *) act[p]->buf[0];
981 sneic->InHdrErrors = moveto_long_long(&sneip->InHdrErrors, endian_mismatch, arch_64);
982 sneic->InAddrErrors = moveto_long_long(&sneip->InAddrErrors, endian_mismatch, arch_64);
983 sneic->InUnknownProtos = moveto_long_long(&sneip->InUnknownProtos, endian_mismatch, arch_64);
984 sneic->InDiscards = moveto_long_long(&sneip->InDiscards, endian_mismatch, arch_64);
985 sneic->OutDiscards = moveto_long_long(&sneip->OutDiscards, endian_mismatch, arch_64);
986 sneic->OutNoRoutes = moveto_long_long(&sneip->OutNoRoutes, endian_mismatch, arch_64);
987 sneic->ReasmFails = moveto_long_long(&sneip->ReasmFails, endian_mismatch, arch_64);
988 sneic->FragFails = moveto_long_long(&sneip->FragFails, endian_mismatch, arch_64);
991 struct stats_net_eip_8b *sneip = (struct stats_net_eip_8b *) act[p]->buf[0];
993 sneic->InHdrErrors = sneip->InHdrErrors;
994 sneic->InAddrErrors = sneip->InAddrErrors;
995 sneic->InUnknownProtos = sneip->InUnknownProtos;
996 sneic->InDiscards = sneip->InDiscards;
997 sneic->OutDiscards = sneip->OutDiscards;
998 sneic->OutNoRoutes = sneip->OutNoRoutes;
999 sneic->ReasmFails = sneip->ReasmFails;
1000 sneic->FragFails = sneip->FragFails;
1005 ***************************************************************************
1006 * Upgrade stats_net_ip6 structure (from ACTIVITY_MAGIC_BASE format to
1007 * ACTIVITY_MAGIC_BASE + 1 format).
1010 * @act Array of activities.
1011 * @p Position of activity in array.
1012 * @magic Structure format magic value.
1014 * TRUE if data read from file don't match current machine's
1016 * @arch_64 TRUE if file's data come from a 64-bit machine.
1017 ***************************************************************************
1019 void upgrade_stats_net_ip6(struct activity *act[], int p, unsigned int magic,
1020 int endian_mismatch, int arch_64)
1022 struct stats_net_ip6 *snic6 = (struct stats_net_ip6 *) act[p]->buf[1];
1024 if (magic == ACTIVITY_MAGIC_BASE) {
1025 struct stats_net_ip6_8a *snip6 = (struct stats_net_ip6_8a *) act[p]->buf[0];
1027 snic6->InReceives6 = moveto_long_long(&snip6->InReceives6, endian_mismatch, arch_64);
1028 snic6->OutForwDatagrams6 = moveto_long_long(&snip6->OutForwDatagrams6, endian_mismatch, arch_64);
1029 snic6->InDelivers6 = moveto_long_long(&snip6->InDelivers6, endian_mismatch, arch_64);
1030 snic6->OutRequests6 = moveto_long_long(&snip6->OutRequests6, endian_mismatch, arch_64);
1031 snic6->ReasmReqds6 = moveto_long_long(&snip6->ReasmReqds6, endian_mismatch, arch_64);
1032 snic6->ReasmOKs6 = moveto_long_long(&snip6->ReasmOKs6, endian_mismatch, arch_64);
1033 snic6->InMcastPkts6 = moveto_long_long(&snip6->InMcastPkts6, endian_mismatch, arch_64);
1034 snic6->OutMcastPkts6 = moveto_long_long(&snip6->OutMcastPkts6, endian_mismatch, arch_64);
1035 snic6->FragOKs6 = moveto_long_long(&snip6->FragOKs6, endian_mismatch, arch_64);
1036 snic6->FragCreates6 = moveto_long_long(&snip6->FragCreates6, endian_mismatch, arch_64);
1039 struct stats_net_ip6_8b *snip6 = (struct stats_net_ip6_8b *) act[p]->buf[0];
1041 snic6->InReceives6 = snip6->InReceives6;
1042 snic6->OutForwDatagrams6 = snip6->OutForwDatagrams6;
1043 snic6->InDelivers6 = snip6->InDelivers6;
1044 snic6->OutRequests6 = snip6->OutRequests6;
1045 snic6->ReasmReqds6 = snip6->ReasmReqds6;
1046 snic6->ReasmOKs6 = snip6->ReasmOKs6;
1047 snic6->InMcastPkts6 = snip6->InMcastPkts6;
1048 snic6->OutMcastPkts6 = snip6->OutMcastPkts6;
1049 snic6->FragOKs6 = snip6->FragOKs6;
1050 snic6->FragCreates6 = snip6->FragCreates6;
1055 ***************************************************************************
1056 * Upgrade stats_net_eip6 structure (from ACTIVITY_MAGIC_BASE format to
1057 * ACTIVITY_MAGIC_BASE + 1 format).
1060 * @act Array of activities.
1061 * @p Position of activity in array.
1062 * @magic Structure format magic value.
1064 * TRUE if data read from file don't match current machine's
1066 * @arch_64 TRUE if file's data come from a 64-bit machine.
1067 ***************************************************************************
1069 void upgrade_stats_net_eip6(struct activity *act[], int p, unsigned int magic,
1070 int endian_mismatch, int arch_64)
1072 struct stats_net_eip6 *sneic6 = (struct stats_net_eip6 *) act[p]->buf[1];
1074 if (magic == ACTIVITY_MAGIC_BASE) {
1075 struct stats_net_eip6_8a *sneip6 = (struct stats_net_eip6_8a *) act[p]->buf[0];
1077 sneic6->InHdrErrors6 = moveto_long_long(&sneip6->InHdrErrors6, endian_mismatch, arch_64);
1078 sneic6->InAddrErrors6 = moveto_long_long(&sneip6->InAddrErrors6, endian_mismatch, arch_64);
1079 sneic6->InUnknownProtos6 = moveto_long_long(&sneip6->InUnknownProtos6, endian_mismatch, arch_64);
1080 sneic6->InTooBigErrors6 = moveto_long_long(&sneip6->InTooBigErrors6, endian_mismatch, arch_64);
1081 sneic6->InDiscards6 = moveto_long_long(&sneip6->InDiscards6, endian_mismatch, arch_64);
1082 sneic6->OutDiscards6 = moveto_long_long(&sneip6->OutDiscards6, endian_mismatch, arch_64);
1083 sneic6->InNoRoutes6 = moveto_long_long(&sneip6->InNoRoutes6, endian_mismatch, arch_64);
1084 sneic6->OutNoRoutes6 = moveto_long_long(&sneip6->OutNoRoutes6, endian_mismatch, arch_64);
1085 sneic6->ReasmFails6 = moveto_long_long(&sneip6->ReasmFails6, endian_mismatch, arch_64);
1086 sneic6->FragFails6 = moveto_long_long(&sneip6->FragFails6, endian_mismatch, arch_64);
1087 sneic6->InTruncatedPkts6 = moveto_long_long(&sneip6->InTruncatedPkts6, endian_mismatch, arch_64);
1090 struct stats_net_eip6_8b *sneip6 = (struct stats_net_eip6_8b *) act[p]->buf[0];
1092 sneic6->InHdrErrors6 = sneip6->InHdrErrors6;
1093 sneic6->InAddrErrors6 = sneip6->InAddrErrors6;
1094 sneic6->InUnknownProtos6 = sneip6->InUnknownProtos6;
1095 sneic6->InTooBigErrors6 = sneip6->InTooBigErrors6;
1096 sneic6->InDiscards6 = sneip6->InDiscards6;
1097 sneic6->OutDiscards6 = sneip6->OutDiscards6;
1098 sneic6->InNoRoutes6 = sneip6->InNoRoutes6;
1099 sneic6->OutNoRoutes6 = sneip6->OutNoRoutes6;
1100 sneic6->ReasmFails6 = sneip6->ReasmFails6;
1101 sneic6->FragFails6 = sneip6->FragFails6;
1102 sneic6->InTruncatedPkts6 = sneip6->InTruncatedPkts6;
1107 ***************************************************************************
1108 * Upgrade stats_huge structure (from ACTIVITY_MAGIC_BASE format to
1109 * ACTIVITY_MAGIC_BASE + 1 format).
1112 * @act Array of activities.
1113 * @p Position of activity in array.
1115 * TRUE if data read from file don't match current machine's
1117 * @arch_64 TRUE if file's data come from a 64-bit machine.
1118 ***************************************************************************
1120 void upgrade_stats_huge(struct activity *act[], int p,
1121 int endian_mismatch, int arch_64)
1123 struct stats_huge *shc = (struct stats_huge *) act[p]->buf[1];
1124 struct stats_huge_8a *shp = (struct stats_huge_8a *) act[p]->buf[0];
1126 shc->frhkb = moveto_long_long(&shp->frhkb, endian_mismatch, arch_64);
1127 shc->tlhkb = moveto_long_long(&shp->tlhkb, endian_mismatch, arch_64);
1131 ***************************************************************************
1132 * Upgrade stats_pwr_wghfreq structure (from ACTIVITY_MAGIC_BASE format to
1133 * ACTIVITY_MAGIC_BASE + 1 format).
1136 * @act Array of activities.
1137 * @p Position of activity in array.
1138 ***************************************************************************
1140 void upgrade_stats_pwr_wghfreq(struct activity *act[], int p)
1144 struct stats_pwr_wghfreq *spc, *spc_k;
1145 struct stats_pwr_wghfreq_8a *spp, *spp_k;
1147 for (i = 0; i < act[p]->nr_ini; i++) {
1148 spp = (struct stats_pwr_wghfreq_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize * act[p]->nr2);
1149 spc = (struct stats_pwr_wghfreq *) ((char *) act[p]->buf[1] + i * act[p]->fsize * act[p]->nr2);
1151 for (k = 0; k < act[p]->nr2; k++) {
1152 spc_k = (struct stats_pwr_wghfreq *) ((char *) spc + k * act[p]->fsize);
1155 spp_k = (struct stats_pwr_wghfreq_8a *) ((char *) spp + k * act[p]->msize);
1157 spc_k->time_in_state = spp_k->time_in_state;
1158 memcpy(&spc_k->freq, &spp_k->freq, 8);
1164 ***************************************************************************
1165 * Upgrade stats_filesystem structure (from ACTIVITY_MAGIC_BASE format to
1166 * ACTIVITY_MAGIC_BASE + 1 format).
1169 * @act Array of activities.
1170 * @p Position of activity in array.
1171 * @st_size Size of the structure read from file.
1172 ***************************************************************************
1174 void upgrade_stats_filesystem(struct activity *act[], int p, int st_size)
1177 struct stats_filesystem *sfc;
1178 struct stats_filesystem_8a *sfp;
1180 for (i = 0; i < act[p]->nr_ini; i++) {
1181 sfp = (struct stats_filesystem_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
1182 sfc = (struct stats_filesystem *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1184 sfc->f_blocks = sfp->f_blocks;
1185 sfc->f_bfree = sfp->f_bfree;
1186 sfc->f_bavail = sfp->f_bavail;
1187 sfc->f_files = sfp->f_files;
1188 sfc->f_ffree = sfp->f_ffree;
1189 strncpy(sfc->fs_name, sfp->fs_name, MAX_FS_LEN);
1190 sfc->fs_name[MAX_FS_LEN - 1] = '\0';
1192 if (st_size <= STATS_FILESYSTEM_8A_1_SIZE) {
1193 /* mountp didn't exist with older versions */
1194 sfc->mountp[0] = '\0';
1197 strncpy(sfc->mountp, sfp->mountp, MAX_FS_LEN);
1198 sfc->mountp[MAX_FS_LEN - 1] = '\0';
1204 ***************************************************************************
1205 * Count number of stats_disk structures that need to be written.
1208 * @act Array of activities.
1209 * @p Position of activity in array.
1210 ***************************************************************************
1212 __nr_t count_stats_disk(struct activity *act[], int p)
1216 struct stats_disk *sdc;
1218 for (i = 0; i < act[p]->nr_ini; i++) {
1219 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1220 if (!(sdc->major + sdc->minor))
1230 ***************************************************************************
1231 * Count number of stats_net_dev structures that need to be written.
1234 * @act Array of activities.
1235 * @p Position of activity in array.
1236 ***************************************************************************
1238 __nr_t count_stats_net_dev(struct activity *act[], int p)
1242 struct stats_net_dev *sndc;
1244 for (i = 0; i < act[p]->nr_ini; i++) {
1245 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1246 if (!strcmp(sndc->interface, ""))
1256 ***************************************************************************
1257 * Count number of stats_net_edev structures that need to be written.
1260 * @act Array of activities.
1261 * @p Position of activity in array.
1262 ***************************************************************************
1264 __nr_t count_stats_net_edev(struct activity *act[], int p)
1268 struct stats_net_edev *snedc;
1270 for (i = 0; i < act[p]->nr_ini; i++) {
1271 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1272 if (!strcmp(snedc->interface, ""))
1282 ***************************************************************************
1283 * Count number of stats_pwr_usb structures that need to be written.
1286 * @act Array of activities.
1287 * @p Position of activity in array.
1288 ***************************************************************************
1290 __nr_t count_stats_pwr_usb(struct activity *act[], int p)
1294 struct stats_pwr_usb *suc;
1296 for (i = 0; i < act[p]->nr_ini; i++) {
1297 suc = (struct stats_pwr_usb *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1308 ***************************************************************************
1309 * Count number of stats_filesystem structures that need to be written.
1312 * @act Array of activities.
1313 * @p Position of activity in array.
1314 ***************************************************************************
1316 __nr_t count_stats_filesystem(struct activity *act[], int p)
1320 struct stats_filesystem *sfc;
1322 for (i = 0; i < act[p]->nr_ini; i++) {
1323 sfc = (struct stats_filesystem *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1334 ***************************************************************************
1335 * Count number of stats_fchost structures that need to be written.
1338 * @act Array of activities.
1339 * @p Position of activity in array.
1340 ***************************************************************************
1342 __nr_t count_stats_fchost(struct activity *act[], int p)
1346 struct stats_fchost *sfcc;
1348 for (i = 0; i < act[p]->nr_ini; i++) {
1349 sfcc = (struct stats_fchost *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1350 if (!sfcc->fchost_name[0])
1360 ***************************************************************************
1361 * Upgrade file's activity list section.
1364 * @stdfd File descriptor for STDOUT.
1365 * @act Array of activities.
1366 * @file_hdr Pointer on file_header structure.
1367 * @ofile_actlst Activity list in file.
1369 * TRUE if data read from file don't match current machine's
1371 * @arch_64 TRUE if file's data come from a 64-bit machine.
1374 * @file_actlst Activity list with up-to-date format.
1377 * -1 on error, 0 otherwise.
1378 ***************************************************************************
1380 int upgrade_activity_section(int stdfd, struct activity *act[],
1381 struct file_header *file_hdr,
1382 struct old_file_activity *ofile_actlst,
1383 struct file_activity **file_actlst,
1384 int endian_mismatch, int arch_64)
1387 struct old_file_activity *ofal;
1388 struct file_activity *fal, fa;
1390 fprintf(stderr, "file_activity: ");
1392 SREALLOC(*file_actlst, struct file_activity, FILE_ACTIVITY_SIZE * file_hdr->sa_act_nr);
1394 ofal = ofile_actlst;
1396 for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++, fal++) {
1398 /* Every activity should be known at the moment (may change in the future) */
1399 p = get_activity_position(act, ofal->id, EXIT_IF_NOT_FOUND);
1402 fal->nr2 = ofal->nr2;
1403 fal->magic = act[p]->magic; /* Update activity magic number */
1404 fal->has_nr = HAS_COUNT_FUNCTION(act[p]->options);
1405 /* Also update its size, which may have changed with recent versions */
1406 fal->size = act[p]->fsize;
1407 for (j = 0; j < 3; j++) {
1408 fal->types_nr[j] = act[p]->gtypes_nr[j];
1411 memcpy(&fa, fal, FILE_ACTIVITY_SIZE);
1412 /* Restore endianness before writing */
1413 if (endian_mismatch) {
1414 /* Start swapping at field "header_size" position */
1415 swap_struct(act_types_nr, &fa, arch_64);
1419 * Even unknown activities must be written
1420 * (they are counted in sa_act_nr).
1422 if (write(stdfd, &fa, FILE_ACTIVITY_SIZE) != FILE_ACTIVITY_SIZE) {
1423 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1426 fprintf(stderr, "%s ", act[p]->name);
1429 fprintf(stderr, "OK\n");
1435 ***************************************************************************
1436 * Upgrade a record header.
1439 * @fd File descriptor for sa datafile to convert.
1440 * @stdfd File descriptor for STDOUT.
1441 * @orec_hdr Record's header structure to convert.
1443 * TRUE if data read from file don't match current machine's
1445 * @arch_64 TRUE if file's data come from a 64-bit machine.
1448 * -1 on error, 0 otherwise.
1449 ***************************************************************************
1451 int upgrade_record_header(int fd, int stdfd, struct old_record_header *orec_hdr,
1452 int endian_mismatch, int arch_64)
1454 struct record_header rec_hdr;
1456 /* Convert current record header */
1457 rec_hdr.uptime_cs = orec_hdr->uptime0 * 100 / HZ; /* Uptime in cs, not jiffies */
1458 rec_hdr.ust_time = (unsigned long long) orec_hdr->ust_time;
1459 rec_hdr.record_type = orec_hdr->record_type;
1460 rec_hdr.hour = orec_hdr->hour;
1461 rec_hdr.minute = orec_hdr->minute;
1462 rec_hdr.second = orec_hdr->second;
1464 /* Restore endianness before writing */
1465 if (endian_mismatch) {
1466 swap_struct(rec_types_nr, &rec_hdr, arch_64);
1469 /* Write record header */
1470 if (write(stdfd, &rec_hdr, RECORD_HEADER_SIZE) != RECORD_HEADER_SIZE) {
1471 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1475 fprintf(stderr, "H");
1481 ***************************************************************************
1482 * Upgrade a COMMENT record.
1485 * @fd File descriptor for sa datafile to convert.
1486 * @stdfd File descriptor for STDOUT.
1489 * -1 on error, 0 otherwise.
1490 ***************************************************************************
1492 int upgrade_comment_record(int fd, int stdfd)
1494 char file_comment[MAX_COMMENT_LEN];
1496 /* Read the COMMENT record */
1497 sa_fread(fd, file_comment, MAX_COMMENT_LEN, HARD_SIZE);
1498 file_comment[MAX_COMMENT_LEN - 1] = '\0';
1500 /* Then write it. No changes at this time */
1501 if (write(stdfd, file_comment, MAX_COMMENT_LEN) != MAX_COMMENT_LEN) {
1502 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1506 fprintf(stderr, "C");
1512 ***************************************************************************
1513 * Upgrade a RESTART record.
1516 * @fd File descriptor for sa datafile to convert.
1517 * @stdfd File descriptor for STDOUT.
1518 * @act Array of activities.
1519 * @file_hdr Pointer on file_header structure.
1521 * TRUE is sa datafile has an old format which is no longer
1522 * compatible with current one.
1524 * TRUE if data read from file don't match current machine's
1526 * @arch_64 TRUE if file's data come from a 64-bit machine.
1527 * @vol_act_nr Number of volatile activity structures.
1530 * -1 on error, 0 otherwise.
1531 ***************************************************************************
1533 int upgrade_restart_record(int fd, int stdfd, struct activity *act[],
1534 struct file_header *file_hdr, int previous_format,
1535 int endian_mismatch, int arch_64, unsigned int vol_act_nr)
1539 struct old_file_activity ofile_act;
1540 /* Number of cpu read in the activity list. See upgrade_header_section() */
1541 __nr_t cpu_nr = file_hdr->sa_cpu_nr;
1543 if (previous_format == FORMAT_MAGIC_2173) {
1545 * For versions from 10.3.1 to 11.6.x,
1546 * the restart record is followed by a list
1547 * of volatile activity structures. Among them is A_CPU activity.
1549 for (i = 0; i < vol_act_nr; i++) {
1550 sa_fread(fd, &ofile_act, OLD_FILE_ACTIVITY_SIZE, HARD_SIZE);
1552 /* Normalize endianness for file_activity structures */
1553 if (endian_mismatch) {
1554 swap_struct(oact_types_nr, &ofile_act, arch_64);
1557 if (ofile_act.id && (ofile_act.nr > 0)) {
1558 p = get_activity_position(act, ofile_act.id, EXIT_IF_NOT_FOUND);
1559 act[p]->nr_ini = ofile_act.nr;
1561 if (ofile_act.id == A_CPU) {
1562 cpu_nr = ofile_act.nr;
1566 /* Reallocate structures */
1567 allocate_structures(act);
1570 /* Restore endianness before writing */
1571 if (endian_mismatch) {
1572 cpu_nr = __builtin_bswap32(cpu_nr);
1575 /* Write new number of CPU following the restart record */
1576 if (write(stdfd, &cpu_nr, sizeof(__nr_t)) != sizeof(__nr_t)) {
1577 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1581 fprintf(stderr, "R");
1587 ***************************************************************************
1588 * Upgrade a record which is not a COMMENT or a RESTART one.
1591 * @fd File descriptor for sa datafile to convert.
1592 * @stdfd File descriptor for STDOUT.
1593 * @act Array of activities.
1594 * @file_hdr Pointer on file_header structure (up-to-date format).
1596 * Activity list in file.
1597 * @file_actlst Activity list in file (up-to-date format).
1599 * TRUE if data read from file don't match current machine's
1601 * @arch_64 TRUE if file's data come from a 64-bit machine.
1604 * -1 on error, 0 otherwise.
1605 ***************************************************************************
1607 int upgrade_common_record(int fd, int stdfd, struct activity *act[], struct file_header *file_hdr,
1608 struct old_file_activity *ofile_actlst, struct file_activity *file_actlst,
1609 int endian_mismatch, int arch_64)
1612 __nr_t nr_struct, nr;
1613 struct old_file_activity *ofal = ofile_actlst;
1614 struct file_activity *fal = file_actlst;
1618 * This is not a special record, so read the extra fields,
1619 * even if the format of the activity is unknown.
1621 for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++, fal++) {
1623 /* Every activity should be known at the moment (may change in the future) */
1624 p = get_activity_position(act, fal->id, EXIT_IF_NOT_FOUND);
1626 /* Warning: Stats structures keep their original endianness here */
1627 if ((act[p]->nr_ini > 0) &&
1628 ((act[p]->nr_ini > 1) || (act[p]->nr2 > 1)) &&
1629 (act[p]->msize > ofal->size)) {
1630 for (j = 0; j < act[p]->nr_ini; j++) {
1631 for (k = 0; k < act[p]->nr2; k++) {
1633 (char *) act[p]->buf[0] + (j * act[p]->nr2 + k) * act[p]->msize,
1634 ofal->size, HARD_SIZE);
1638 else if (act[p]->nr_ini > 0) {
1639 sa_fread(fd, act[p]->buf[0], ofal->size * act[p]->nr_ini * act[p]->nr2, HARD_SIZE);
1643 * NB: Cannot upgrade a stats structure with
1644 * a magic number higher than currently known.
1646 if (ofal->magic < act[p]->magic) {
1649 /* Known activity but old format */
1653 upgrade_stats_cpu(act, p, ofal->size);
1657 upgrade_stats_pcsw(act, p);
1661 upgrade_stats_irq(act, p);
1665 upgrade_stats_io(act, p, endian_mismatch);
1669 upgrade_stats_queue(act, p, ofal->magic,
1670 endian_mismatch, arch_64);
1674 upgrade_stats_memory(act, p, ofal->size,
1675 endian_mismatch, arch_64);
1679 upgrade_stats_ktables(act, p, endian_mismatch);
1683 upgrade_stats_serial(act, p, endian_mismatch);
1687 upgrade_stats_disk(act, p, ofal->magic,
1688 endian_mismatch, arch_64);
1692 upgrade_stats_net_dev(act, p, ofal->magic,
1693 endian_mismatch, arch_64);
1697 upgrade_stats_net_edev(act, p, ofal->magic,
1698 endian_mismatch, arch_64);
1702 upgrade_stats_net_ip(act, p, ofal->magic,
1703 endian_mismatch, arch_64);
1707 upgrade_stats_net_eip(act, p, ofal->magic,
1708 endian_mismatch, arch_64);
1712 upgrade_stats_net_ip6(act, p, ofal->magic,
1713 endian_mismatch, arch_64);
1717 upgrade_stats_net_eip6(act, p, ofal->magic,
1718 endian_mismatch, arch_64);
1722 upgrade_stats_huge(act, p, endian_mismatch, arch_64);
1726 upgrade_stats_pwr_wghfreq(act, p);
1730 upgrade_stats_filesystem(act, p, ofal->size);
1736 /* Known activity with current up-to-date format */
1737 for (j = 0; j < act[p]->nr_ini; j++) {
1738 for (k = 0; k < act[p]->nr2; k++) {
1739 memcpy((char *) act[p]->buf[1] + (j * act[p]->nr2 + k) * act[p]->msize,
1740 (char *) act[p]->buf[0] + (j * act[p]->nr2 + k) * act[p]->msize,
1746 nr_struct = act[p]->nr_ini;
1752 /* Nothing to do: Already done in upgrade_stats_serial() */
1756 nr_struct = count_stats_disk(act, p);
1760 nr_struct = count_stats_net_dev(act, p);
1764 nr_struct = count_stats_net_edev(act, p);
1768 nr_struct = count_stats_pwr_usb(act, p);
1772 nr_struct = count_stats_filesystem(act, p);
1776 nr_struct = count_stats_fchost(act, p);
1780 /* Restore endianness before writing */
1781 if (endian_mismatch) {
1782 nr = __builtin_bswap32(nr_struct);
1788 /* Write number of structures for current activity */
1789 if (write(stdfd, &nr, sizeof(__nr_t)) != sizeof(__nr_t))
1792 fprintf(stderr, "n");
1795 for (j = 0; j < nr_struct; j++) {
1796 for (k = 0; k < act[p]->nr2; k++) {
1798 (char *) act[p]->buf[1] + (j * act[p]->nr2 + k) * act[p]->fsize,
1799 act[p]->fsize) != act[p]->fsize)
1803 fprintf(stderr, "%c", cc);
1810 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1817 ***************************************************************************
1818 * Upgrade statistics records.
1821 * @fd File descriptor for sa datafile to convert.
1822 * @stdfd File descriptor for STDOUT.
1823 * @act Array of activities.
1824 * @file_hdr Pointer on file_header structure.
1826 * Activity list in file.
1827 * @file_actlst Activity list with up-to-date format.
1829 * TRUE is sa datafile has an old format which is no longer * @endian_mismatch
1830 * TRUE if data read from file don't match current machine's
1832 * @arch_64 TRUE if file's data come from a 64-bit machine.
1834 * compatible with current one.
1836 * TRUE if data read from file don't match current machine's
1838 * @arch_64 TRUE if file's data come from a 64-bit machine.
1839 * @vol_act_nr Number of volatile activity structures.
1842 * -1 on error, 0 otherwise.
1843 ***************************************************************************
1845 int upgrade_stat_records(int fd, int stdfd, struct activity *act[], struct file_header *file_hdr,
1846 struct old_file_activity *ofile_actlst, struct file_activity *file_actlst,
1847 int previous_format, int endian_mismatch, int arch_64,
1848 unsigned int vol_act_nr)
1852 struct old_record_header orec_hdr;
1853 unsigned int orec_types_nr[] = {OLD_RECORD_HEADER_ULL_NR, OLD_RECORD_HEADER_UL_NR, OLD_RECORD_HEADER_U_NR};
1855 fprintf(stderr, _("Statistics:\n"));
1858 eosaf = sa_fread(fd, &orec_hdr, OLD_RECORD_HEADER_SIZE, SOFT_SIZE);
1860 /* Normalize endianness */
1861 if (endian_mismatch) {
1862 swap_struct(orec_types_nr, &orec_hdr, arch_64);
1864 rtype = orec_hdr.record_type;
1867 /* Upgrade current record header */
1868 if (upgrade_record_header(fd, stdfd, &orec_hdr,
1869 endian_mismatch, arch_64) < 0)
1872 if (rtype == R_COMMENT) {
1873 /* Upgrade the COMMENT record */
1874 if (upgrade_comment_record(fd, stdfd) < 0)
1877 else if (rtype == R_RESTART) {
1878 /* Upgrade the RESTART record */
1879 if (upgrade_restart_record(fd, stdfd, act, file_hdr,
1880 previous_format, endian_mismatch,
1881 arch_64, vol_act_nr) < 0)
1885 /* Upgrade current statistics record */
1886 if (upgrade_common_record(fd, stdfd, act, file_hdr, ofile_actlst,
1887 file_actlst, endian_mismatch, arch_64) < 0)
1894 fprintf(stderr, "\n");
1900 ***************************************************************************
1901 * Close file descriptors and exit.
1904 * @fd File descriptor for sa datafile to convert.
1905 * @stdfd File descriptor for STDOUT.
1906 * @exit_code Exit code.
1907 ***************************************************************************
1909 void upgrade_exit(int fd, int stdfd, int exit_code)
1923 ***************************************************************************
1924 * Convert a sysstat activity data file from a previous version to the
1925 * up-to-date format. Presently data files from sysstat version 9.1.6 and
1926 * later are converted to current sysstat version format.
1929 * @dfile System activity data file name.
1930 * @act Array of activities.
1931 ***************************************************************************
1933 void convert_file(char dfile[], struct activity *act[])
1935 int fd = 0, stdfd = 0, previous_format = 0;
1937 unsigned int vol_act_nr = 0, hdr_size;
1938 struct file_magic file_magic;
1939 struct file_header file_hdr;
1940 struct file_activity *file_actlst = NULL;
1941 struct old_file_activity *ofile_actlst = NULL;
1944 if ((stdfd = dup(STDOUT_FILENO)) < 0) {
1946 upgrade_exit(0, 0, 2);
1949 /* Upgrade file's magic section */
1950 if (upgrade_magic_section(dfile, &fd, stdfd, &file_magic, &hdr_size,
1951 &previous_format, &endian_mismatch) < 0) {
1952 upgrade_exit(fd, stdfd, 2);
1954 if (previous_format == FORMAT_MAGIC) {
1955 /* Nothing to do at the present time */
1956 fprintf(stderr, _("\nFile format already up-to-date\n"));
1962 fprintf(stderr, _("HZ: Using current value: %lu\n"), HZ);
1964 /* Upgrade file's header section */
1965 if (upgrade_header_section(dfile, fd, stdfd, act, &file_magic,
1966 &file_hdr, hdr_size, previous_format, &arch_64,
1967 endian_mismatch, &vol_act_nr, &ofile_actlst) < 0) {
1968 upgrade_exit(fd, stdfd, 2);
1971 /* Upgrade file's activity list section */
1972 if (upgrade_activity_section(stdfd, act, &file_hdr,
1973 ofile_actlst, &file_actlst,
1974 endian_mismatch, arch_64) < 0) {
1975 upgrade_exit(fd, stdfd, 2);
1978 /* Perform required allocations */
1979 allocate_structures(act);
1981 /* Upgrade statistics records */
1982 if (upgrade_stat_records(fd, stdfd, act, &file_hdr, ofile_actlst, file_actlst,
1983 previous_format, endian_mismatch, arch_64,
1985 upgrade_exit(fd, stdfd, 2);
1990 free_structures(act);
1993 _("File successfully converted to sysstat format version %s\n"),
1997 upgrade_exit(fd, stdfd, 0);