46#define BBOX_DIR_MODE 0750
47#define BBOX_FILE_MODE 0640
57int FullWriteFile(
const char *filePath,
const char *buf,
size_t bufSize,
int isAppend)
61 int totalToWrite = (
int)bufSize;
64 if (filePath == NULL || buf == NULL || bufSize == 0) {
65 BBOX_PRINT_ERR(
"filePath: %p, buf: %p, bufSize: %lu!\n", filePath, buf, bufSize);
70 BBOX_PRINT_ERR(
"log path [%s] isn't ready to be written!\n", LOSCFG_BLACKBOX_LOG_ROOT_PATH);
73 fd = open(filePath, O_CREAT | O_RDWR | (isAppend ? O_APPEND : O_TRUNC), BBOX_FILE_MODE);
75 BBOX_PRINT_ERR(
"Create file [%s] failed, fd: %d!\n", filePath, fd);
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);
86 totalToWrite -= writeThisTime;
87 totalWrite += writeThisTime;
92 return (totalWrite == (
int)bufSize) ? 0 : -1;
106 if (filePath == NULL || info == NULL) {
107 BBOX_PRINT_ERR(
"filePath: %p, event: %p!\n", filePath, info);
113 BBOX_PRINT_ERR(
"LOS_MemAlloc failed!\n");
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,
119 *(buf + ERROR_INFO_MAX_LEN - 1) =
'\0';
122 BBOX_PRINT_ERR(
"buf is not enough or snprintf_s failed!\n");
131static int IsLogPartMounted(
const char *devPoint,
const char *mountPoint,
struct statfs *statBuf,
void *arg)
136 if (mountPoint != NULL && arg != NULL) {
137 if (strcmp(mountPoint, (
char *)arg) == 0) {
163 if (dirPath == NULL) {
164 BBOX_PRINT_ERR(
"dirPath is NULL!\n");
172 ret = mkdir(dirPath, BBOX_DIR_MODE);
174 BBOX_PRINT_ERR(
"mkdir [%s] failed!\n", dirPath);
183 const char *temp = dirPath;
184 char curPath[PATH_MAX_LEN];
187 if (dirPath == NULL) {
188 BBOX_PRINT_ERR(
"dirPath is NULL!\n");
191 if (*dirPath !=
'/') {
192 BBOX_PRINT_ERR(
"Invalid dirPath: %s\n", dirPath);
195 (
void)memset_s(curPath,
sizeof(curPath), 0,
sizeof(curPath));
196 curPath[idx++] = *dirPath++;
197 while (*dirPath !=
'\0' && idx <
sizeof(curPath)) {
198 if (*dirPath ==
'/') {
203 curPath[idx] = *dirPath;
207 if (*dirPath !=
'\0') {
208 BBOX_PRINT_ERR(
"dirPath [%s] is too long!\n", temp);
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
bool IsLogPartReady(void)
int FullWriteFile(const char *filePath, const char *buf, size_t bufSize, int isAppend)
static int IsLogPartMounted(const char *devPoint, const char *mountPoint, struct statfs *statBuf, void *arg)
int SaveBasicErrorInfo(const char *filePath, const struct ErrorInfo *info)
int CreateNewDir(const char *dirPath)
static bool g_isLogPartReady
int CreateLogDir(const char *dirPath)
int(* foreach_mountpoint_t)(const char *devpoint, const char *mountpoint, struct statfs *statbuf, void *arg)
int foreach_mountpoint(foreach_mountpoint_t handler, void *arg)
char errorDesc[ERROR_DESC_MAX_LEN]
char module[MODULE_MAX_LEN]
char event[EVENT_MAX_LEN]
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
int access(const char *path, int amode)