MCPcopy Create free account
hub / github.com/coreboot/coreboot / do_stream

Function do_stream

util/msrtool/msrtool.c:100–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100int do_stream(const char *streamfn, uint8_t ignoreinput) {
101 char tmpfn[20], line[256];
102 uint8_t tn;
103 size_t start, len;
104 int ret = 1;
105 int fdout = -1;
106 FILE *fin = NULL, *fout = NULL;
107 uint32_t addr, linenum;
108 struct msr m = MSR1(0);
109
110 if (0 == strcmp(streamfn, "-")) {
111 fin = stdin;
112 fout = stdout;
113 } else {
114 if (!ignoreinput) {
115 if (NULL == (fin = fopen(streamfn, "r"))) {
116 perror("fopen()");
117 return 1;
118 }
119 if (snprintf(tmpfn, sizeof(tmpfn), "msrtoolXXXXXX") >= sizeof(tmpfn)) {
120 perror("snprintf");
121 return 1;
122 }
123 if (-1 == (fdout = mkstemp(tmpfn))) {
124 perror("mkstemp");
125 return 1;
126 }
127 if (NULL == (fout = fdopen(fdout, "w"))) {
128 perror("fdopen");
129 return 1;
130 }
131 } else {
132 if (NULL == (fout = fopen(streamfn, "w"))) {
133 perror("fopen");
134 return 1;
135 }
136 }
137 }
138
139 if (!found_system())
140 goto done;
141 if (!sys->open(cpu, SYS_RDONLY))
142 goto done;
143 if (ignoreinput) {
144 for (tn = 0; tn < targets_found; tn++)
145 if (dumpmsrdefsvals(fout, targets[tn], cpu)) {
146 ret = 1;
147 break;
148 }
149 } else {
150 for (linenum = 1; NULL != fgets(line, sizeof(line), fin); ++linenum) {
151 start = (0 == strncmp("0x", line, 2)) ? 2 : 0;
152 if (1 == sscanf(line + start, "%8x", &addr)) {
153 if (!sys->rdmsr(cpu, addr, &m))
154 goto done;
155 fprintf(fout, "0x%08x 0x%08x%08x\n", addr, m.hi, m.lo);
156 continue;
157 }

Callers 1

mainFunction · 0.85

Calls 12

fopenFunction · 0.85
perrorFunction · 0.85
found_systemFunction · 0.85
dumpmsrdefsvalsFunction · 0.85
fprintfFunction · 0.85
strlenFunction · 0.85
strerrorFunction · 0.85
fcloseFunction · 0.85
strcmpFunction · 0.50
snprintfFunction · 0.50
strncmpFunction · 0.50
strchrFunction · 0.50

Tested by

no test coverage detected