[go: up one dir, main page]

File: ipl.c

package info (click to toggle)
s390-tools 1.8.3-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,584 kB
  • ctags: 5,973
  • sloc: ansic: 34,053; cpp: 8,153; sh: 7,784; asm: 5,573; perl: 2,519; makefile: 799
file content (152 lines) | stat: -rw-r--r-- 3,807 bytes parent folder | download
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
/*
 * Copyright IBM Corp 2008
 * Author: Hans-Joachim Picht <hans@linux.vnet.ibm.com>
 *
 *  Linux for System z shutdown actions
 *
 * 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.
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <ctype.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <signal.h>
#include <syslog.h>
#include <pthread.h>
#include "chreipl.h"


/*
 * return the ipl type based on /sys/firmware/ipl/ipl_type
 * returns 0 in case of fcp and 1 in case of ccw, -1 otherwise
 */
int get_ipl_type()
{
	FILE *filp;
	char reipltype[4];
	char path[4096];
	int rc;

	strcpy(path, "/sys/firmware/ipl/ipl_type");
	if (access(path, R_OK) == 0) {
		filp = fopen(path, "r");
		if (!filp) {
			fprintf(stderr,	"%s: Can not open /sys/firmware/ipl/"
				"ipl_type: ", name);
			fprintf(stderr, "%s\n", strerror(errno));
			return -1;
		}
		rc = fscanf(filp, "%s", reipltype);
		fclose(filp);
		if (rc < 0) {
			fprintf(stderr, "%s: Failed to read "
				"/sys/firmware/ipl/ipl_type: ", name);
			fprintf(stderr, "%s\n", strerror(errno));
			return -1;
		}
		if (strncmp(reipltype, "fcp", strlen("fcp")) == 0)
			return T_FCP;
		else if (strncmp(reipltype, "ccw", strlen("ccw")) == 0)
			return T_CCW;
	} else {
		fprintf(stderr, "%s: Can not open /sys/firmware/ipl/"
			"ipl_type:", name);
		fprintf(stderr, " %s\n", strerror(errno));
	}
	return -1;
}

/*
 * return the loadparameter from /sys/firmware/ipl/loadparm
 */
int get_ipl_loadparam(void)
{
	FILE *filp;
	char path[4096];
	int rc, val;

	strcpy(path, "/sys/firmware/ipl/loadparm");
	if (access(path, R_OK) == 0) {
		filp = fopen(path, "r");
		if (!filp) {
			fprintf(stderr,	"%s: Can not open /sys/firmware/ipl"
				"/loadparm: ", name);
			fprintf(stderr, "%s\n", strerror(errno));
			return -1;
		}
		rc = fscanf(filp, "%d", &val);
		fclose(filp);
		if (rc < 0)
			return -1;
		 else
			return val;
	} else {
		fprintf(stderr, "%s: Can not open /sys/firmware/ipl/"
			"loadparm: ", name);
		fprintf(stderr, "%s\n", strerror(errno));
	}
	return -1;
}

/*
 * print out the settings discovery in the /sys/firmware/ipl filesystem
 * structure
 */

void print_ipl_settings(void)
{
	int rc, type;
	char bootprog[1024], lba[1024];

	type = get_ipl_type();
	/*
	 * TODO: add nss support
	 */
	if (type == 1)
		printf("IPL type:      ccw\n");
	if (type == 0)
		printf("IPL type:      fcp\n");
	rc = strrd(devno, "/sys/firmware/ipl/device");
	if (rc != 0)
		exit(1) /* the error msg comes from get_ipl_device */;
	if (strlen(devno) > 0)
		printf("Device:        %s\n", devno);
	if (type == 1) {
		rc = get_ipl_loadparam();
		if (rc != -1)
			printf("Loadparm:      %d\n", rc);
		else
			printf("Loadparm:      \n");
	}
	if (type == 0) {
		/* these settings are only available for fcp */
		rc = strrd(wwpn, "/sys/firmware/reipl/fcp/wwpn");
		if (rc != -1 && strlen(wwpn) > 0)
			printf("WWPN:          %s\n", wwpn);
		rc = strrd(lun, "/sys/firmware/ipl/lun");
		if (rc != -1 && strlen(lun) > 0)
			printf("LUN:           %s\n", lun);
		rc = strrd(bootprog, "/sys/firmware/reipl/fcp/bootprog");
		if (rc != -1 && strlen(bootprog) > 0)
			printf("bootprog:      %s\n", bootprog);
		rc = strrd(lba, "/sys/firmware/ipl/br_lba");
		if (rc != -1 &&  strlen(lba) > 0)
			printf("br_lba:        %s\n", lba);
	}
	exit(0);
}