Lines Matching refs:fp

40 boolean InitHiviewFile(HiviewFile *fp, HiviewFileType type, uint32 size)  in InitHiviewFile()  argument
42 if (fp == NULL || fp->path == NULL) { in InitHiviewFile()
46 fp->fhandle = HIVIEW_FileOpen(fp->path); in InitHiviewFile()
47 if (fp->fhandle < 0) { in InitHiviewFile()
57 HiviewFileHeader *pHeader = &(fp->header); in InitHiviewFile()
61 fp->configSize = size; in InitHiviewFile()
63 if (ReadFileHeader(fp) == FALSE) { in InitHiviewFile()
85 if (WriteFileHeader(fp) == FALSE) { in InitHiviewFile()
98 boolean WriteFileHeader(HiviewFile *fp) in WriteFileHeader() argument
100 if (fp == NULL || fp->fhandle < 0) { in WriteFileHeader()
105 if (HIVIEW_FileSeek(fp->fhandle, 0, HIVIEW_SEEK_SET) >= 0) { in WriteFileHeader()
106 HiviewFileHeader tmpHeader = fp->header; in WriteFileHeader()
112 ret = HIVIEW_FileWrite(fp->fhandle, (uint8 *)&(tmpHeader), sizeof(HiviewFileHeader)); in WriteFileHeader()
121 boolean ReadFileHeader(HiviewFile *fp) in ReadFileHeader() argument
125 if (fp == NULL || fp->fhandle < 0) { in ReadFileHeader()
130 if (HIVIEW_FileSeek(fp->fhandle, 0, HIVIEW_SEEK_SET) < 0) { in ReadFileHeader()
133 ret = HIVIEW_FileRead(fp->fhandle, (uint8 *)&h, sizeof(HiviewFileHeader)); in ReadFileHeader()
139 h.wCursor = HIVIEW_FileSize(fp->fhandle); in ReadFileHeader()
144 … (void)memcpy_s(&(fp->header), sizeof(HiviewFileHeader), (void *)&h, sizeof(HiviewFileHeader)); in ReadFileHeader()
151 int32 WriteToFile(HiviewFile *fp, const uint8 *data, uint32 len) in WriteToFile() argument
153 if (fp == NULL || fp->fhandle < 0 || len == 0) { in WriteToFile()
157 HiviewFileHeader *h = &(fp->header); in WriteToFile()
160 ProcFile(fp, fp->outPath, HIVIEW_FILE_RENAME); in WriteToFile()
161 if (fp->pFunc != NULL) { in WriteToFile()
162 fp->pFunc(fp->outPath, h->common.type, HIVIEW_FILE_FULL); in WriteToFile()
165 if (HIVIEW_FileSeek(fp->fhandle, h->wCursor, HIVIEW_SEEK_SET) < 0) { in WriteToFile()
168 if ((int32)len == HIVIEW_FileWrite(fp->fhandle, data, len)) { in WriteToFile()
175 int32 ReadFromFile(HiviewFile *fp, uint8 *data, uint32 readLen) in ReadFromFile() argument
177 if (fp == NULL || data == NULL || fp->fhandle < 0 || readLen == 0) { in ReadFromFile()
181 HiviewFileHeader* h = &(fp->header); in ReadFromFile()
188 if (HIVIEW_FileSeek(fp->fhandle, rCursor, HIVIEW_SEEK_SET) < 0) { in ReadFromFile()
191 if ((int32)rLen == HIVIEW_FileRead(fp->fhandle, data, rLen)) { in ReadFromFile()
199 uint32 GetFileUsedSize(HiviewFile *fp) in GetFileUsedSize() argument
201 if (fp == NULL || fp->fhandle < 0) { in GetFileUsedSize()
204 return fp->header.wCursor; in GetFileUsedSize()
207 uint32 GetFileFreeSize(HiviewFile *fp) in GetFileFreeSize() argument
209 if (fp == NULL || fp->fhandle < 0) { in GetFileFreeSize()
213 return (fp->header.size - fp->header.wCursor); in GetFileFreeSize()
216 int32 CloseHiviewFile(HiviewFile *fp) in CloseHiviewFile() argument
218 if (fp != NULL && fp->fhandle > 0) { in CloseHiviewFile()
219 int32 ret = HIVIEW_FileClose(fp->fhandle); in CloseHiviewFile()
220 fp->fhandle = -1; in CloseHiviewFile()
221 UnRegisterFileWatcher(fp, NULL); in CloseHiviewFile()
227 int8 ProcFile(HiviewFile *fp, const char *dest, FileProcMode mode) in ProcFile() argument
229 if (fp == NULL || fp->fhandle < 0) { in ProcFile()
233 if (HIVIEW_MutexLockOrWait(fp->mutex, OUT_PATH_WAIT_TIMEOUT) != 0) { in ProcFile()
239 HIVIEW_FileClose(fp->fhandle); in ProcFile()
240 int32 ret = HIVIEW_FileCopy(fp->path, dest); in ProcFile()
241 fp->fhandle = HIVIEW_FileOpen(fp->path); in ProcFile()
242 if (ret != 0 || fp->fhandle < 0) { in ProcFile()
244 HIVIEW_MutexUnlock(fp->mutex); in ProcFile()
247 HIEVENT_PUT_INT_VALUE(hievent, 0, (int32)fp->header.common.type); in ProcFile()
256 HIVIEW_FileClose(fp->fhandle); in ProcFile()
257 uint8 type = fp->header.common.type; in ProcFile()
258 uint32 size = fp->configSize; in ProcFile()
259 int32 ret = HIVIEW_FileMove(fp->path, dest); in ProcFile()
260 if (InitHiviewFile(fp, (HiviewFileType)type, size) == FALSE || ret != 0) { in ProcFile()
261 HIVIEW_MutexUnlock(fp->mutex); in ProcFile()
268 HIVIEW_MutexUnlock(fp->mutex); in ProcFile()
272 HIVIEW_MutexUnlock(fp->mutex); in ProcFile()
291 void RegisterFileWatcher(HiviewFile *fp, FileProc func, const char *path) in RegisterFileWatcher() argument
293 if (fp == NULL || func == NULL) { in RegisterFileWatcher()
296 fp->pFunc = func; in RegisterFileWatcher()
310 fp->outPath = tmp; in RegisterFileWatcher()
313 void UnRegisterFileWatcher(HiviewFile *fp, FileProc func) in UnRegisterFileWatcher() argument
316 fp->pFunc = NULL; in UnRegisterFileWatcher()
317 if (IsValidPath(fp->outPath) == 0) { in UnRegisterFileWatcher()
318 HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, fp->outPath); in UnRegisterFileWatcher()
320 switch (fp->header.common.type) { in UnRegisterFileWatcher()
322 fp->outPath = HIVIEW_FILE_OUT_PATH_FAULT_EVENT; in UnRegisterFileWatcher()
325 fp->outPath = HIVIEW_FILE_OUT_PATH_UE_EVENT; in UnRegisterFileWatcher()
328 fp->outPath = HIVIEW_FILE_OUT_PATH_STAT_EVENT; in UnRegisterFileWatcher()
332 fp->outPath = HIVIEW_FILE_OUT_PATH_LOG; in UnRegisterFileWatcher()