更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
dmesg.h 文件参考

浏览源代码.

函数

UINT32 LOS_DmesgMemSet (const VOID *addr, UINT32 size)
 Set dmesg buffer. 更多...
 
INT32 LOS_DmesgRead (CHAR *buf, UINT32 len)
 Read log from dmesg buffer. 更多...
 
VOID LOS_DmesgClear (VOID)
 Clear dmesg log. 更多...
 
INT32 LOS_DmesgToFile (const CHAR *filename)
 Copy log to file. 更多...
 
UINT32 LOS_DmesgLvSet (UINT32 level)
 Set the dmesg level 更多...
 

函数说明

◆ LOS_DmesgClear()

VOID LOS_DmesgClear ( VOID  )

Clear dmesg log.

Description:
This API is used to clear dmesg log.
注意
None.
参数
None.
返回值
None.
Dependency:
  • dmesg.h: the header file that contains the API declaration.
参见
LOS_DmesgClear

在文件 dmesg.c621 行定义.

622{
623 UINT32 intSave;
624
625 LOS_SpinLockSave(&g_dmesgSpin, &intSave);
626 (VOID)memset_s(g_dmesgInfo->logBuf, g_logBufSize, 0, g_logBufSize);
627 g_dmesgInfo->logHead = 0;
628 g_dmesgInfo->logTail = 0;
629 g_dmesgInfo->logSize = 0;
630 LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
631}
STATIC UINT32 g_logBufSize
缓冲区内容体大小
Definition: dmesg.c:79
STATIC DmesgInfo * g_dmesgInfo
保存在 g_mallocAddr 的开始位置,即头信息
Definition: dmesg.c:78
VOID LOS_SpinUnlockRestore(SPIN_LOCK_S *lock, UINT32 intSave)
Definition: los_spinlock.c:108
VOID LOS_SpinLockSave(SPIN_LOCK_S *lock, UINT32 *intSave)
Definition: los_spinlock.c:98
unsigned int UINT32
Definition: los_typedef.h:57
UINT32 logTail
Definition: dmesg_pri.h:51
UINT32 logSize
Definition: dmesg_pri.h:49
UINT32 logHead
Definition: dmesg_pri.h:50
CHAR * logBuf
Definition: dmesg_pri.h:52
函数调用图:
这是这个函数的调用关系图:

◆ LOS_DmesgLvSet()

UINT32 LOS_DmesgLvSet ( UINT32  level)

Set the dmesg level

Description:
This API is used to set the level of log that want to stored in dmesg buffer.
注意
  • It would be useless if the level is less than print level.
参数
level[IN] Type UINT32 The level expected to set, range from 0 to 5.
返回值
#1Set dmesg level fail.
#0Set dmesg level success.
Dependency:
  • dmesg.h: the header file that contains the API declaration.
参见
LOS_DmesgLvSet

在文件 dmesg.c611 行定义.

612{
613 if (level > 5) { /* 5: count of level */
614 return LOS_NOK;
615 }
616
617 g_dmesgLogLevel = level;
618 return LOS_OK;
619}
STATIC UINT32 g_dmesgLogLevel
日志等级
Definition: dmesg.c:81
这是这个函数的调用关系图:

◆ LOS_DmesgMemSet()

UINT32 LOS_DmesgMemSet ( const VOID *  addr,
UINT32  size 
)

Set dmesg buffer.

Description:
This API is used to set dmesg buffer to memory-assigned, or just change the buffer size.
注意
  • If the addr is NULL, this function will only change the buffer size.
参数
addr[IN] Type #VOID* The addr of memory space to set.
size[IN] Type UINT32 The dmesg buffer size to set, depend on the app user, should be a valid value, otherwise system will crash, and should not larger than MAX_KERNEL_LOG_BUF_SIZE.
返回值
#LOS_NOKSet dmesg buffer fail.
#LOS_OKSet dmesg buffer success.
Dependency:
  • dmesg.h: the header file that contains the API declaration.
参见
LOS_DmesgMemSet

Set dmesg buffer.

在文件 dmesg.c633 行定义.

634{
635 UINT32 ret = 0;
636
637 if (addr == NULL) {
638 ret = OsDmesgChangeSize(size);
639 } else {
640 ret = OsDmesgResetMem(addr, size);
641 }
642 return ret;
643}
STATIC UINT32 OsDmesgResetMem(const VOID *addr, UINT32 size)
重置内存
Definition: dmesg.c:232
STATIC UINT32 OsDmesgChangeSize(UINT32 size)
调整缓冲区大小,如下五个步骤
Definition: dmesg.c:273
函数调用图:
这是这个函数的调用关系图:

◆ LOS_DmesgRead()

INT32 LOS_DmesgRead ( CHAR buf,
UINT32  len 
)

Read log from dmesg buffer.

Description:
This API is used to get log from dmesg buffer in core and copy to the point buffer.
注意
  • Length of log been read may be less than the len if log in dmesg buffer is not enough.
参数
buf[IN] Type CHAR* The buffer expected copy to.
len[IN] Type UINT32 The maximum number of bytes that can be accommodated in the buf.
返回值
#-1Read log from dmesg buffer fail.
#0Nothing has been read.
INT32The length of log has been read.
Dependency:
  • dmesg.h: the header file that contains the API declaration.
参见
LOS_DmesgRead

Read log from dmesg buffer.

在文件 dmesg.c645 行定义.

646{
647 INT32 ret;
648 UINT32 intSave;
649
650 if (buf == NULL) {
651 return -1;
652 }
653 if (len == 0) {
654 return 0;
655 }
656
657 LOS_SpinLockSave(&g_dmesgSpin, &intSave);
658 ret = OsDmesgRead(buf, len);
659 LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
660 return ret;
661}
STATIC INT32 OsDmesgRead(CHAR *buf, UINT32 len)
Definition: dmesg.c:131
signed int INT32
Definition: los_typedef.h:60
函数调用图:

◆ LOS_DmesgToFile()

INT32 LOS_DmesgToFile ( const CHAR filename)

Copy log to file.

Description:
This API is used to copy all log from dmesg buffer and write it to the file.
注意
  • Files rely on file system, the file system of filename dependent must be already mounted.
参数
filename[IN] Type CHAR* The buffer expected copy to.
返回值
#-1Copy log to file fail.
#0Maybe there is no log in the buffer.
INT32The length of log has been written to file.
Dependency:
  • dmesg.h: the header file that contains the API declaration.
参见
LOS_DmesgToFile

Copy log to file.

在文件 dmesg.c678 行定义.

679{
680 CHAR *fullpath = NULL;
681 CHAR *buf = NULL;
682 INT32 ret;
683 CHAR *shellWorkingDirectory = OsShellGetWorkingDirectory();//获取工作路径
684 UINT32 logSize, bufSize, head, tail, intSave;
685 CHAR *logBuf = NULL;
686
687 LOS_SpinLockSave(&g_dmesgSpin, &intSave);
688 if (OsCheckError()) {
689 LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
690 return -1;
691 }
692 logSize = g_dmesgInfo->logSize;
693 bufSize = g_logBufSize;
694 head = g_dmesgInfo->logHead;
695 tail = g_dmesgInfo->logTail;
696 logBuf = g_dmesgInfo->logBuf;
697 LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
698
699 ret = vfs_normalize_path(shellWorkingDirectory, filename, &fullpath);//获取绝对路径
700 if (ret != 0) {
701 return -1;
702 }
703
704 buf = (CHAR *)malloc(logSize);
705 if (buf == NULL) {
706 goto ERR_OUT2;
707 }
708
709 if (head < tail) {
710 ret = memcpy_s(buf, logSize, logBuf + head, logSize);
711 if (ret != EOK) {
712 goto ERR_OUT3;
713 }
714 } else {
715 ret = memcpy_s(buf, logSize, logBuf + head, bufSize - head);
716 if (ret != EOK) {
717 goto ERR_OUT3;
718 }
719 ret = memcpy_s(buf + bufSize - head, logSize - (bufSize - head), logBuf, tail);
720 if (ret != EOK) {
721 goto ERR_OUT3;
722 }
723 }
724
725 ret = OsDmesgWrite2File(fullpath, buf, logSize);//写文件
726ERR_OUT3:
727 free(buf);
728ERR_OUT2:
729 free(fullpath);
730 return ret;
731}
char * OsShellGetWorkingDirectory(void)
Definition: shcmd.c:94
STATIC UINT32 OsCheckError(VOID)
读取dmesg日志
Definition: dmesg.c:113
INT32 OsDmesgWrite2File(const CHAR *fullpath, const CHAR *buf, UINT32 logSize)
Definition: dmesg.c:663
int vfs_normalize_path(const char *directory, const char *filename, char **pathname)
Definition: fullpath.c:245
char CHAR
Definition: los_typedef.h:63
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
函数调用图:
这是这个函数的调用关系图: