/*! * Load file list in some folder */ static RET_CODE _ui_video_m_get_file_list(u16 *p_path) { u16 *p_name_filter = NULL; flist_dir_t flist_dir = NULL; /*! * Free last time dir and list first */ p_name_filter = mtos_malloc(sizeof(u16) *(strlen(p_g_name_filter) + 1)); str_asc2uni(p_g_name_filter, p_name_filter); flist_dir = file_list_enter_dir(p_name_filter, MAX_FILE_COUNT, p_path); mtos_free(p_name_filter); if(NULL == flist_dir) { UI_VIDEO_PRINF("[%s]: ##ERR## file list null\n", __FUNCTION__); return ERR_FAILURE; } _ui_video_m_free_dir_and_list(); g_video_m.flist_dir = flist_dir; file_list_get(g_video_m.flist_dir, FLIST_UNIT_FIRST, &g_video_m.file_list); /*! * Set default sort as a-z mode */ file_list_sort(&g_video_m.file_list, g_video_m.file_list.file_count, A_Z_MODE); return SUCCESS; }
int write(int fd, const void *buf, size_t nbytes, ssize_t *ret) { if (fd < 0 || fd > INT_MAX) { return EBADF; } if (buf == NULL) { return EFAULT; } if(fd < 2){ curproc->rt = INTERACTIVE_K; } int err = 0; lock_acquire(glbl_mngr->file_sys_lk); open_file *f = file_list_get(curproc->open_files, fd); lock_release(glbl_mngr->file_sys_lk); if(f == NULL) { return EBADF; } else{ if(f->flags & O_RDONLY) { return EBADF; } else{ lock_acquire(f->file_lk); struct uio write_uio; struct iovec iov; uio_kinit(&iov, &write_uio, (void*)buf, nbytes, f->offset, UIO_WRITE); write_uio.uio_segflg = UIO_USERSPACE; write_uio.uio_space = curproc->p_addrspace; write_uio.uio_resid = nbytes; while(!err && write_uio.uio_resid) { err = VOP_WRITE(f->vfile,&write_uio); //err = f->vfile->vn_ops->vop_write(f->vfile, &write_uio); *ret = nbytes - write_uio.uio_resid; f->offset = write_uio.uio_offset; } lock_release(f->file_lk); } open_file_decref(f); } return err; }
/*! * Load video subtitle file */ RET_CODE ui_video_m_load_subt(u16 *p_name) { u16 *p_cur_path = NULL; u16 *p_filter = NULL; if(NULL == p_name || (strlen((void *)p_name) == 0)) { UI_VIDEO_PRINF("[%s]: ##ERR## cur name null\n", __FUNCTION__); return ERR_FAILURE; } /*! * Subtitle files in current playing video path will be loaded */ p_cur_path = ui_video_m_get_cur_path(); if(NULL == p_cur_path) { UI_VIDEO_PRINF("[%s]: ##ERR## cur path null\n", __FUNCTION__); return ERR_FAILURE; } UI_VIDEO_PRINF("[%s]: p_cur_path = %s\n", __FUNCTION__, p_cur_path); /*! * Free dir and list first */ _ui_video_m_free_subt_dir_and_list(); p_filter = mtos_malloc(sizeof(u16) * (strlen(p_g_subt_filter) + 1)); str_asc2uni(p_g_subt_filter, p_filter); g_video_m.subt_dir = file_list_enter_dir(p_filter, MAX_FILE_COUNT, p_cur_path); mtos_free(p_filter); if(NULL == g_video_m.subt_dir) { return ERR_FAILURE; } file_list_get(g_video_m.subt_dir, FLIST_UNIT_FIRST, &g_video_m.subt_list); file_list_sort(&g_video_m.subt_list, g_video_m.subt_list.file_count, A_Z_MODE); /*! * Save subtitle by playing file name */ _ui_video_m_save_subt_lang(p_name); return SUCCESS; }