diff options
Diffstat (limited to 'kernel/printk.c')
-rw-r--r-- | kernel/printk.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/kernel/printk.c b/kernel/printk.c index b2b5c3a22a36..52493474f0ab 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
@@ -220,6 +220,58 @@ static inline void boot_delay_msec(void) | |||
220 | #endif | 220 | #endif |
221 | 221 | ||
222 | /* | 222 | /* |
223 | * Return the number of unread characters in the log buffer. | ||
224 | */ | ||
225 | int log_buf_get_len(void) | ||
226 | { | ||
227 | return logged_chars; | ||
228 | } | ||
229 | |||
230 | /* | ||
231 | * Copy a range of characters from the log buffer. | ||
232 | */ | ||
233 | int log_buf_copy(char *dest, int idx, int len) | ||
234 | { | ||
235 | int ret, max; | ||
236 | bool took_lock = false; | ||
237 | |||
238 | if (!oops_in_progress) { | ||
239 | spin_lock_irq(&logbuf_lock); | ||
240 | took_lock = true; | ||
241 | } | ||
242 | |||
243 | max = log_buf_get_len(); | ||
244 | if (idx < 0 || idx >= max) { | ||
245 | ret = -1; | ||
246 | } else { | ||
247 | if (len > max) | ||
248 | len = max; | ||
249 | ret = len; | ||
250 | idx += (log_end - max); | ||
251 | while (len-- > 0) | ||
252 | dest[len] = LOG_BUF(idx + len); | ||
253 | } | ||
254 | |||
255 | if (took_lock) | ||
256 | spin_unlock_irq(&logbuf_lock); | ||
257 | |||
258 | return ret; | ||
259 | } | ||
260 | |||
261 | /* | ||
262 | * Extract a single character from the log buffer. | ||
263 | */ | ||
264 | int log_buf_read(int idx) | ||
265 | { | ||
266 | char ret; | ||
267 | |||
268 | if (log_buf_copy(&ret, idx, 1) == 1) | ||
269 | return ret; | ||
270 | else | ||
271 | return -1; | ||
272 | } | ||
273 | |||
274 | /* | ||
223 | * Commands to do_syslog: | 275 | * Commands to do_syslog: |
224 | * | 276 | * |
225 | * 0 -- Close the log. Currently a NOP. | 277 | * 0 -- Close the log. Currently a NOP. |