mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 18:51:56 -04:00
printk: add interfaces for external access to the log buffer
Add two new functions for reading the kernel log buffer. The intention is for them to be used by recovery/dump/debug code so the kernel log can be easily retrieved/parsed in a crash scenario, but they are generic enough for other people to dream up other fun uses. [[email protected]: buncha fixes] Signed-off-by: Mike Frysinger <[email protected]> Cc: Robin Getz <[email protected]> Cc: Greg Ungerer <[email protected]> Cc: Russell King <[email protected]> Cc: Paul Mundt <[email protected]> Acked-by: Tim Bird <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
d823e3e754
commit
0b15d04af3
2 changed files with 58 additions and 0 deletions
|
|
@ -219,6 +219,58 @@ static inline void boot_delay_msec(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Return the number of unread characters in the log buffer.
|
||||
*/
|
||||
int log_buf_get_len(void)
|
||||
{
|
||||
return logged_chars;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy a range of characters from the log buffer.
|
||||
*/
|
||||
int log_buf_copy(char *dest, int idx, int len)
|
||||
{
|
||||
int ret, max;
|
||||
bool took_lock = false;
|
||||
|
||||
if (!oops_in_progress) {
|
||||
spin_lock_irq(&logbuf_lock);
|
||||
took_lock = true;
|
||||
}
|
||||
|
||||
max = log_buf_get_len();
|
||||
if (idx < 0 || idx >= max) {
|
||||
ret = -1;
|
||||
} else {
|
||||
if (len > max)
|
||||
len = max;
|
||||
ret = len;
|
||||
idx += (log_end - max);
|
||||
while (len-- > 0)
|
||||
dest[len] = LOG_BUF(idx + len);
|
||||
}
|
||||
|
||||
if (took_lock)
|
||||
spin_unlock_irq(&logbuf_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract a single character from the log buffer.
|
||||
*/
|
||||
int log_buf_read(int idx)
|
||||
{
|
||||
char ret;
|
||||
|
||||
if (log_buf_copy(&ret, idx, 1) == 1)
|
||||
return ret;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Commands to do_syslog:
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue