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

浏览源代码.

函数

int FullWriteFile (const char *filePath, const char *buf, size_t bufSize, int isAppend)
 
int SaveBasicErrorInfo (const char *filePath, const struct ErrorInfo *info)
 
int CreateLogDir (const char *dirPath)
 
bool IsLogPartReady (void)
 

函数说明

◆ CreateLogDir()

int CreateLogDir ( const char *  dirPath)

在文件 los_blackbox_common.c181 行定义.

182{
183 const char *temp = dirPath;
184 char curPath[PATH_MAX_LEN];
185 int idx = 0;
186
187 if (dirPath == NULL) {
188 BBOX_PRINT_ERR("dirPath is NULL!\n");
189 return -1;
190 }
191 if (*dirPath != '/') {
192 BBOX_PRINT_ERR("Invalid dirPath: %s\n", dirPath);
193 return -1;
194 }
195 (void)memset_s(curPath, sizeof(curPath), 0, sizeof(curPath));
196 curPath[idx++] = *dirPath++;
197 while (*dirPath != '\0' && idx < sizeof(curPath)) {
198 if (*dirPath == '/') {
199 if (CreateNewDir(curPath) != 0) {
200 return -1;
201 }
202 }
203 curPath[idx] = *dirPath;
204 dirPath++;
205 idx++;
206 }
207 if (*dirPath != '\0') {
208 BBOX_PRINT_ERR("dirPath [%s] is too long!\n", temp);
209 return -1;
210 }
211
212 return CreateNewDir(curPath);
213}
int CreateNewDir(const char *dirPath)
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
函数调用图:
这是这个函数的调用关系图:

◆ FullWriteFile()

int FullWriteFile ( const char *  filePath,
const char *  buf,
size_t  bufSize,
int  isAppend 
)

在文件 los_blackbox_common.c57 行定义.

58{
59#ifdef LOSCFG_FS_VFS
60 int fd;
61 int totalToWrite = (int)bufSize;
62 int totalWrite = 0;
63
64 if (filePath == NULL || buf == NULL || bufSize == 0) {
65 BBOX_PRINT_ERR("filePath: %p, buf: %p, bufSize: %lu!\n", filePath, buf, bufSize);
66 return -1;
67 }
68
69 if (!IsLogPartReady()) {
70 BBOX_PRINT_ERR("log path [%s] isn't ready to be written!\n", LOSCFG_BLACKBOX_LOG_ROOT_PATH);
71 return -1;
72 }
73 fd = open(filePath, O_CREAT | O_RDWR | (isAppend ? O_APPEND : O_TRUNC), BBOX_FILE_MODE);
74 if (fd < 0) {
75 BBOX_PRINT_ERR("Create file [%s] failed, fd: %d!\n", filePath, fd);
76 return -1;
77 }
78 while (totalToWrite > 0) {
79 int writeThisTime = write(fd, buf, totalToWrite);
80 if (writeThisTime < 0) {
81 BBOX_PRINT_ERR("Failed to write file [%s]!\n", filePath);
82 (void)close(fd);
83 return -1;
84 }
85 buf += writeThisTime;
86 totalToWrite -= writeThisTime;
87 totalWrite += writeThisTime;
88 }
89 (void)fsync(fd);
90 (void)close(fd);
91
92 return (totalWrite == (int)bufSize) ? 0 : -1;
93#else
94 (VOID)filePath;
95 (VOID)buf;
96 (VOID)bufSize;
97 (VOID)isAppend;
98 return -1;
99#endif
100}
bool IsLogPartReady(void)
ARG_NUM_3 int
函数调用图:
这是这个函数的调用关系图:

◆ IsLogPartReady()

bool IsLogPartReady ( void  )

在文件 los_blackbox_common.c144 行定义.

145{
146 if (!g_isLogPartReady) {
147 (void)foreach_mountpoint((foreach_mountpoint_t)IsLogPartMounted, LOSCFG_BLACKBOX_LOG_PART_MOUNT_POINT);
148 }
149 return g_isLogPartReady;
150}
static int IsLogPartMounted(const char *devPoint, const char *mountPoint, struct statfs *statBuf, void *arg)
static bool g_isLogPartReady
int(* foreach_mountpoint_t)(const char *devpoint, const char *mountpoint, struct statfs *statbuf, void *arg)
Definition: mount.h:96
int foreach_mountpoint(foreach_mountpoint_t handler, void *arg)
函数调用图:
这是这个函数的调用关系图:

◆ SaveBasicErrorInfo()

int SaveBasicErrorInfo ( const char *  filePath,
const struct ErrorInfo info 
)

在文件 los_blackbox_common.c102 行定义.

103{
104 char *buf = NULL;
105
106 if (filePath == NULL || info == NULL) {
107 BBOX_PRINT_ERR("filePath: %p, event: %p!\n", filePath, info);
108 return -1;
109 }
110
111 buf = LOS_MemAlloc(m_aucSysMem1, ERROR_INFO_MAX_LEN);
112 if (buf == NULL) {
113 BBOX_PRINT_ERR("LOS_MemAlloc failed!\n");
114 return -1;
115 }
116 (void)memset_s(buf, ERROR_INFO_MAX_LEN, 0, ERROR_INFO_MAX_LEN);
117 if (snprintf_s(buf, ERROR_INFO_MAX_LEN, ERROR_INFO_MAX_LEN - 1,
118 ERROR_INFO_HEADER_FORMAT, info->event, info->module, info->errorDesc) != -1) {
119 *(buf + ERROR_INFO_MAX_LEN - 1) = '\0';
120 (void)FullWriteFile(filePath, buf, strlen(buf), 0);
121 } else {
122 BBOX_PRINT_ERR("buf is not enough or snprintf_s failed!\n");
123 }
124
126
127 return 0;
128}
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
Definition: los_memory.c:108
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
int FullWriteFile(const char *filePath, const char *buf, size_t bufSize, int isAppend)
char errorDesc[ERROR_DESC_MAX_LEN]
Definition: los_blackbox.h:64
char module[MODULE_MAX_LEN]
Definition: los_blackbox.h:63
char event[EVENT_MAX_LEN]
Definition: los_blackbox.h:62
函数调用图:
这是这个函数的调用关系图: