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