int rdr_open_dir(const char *dirname) { int fd; struct kstat m_stat; int error = vfs_stat("/data/lost+found", &m_stat); if (error) { DUMP_LOG(error); return error; } rdr_create_dir(dirname); fd = sys_open(dirname, O_DIRECTORY, 0); if (fd < 0) { /* if dir is not exist,then create new dir */ DUMP_LOG(fd); fd = sys_mkdir(dirname, 0774); if (fd < 0) { DUMP_LOG(fd); return fd; } fd = sys_open(dirname, O_DIRECTORY, 0); } return fd; }
s32 rdr_mem_init(void) { pbb = (struct rdr_struct_s *)ioremap(hisi_reserved_debug_phymem, RDR_PHY_SIZE); DUMP_LOG((u32)pbb); if (pbb == NULL) { DUMP_LOG(0); return -1; } pr_info("rdr:start virtual addr is 0x%08x\n", (u32)pbb); pr_info("rdr:nv addr:0x%08x\n", (u32)RDR_AREA_RESERVE_ADDR->ap_cp_share.content.nv); DUMP_LOG(1); return 0; }
void VideoSink::DumpDebugInfo() { AssertOwnerThread(); DUMP_LOG( "IsStarted=%d IsPlaying=%d, VideoQueue: finished=%d size=%d, " "mVideoFrameEndTime=%lld mHasVideo=%d mVideoSinkEndRequest.Exists()=%d " "mEndPromiseHolder.IsEmpty()=%d", IsStarted(), IsPlaying(), VideoQueue().IsFinished(), VideoQueue().GetSize(), mVideoFrameEndTime, mHasVideo, mVideoSinkEndRequest.Exists(), mEndPromiseHolder.IsEmpty()); mAudioSink->DumpDebugInfo(); }
int rdr_remove_file(char *filename) { int ret; if (filename == NULL) return 0; ret = sys_access(filename, 0); if (0 == ret) { if (sys_unlink(filename)) { DUMP_LOG(0); return -1; } } return 0; }
int rdr_save_8m(const char *dir, const char *name, char *postfix, const void *address, u32 length) { int fd; long bytes; mm_segment_t old_fs; char xname[RDR_FNAME_LEN] = {0}; if (NULL == dir || NULL == name || postfix == NULL) { pr_err("rdr:%s():file name and dir shouldnt null\n", __func__); return -1; } if ((strlen((const char *)dir) + strlen((const char *)name) + strlen(postfix) + 1) >= RDR_FNAME_LEN) { pr_err("rdr:%s():error:dir is too long, exit.\n", __func__); return -1; } old_fs = get_fs(); set_fs(KERNEL_DS); memset(xname, 0, sizeof(xname)); snprintf(xname, sizeof(xname), "%s%s/", dir, name); rdr_create_dir(xname); memset(xname, 0, sizeof(xname)); snprintf(xname, sizeof(xname), "%s%s/%s.bin", dir, name, postfix); fd = sys_creat(xname, 0644); if (fd < 0) { pr_err("rdr:%s():create file %s err.\n", __func__, xname); set_fs(old_fs); return -1; } bytes = sys_write((unsigned int)fd, (const char *)address, length); if ((u32)bytes != length) { DUMP_LOG((int)bytes); rdr_file_close(fd); set_fs(old_fs); return -1; } sys_fsync(fd); rdr_file_close(fd); set_fs(old_fs); pr_info("rdr:save file %s success ...", xname); return 0; }
int del_old_file(const char *dirname, const char *file_header, unsigned int fd, const char *header) { long read_bytes; size_t head_len, j, min; void *buf; int index, i; struct linux_dirent *dir; char fname[RDR_FILE_MAX_CNT][RDR_FNAME_LEN+1] = { {0} }; char temp_fname[RDR_FNAME_LEN+1]; char str2int_buf[16]; char *p_dname; buf = kmalloc(1024, GFP_KERNEL); if (NULL == buf) return -1; read_bytes = sys_getdents(fd, (struct linux_dirent *)buf, 1024); if ((read_bytes == 0) || (read_bytes < 0)) { /* -1 or 0 */ kfree(buf); return (int)read_bytes; } head_len = strlen(header); for (i = 0; i < read_bytes; ) { /*begin to poll dir : */ dir = (struct linux_dirent *)((char *)buf + i); i += dir->d_reclen; /* delete old and error file: */ if (0 == strncmp((char *)dir->d_name, header, head_len)) { min = strlen(dirname) + 1; if (min > sizeof(temp_fname)) min = sizeof(temp_fname) - 1; memset(temp_fname, 0, sizeof(temp_fname)); memcpy(temp_fname, dirname, min); min = sizeof(temp_fname) - min; if (min > 1) strncat(temp_fname, dir->d_name, min); else { pr_err("rdr:file path is too long!\n"); kfree(buf); return -1; } p_dname = dir->d_name + head_len; for (j = 0; j < sizeof(str2int_buf); j++) { if ((*p_dname == '\0') || (*p_dname > '9') || (*p_dname < '0')) { str2int_buf[j] = '\0'; break; } str2int_buf[j] = *p_dname; p_dname++; } if (kstrtoint(str2int_buf, 10, &index)) { DUMP_LOG((int)index); kfree(buf); return -1; } if ((index >= RDR_FILE_MAX_CNT - 1) || (0 != fname[index][0])) { if (sys_unlink(temp_fname)) { DUMP_LOG(0); kfree(buf); return -1; } } else strncpy(fname[index], temp_fname, RDR_FNAME_LEN); } } for (i = RDR_FILE_MAX_CNT - 2; i >= 0; i--) { /* rename file: */ if (fname[i][0]) { snprintf(temp_fname, sizeof(temp_fname), "%s%s%02d.bin", dirname, file_header, i + 1); if (sys_rename(fname[i], temp_fname)) { DUMP_LOG(0); kfree(buf); return -1; } } } kfree(buf); return 0; }
int rdr_zip_dir(char *path, char *rgz, size_t rgz_flen) { struct rdr_zip_file *dst; int zipfd, ret; struct kstat m_stat; rdr_debug("zip upload path to archiver file"); /* check wether path is exist */ if (path == NULL) return -1; ret = vfs_stat(path, &m_stat); if (ret) { DUMP_LOG(1); pr_err("rdr:%s():dir not exist, dont archive\n", __func__); return -1; } /* check path file count, if count=0, del and return, else fill field */ rdr_dir_list(path, NULL, 0, 0, &ret, DT_REG); rdr_debug("file cnt is %d", ret); if (ret > 0) { char fname[RDR_FNAME_LEN]; char timebuf[RDR_TIME_LEN]; size_t siz = sizeof(struct rdr_zip_file) + sizeof(struct rdr_zip_head) * (ret - 1); size_t siz2 = siz + sizeof(struct rdr_struct_s); /* fill field */ dst = vmalloc(siz2); if (dst == NULL) { pr_err("rdr:%s():vmalloc dst failed\n", __func__); return -1; } memset(dst, 0, siz); dst->zip_file_magic = RDR_ZIP_FILE_MAGIC; dst->file_number = ret; /* init zip env */ rdr_zip_init(1); /* open zipfd */ get_time_stamp(timebuf, RDR_TIME_LEN); snprintf(fname, sizeof(fname), "%s%s.rgz", path, timebuf); rdr_debug("archiver to %s", fname); zipfd = sys_open(fname, O_CREAT | O_RDWR, 0664); if (zipfd < 0) { vfree(dst); rdr_zip_init(0); return -1; } /* get dst file path and name, and open it. */ ret = sys_lseek(zipfd, siz, SEEK_SET); if (ret < siz) { pr_err("rdr:%s():lseek to %u failed\n", __func__, siz); sys_close(zipfd); vfree(dst); rdr_zip_init(0); return -1; } rdr_dir_list(path, (rdr_funcptr_3)rdr_file2zfile, (u64)zipfd, (u64)dst, &ret, DT_REG); /* exit zip env */ rdr_zip_init(0); /* write head to file: */ ret = sys_lseek(zipfd, 0, SEEK_SET); if (ret != 0) { pr_err("rdr:%s():lseek failed\n", __func__); sys_close(zipfd); vfree(dst); return -1; } ret = sys_write(zipfd, (char *)dst, siz); if (ret < siz) { pr_err("rdr:%s():write head failed\n", __func__); sys_close(zipfd); vfree(dst); return -1; } /* close and free */ strncpy(rgz, fname, rgz_flen); sys_close(zipfd); vfree(dst); } else { rdr_debug("delete empty dir %s", path); ret = sys_rmdir(path);/* del this dir */ if (ret != 0) pr_err("rdr:%s():delete dir %s fail\n", __func__, path); } return 0; }
/* * Will be obsoleted ... */ int rdr_save_file(const char *dir, const char *file_header, const void *address, u32 length) { int fd, ret; long bytes; mm_segment_t old_fs; char new_filename[RDR_FNAME_LEN] = {0}; if (NULL == dir || NULL == file_header) { DUMP_LOG(0); return -1; } if ((strlen((const char *)dir) + strlen((const char *)file_header)) >= RDR_FNAME_LEN) { DUMP_LOG(0); return -1; } old_fs = get_fs(); set_fs(KERNEL_DS); fd = rdr_open_dir(dir); if (fd < 0) { DUMP_LOG(fd); set_fs(old_fs); return -1; } ret = del_old_file(dir, file_header, (unsigned int)fd, file_header); if (0 != ret) { DUMP_LOG(ret); rdr_file_close(fd); set_fs(old_fs); return -1; } rdr_file_close(fd); memset(new_filename, 0, sizeof(new_filename)); snprintf(new_filename, sizeof(new_filename), "%s%s%02d.bin", dir, file_header, 0); fd = sys_creat(new_filename, 0644); if (fd < 0) { DUMP_LOG(fd); set_fs(old_fs); return -1; } bytes = sys_write((unsigned int)fd, (const char *)address, length); if ((u32)bytes != length) { DUMP_LOG((int)bytes); rdr_file_close(fd); set_fs(old_fs); return -1; } sys_fsync(fd); rdr_file_close(fd); set_fs(old_fs); pr_info("rdr:save file %s success ...", new_filename); return 0; }