forked from sysstat/sysstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sa_conv.c
2006 lines (1759 loc) · 64.2 KB
/
sa_conv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* sa_conv.c: Convert an old format sa file to the up-to-date format.
* (C) 1999-2018 by Sebastien GODARD (sysstat <at> orange.fr)
*
***************************************************************************
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without the implied warranty of MERCHANTABILITY *
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
* for more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *
***************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "version.h"
#include "sadf.h"
#include "sa_conv.h"
#ifdef USE_NLS
# include <locale.h>
# include <libintl.h>
# define _(string) gettext(string)
#else
# define _(string) (string)
#endif
extern int endian_mismatch;
extern unsigned int act_types_nr[];
extern unsigned int rec_types_nr[];
extern unsigned int hdr_types_nr[];
unsigned int oact_types_nr[] = {OLD_FILE_ACTIVITY_ULL_NR, OLD_FILE_ACTIVITY_UL_NR, OLD_FILE_ACTIVITY_U_NR};
/*
***************************************************************************
* Read and upgrade file's magic data section.
*
* IN:
* @dfile System activity data file name.
* @stdfd File descriptor for STDOUT.
*
* OUT:
* @fd File descriptor for sa datafile to convert.
* @file_magic File's magic structure.
* @hdr_size Size of header structure read from file.
* @previous_format
* Format magic number of file to convert, converted to
* current endianness.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
*
* RETURNS:
* -1 on error, 0 otherwise.
***************************************************************************
*/
int upgrade_magic_section(char dfile[], int *fd, int stdfd, struct file_magic *file_magic,
unsigned int *hdr_size, int *previous_format, int *endian_mismatch)
{
struct file_magic fm;
unsigned int fm_types_nr[] = {FILE_MAGIC_ULL_NR, FILE_MAGIC_UL_NR, FILE_MAGIC_U_NR};
/* Open and read sa magic structure */
sa_open_read_magic(fd, dfile, file_magic, TRUE, endian_mismatch, FALSE);
switch (file_magic->format_magic) {
case FORMAT_MAGIC:
case FORMAT_MAGIC_SWAPPED:
*previous_format = FORMAT_MAGIC;
return 0;
break;
case FORMAT_MAGIC_2171:
case FORMAT_MAGIC_2171_SWAPPED:
*previous_format = FORMAT_MAGIC_2171;
break;
case FORMAT_MAGIC_2173:
case FORMAT_MAGIC_2173_SWAPPED:
*previous_format = FORMAT_MAGIC_2173;
break;
default:
fprintf(stderr, _("Cannot convert the format of this file\n"));
return -1;
break;
}
fprintf(stderr, "file_magic: ");
if (*previous_format == FORMAT_MAGIC_2171) {
/*
* We have read too many bytes: file_magic structure
* was smaller with previous sysstat versions.
* Go back 4 (unsigned int header_size) + 64 (char pad[64]) bytes.
*/
if (lseek(*fd, -68, SEEK_CUR) < 0) {
fprintf(stderr, "\nlseek: %s\n", strerror(errno));
return -1;
}
}
/* Set format magic number to that of current version */
file_magic->format_magic = (*endian_mismatch ? FORMAT_MAGIC_SWAPPED
: FORMAT_MAGIC);
/* Save original header structure's size */
*hdr_size = file_magic->header_size;
/* Fill new structure members */
file_magic->header_size = FILE_HEADER_SIZE;
file_magic->hdr_types_nr[0] = FILE_HEADER_ULL_NR;
file_magic->hdr_types_nr[1] = FILE_HEADER_UL_NR;
file_magic->hdr_types_nr[2] = FILE_HEADER_U_NR;
memset(file_magic->pad, 0, sizeof(unsigned char) * FILE_MAGIC_PADDING);
/* Indicate that file has been upgraded */
enum_version_nr(&fm);
file_magic->upgraded = (fm.sysstat_patchlevel << 8) +
fm.sysstat_sublevel + 1;
memcpy(&fm, file_magic, FILE_MAGIC_SIZE);
/* Restore endianness before writing */
if (*endian_mismatch) {
/* Start swapping at field "header_size" position */
swap_struct(fm_types_nr, &(fm.header_size), 0);
}
/* Write file's magic structure */
if (write_all(stdfd, &fm, FILE_MAGIC_SIZE) != FILE_MAGIC_SIZE) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
fprintf(stderr, "OK\n");
return 0;
}
/*
***************************************************************************
* Upgrade file_header structure (from 0x2171 format to current format).
*
* IN:
* @buffer File's header structure (as read from file).
* @previous_format
* Format magic number of file to convert.
* @endian_mismatch
* TRUE if data read from file don't match current
* machine's endianness.
*
* OUT:
* @file_hdr File's header structure (up-to-date format).
* @arch_64 TRUE if file's data come from a 64-bit machine.
* @vol_act_nr Number of volatile activity structures following a restart
* record for 0x2173 file format.
***************************************************************************
*/
void upgrade_file_header(void *buffer, struct file_header *file_hdr, int previous_format,
int endian_mismatch, int *arch_64, unsigned int *vol_act_nr)
{
struct file_header_2171 *f_hdr_2171 = (struct file_header_2171 *) buffer;
struct file_header_2173 *f_hdr_2173 = (struct file_header_2173 *) buffer;
unsigned int hdr_2171_types_nr[] = {FILE_HEADER_2171_ULL_NR, FILE_HEADER_2171_UL_NR, FILE_HEADER_2171_U_NR};
unsigned int hdr_2173_types_nr[] = {FILE_HEADER_2173_ULL_NR, FILE_HEADER_2173_UL_NR, FILE_HEADER_2173_U_NR};
int i;
memset(file_hdr, 0, FILE_HEADER_SIZE);
file_hdr->sa_hz = HZ;
if (previous_format == FORMAT_MAGIC_2171) {
*arch_64 = (f_hdr_2171->sa_sizeof_long == SIZEOF_LONG_64BIT);
/* Normalize endianness for f_hdr_2171 structure */
if (endian_mismatch) {
swap_struct(hdr_2171_types_nr, f_hdr_2171, *arch_64);
}
file_hdr->sa_ust_time = (unsigned long long) f_hdr_2171->sa_ust_time;
/* sa_cpu_nr field will be updated later */
file_hdr->sa_act_nr = f_hdr_2171->sa_act_nr;
file_hdr->sa_year = (int) f_hdr_2171->sa_year;
file_hdr->sa_day = f_hdr_2171->sa_day;
file_hdr->sa_month = f_hdr_2171->sa_month;
file_hdr->sa_sizeof_long = f_hdr_2171->sa_sizeof_long;
strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, UTSNAME_LEN);
file_hdr->sa_sysname[UTSNAME_LEN - 1] = '\0';
strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, UTSNAME_LEN);
file_hdr->sa_nodename[UTSNAME_LEN - 1] = '\0';
strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, UTSNAME_LEN);
file_hdr->sa_release[UTSNAME_LEN - 1] = '\0';
strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, UTSNAME_LEN);
file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
}
else if (previous_format == FORMAT_MAGIC_2173) {
*arch_64 = (f_hdr_2173->sa_sizeof_long == SIZEOF_LONG_64BIT);
/* Normalize endianness for f_hdr_2171 structure */
if (endian_mismatch) {
swap_struct(hdr_2173_types_nr, f_hdr_2173, *arch_64);
}
file_hdr->sa_ust_time = (unsigned long long) f_hdr_2173->sa_ust_time;
/* sa_cpu_nr field will be updated later */
file_hdr->sa_act_nr = f_hdr_2173->sa_act_nr;
file_hdr->sa_year = (int) f_hdr_2173->sa_year;
file_hdr->sa_day = f_hdr_2173->sa_day;
file_hdr->sa_month = f_hdr_2173->sa_month;
file_hdr->sa_sizeof_long = f_hdr_2173->sa_sizeof_long;
strncpy(file_hdr->sa_sysname, f_hdr_2173->sa_sysname, UTSNAME_LEN);
file_hdr->sa_sysname[UTSNAME_LEN - 1] = '\0';
strncpy(file_hdr->sa_nodename, f_hdr_2173->sa_nodename, UTSNAME_LEN);
file_hdr->sa_nodename[UTSNAME_LEN - 1] = '\0';
strncpy(file_hdr->sa_release, f_hdr_2173->sa_release, UTSNAME_LEN);
file_hdr->sa_release[UTSNAME_LEN - 1] = '\0';
strncpy(file_hdr->sa_machine, f_hdr_2173->sa_machine, UTSNAME_LEN);
file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
*vol_act_nr = f_hdr_2173->sa_vol_act_nr;
}
for (i = 0; i < 3; i++) {
file_hdr->act_types_nr[i] = act_types_nr[i];
file_hdr->rec_types_nr[i] = rec_types_nr[i];
}
file_hdr->act_size = FILE_ACTIVITY_SIZE;
file_hdr->rec_size = RECORD_HEADER_SIZE;
}
/*
***************************************************************************
* Read and upgrade file's header section.
*
* IN:
* @dfile System activity data file name.
* @fd File descriptor for sa datafile to convert.
* @stdfd File descriptor for STDOUT.
* @act Array of activities.
* @file_magic File's magic structure.
* @hdr_size Size of header structure read from file.
* @previous_format
* Format magic number of file to convert.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
*
* OUT:
* @file_hdr File's header structure (up-to-date format).
* @arch_64 TRUE if file's data come from a 64-bit machine.
* @vol_act_nr Number of volatile activity structures following a restart
* record for 0x2173 file format.
* @ofile_actlst
* Activity list in file.
*
* RETURNS:
* -1 on error, 0 otherwise.
***************************************************************************
*/
int upgrade_header_section(char dfile[], int fd, int stdfd, struct activity *act[],
struct file_magic *file_magic, struct file_header *file_hdr,
unsigned int hdr_size, int previous_format, int *arch_64,
int endian_mismatch, unsigned int *vol_act_nr,
struct old_file_activity **ofile_actlst)
{
struct old_file_activity *ofal;
struct file_header fh;
int i, n, p;
unsigned int a_cpu = FALSE;
void *buffer = NULL;
fprintf(stderr, "file_header: ");
/* Read file header structure */
n = (previous_format == FORMAT_MAGIC_2171 ? FILE_HEADER_SIZE_2171
: hdr_size);
SREALLOC(buffer, char, n);
sa_fread(fd, buffer, (size_t) n, HARD_SIZE, UEOF_STOP);
/* Upgrade file_header structure */
upgrade_file_header(buffer, file_hdr, previous_format,
endian_mismatch, arch_64, vol_act_nr);
free(buffer);
/* Sanity check */
if (file_hdr->sa_act_nr > MAX_NR_ACT)
goto invalid_header;
/* Read file activity list */
SREALLOC(*ofile_actlst, struct old_file_activity, OLD_FILE_ACTIVITY_SIZE * file_hdr->sa_act_nr);
ofal = *ofile_actlst;
for (i = 0; i < file_hdr->sa_act_nr; i++, ofal++) {
sa_fread(fd, ofal, OLD_FILE_ACTIVITY_SIZE, HARD_SIZE, UEOF_STOP);
/* Normalize endianness for file_activity structures */
if (endian_mismatch) {
swap_struct(oact_types_nr, ofal, *arch_64);
}
if ((ofal->nr < 1) || (ofal->nr2 < 1))
/*
* Every activity, known or unknown,
* should have at least one item and sub-item.
*/
goto invalid_header;
if ((p = get_activity_position(act, ofal->id, RESUME_IF_NOT_FOUND)) >= 0) {
/* This is a known activity, maybe with an unknown format */
if ((ofal->id == A_CPU) && !a_cpu) {
/*
* We have found the CPU activity: Set sa_cpu_nr field
* in file_header structure that should contains the
* number of CPU when the file was created.
*/
file_hdr->sa_cpu_nr = ofal->nr;
a_cpu = TRUE;
}
/* Size of an activity cannot be zero */
if (!ofal->size)
goto invalid_header;
/* Size of activity in file is larger than up-to-date activity size */
if (ofal->size > act[p]->msize) {
act[p]->msize = ofal->size;
}
/*
* When upgrading a file:
* ofal->size : Size of an item for current activity, as
* read from the file.
* act[p]->msize: Size of the buffer in memory where an item
* for current activity, as read from the file,
* will be saved. We have:
* act[p]->msize >= {ofal->size ; act[p]->fsize}
* act[p]->fsize: Size of an item for current activity with
* up-to-date format.
*/
act[p]->nr_ini = ofal->nr;
act[p]->nr2 = ofal->nr2;
/*
* Don't set act[p]->fsize! Should retain the size of an item
* for up-to-date format!
*/
}
}
if (!a_cpu) {
/*
* CPU activity should always be in file for versions older than 11.7.1
* and have a known format (expected magical number).
*/
fprintf(stderr, _("\nCPU activity not found in file. Aborting...\n"));
return -1;
}
memcpy(&fh, file_hdr, FILE_HEADER_SIZE);
/* Restore endianness before writing */
if (endian_mismatch) {
/* Start swapping at field "header_size" position */
swap_struct(hdr_types_nr, &fh, *arch_64);
}
/* Write file_header structure */
if ((n = write_all(stdfd, &fh, FILE_HEADER_SIZE)) != FILE_HEADER_SIZE) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
fprintf(stderr, "OK\n");
return 0;
invalid_header:
fprintf(stderr, _("\nInvalid data found. Aborting...\n"));
return -1;
}
/*
***************************************************************************
* Convert a long integer value to a long long integer value.
* The long integer value may be 32 or 64-bit wide and come from a 32 or
* 64-bit architecture.
*
* Note: Consider the value 0x01020304 read on a 32-bit machine.
* Big-endian, saved as: 01 02 03 04
* Lille-endian, saved as: 04 03 02 01
* The value should be saved as a 64-bit value and endianness should be
* preserved:
* Big-endian: 00 00 00 00 01 02 03 04
* Little-endian: 04 03 02 01 00 00 00 00
*
* IN:
* @buffer Address of value to convert.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
* @arch_64 TRUE if file's data come from a 64-bit machine.
***************************************************************************
*/
unsigned long long moveto_long_long(void *buffer, int endian_mismatch, int arch_64)
{
unsigned int *u_int;
unsigned long long *ull_int, ull_i;
if (arch_64) {
ull_int = (unsigned long long *) buffer;
return *ull_int;
}
u_int = (unsigned int *) buffer;
if (endian_mismatch) {
ull_i = (unsigned long long) *u_int;
return (ull_i >> 32) | (ull_i << 32);
}
else {
return (unsigned long long) *u_int;
}
}
/*
***************************************************************************
* Upgrade stats_cpu structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @st_size Size of the structure read from file.
***************************************************************************
*/
void upgrade_stats_cpu(struct activity *act[], int p, int st_size)
{
int i;
struct stats_cpu *scc;
struct stats_cpu_8a *scp;
for (i = 0; i < act[p]->nr_ini; i++) {
/*
* For previous structure's format: Use msize (which has possibly been set to
* the size of the structure read from disk if it's greater than that of
* current format: See upgrade_header_section()).
* For current structure format: Use fsize. This is the normal size of
* structure's up-to-date format that will be written to file.
*/
scp = (struct stats_cpu_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
scc = (struct stats_cpu *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
scc->cpu_user = scp->cpu_user;
scc->cpu_nice = scp->cpu_nice;
scc->cpu_sys = scp->cpu_sys;
scc->cpu_idle = scp->cpu_idle;
scc->cpu_iowait = scp->cpu_iowait;
scc->cpu_steal = scp->cpu_steal;
scc->cpu_hardirq = scp->cpu_hardirq;
scc->cpu_softirq = scp->cpu_softirq;
scc->cpu_guest = scp->cpu_guest;
if (st_size >= STATS_CPU_8A_SIZE) {
/* guest_nice field has been added without a structure format change */
scc->cpu_guest_nice = scp->cpu_guest_nice;
}
}
}
/*
***************************************************************************
* Upgrade stats_pcsw structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
***************************************************************************
*/
void upgrade_stats_pcsw(struct activity *act[], int p)
{
struct stats_pcsw *spc = (struct stats_pcsw *) act[p]->buf[1];
struct stats_pcsw_8a *spp = (struct stats_pcsw_8a *) act[p]->buf[0];
spc->context_switch = spp->context_switch;
/*
* Copy a long into a long. Take into account that file may have been
* created on a 64-bit machine and we may be converting on a 32-bit machine.
*/
memcpy(&spc->processes, &spp->processes, 8);
}
/*
***************************************************************************
* Upgrade stats_irq structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
***************************************************************************
*/
void upgrade_stats_irq(struct activity *act[], int p)
{
int i;
struct stats_irq *sic;
struct stats_irq_8a *sip;
for (i = 0; i < act[p]->nr_ini; i++) {
sip = (struct stats_irq_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
sic = (struct stats_irq *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
sic->irq_nr = sip->irq_nr;
}
}
/*
***************************************************************************
* Upgrade stats_io structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
***************************************************************************
*/
void upgrade_stats_io(struct activity *act[], int p, int endian_mismatch)
{
struct stats_io *sic = (struct stats_io *) act[p]->buf[1];
struct stats_io_8a *sip = (struct stats_io_8a *) act[p]->buf[0];
sic->dk_drive = moveto_long_long(&sip->dk_drive, endian_mismatch, FALSE);
sic->dk_drive_rio = moveto_long_long(&sip->dk_drive_rio, endian_mismatch, FALSE);
sic->dk_drive_wio = moveto_long_long(&sip->dk_drive_wio, endian_mismatch, FALSE);
sic->dk_drive_rblk = moveto_long_long(&sip->dk_drive_rblk, endian_mismatch, FALSE);
sic->dk_drive_wblk = moveto_long_long(&sip->dk_drive_wblk, endian_mismatch, FALSE);
}
/*
***************************************************************************
* Upgrade stats_memory structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @st_size Size of the structure read from file.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
* @arch_64 TRUE if file's data come from a 64-bit machine.
***************************************************************************
*/
void upgrade_stats_memory(struct activity *act[], int p, int st_size,
int endian_mismatch, int arch_64)
{
struct stats_memory *smc = (struct stats_memory *) act[p]->buf[1];
struct stats_memory_8a *smp = (struct stats_memory_8a *) act[p]->buf[0];
smc->frmkb = moveto_long_long(&smp->frmkb, endian_mismatch, arch_64);
smc->bufkb = moveto_long_long(&smp->bufkb, endian_mismatch, arch_64);
smc->camkb = moveto_long_long(&smp->camkb, endian_mismatch, arch_64);
smc->tlmkb = moveto_long_long(&smp->tlmkb, endian_mismatch, arch_64);
smc->frskb = moveto_long_long(&smp->frskb, endian_mismatch, arch_64);
smc->tlskb = moveto_long_long(&smp->tlskb, endian_mismatch, arch_64);
smc->caskb = moveto_long_long(&smp->caskb, endian_mismatch, arch_64);
smc->comkb = moveto_long_long(&smp->comkb, endian_mismatch, arch_64);
smc->activekb = moveto_long_long(&smp->activekb, endian_mismatch, arch_64);
smc->inactkb = moveto_long_long(&smp->inactkb, endian_mismatch, arch_64);
/* Some fields have been added without a structure format change */
if (st_size >= STATS_MEMORY_8A_1_SIZE) {
smc->dirtykb = moveto_long_long(&smp->dirtykb, endian_mismatch, arch_64);
}
if (st_size >= STATS_MEMORY_8A_2_SIZE) {
smc->anonpgkb = moveto_long_long(&smp->anonpgkb, endian_mismatch, arch_64);
smc->slabkb = moveto_long_long(&smp->slabkb, endian_mismatch, arch_64);
smc->kstackkb = moveto_long_long(&smp->kstackkb, endian_mismatch, arch_64);
smc->pgtblkb = moveto_long_long(&smp->pgtblkb, endian_mismatch, arch_64);
smc->vmusedkb = moveto_long_long(&smp->vmusedkb, endian_mismatch, arch_64);
}
if (st_size >= STATS_MEMORY_8A_SIZE) {
smc->availablekb = moveto_long_long(&(smp->availablekb), endian_mismatch, arch_64);;
}
}
/*
***************************************************************************
* Upgrade stats_ktables structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
***************************************************************************
*/
void upgrade_stats_ktables(struct activity *act[], int p, int endian_mismatch)
{
struct stats_ktables *skc = (struct stats_ktables *) act[p]->buf[1];
struct stats_ktables_8a *skp = (struct stats_ktables_8a *) act[p]->buf[0];
skc->file_used = moveto_long_long(&skp->file_used, endian_mismatch, FALSE);
skc->inode_used = moveto_long_long(&skp->inode_used, endian_mismatch, FALSE);
skc->dentry_stat = moveto_long_long(&skp->dentry_stat, endian_mismatch, FALSE);
skc->pty_nr = moveto_long_long(&skp->pty_nr, endian_mismatch, FALSE);
}
/*
***************************************************************************
* Upgrade stats_queue structure (from ACTIVITY_MAGIC_BASE or
* ACTIVITY_MAGIC_BASE + 1 format to ACTIVITY_MAGIC_BASE + 2 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @magic Structure format magic value.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
* @arch_64 TRUE if file's data come from a 64-bit machine.
***************************************************************************
*/
void upgrade_stats_queue(struct activity *act[], int p, unsigned int magic,
int endian_mismatch, int arch_64)
{
struct stats_queue *sqc = (struct stats_queue *) act[p]->buf[1];
if (magic == ACTIVITY_MAGIC_BASE) {
struct stats_queue_8a *sqp = (struct stats_queue_8a *) act[p]->buf[0];
sqc->nr_running = moveto_long_long(&sqp->nr_running, endian_mismatch, arch_64);
sqc->procs_blocked = 0ULL; /* New field */
sqc->nr_threads = moveto_long_long(&sqp->nr_threads, endian_mismatch, FALSE);
sqc->load_avg_1 = sqp->load_avg_1;
sqc->load_avg_5 = sqp->load_avg_5;
sqc->load_avg_15 = sqp->load_avg_15;
}
else {
struct stats_queue_8b *sqp = (struct stats_queue_8b *) act[p]->buf[0];
sqc->nr_running = moveto_long_long(&sqp->nr_running, endian_mismatch, arch_64);
sqc->procs_blocked = moveto_long_long(&sqp->procs_blocked, endian_mismatch, arch_64);
sqc->nr_threads = moveto_long_long(&sqp->nr_threads, endian_mismatch, FALSE);
sqc->load_avg_1 = sqp->load_avg_1;
sqc->load_avg_5 = sqp->load_avg_5;
sqc->load_avg_15 = sqp->load_avg_15;
}
}
/*
***************************************************************************
* Upgrade stats_serial structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @st_size Size of the structure read from file.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
*
* RETURNS:
* Number of serial line structures that actually need to be written to
* disk.
***************************************************************************
*/
int upgrade_stats_serial(struct activity *act[], int p, size_t st_size, int endian_mismatch)
{
int i;
unsigned int line;
struct stats_serial *ssc;
/* Copy TTY stats to target structure */
memcpy(act[p]->buf[1], act[p]->buf[0], (size_t) act[p]->nr_ini * st_size);
for (i = 0; i < act[p]->nr_ini; i++) {
ssc = (struct stats_serial *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
/* Line number now starts at 0 instead of 1 */
line = (endian_mismatch ? __builtin_bswap32(ssc->line) : ssc->line);
if (!line)
break;
line--;
ssc->line = (endian_mismatch ? __builtin_bswap32(line) : line);
}
return i;
}
/*
***************************************************************************
* Upgrade stats_disk structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @magic Structure format magic value.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
* @arch_64 TRUE if file's data come from a 64-bit machine.
***************************************************************************
*/
void upgrade_stats_disk(struct activity *act[], int p, unsigned int magic,
int endian_mismatch, int arch_64)
{
int i;
struct stats_disk *sdc;
if (magic == ACTIVITY_MAGIC_BASE) {
struct stats_disk_8a *sdp;
for (i = 0; i < act[p]->nr_ini; i++) {
sdp = (struct stats_disk_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
sdc->nr_ios = moveto_long_long(&sdp->nr_ios, endian_mismatch, arch_64);
sdc->rd_sect = (unsigned long) sdp->rd_sect;
sdc->wr_sect = (unsigned long) sdp->wr_sect;
sdc->rd_ticks = (unsigned int) sdp->rd_ticks;
sdc->wr_ticks = (unsigned int) sdp->wr_ticks;
sdc->tot_ticks = (unsigned int) sdp->tot_ticks;
sdc->rq_ticks = (unsigned int) sdp->rq_ticks;
sdc->major = sdp->major;
sdc->minor = sdp->minor;
}
}
else {
struct stats_disk_8b *sdp;
for (i = 0; i < act[p]->nr_ini; i++) {
sdp = (struct stats_disk_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
sdc = (struct stats_disk *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
sdc->nr_ios = sdp->nr_ios;
memcpy(&sdc->rd_sect, &sdp->rd_sect, 8);
memcpy(&sdc->wr_sect, &sdp->wr_sect, 8);
sdc->rd_ticks = sdp->rd_ticks;
sdc->wr_ticks = sdp->wr_ticks;
sdc->tot_ticks = sdp->tot_ticks;
sdc->rq_ticks = sdp->rq_ticks;
sdc->major = sdp->major;
sdc->minor = sdp->minor;
}
}
}
/*
***************************************************************************
* Upgrade stats_net_dev structure (from ACTIVITY_MAGIC_BASE or
* ACTIVITY_MAGIC_BASE + 1 format to ACTIVITY_MAGIC_BASE + 3 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @magic Structure format magic value.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
* @arch_64 TRUE if file's data come from a 64-bit machine.
***************************************************************************
*/
void upgrade_stats_net_dev(struct activity *act[], int p, unsigned int magic,
int endian_mismatch, int arch_64)
{
int i;
struct stats_net_dev *sndc;
if (magic == ACTIVITY_MAGIC_BASE) {
struct stats_net_dev_8a *sndp;
for (i = 0; i < act[p]->nr_ini; i++) {
sndp = (struct stats_net_dev_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
sndc->rx_packets = moveto_long_long(&sndp->rx_packets, endian_mismatch, arch_64);
sndc->tx_packets = moveto_long_long(&sndp->tx_packets, endian_mismatch, arch_64);
sndc->rx_bytes = moveto_long_long(&sndp->rx_bytes, endian_mismatch, arch_64);
sndc->tx_bytes = moveto_long_long(&sndp->tx_bytes, endian_mismatch, arch_64);
sndc->rx_compressed = moveto_long_long(&sndp->rx_compressed, endian_mismatch, arch_64);
sndc->tx_compressed = moveto_long_long(&sndp->tx_compressed, endian_mismatch, arch_64);
sndc->multicast = moveto_long_long(&sndp->multicast, endian_mismatch, arch_64);
sndc->speed = 0; /* New field */
strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
sndc->interface[MAX_IFACE_LEN - 1] = '\0';
sndc->duplex = '\0'; /* New field */
}
}
else if (magic == ACTIVITY_MAGIC_BASE + 1) {
struct stats_net_dev_8b *sndp;
for (i = 0; i < act[p]->nr_ini; i++) {
sndp = (struct stats_net_dev_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
sndc->rx_packets = sndp->rx_packets;
sndc->tx_packets = sndp->tx_packets;
sndc->rx_bytes = sndp->rx_bytes;
sndc->tx_bytes = sndp->tx_bytes;
sndc->rx_compressed = sndp->rx_compressed;
sndc->tx_compressed = sndp->tx_compressed;
sndc->multicast = sndp->multicast;
sndc->speed = 0; /* New field */
strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
sndc->interface[MAX_IFACE_LEN - 1] = '\0';
sndc->duplex = '\0'; /* New field */
}
}
else {
struct stats_net_dev_8c *sndp;
for (i = 0; i < act[p]->nr_ini; i++) {
sndp = (struct stats_net_dev_8c *) ((char *) act[p]->buf[0] + i * act[p]->msize);
sndc = (struct stats_net_dev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
sndc->rx_packets = sndp->rx_packets;
sndc->tx_packets = sndp->tx_packets;
sndc->rx_bytes = sndp->rx_bytes;
sndc->tx_bytes = sndp->tx_bytes;
sndc->rx_compressed = sndp->rx_compressed;
sndc->tx_compressed = sndp->tx_compressed;
sndc->multicast = sndp->multicast;
sndc->speed = sndp->speed;
strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
sndc->interface[MAX_IFACE_LEN - 1] = '\0';
sndc->duplex = sndp->duplex;
}
}
}
/*
***************************************************************************
* Upgrade stats_net_edev structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @magic Structure format magic value.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
* @arch_64 TRUE if file's data come from a 64-bit machine.
***************************************************************************
*/
void upgrade_stats_net_edev(struct activity *act[], int p, unsigned int magic,
int endian_mismatch, int arch_64)
{
int i;
struct stats_net_edev *snedc;
if (magic == ACTIVITY_MAGIC_BASE) {
struct stats_net_edev_8a *snedp;
for (i = 0; i < act[p]->nr_ini; i++) {
snedp = (struct stats_net_edev_8a *) ((char *) act[p]->buf[0] + i * act[p]->msize);
snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
snedc->collisions = moveto_long_long(&snedp->collisions, endian_mismatch, arch_64);
snedc->rx_errors = moveto_long_long(&snedp->rx_errors, endian_mismatch, arch_64);
snedc->tx_errors = moveto_long_long(&snedp->tx_errors, endian_mismatch, arch_64);
snedc->rx_dropped = moveto_long_long(&snedp->rx_dropped, endian_mismatch, arch_64);
snedc->tx_dropped = moveto_long_long(&snedp->tx_dropped, endian_mismatch, arch_64);
snedc->rx_fifo_errors = moveto_long_long(&snedp->rx_fifo_errors, endian_mismatch, arch_64);
snedc->tx_fifo_errors = moveto_long_long(&snedp->tx_fifo_errors, endian_mismatch, arch_64);
snedc->rx_frame_errors = moveto_long_long(&snedp->rx_frame_errors, endian_mismatch, arch_64);
snedc->tx_carrier_errors = moveto_long_long(&snedp->tx_carrier_errors, endian_mismatch, arch_64);
strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
snedc->interface[MAX_IFACE_LEN - 1] = '\0';
}
}
else {
struct stats_net_edev_8b *snedp;
for (i = 0; i < act[p]->nr_ini; i++) {
snedp = (struct stats_net_edev_8b *) ((char *) act[p]->buf[0] + i * act[p]->msize);
snedc = (struct stats_net_edev *) ((char *) act[p]->buf[1] + i * act[p]->fsize);
snedc->collisions = snedp->collisions;
snedc->rx_errors = snedp->rx_errors;
snedc->tx_errors = snedp->tx_errors;
snedc->rx_dropped = snedp->rx_dropped;
snedc->tx_dropped = snedp->tx_dropped;
snedc->rx_fifo_errors = snedp->rx_fifo_errors;
snedc->tx_fifo_errors = snedp->tx_fifo_errors;
snedc->rx_frame_errors = snedp->rx_frame_errors;
snedc->tx_carrier_errors = snedp->tx_carrier_errors;
strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
snedc->interface[MAX_IFACE_LEN - 1] = '\0';
}
}
}
/*
***************************************************************************
* Upgrade stats_net_ip structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @magic Structure format magic value.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
* @arch_64 TRUE if file's data come from a 64-bit machine.
***************************************************************************
*/
void upgrade_stats_net_ip(struct activity *act[], int p, unsigned int magic,
int endian_mismatch, int arch_64)
{
struct stats_net_ip *snic = (struct stats_net_ip *) act[p]->buf[1];
if (magic == ACTIVITY_MAGIC_BASE) {
struct stats_net_ip_8a *snip = (struct stats_net_ip_8a *) act[p]->buf[0];
snic->InReceives = moveto_long_long(&snip->InReceives, endian_mismatch, arch_64);
snic->ForwDatagrams = moveto_long_long(&snip->ForwDatagrams, endian_mismatch, arch_64);
snic->InDelivers = moveto_long_long(&snip->InDelivers, endian_mismatch, arch_64);
snic->OutRequests = moveto_long_long(&snip->OutRequests, endian_mismatch, arch_64);
snic->ReasmReqds = moveto_long_long(&snip->ReasmReqds, endian_mismatch, arch_64);
snic->ReasmOKs = moveto_long_long(&snip->ReasmOKs, endian_mismatch, arch_64);
snic->FragOKs = moveto_long_long(&snip->FragOKs, endian_mismatch, arch_64);
snic->FragCreates = moveto_long_long(&snip->FragCreates, endian_mismatch, arch_64);
}
else {
struct stats_net_ip_8b *snip = (struct stats_net_ip_8b *) act[p]->buf[0];
snic->InReceives = snip->InReceives;
snic->ForwDatagrams = snip->ForwDatagrams;
snic->InDelivers = snip->InDelivers;
snic->OutRequests = snip->OutRequests;
snic->ReasmReqds = snip->ReasmReqds;
snic->ReasmOKs = snip->ReasmOKs;
snic->FragOKs = snip->FragOKs;
snic->FragCreates = snip->FragCreates;
}
}
/*
***************************************************************************
* Upgrade stats_net_eip structure (from ACTIVITY_MAGIC_BASE format to
* ACTIVITY_MAGIC_BASE + 1 format).
*
* IN:
* @act Array of activities.
* @p Position of activity in array.
* @magic Structure format magic value.
* @endian_mismatch
* TRUE if data read from file don't match current machine's
* endianness.
* @arch_64 TRUE if file's data come from a 64-bit machine.
***************************************************************************
*/
void upgrade_stats_net_eip(struct activity *act[], int p, unsigned int magic,
int endian_mismatch, int arch_64)
{
struct stats_net_eip *sneic = (struct stats_net_eip *) act[p]->buf[1];
if (magic == ACTIVITY_MAGIC_BASE) {
struct stats_net_eip_8a *sneip = (struct stats_net_eip_8a *) act[p]->buf[0];
sneic->InHdrErrors = moveto_long_long(&sneip->InHdrErrors, endian_mismatch, arch_64);
sneic->InAddrErrors = moveto_long_long(&sneip->InAddrErrors, endian_mismatch, arch_64);
sneic->InUnknownProtos = moveto_long_long(&sneip->InUnknownProtos, endian_mismatch, arch_64);
sneic->InDiscards = moveto_long_long(&sneip->InDiscards, endian_mismatch, arch_64);
sneic->OutDiscards = moveto_long_long(&sneip->OutDiscards, endian_mismatch, arch_64);
sneic->OutNoRoutes = moveto_long_long(&sneip->OutNoRoutes, endian_mismatch, arch_64);
sneic->ReasmFails = moveto_long_long(&sneip->ReasmFails, endian_mismatch, arch_64);
sneic->FragFails = moveto_long_long(&sneip->FragFails, endian_mismatch, arch_64);
}
else {
struct stats_net_eip_8b *sneip = (struct stats_net_eip_8b *) act[p]->buf[0];
sneic->InHdrErrors = sneip->InHdrErrors;
sneic->InAddrErrors = sneip->InAddrErrors;
sneic->InUnknownProtos = sneip->InUnknownProtos;