2 * sa_conv.c: Convert an old format sa file to the up-to-date format.
3 * (C) 1999-2019 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_all(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, (size_t) n, HARD_SIZE, UEOF_STOP);
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, UEOF_STOP);
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_all(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 a 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 * @st_size Size of the structure read from file.
681 * TRUE if data read from file don't match current machine's
685 * Number of serial line structures that actually need to be written to
687 ***************************************************************************
689 int upgrade_stats_serial(struct activity *act[], int p, size_t st_size, int endian_mismatch)
693 struct stats_serial *ssc;
695 /* Copy TTY stats to target structure */
696 memcpy(act[p]->buf[1], act[p]->buf[0], (size_t) act[p]->nr_ini * st_size);
698 for (i = 0; i < act[p]->nr_ini; i++) {
699 ssc = (struct stats_serial *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
701 /* Line number now starts at 0 instead of 1 */
702 line = (endian_mismatch ? __builtin_bswap32(ssc->line) : ssc->line);
706 ssc->line = (endian_mismatch ? __builtin_bswap32(line) : line);
713 ***************************************************************************
714 * Upgrade stats_disk structure (from ACTIVITY_MAGIC_BASE format to
715 * ACTIVITY_MAGIC_BASE + 1 format).
718 * @act Array of activities.
719 * @p Position of activity in array.
720 * @magic Structure format magic value.
722 * TRUE if data read from file don't match current machine's
724 * @arch_64 TRUE if file's data come from a 64-bit machine.
725 ***************************************************************************
727 void upgrade_stats_disk(struct activity *act[], int p, unsigned int magic,
728 int endian_mismatch, int arch_64)
731 struct stats_disk *sdc;
733 if (magic == ACTIVITY_MAGIC_BASE) {
734 struct stats_disk_8a *sdp;
736 for (i = 0; i < act[p]->nr_ini; i++) {
737 sdp = (struct stats_disk_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
738 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
740 sdc->nr_ios = moveto_long_long(&sdp->nr_ios, endian_mismatch, arch_64);
741 sdc->rd_sect = (unsigned long) sdp->rd_sect;
742 sdc->wr_sect = (unsigned long) sdp->wr_sect;
743 sdc->rd_ticks = (unsigned int) sdp->rd_ticks;
744 sdc->wr_ticks = (unsigned int) sdp->wr_ticks;
745 sdc->tot_ticks = (unsigned int) sdp->tot_ticks;
746 sdc->rq_ticks = (unsigned int) sdp->rq_ticks;
747 sdc->major = sdp->major;
748 sdc->minor = sdp->minor;
752 struct stats_disk_8b *sdp;
754 for (i = 0; i < act[p]->nr_ini; i++) {
755 sdp = (struct stats_disk_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
756 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
758 sdc->nr_ios = sdp->nr_ios;
759 memcpy(&sdc->rd_sect, &sdp->rd_sect, 8);
760 memcpy(&sdc->wr_sect, &sdp->wr_sect, 8);
761 sdc->rd_ticks = sdp->rd_ticks;
762 sdc->wr_ticks = sdp->wr_ticks;
763 sdc->tot_ticks = sdp->tot_ticks;
764 sdc->rq_ticks = sdp->rq_ticks;
765 sdc->major = sdp->major;
766 sdc->minor = sdp->minor;
772 ***************************************************************************
773 * Upgrade stats_net_dev structure (from ACTIVITY_MAGIC_BASE or
774 * ACTIVITY_MAGIC_BASE + 1 format to ACTIVITY_MAGIC_BASE + 3 format).
777 * @act Array of activities.
778 * @p Position of activity in array.
779 * @magic Structure format magic value.
781 * TRUE if data read from file don't match current machine's
783 * @arch_64 TRUE if file's data come from a 64-bit machine.
784 ***************************************************************************
786 void upgrade_stats_net_dev(struct activity *act[], int p, unsigned int magic,
787 int endian_mismatch, int arch_64)
790 struct stats_net_dev *sndc;
792 if (magic == ACTIVITY_MAGIC_BASE) {
793 struct stats_net_dev_8a *sndp;
795 for (i = 0; i < act[p]->nr_ini; i++) {
796 sndp = (struct stats_net_dev_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
797 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
799 sndc->rx_packets = moveto_long_long(&sndp->rx_packets, endian_mismatch, arch_64);
800 sndc->tx_packets = moveto_long_long(&sndp->tx_packets, endian_mismatch, arch_64);
801 sndc->rx_bytes = moveto_long_long(&sndp->rx_bytes, endian_mismatch, arch_64);
802 sndc->tx_bytes = moveto_long_long(&sndp->tx_bytes, endian_mismatch, arch_64);
803 sndc->rx_compressed = moveto_long_long(&sndp->rx_compressed, endian_mismatch, arch_64);
804 sndc->tx_compressed = moveto_long_long(&sndp->tx_compressed, endian_mismatch, arch_64);
805 sndc->multicast = moveto_long_long(&sndp->multicast, endian_mismatch, arch_64);
806 sndc->speed = 0; /* New field */
807 strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
808 sndc->interface[MAX_IFACE_LEN - 1] = '\0';
809 sndc->duplex = '\0'; /* New field */
812 else if (magic == ACTIVITY_MAGIC_BASE + 1) {
813 struct stats_net_dev_8b *sndp;
815 for (i = 0; i < act[p]->nr_ini; i++) {
816 sndp = (struct stats_net_dev_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
817 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
819 sndc->rx_packets = sndp->rx_packets;
820 sndc->tx_packets = sndp->tx_packets;
821 sndc->rx_bytes = sndp->rx_bytes;
822 sndc->tx_bytes = sndp->tx_bytes;
823 sndc->rx_compressed = sndp->rx_compressed;
824 sndc->tx_compressed = sndp->tx_compressed;
825 sndc->multicast = sndp->multicast;
826 sndc->speed = 0; /* New field */
827 strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
828 sndc->interface[MAX_IFACE_LEN - 1] = '\0';
829 sndc->duplex = '\0'; /* New field */
833 struct stats_net_dev_8c *sndp;
835 for (i = 0; i < act[p]->nr_ini; i++) {
836 sndp = (struct stats_net_dev_8c *) ((char *) act[p]->buf[0] + i * act[p]->msize);
837 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
839 sndc->rx_packets = sndp->rx_packets;
840 sndc->tx_packets = sndp->tx_packets;
841 sndc->rx_bytes = sndp->rx_bytes;
842 sndc->tx_bytes = sndp->tx_bytes;
843 sndc->rx_compressed = sndp->rx_compressed;
844 sndc->tx_compressed = sndp->tx_compressed;
845 sndc->multicast = sndp->multicast;
846 sndc->speed = sndp->speed;
847 strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
848 sndc->interface[MAX_IFACE_LEN - 1] = '\0';
849 sndc->duplex = sndp->duplex;
855 ***************************************************************************
856 * Upgrade stats_net_edev structure (from ACTIVITY_MAGIC_BASE format to
857 * ACTIVITY_MAGIC_BASE + 1 format).
860 * @act Array of activities.
861 * @p Position of activity in array.
862 * @magic Structure format magic value.
864 * TRUE if data read from file don't match current machine's
866 * @arch_64 TRUE if file's data come from a 64-bit machine.
867 ***************************************************************************
869 void upgrade_stats_net_edev(struct activity *act[], int p, unsigned int magic,
870 int endian_mismatch, int arch_64)
873 struct stats_net_edev *snedc;
875 if (magic == ACTIVITY_MAGIC_BASE) {
876 struct stats_net_edev_8a *snedp;
878 for (i = 0; i < act[p]->nr_ini; i++) {
879 snedp = (struct stats_net_edev_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
880 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
882 snedc->collisions = moveto_long_long(&snedp->collisions, endian_mismatch, arch_64);
883 snedc->rx_errors = moveto_long_long(&snedp->rx_errors, endian_mismatch, arch_64);
884 snedc->tx_errors = moveto_long_long(&snedp->tx_errors, endian_mismatch, arch_64);
885 snedc->rx_dropped = moveto_long_long(&snedp->rx_dropped, endian_mismatch, arch_64);
886 snedc->tx_dropped = moveto_long_long(&snedp->tx_dropped, endian_mismatch, arch_64);
887 snedc->rx_fifo_errors = moveto_long_long(&snedp->rx_fifo_errors, endian_mismatch, arch_64);
888 snedc->tx_fifo_errors = moveto_long_long(&snedp->tx_fifo_errors, endian_mismatch, arch_64);
889 snedc->rx_frame_errors = moveto_long_long(&snedp->rx_frame_errors, endian_mismatch, arch_64);
890 snedc->tx_carrier_errors = moveto_long_long(&snedp->tx_carrier_errors, endian_mismatch, arch_64);
891 strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
892 snedc->interface[MAX_IFACE_LEN - 1] = '\0';
896 struct stats_net_edev_8b *snedp;
898 for (i = 0; i < act[p]->nr_ini; i++) {
899 snedp = (struct stats_net_edev_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
900 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
902 snedc->collisions = snedp->collisions;
903 snedc->rx_errors = snedp->rx_errors;
904 snedc->tx_errors = snedp->tx_errors;
905 snedc->rx_dropped = snedp->rx_dropped;
906 snedc->tx_dropped = snedp->tx_dropped;
907 snedc->rx_fifo_errors = snedp->rx_fifo_errors;
908 snedc->tx_fifo_errors = snedp->tx_fifo_errors;
909 snedc->rx_frame_errors = snedp->rx_frame_errors;
910 snedc->tx_carrier_errors = snedp->tx_carrier_errors;
911 strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
912 snedc->interface[MAX_IFACE_LEN - 1] = '\0';
918 ***************************************************************************
919 * Upgrade stats_net_ip structure (from ACTIVITY_MAGIC_BASE format to
920 * ACTIVITY_MAGIC_BASE + 1 format).
923 * @act Array of activities.
924 * @p Position of activity in array.
925 * @magic Structure format magic value.
927 * TRUE if data read from file don't match current machine's
929 * @arch_64 TRUE if file's data come from a 64-bit machine.
930 ***************************************************************************
932 void upgrade_stats_net_ip(struct activity *act[], int p, unsigned int magic,
933 int endian_mismatch, int arch_64)
935 struct stats_net_ip *snic = (struct stats_net_ip *) act[p]->buf[1];
937 if (magic == ACTIVITY_MAGIC_BASE) {
938 struct stats_net_ip_8a *snip = (struct stats_net_ip_8a *) act[p]->buf[0];
940 snic->InReceives = moveto_long_long(&snip->InReceives, endian_mismatch, arch_64);
941 snic->ForwDatagrams = moveto_long_long(&snip->ForwDatagrams, endian_mismatch, arch_64);
942 snic->InDelivers = moveto_long_long(&snip->InDelivers, endian_mismatch, arch_64);
943 snic->OutRequests = moveto_long_long(&snip->OutRequests, endian_mismatch, arch_64);
944 snic->ReasmReqds = moveto_long_long(&snip->ReasmReqds, endian_mismatch, arch_64);
945 snic->ReasmOKs = moveto_long_long(&snip->ReasmOKs, endian_mismatch, arch_64);
946 snic->FragOKs = moveto_long_long(&snip->FragOKs, endian_mismatch, arch_64);
947 snic->FragCreates = moveto_long_long(&snip->FragCreates, endian_mismatch, arch_64);
950 struct stats_net_ip_8b *snip = (struct stats_net_ip_8b *) act[p]->buf[0];
952 snic->InReceives = snip->InReceives;
953 snic->ForwDatagrams = snip->ForwDatagrams;
954 snic->InDelivers = snip->InDelivers;
955 snic->OutRequests = snip->OutRequests;
956 snic->ReasmReqds = snip->ReasmReqds;
957 snic->ReasmOKs = snip->ReasmOKs;
958 snic->FragOKs = snip->FragOKs;
959 snic->FragCreates = snip->FragCreates;
964 ***************************************************************************
965 * Upgrade stats_net_eip structure (from ACTIVITY_MAGIC_BASE format to
966 * ACTIVITY_MAGIC_BASE + 1 format).
969 * @act Array of activities.
970 * @p Position of activity in array.
971 * @magic Structure format magic value.
973 * TRUE if data read from file don't match current machine's
975 * @arch_64 TRUE if file's data come from a 64-bit machine.
976 ***************************************************************************
978 void upgrade_stats_net_eip(struct activity *act[], int p, unsigned int magic,
979 int endian_mismatch, int arch_64)
981 struct stats_net_eip *sneic = (struct stats_net_eip *) act[p]->buf[1];
983 if (magic == ACTIVITY_MAGIC_BASE) {
984 struct stats_net_eip_8a *sneip = (struct stats_net_eip_8a *) act[p]->buf[0];
986 sneic->InHdrErrors = moveto_long_long(&sneip->InHdrErrors, endian_mismatch, arch_64);
987 sneic->InAddrErrors = moveto_long_long(&sneip->InAddrErrors, endian_mismatch, arch_64);
988 sneic->InUnknownProtos = moveto_long_long(&sneip->InUnknownProtos, endian_mismatch, arch_64);
989 sneic->InDiscards = moveto_long_long(&sneip->InDiscards, endian_mismatch, arch_64);
990 sneic->OutDiscards = moveto_long_long(&sneip->OutDiscards, endian_mismatch, arch_64);
991 sneic->OutNoRoutes = moveto_long_long(&sneip->OutNoRoutes, endian_mismatch, arch_64);
992 sneic->ReasmFails = moveto_long_long(&sneip->ReasmFails, endian_mismatch, arch_64);
993 sneic->FragFails = moveto_long_long(&sneip->FragFails, endian_mismatch, arch_64);
996 struct stats_net_eip_8b *sneip = (struct stats_net_eip_8b *) act[p]->buf[0];
998 sneic->InHdrErrors = sneip->InHdrErrors;
999 sneic->InAddrErrors = sneip->InAddrErrors;
1000 sneic->InUnknownProtos = sneip->InUnknownProtos;
1001 sneic->InDiscards = sneip->InDiscards;
1002 sneic->OutDiscards = sneip->OutDiscards;
1003 sneic->OutNoRoutes = sneip->OutNoRoutes;
1004 sneic->ReasmFails = sneip->ReasmFails;
1005 sneic->FragFails = sneip->FragFails;
1010 ***************************************************************************
1011 * Upgrade stats_net_ip6 structure (from ACTIVITY_MAGIC_BASE format to
1012 * ACTIVITY_MAGIC_BASE + 1 format).
1015 * @act Array of activities.
1016 * @p Position of activity in array.
1017 * @magic Structure format magic value.
1019 * TRUE if data read from file don't match current machine's
1021 * @arch_64 TRUE if file's data come from a 64-bit machine.
1022 ***************************************************************************
1024 void upgrade_stats_net_ip6(struct activity *act[], int p, unsigned int magic,
1025 int endian_mismatch, int arch_64)
1027 struct stats_net_ip6 *snic6 = (struct stats_net_ip6 *) act[p]->buf[1];
1029 if (magic == ACTIVITY_MAGIC_BASE) {
1030 struct stats_net_ip6_8a *snip6 = (struct stats_net_ip6_8a *) act[p]->buf[0];
1032 snic6->InReceives6 = moveto_long_long(&snip6->InReceives6, endian_mismatch, arch_64);
1033 snic6->OutForwDatagrams6 = moveto_long_long(&snip6->OutForwDatagrams6, endian_mismatch, arch_64);
1034 snic6->InDelivers6 = moveto_long_long(&snip6->InDelivers6, endian_mismatch, arch_64);
1035 snic6->OutRequests6 = moveto_long_long(&snip6->OutRequests6, endian_mismatch, arch_64);
1036 snic6->ReasmReqds6 = moveto_long_long(&snip6->ReasmReqds6, endian_mismatch, arch_64);
1037 snic6->ReasmOKs6 = moveto_long_long(&snip6->ReasmOKs6, endian_mismatch, arch_64);
1038 snic6->InMcastPkts6 = moveto_long_long(&snip6->InMcastPkts6, endian_mismatch, arch_64);
1039 snic6->OutMcastPkts6 = moveto_long_long(&snip6->OutMcastPkts6, endian_mismatch, arch_64);
1040 snic6->FragOKs6 = moveto_long_long(&snip6->FragOKs6, endian_mismatch, arch_64);
1041 snic6->FragCreates6 = moveto_long_long(&snip6->FragCreates6, endian_mismatch, arch_64);
1044 struct stats_net_ip6_8b *snip6 = (struct stats_net_ip6_8b *) act[p]->buf[0];
1046 snic6->InReceives6 = snip6->InReceives6;
1047 snic6->OutForwDatagrams6 = snip6->OutForwDatagrams6;
1048 snic6->InDelivers6 = snip6->InDelivers6;
1049 snic6->OutRequests6 = snip6->OutRequests6;
1050 snic6->ReasmReqds6 = snip6->ReasmReqds6;
1051 snic6->ReasmOKs6 = snip6->ReasmOKs6;
1052 snic6->InMcastPkts6 = snip6->InMcastPkts6;
1053 snic6->OutMcastPkts6 = snip6->OutMcastPkts6;
1054 snic6->FragOKs6 = snip6->FragOKs6;
1055 snic6->FragCreates6 = snip6->FragCreates6;
1060 ***************************************************************************
1061 * Upgrade stats_net_eip6 structure (from ACTIVITY_MAGIC_BASE format to
1062 * ACTIVITY_MAGIC_BASE + 1 format).
1065 * @act Array of activities.
1066 * @p Position of activity in array.
1067 * @magic Structure format magic value.
1069 * TRUE if data read from file don't match current machine's
1071 * @arch_64 TRUE if file's data come from a 64-bit machine.
1072 ***************************************************************************
1074 void upgrade_stats_net_eip6(struct activity *act[], int p, unsigned int magic,
1075 int endian_mismatch, int arch_64)
1077 struct stats_net_eip6 *sneic6 = (struct stats_net_eip6 *) act[p]->buf[1];
1079 if (magic == ACTIVITY_MAGIC_BASE) {
1080 struct stats_net_eip6_8a *sneip6 = (struct stats_net_eip6_8a *) act[p]->buf[0];
1082 sneic6->InHdrErrors6 = moveto_long_long(&sneip6->InHdrErrors6, endian_mismatch, arch_64);
1083 sneic6->InAddrErrors6 = moveto_long_long(&sneip6->InAddrErrors6, endian_mismatch, arch_64);
1084 sneic6->InUnknownProtos6 = moveto_long_long(&sneip6->InUnknownProtos6, endian_mismatch, arch_64);
1085 sneic6->InTooBigErrors6 = moveto_long_long(&sneip6->InTooBigErrors6, endian_mismatch, arch_64);
1086 sneic6->InDiscards6 = moveto_long_long(&sneip6->InDiscards6, endian_mismatch, arch_64);
1087 sneic6->OutDiscards6 = moveto_long_long(&sneip6->OutDiscards6, endian_mismatch, arch_64);
1088 sneic6->InNoRoutes6 = moveto_long_long(&sneip6->InNoRoutes6, endian_mismatch, arch_64);
1089 sneic6->OutNoRoutes6 = moveto_long_long(&sneip6->OutNoRoutes6, endian_mismatch, arch_64);
1090 sneic6->ReasmFails6 = moveto_long_long(&sneip6->ReasmFails6, endian_mismatch, arch_64);
1091 sneic6->FragFails6 = moveto_long_long(&sneip6->FragFails6, endian_mismatch, arch_64);
1092 sneic6->InTruncatedPkts6 = moveto_long_long(&sneip6->InTruncatedPkts6, endian_mismatch, arch_64);
1095 struct stats_net_eip6_8b *sneip6 = (struct stats_net_eip6_8b *) act[p]->buf[0];
1097 sneic6->InHdrErrors6 = sneip6->InHdrErrors6;
1098 sneic6->InAddrErrors6 = sneip6->InAddrErrors6;
1099 sneic6->InUnknownProtos6 = sneip6->InUnknownProtos6;
1100 sneic6->InTooBigErrors6 = sneip6->InTooBigErrors6;
1101 sneic6->InDiscards6 = sneip6->InDiscards6;
1102 sneic6->OutDiscards6 = sneip6->OutDiscards6;
1103 sneic6->InNoRoutes6 = sneip6->InNoRoutes6;
1104 sneic6->OutNoRoutes6 = sneip6->OutNoRoutes6;
1105 sneic6->ReasmFails6 = sneip6->ReasmFails6;
1106 sneic6->FragFails6 = sneip6->FragFails6;
1107 sneic6->InTruncatedPkts6 = sneip6->InTruncatedPkts6;
1112 ***************************************************************************
1113 * Upgrade stats_huge structure (from ACTIVITY_MAGIC_BASE format to
1114 * ACTIVITY_MAGIC_BASE + 1 format).
1117 * @act Array of activities.
1118 * @p Position of activity in array.
1120 * TRUE if data read from file don't match current machine's
1122 * @arch_64 TRUE if file's data come from a 64-bit machine.
1123 ***************************************************************************
1125 void upgrade_stats_huge(struct activity *act[], int p,
1126 int endian_mismatch, int arch_64)
1128 struct stats_huge *shc = (struct stats_huge *) act[p]->buf[1];
1129 struct stats_huge_8a *shp = (struct stats_huge_8a *) act[p]->buf[0];
1131 shc->frhkb = moveto_long_long(&shp->frhkb, endian_mismatch, arch_64);
1132 shc->tlhkb = moveto_long_long(&shp->tlhkb, endian_mismatch, arch_64);
1136 ***************************************************************************
1137 * Upgrade stats_pwr_wghfreq structure (from ACTIVITY_MAGIC_BASE format to
1138 * ACTIVITY_MAGIC_BASE + 1 format).
1141 * @act Array of activities.
1142 * @p Position of activity in array.
1143 ***************************************************************************
1145 void upgrade_stats_pwr_wghfreq(struct activity *act[], int p)
1149 struct stats_pwr_wghfreq *spc, *spc_k;
1150 struct stats_pwr_wghfreq_8a *spp, *spp_k;
1152 for (i = 0; i < act[p]->nr_ini; i++) {
1153 spp = (struct stats_pwr_wghfreq_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize * act[p]->nr2);
1154 spc = (struct stats_pwr_wghfreq *) ((char *) act[p]->buf[1] + i * act[p]->fsize * act[p]->nr2);
1156 for (k = 0; k < act[p]->nr2; k++) {
1157 spp_k = (struct stats_pwr_wghfreq_8a *) ((char *) spp + k * act[p]->msize);
1160 spc_k = (struct stats_pwr_wghfreq *) ((char *) spc + k * act[p]->fsize);
1162 spc_k->time_in_state = spp_k->time_in_state;
1163 memcpy(&spc_k->freq, &spp_k->freq, 8);
1169 ***************************************************************************
1170 * Upgrade stats_filesystem structure (from ACTIVITY_MAGIC_BASE format to
1171 * ACTIVITY_MAGIC_BASE + 1 format).
1174 * @act Array of activities.
1175 * @p Position of activity in array.
1176 * @st_size Size of the structure read from file.
1177 ***************************************************************************
1179 void upgrade_stats_filesystem(struct activity *act[], int p, int st_size)
1182 struct stats_filesystem *sfc;
1183 struct stats_filesystem_8a *sfp;
1185 for (i = 0; i < act[p]->nr_ini; i++) {
1186 sfp = (struct stats_filesystem_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
1187 sfc = (struct stats_filesystem *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1189 sfc->f_blocks = sfp->f_blocks;
1190 sfc->f_bfree = sfp->f_bfree;
1191 sfc->f_bavail = sfp->f_bavail;
1192 sfc->f_files = sfp->f_files;
1193 sfc->f_ffree = sfp->f_ffree;
1194 strncpy(sfc->fs_name, sfp->fs_name, MAX_FS_LEN);
1195 sfc->fs_name[MAX_FS_LEN - 1] = '\0';
1197 if (st_size <= STATS_FILESYSTEM_8A_1_SIZE) {
1198 /* mountp didn't exist with older versions */
1199 sfc->mountp[0] = '\0';
1202 strncpy(sfc->mountp, sfp->mountp, MAX_FS_LEN);
1203 sfc->mountp[MAX_FS_LEN - 1] = '\0';
1209 ***************************************************************************
1210 * Count number of stats_disk structures that need to be written.
1213 * @act Array of activities.
1214 * @p Position of activity in array.
1215 ***************************************************************************
1217 __nr_t count_stats_disk(struct activity *act[], int p)
1221 struct stats_disk *sdc;
1223 for (i = 0; i < act[p]->nr_ini; i++) {
1224 sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1225 if (!(sdc->major + sdc->minor))
1235 ***************************************************************************
1236 * Count number of stats_net_dev structures that need to be written.
1239 * @act Array of activities.
1240 * @p Position of activity in array.
1241 ***************************************************************************
1243 __nr_t count_stats_net_dev(struct activity *act[], int p)
1247 struct stats_net_dev *sndc;
1249 for (i = 0; i < act[p]->nr_ini; i++) {
1250 sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1251 if (!strcmp(sndc->interface, ""))
1261 ***************************************************************************
1262 * Count number of stats_net_edev structures that need to be written.
1265 * @act Array of activities.
1266 * @p Position of activity in array.
1267 ***************************************************************************
1269 __nr_t count_stats_net_edev(struct activity *act[], int p)
1273 struct stats_net_edev *snedc;
1275 for (i = 0; i < act[p]->nr_ini; i++) {
1276 snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1277 if (!strcmp(snedc->interface, ""))
1287 ***************************************************************************
1288 * Count number of stats_pwr_usb structures that need to be written.
1291 * @act Array of activities.
1292 * @p Position of activity in array.
1293 ***************************************************************************
1295 __nr_t count_stats_pwr_usb(struct activity *act[], int p)
1299 struct stats_pwr_usb *suc;
1301 for (i = 0; i < act[p]->nr_ini; i++) {
1302 suc = (struct stats_pwr_usb *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1313 ***************************************************************************
1314 * Count number of stats_filesystem structures that need to be written.
1317 * @act Array of activities.
1318 * @p Position of activity in array.
1319 ***************************************************************************
1321 __nr_t count_stats_filesystem(struct activity *act[], int p)
1325 struct stats_filesystem *sfc;
1327 for (i = 0; i < act[p]->nr_ini; i++) {
1328 sfc = (struct stats_filesystem *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1339 ***************************************************************************
1340 * Count number of stats_fchost structures that need to be written.
1343 * @act Array of activities.
1344 * @p Position of activity in array.
1345 ***************************************************************************
1347 __nr_t count_stats_fchost(struct activity *act[], int p)
1351 struct stats_fchost *sfcc;
1353 for (i = 0; i < act[p]->nr_ini; i++) {
1354 sfcc = (struct stats_fchost *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
1355 if (!sfcc->fchost_name[0])
1365 ***************************************************************************
1366 * Upgrade file's activity list section.
1369 * @stdfd File descriptor for STDOUT.
1370 * @act Array of activities.
1371 * @file_hdr Pointer on file_header structure.
1372 * @ofile_actlst Activity list in file.
1374 * TRUE if data read from file don't match current machine's
1376 * @arch_64 TRUE if file's data come from a 64-bit machine.
1379 * @file_actlst Activity list with up-to-date format.
1382 * -1 on error, 0 otherwise.
1383 ***************************************************************************
1385 int upgrade_activity_section(int stdfd, struct activity *act[],
1386 struct file_header *file_hdr,
1387 struct old_file_activity *ofile_actlst,
1388 struct file_activity **file_actlst,
1389 int endian_mismatch, int arch_64)
1392 struct old_file_activity *ofal;
1393 struct file_activity *fal, fa;
1395 fprintf(stderr, "file_activity: ");
1397 SREALLOC(*file_actlst, struct file_activity, FILE_ACTIVITY_SIZE * file_hdr->sa_act_nr);
1399 ofal = ofile_actlst;
1401 for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++, fal++) {
1403 /* Every activity should be known at the moment (may change in the future) */
1404 p = get_activity_position(act, ofal->id, EXIT_IF_NOT_FOUND);
1407 fal->nr2 = ofal->nr2;
1408 fal->magic = act[p]->magic; /* Update activity magic number */
1409 fal->has_nr = HAS_COUNT_FUNCTION(act[p]->options);
1410 /* Also update its size, which may have changed with recent versions */
1411 fal->size = act[p]->fsize;
1412 for (j = 0; j < 3; j++) {
1413 fal->types_nr[j] = act[p]->gtypes_nr[j];
1416 memcpy(&fa, fal, FILE_ACTIVITY_SIZE);
1417 /* Restore endianness before writing */
1418 if (endian_mismatch) {
1419 /* Start swapping at field "header_size" position */
1420 swap_struct(act_types_nr, &fa, arch_64);
1424 * Even unknown activities must be written
1425 * (they are counted in sa_act_nr).
1427 if (write_all(stdfd, &fa, FILE_ACTIVITY_SIZE) != FILE_ACTIVITY_SIZE) {
1428 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1431 fprintf(stderr, "%s ", act[p]->name);
1434 fprintf(stderr, "OK\n");
1440 ***************************************************************************
1441 * Upgrade a record header.
1444 * @fd File descriptor for sa datafile to convert.
1445 * @stdfd File descriptor for STDOUT.
1446 * @orec_hdr Record's header structure to convert.
1448 * TRUE if data read from file don't match current machine's
1450 * @arch_64 TRUE if file's data come from a 64-bit machine.
1453 * -1 on error, 0 otherwise.
1454 ***************************************************************************
1456 int upgrade_record_header(int fd, int stdfd, struct old_record_header *orec_hdr,
1457 int endian_mismatch, int arch_64)
1459 struct record_header rec_hdr;
1461 memset(&rec_hdr, 0, sizeof(struct record_header));
1463 /* Convert current record header */
1464 rec_hdr.uptime_cs = orec_hdr->uptime0 * 100 / HZ; /* Uptime in cs, not jiffies */
1465 rec_hdr.ust_time = (unsigned long long) orec_hdr->ust_time;
1466 rec_hdr.record_type = orec_hdr->record_type;
1467 rec_hdr.hour = orec_hdr->hour;
1468 rec_hdr.minute = orec_hdr->minute;
1469 rec_hdr.second = orec_hdr->second;
1471 /* Restore endianness before writing */
1472 if (endian_mismatch) {
1473 swap_struct(rec_types_nr, &rec_hdr, arch_64);
1476 /* Write record header */
1477 if (write_all(stdfd, &rec_hdr, RECORD_HEADER_SIZE) != RECORD_HEADER_SIZE) {
1478 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1482 fprintf(stderr, "H");
1488 ***************************************************************************
1489 * Upgrade a COMMENT record.
1492 * @fd File descriptor for sa datafile to convert.
1493 * @stdfd File descriptor for STDOUT.
1496 * -1 on error, 0 otherwise.
1497 ***************************************************************************
1499 int upgrade_comment_record(int fd, int stdfd)
1501 char file_comment[MAX_COMMENT_LEN];
1503 /* Read the COMMENT record */
1504 sa_fread(fd, file_comment, MAX_COMMENT_LEN, HARD_SIZE, UEOF_STOP);
1505 file_comment[MAX_COMMENT_LEN - 1] = '\0';
1507 /* Then write it. No changes at this time */
1508 if (write_all(stdfd, file_comment, MAX_COMMENT_LEN) != MAX_COMMENT_LEN) {
1509 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1513 fprintf(stderr, "C");
1519 ***************************************************************************
1520 * Upgrade a RESTART record.
1523 * @fd File descriptor for sa datafile to convert.
1524 * @stdfd File descriptor for STDOUT.
1525 * @act Array of activities.
1526 * @file_hdr Pointer on file_header structure.
1528 * TRUE is sa datafile has an old format which is no longer
1529 * compatible with current one.
1531 * TRUE if data read from file don't match current machine's
1533 * @arch_64 TRUE if file's data come from a 64-bit machine.
1534 * @vol_act_nr Number of volatile activity structures.
1537 * -1 on error, 0 otherwise.
1538 ***************************************************************************
1540 int upgrade_restart_record(int fd, int stdfd, struct activity *act[],
1541 struct file_header *file_hdr, int previous_format,
1542 int endian_mismatch, int arch_64, unsigned int vol_act_nr)
1546 struct old_file_activity ofile_act;
1547 /* Number of cpu read in the activity list. See upgrade_header_section() */
1548 __nr_t cpu_nr = file_hdr->sa_cpu_nr;
1550 if (previous_format == FORMAT_MAGIC_2173) {
1552 * For versions from 10.3.1 to 11.6.x,
1553 * the restart record is followed by a list
1554 * of volatile activity structures. Among them is A_CPU activity.
1556 for (i = 0; i < vol_act_nr; i++) {
1557 sa_fread(fd, &ofile_act, OLD_FILE_ACTIVITY_SIZE, HARD_SIZE, UEOF_STOP);
1559 /* Normalize endianness for file_activity structures */
1560 if (endian_mismatch) {
1561 swap_struct(oact_types_nr, &ofile_act, arch_64);
1564 if (ofile_act.id && (ofile_act.nr > 0)) {
1565 p = get_activity_position(act, ofile_act.id, EXIT_IF_NOT_FOUND);
1566 act[p]->nr_ini = ofile_act.nr;
1568 if (ofile_act.id == A_CPU) {
1569 cpu_nr = ofile_act.nr;
1573 /* Reallocate structures */
1574 allocate_structures(act);
1577 /* Restore endianness before writing */
1578 if (endian_mismatch) {
1579 cpu_nr = __builtin_bswap32(cpu_nr);
1582 /* Write new number of CPU following the restart record */
1583 if (write_all(stdfd, &cpu_nr, sizeof(__nr_t)) != sizeof(__nr_t)) {
1584 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1588 fprintf(stderr, "R");
1594 ***************************************************************************
1595 * Upgrade a record which is not a COMMENT or a RESTART one.
1598 * @fd File descriptor for sa datafile to convert.
1599 * @stdfd File descriptor for STDOUT.
1600 * @act Array of activities.
1601 * @file_hdr Pointer on file_header structure (up-to-date format).
1603 * Activity list in file.
1604 * @file_actlst Activity list in file (up-to-date format).
1606 * TRUE if data read from file don't match current machine's
1608 * @arch_64 TRUE if file's data come from a 64-bit machine.
1611 * -1 on error, 0 otherwise.
1612 ***************************************************************************
1614 int upgrade_common_record(int fd, int stdfd, struct activity *act[], struct file_header *file_hdr,
1615 struct old_file_activity *ofile_actlst, struct file_activity *file_actlst,
1616 int endian_mismatch, int arch_64)
1619 __nr_t nr_struct, nr;
1620 struct old_file_activity *ofal = ofile_actlst;
1621 struct file_activity *fal = file_actlst;
1625 * This is not a special record, so read the extra fields,
1626 * even if the format of the activity is unknown.
1628 for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++, fal++) {
1630 /* Every activity should be known at the moment (may change in the future) */
1631 p = get_activity_position(act, fal->id, EXIT_IF_NOT_FOUND);
1633 /* Warning: Stats structures keep their original endianness here */
1634 if ((act[p]->nr_ini > 0) &&
1635 ((act[p]->nr_ini > 1) || (act[p]->nr2 > 1)) &&
1636 (act[p]->msize > ofal->size)) {
1637 for (j = 0; j < act[p]->nr_ini; j++) {
1638 for (k = 0; k < act[p]->nr2; k++) {
1640 (char *) act[p]->buf[0] + (j * act[p]->nr2 + k) * act[p]->msize,
1641 (size_t) ofal->size, HARD_SIZE, UEOF_STOP);
1645 else if (act[p]->nr_ini > 0) {
1646 sa_fread(fd, act[p]->buf[0],
1647 (size_t) ofal->size * (size_t) act[p]->nr_ini * (size_t) act[p]->nr2,
1648 HARD_SIZE, UEOF_STOP);
1651 nr_struct = act[p]->nr_ini;
1653 * NB: Cannot upgrade a stats structure with
1654 * a magic number higher than currently known.
1656 if (ofal->magic < act[p]->magic) {
1659 /* Known activity but old format */
1663 upgrade_stats_cpu(act, p, ofal->size);
1667 upgrade_stats_pcsw(act, p);
1671 upgrade_stats_irq(act, p);
1675 upgrade_stats_io(act, p, endian_mismatch);
1679 upgrade_stats_queue(act, p, ofal->magic,
1680 endian_mismatch, arch_64);
1684 upgrade_stats_memory(act, p, ofal->size,
1685 endian_mismatch, arch_64);
1689 upgrade_stats_ktables(act, p, endian_mismatch);
1693 nr_struct = upgrade_stats_serial(act, p, ofal->size,
1698 upgrade_stats_disk(act, p, ofal->magic,
1699 endian_mismatch, arch_64);
1703 upgrade_stats_net_dev(act, p, ofal->magic,
1704 endian_mismatch, arch_64);
1708 upgrade_stats_net_edev(act, p, ofal->magic,
1709 endian_mismatch, arch_64);
1713 upgrade_stats_net_ip(act, p, ofal->magic,
1714 endian_mismatch, arch_64);
1718 upgrade_stats_net_eip(act, p, ofal->magic,
1719 endian_mismatch, arch_64);
1723 upgrade_stats_net_ip6(act, p, ofal->magic,
1724 endian_mismatch, arch_64);
1728 upgrade_stats_net_eip6(act, p, ofal->magic,
1729 endian_mismatch, arch_64);
1733 upgrade_stats_huge(act, p, endian_mismatch, arch_64);
1737 upgrade_stats_pwr_wghfreq(act, p);
1741 upgrade_stats_filesystem(act, p, ofal->size);
1747 /* Known activity with current up-to-date format */
1748 for (j = 0; j < act[p]->nr_ini; j++) {
1749 for (k = 0; k < act[p]->nr2; k++) {
1750 memcpy((char *) act[p]->buf[1] + (j * act[p]->nr2 + k) * act[p]->msize,
1751 (char *) act[p]->buf[0] + (j * act[p]->nr2 + k) * act[p]->msize,
1762 /* Nothing to do: Already done in upgrade_stats_serial() */
1766 nr_struct = count_stats_disk(act, p);
1770 nr_struct = count_stats_net_dev(act, p);
1774 nr_struct = count_stats_net_edev(act, p);
1778 nr_struct = count_stats_pwr_usb(act, p);
1782 nr_struct = count_stats_filesystem(act, p);
1786 nr_struct = count_stats_fchost(act, p);
1790 /* Restore endianness before writing */
1791 if (endian_mismatch) {
1792 nr = __builtin_bswap32(nr_struct);
1798 /* Write number of structures for current activity */
1799 if (write_all(stdfd, &nr, sizeof(__nr_t)) != sizeof(__nr_t))
1802 fprintf(stderr, "n");
1805 for (j = 0; j < nr_struct; j++) {
1806 for (k = 0; k < act[p]->nr2; k++) {
1807 if (write_all(stdfd,
1808 (char *) act[p]->buf[1] + (j * act[p]->nr2 + k) * act[p]->fsize,
1809 act[p]->fsize) != act[p]->fsize)
1813 fprintf(stderr, "%c", cc);
1820 fprintf(stderr, "\nwrite: %s\n", strerror(errno));
1827 ***************************************************************************
1828 * Upgrade statistics records.
1831 * @fd File descriptor for sa datafile to convert.
1832 * @stdfd File descriptor for STDOUT.
1833 * @act Array of activities.
1834 * @file_hdr Pointer on file_header structure.
1836 * Activity list in file.
1837 * @file_actlst Activity list with up-to-date format.
1839 * TRUE is sa datafile has an old format which is no longer * @endian_mismatch
1840 * TRUE if data read from file don't match current machine's
1842 * @arch_64 TRUE if file's data come from a 64-bit machine.
1844 * compatible with current one.
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.
1849 * @vol_act_nr Number of volatile activity structures.
1852 * -1 on error, 0 otherwise.
1853 ***************************************************************************
1855 int upgrade_stat_records(int fd, int stdfd, struct activity *act[], struct file_header *file_hdr,
1856 struct old_file_activity *ofile_actlst, struct file_activity *file_actlst,
1857 int previous_format, int endian_mismatch, int arch_64,
1858 unsigned int vol_act_nr)
1862 struct old_record_header orec_hdr;
1863 unsigned int orec_types_nr[] = {OLD_RECORD_HEADER_ULL_NR, OLD_RECORD_HEADER_UL_NR, OLD_RECORD_HEADER_U_NR};
1865 fprintf(stderr, _("Statistics:\n"));
1868 eosaf = sa_fread(fd, &orec_hdr, OLD_RECORD_HEADER_SIZE, SOFT_SIZE, UEOF_STOP);
1870 /* Normalize endianness */
1871 if (endian_mismatch) {
1872 swap_struct(orec_types_nr, &orec_hdr, arch_64);
1874 rtype = orec_hdr.record_type;
1877 /* Upgrade current record header */
1878 if (upgrade_record_header(fd, stdfd, &orec_hdr,
1879 endian_mismatch, arch_64) < 0)
1882 if (rtype == R_COMMENT) {
1883 /* Upgrade the COMMENT record */
1884 if (upgrade_comment_record(fd, stdfd) < 0)
1887 else if (rtype == R_RESTART) {
1888 /* Upgrade the RESTART record */
1889 if (upgrade_restart_record(fd, stdfd, act, file_hdr,
1890 previous_format, endian_mismatch,
1891 arch_64, vol_act_nr) < 0)
1895 /* Upgrade current statistics record */
1896 if (upgrade_common_record(fd, stdfd, act, file_hdr, ofile_actlst,
1897 file_actlst, endian_mismatch, arch_64) < 0)
1904 fprintf(stderr, "\n");
1910 ***************************************************************************
1911 * Close file descriptors and exit.
1914 * @fd File descriptor for sa datafile to convert.
1915 * @stdfd File descriptor for STDOUT.
1916 * @exit_code Exit code.
1917 ***************************************************************************
1919 void upgrade_exit(int fd, int stdfd, int exit_code)
1933 ***************************************************************************
1934 * Convert a sysstat activity data file from a previous version to the
1935 * up-to-date format. Presently data files from sysstat version 9.1.6 and
1936 * later are converted to current sysstat version format.
1939 * @dfile System activity data file name.
1940 * @act Array of activities.
1941 ***************************************************************************
1943 void convert_file(char dfile[], struct activity *act[])
1945 int fd = 0, stdfd = 0, previous_format = 0;
1947 unsigned int vol_act_nr = 0, hdr_size;
1948 struct file_magic file_magic;
1949 struct file_header file_hdr;
1950 struct file_activity *file_actlst = NULL;
1951 struct old_file_activity *ofile_actlst = NULL;
1954 if ((stdfd = dup(STDOUT_FILENO)) < 0) {
1956 upgrade_exit(0, 0, 2);
1959 /* Upgrade file's magic section */
1960 if (upgrade_magic_section(dfile, &fd, stdfd, &file_magic, &hdr_size,
1961 &previous_format, &endian_mismatch) < 0) {
1962 upgrade_exit(fd, stdfd, 2);
1964 if (previous_format == FORMAT_MAGIC) {
1965 /* Nothing to do at the present time */
1966 fprintf(stderr, _("\nFile format already up-to-date\n"));
1972 fprintf(stderr, _("HZ: Using current value: %lu\n"), HZ);
1974 /* Upgrade file's header section */
1975 if (upgrade_header_section(dfile, fd, stdfd, act, &file_magic,
1976 &file_hdr, hdr_size, previous_format, &arch_64,
1977 endian_mismatch, &vol_act_nr, &ofile_actlst) < 0) {
1978 upgrade_exit(fd, stdfd, 2);
1981 /* Upgrade file's activity list section */
1982 if (upgrade_activity_section(stdfd, act, &file_hdr,
1983 ofile_actlst, &file_actlst,
1984 endian_mismatch, arch_64) < 0) {
1985 upgrade_exit(fd, stdfd, 2);
1988 /* Perform required allocations */
1989 allocate_structures(act);
1991 /* Upgrade statistics records */
1992 if (upgrade_stat_records(fd, stdfd, act, &file_hdr, ofile_actlst, file_actlst,
1993 previous_format, endian_mismatch, arch_64,
1995 upgrade_exit(fd, stdfd, 2);
2000 free_structures(act);
2003 _("File successfully converted to sysstat format version %s\n"),
2007 upgrade_exit(fd, stdfd, 0);