31
31
#include <sys/types.h>
32
32
#include <sys/stat.h>
33
33
34
+ #include "version.h"
34
35
#include "sa.h"
35
36
#include "common.h"
36
37
#include "ioconf.h"
@@ -1209,37 +1210,30 @@ void read_file_stat_bunch(struct activity *act[], int curr, int ifd, int act_nr,
1209
1210
1210
1211
/*
1211
1212
***************************************************************************
1212
- * Open a data file, and perform various checks before reading .
1213
+ * Open a sysstat activity data file and read its magic structure .
1213
1214
*
1214
1215
* IN:
1215
- * @dfile Name of system activity data file
1216
- * @act Array of activities.
1216
+ * @dfile Name of system activity data file.
1217
1217
* @ignore Set to 1 if a true sysstat activity file but with a bad
1218
1218
* format should not yield an error message. Useful with
1219
1219
* sadf -H.
1220
1220
*
1221
1221
* OUT:
1222
- * @ifd System activity data file descriptor
1222
+ * @fd System activity data file descriptor.
1223
1223
* @file_magic file_magic structure containing data read from file magic
1224
- * header
1225
- * @file_hdr file_hdr structure containing data read from file standard
1226
- * header
1227
- * @file_actlst Acvtivity list in file.
1228
- * @id_seq Activity sequence.
1224
+ * header.
1225
+ *
1226
+ * RETURNS:
1227
+ * -1 if data file is a sysstat file with an old format, 0 otherwise.
1229
1228
***************************************************************************
1230
1229
*/
1231
- void check_file_actlst (int * ifd , char * dfile , struct activity * act [],
1232
- struct file_magic * file_magic , struct file_header * file_hdr ,
1233
- struct file_activity * * file_actlst , unsigned int id_seq [],
1230
+ int sa_open_read_magic (int * fd , char * dfile , struct file_magic * file_magic ,
1234
1231
int ignore )
1235
1232
{
1236
- int i , j , n , p ;
1237
- unsigned int a_cpu = FALSE;
1238
- struct file_activity * fal ;
1239
- void * buffer = NULL ;
1233
+ int n ;
1240
1234
1241
1235
/* Open sa data file */
1242
- if ((* ifd = open (dfile , O_RDONLY )) < 0 ) {
1236
+ if ((* fd = open (dfile , O_RDONLY )) < 0 ) {
1243
1237
int saved_errno = errno ;
1244
1238
1245
1239
fprintf (stderr , _ ("Cannot open %s: %s\n" ), dfile , strerror (errno ));
@@ -1251,22 +1245,55 @@ void check_file_actlst(int *ifd, char *dfile, struct activity *act[],
1251
1245
}
1252
1246
1253
1247
/* Read file magic data */
1254
- n = read (* ifd , file_magic , FILE_MAGIC_SIZE );
1248
+ n = read (* fd , file_magic , FILE_MAGIC_SIZE );
1255
1249
1256
1250
if ((n != FILE_MAGIC_SIZE ) ||
1257
1251
(file_magic -> sysstat_magic != SYSSTAT_MAGIC ) ||
1258
- (file_magic -> format_magic != FORMAT_MAGIC )) {
1259
-
1260
- if (ignore &&
1261
- (n == FILE_MAGIC_SIZE ) &&
1262
- (file_magic -> sysstat_magic == SYSSTAT_MAGIC ))
1263
- /* Don't display error message. This is for sadf -H */
1264
- return ;
1265
- else {
1266
- /* Display error message and exit */
1267
- handle_invalid_sa_file (ifd , file_magic , dfile , n );
1268
- }
1252
+ ((file_magic -> format_magic != FORMAT_MAGIC ) && !ignore )) {
1253
+ /* Display error message and exit */
1254
+ handle_invalid_sa_file (fd , file_magic , dfile , n );
1269
1255
}
1256
+ if (file_magic -> format_magic != FORMAT_MAGIC )
1257
+ /* This is an old sa datafile format */
1258
+ return -1 ;
1259
+
1260
+ return 0 ;
1261
+ }
1262
+
1263
+ /*
1264
+ ***************************************************************************
1265
+ * Open a data file, and perform various checks before reading.
1266
+ *
1267
+ * IN:
1268
+ * @dfile Name of system activity data file.
1269
+ * @act Array of activities.
1270
+ * @ignore Set to 1 if a true sysstat activity file but with a bad
1271
+ * format should not yield an error message. Useful with
1272
+ * sadf -H.
1273
+ *
1274
+ * OUT:
1275
+ * @ifd System activity data file descriptor.
1276
+ * @file_magic file_magic structure containing data read from file magic
1277
+ * header.
1278
+ * @file_hdr file_hdr structure containing data read from file standard
1279
+ * header.
1280
+ * @file_actlst Acvtivity list in file.
1281
+ * @id_seq Activity sequence.
1282
+ ***************************************************************************
1283
+ */
1284
+ void check_file_actlst (int * ifd , char * dfile , struct activity * act [],
1285
+ struct file_magic * file_magic , struct file_header * file_hdr ,
1286
+ struct file_activity * * file_actlst , unsigned int id_seq [],
1287
+ int ignore )
1288
+ {
1289
+ int i , j , p ;
1290
+ unsigned int a_cpu = FALSE;
1291
+ struct file_activity * fal ;
1292
+ void * buffer = NULL ;
1293
+
1294
+ /* Open sa data file and read its magic structure */
1295
+ if (sa_open_read_magic (ifd , dfile , file_magic , ignore ) < 0 )
1296
+ return ;
1270
1297
1271
1298
SREALLOC (buffer , char , file_magic -> header_size );
1272
1299
@@ -1940,3 +1967,40 @@ double compute_ifutil(struct stats_net_dev *st_net_dev, double rx, double tx)
1940
1967
return 0 ;
1941
1968
}
1942
1969
1970
+ /*
1971
+ ***************************************************************************
1972
+ * Fill system activity file magic header.
1973
+ *
1974
+ * IN:
1975
+ * @file_magic System activity file magic header.
1976
+ ***************************************************************************
1977
+ */
1978
+ void enum_version_nr (struct file_magic * fm )
1979
+ {
1980
+ char * v ;
1981
+ char version [16 ];
1982
+
1983
+ fm -> sysstat_extraversion = 0 ;
1984
+
1985
+ strcpy (version , VERSION );
1986
+
1987
+ /* Get version number */
1988
+ if ((v = strtok (version , "." )) == NULL )
1989
+ return ;
1990
+ fm -> sysstat_version = atoi (v ) & 0xff ;
1991
+
1992
+ /* Get patchlevel number */
1993
+ if ((v = strtok (NULL , "." )) == NULL )
1994
+ return ;
1995
+ fm -> sysstat_patchlevel = atoi (v ) & 0xff ;
1996
+
1997
+ /* Get sublevel number */
1998
+ if ((v = strtok (NULL , "." )) == NULL )
1999
+ return ;
2000
+ fm -> sysstat_sublevel = atoi (v ) & 0xff ;
2001
+
2002
+ /* Get extraversion number. Don't necessarily exist */
2003
+ if ((v = strtok (NULL , "." )) == NULL )
2004
+ return ;
2005
+ fm -> sysstat_extraversion = atoi (v ) & 0xff ;
2006
+ }
0 commit comments