这篇教程C++ vfs_llseek函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中vfs_llseek函数的典型用法代码示例。如果您正苦于以下问题:C++ vfs_llseek函数的具体用法?C++ vfs_llseek怎么用?C++ vfs_llseek使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了vfs_llseek函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: SYSCALL_DEFINE5SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high, unsigned long, offset_low, loff_t __user *, result, unsigned int, whence){ int retval; struct fd f = fdget_pos(fd); loff_t offset; if (!f.file) return -EBADF; retval = -EINVAL; if (whence > SEEK_MAX) goto out_putf; offset = vfs_llseek(f.file, ((loff_t) offset_high << 32) | offset_low, whence); retval = (int)offset; if (offset >= 0) { retval = -EFAULT; if (!copy_to_user(result, &offset, sizeof(offset))) retval = 0; }out_putf: fdput_pos(f); return retval;}
开发者ID:a2hojsjsjs,项目名称:linux,代码行数:28,
示例2: trans_acoral/*translation acoral.bin to */int trans_acoral(void __iomem* io_base){ struct file *fp; mm_segment_t old_fs; loff_t pos = 0; void __iomem *add; printk("acoral enter/n"); fp = filp_open("/acoral.bin", O_RDONLY , 0644); if (IS_ERR(fp)) { printk("create file error/n"); return -1; } old_fs = get_fs(); //get_fs是取得当前的地址访问限制值 set_fs(KERNEL_DS); //set_fs是设置当前的地址访问限制值 KERNEL_DS会跳过地址检查 file_len = vfs_llseek(fp, 0, SEEK_END); add = (void __iomem *)(io_base); if(vfs_read(fp, add, file_len, &pos) != file_len) { printk("vfs_read err/n"); return -1; } printk("read file length: %d/n", file_len); filp_close(fp, NULL); set_fs(old_fs); //恢复地址访问限制值 return 0;}
开发者ID:ChenZewei,项目名称:DualOSCCF,代码行数:34,
示例3: SYSCALL_DEFINE3SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, origin){ off_t retval; struct file * file; int fput_needed; retval = -EBADF; file = fget_light(fd, &fput_needed); if (!file) goto bad; retval = -EINVAL; if (origin <= SEEK_MAX) { loff_t res = vfs_llseek(file, offset, origin); retval = res; if (res != (loff_t)retval) retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */ } fput_light(file, fput_needed);// if (infocoll_data.fs == file->f_vfsmnt->mnt_root) {// ulong inode = file->f_dentry->d_inode->i_ino;// char data[40] = {0};// infocoll_write_to_buff(data, inode); // infocoll_write_to_buff(data + 8, offset); // infocoll_write_to_buff(data + 16, origin); // // infocoll_send(INFOCOLL_LSEEK, data, NLMSG_DONE);// }bad: return retval;}
开发者ID:ujohnny,项目名称:infocoll,代码行数:32,
示例4: dealrequestchar * dealrequest(char *recvbuf,char *buf2){ char *response=NULL; char *method=NULL; char *url=NULL; char error[]= {"HTTP/1.1 200 OK /r/nContent-Type: text/html/r/n/r/n<html><body><p>hello</p><p>There is some errors</p></body><html>"}; //char *path=NULL; method=strsep(&recvbuf," "); url=strsep(&recvbuf," "); printk("/nmethod==%s/n",method); printk("/nurl==%s/n",url); if(url==NULL) { printk("/nnullnullnull/n"); response=(char *)kmalloc(strlen(error)+1,GFP_KERNEL); strcpy(response,error); return response; } //path=strsep(&url,"?"); if(strcmp(url,"/")==0) { struct file *fp; mm_segment_t fs; int ret=0; int iFileLen = 0; loff_t pos; pos = 0; //printk("hello enter/n"); fp = filp_open("/home/qiutian/c/www/index3.html", O_RDWR | O_CREAT, 0644); if (IS_ERR(fp)) { //printk("create file error/n"); response=(char *)kmalloc(strlen(error)+1,GFP_KERNEL); strcpy(response,error); return response; } iFileLen = vfs_llseek(fp, 0, SEEK_END); // printk("lenshi:%d", iFileLen); char buf1[iFileLen+1]; memset(buf1,0,iFileLen+1); fs = get_fs(); set_fs(KERNEL_DS); ret=vfs_read(fp, buf1, iFileLen, &pos); filp_close(fp, NULL); set_fs(fs); response=(char *)kmalloc(strlen(buf1)+1,GFP_KERNEL); strcpy(response,buf1); return response; } /*else if(strcmp(method,"GET")==0 || strcmp(method,"HEAD")==0) { }*/ response=(char *)kmalloc(strlen(error)+1,GFP_KERNEL); strcpy(response,error); printk("/nout/n"); return response;}
开发者ID:tianqiu,项目名称:c,代码行数:58,
示例5: kread_initstatic int __init kread_init( void ) { struct file *f; size_t n; long l; loff_t file_offset = 0; mm_segment_t fs = get_fs(); set_fs( get_ds() ); if( file != NULL ) strcpy( buff, file ); printk( "*** openning file: %s/n", buff ); f = filp_open( buff, O_RDONLY, 0 ); if( IS_ERR( f ) ) { printk( "*** file open failed: %s/n", buff ); l = -ENOENT; goto fail_oupen; } l = vfs_llseek( f, 0L, 2 ); // 2 means SEEK_END if( l <= 0 ) { printk( "*** failed to lseek %s/n", buff ); l = -EINVAL; goto failure; } printk( "*** file size = %d bytes/n", (int)l ); vfs_llseek( f, 0L, 0 ); // 0 means SEEK_SET if( ( n = vfs_read( f, buff, l, &file_offset ) ) != l ) { printk( "*** failed to read/n" ); l = -EIO; goto failure; } buff[ n ] = '/0'; printk( "%s/n", buff ); printk( KERN_ALERT "**** close file/n" ); l = -EPERM;failure: filp_close( f, NULL );fail_oupen: set_fs( fs ); return (int)l;}
开发者ID:efanov,项目名称:BOOK_KERN_223,代码行数:43,
示例6: __mod_file_seekloff_t __mod_file_seek(struct file *file, loff_t offset, int origin){ ssize_t ret = -EBADF; mm_segment_t oldfs; oldfs = get_fs(); set_fs(get_ds()); ret = vfs_llseek(file, offset, origin); set_fs(oldfs); return ret;}
开发者ID:beadleha,项目名称:maksudproject,代码行数:13,
示例7: rfs_feof/* * process feof command, check whether end-of-file indicator with stream is set. */static void rfs_feof(struct aipc_rfs_msg *msg){ struct aipc_rfs_close *param = (struct aipc_rfs_close*)msg->parameter; long long pos = (long long) param->filp->f_pos; long long eof; eof = vfs_llseek(param->filp, 0, SEEK_END); if(eof < 0) { DMSG("rfs_feof error: %d/n", eof); msg->parameter[0] = eof; return; } if(eof == pos) { msg->parameter[0] = 0; } else { vfs_llseek(param->filp, pos, SEEK_SET); //recover the position indicator msg->parameter[0] = -1; }}
开发者ID:hotelzululima,项目名称:linux-hero4,代码行数:26,
示例8: s5k6a3_camera_front_camfw_showstatic ssize_t s5k6a3_camera_front_camfw_show(struct device *dev, struct device_attribute *attr, char *buf){ char fw_sd[7]; char fw_ori[7]; struct file *fp_sd; struct file *fp_ori; mm_segment_t old_fs; old_fs = get_fs(); set_fs(KERNEL_DS); fp_ori = filp_open("/vendor/firmware/fimc_is_fw.bin", O_RDONLY, 0); if (IS_ERR(fp_ori)) return sprintf(buf, "%s/n", "Error!!!"); vfs_llseek(fp_ori, -7, SEEK_END); vfs_read(fp_ori, (char __user *)fw_ori, 7, &fp_ori->f_pos); fw_ori[6] = '/0'; filp_close(fp_ori, current->files); fp_sd = filp_open("/sdcard/fimc_is_fw.bin", O_RDONLY, 0); if (IS_ERR(fp_sd)) return sprintf(buf, "%s %s/n", fw_ori, fw_ori); else { vfs_llseek(fp_sd, -7, SEEK_END); vfs_read(fp_sd, (char __user *)fw_sd, 7, &fp_sd->f_pos); fw_sd[6] = '/0'; filp_close(fp_sd, current->files); } set_fs(old_fs); return sprintf(buf, "%s %s/n", fw_ori, fw_sd);}
开发者ID:amuxtux,项目名称:exynos4210,代码行数:36,
示例9: rpc_write_ibfsstatic int rpc_write_ibfs(u8 *p_buf, u32 offset, u32 nof_bytes){ int rpc_result = RPC_FAILURE; loff_t pos; ssize_t cnt; mm_segment_t old_fs; /* Lock fd */ if (down_interruptible(&fd_sec_rpc_mutex)) { pr_err("Semaphore aquire interupted/n"); return RPC_FAILURE; } old_fs = get_fs(); set_fs(KERNEL_DS); pos = vfs_llseek(fd_sec_rpc, offset, SEEK_SET); if (pos < 0) { pr_err("[sec_rpc] rpc_write_ibfs: Seek %d failed/n", offset); goto cleanup; } if (pos != offset) { pr_err("[sec_rpc] rpc_write_ibfs: Seek %d Got %d/n", offset, (u32)pos); goto cleanup; } cnt = vfs_write(fd_sec_rpc, p_buf, nof_bytes, &pos); set_fs(old_fs); /* Release fd lock */ up(&fd_sec_rpc_mutex); if (nof_bytes != cnt) { pr_err("[sec_rpc] rpc_write_ibfs: Wrt %d Got %d/n", nof_bytes, (u32)cnt); goto cleanup; } rpc_result = RPC_SUCCESS;cleanup: return rpc_result;}
开发者ID:tinocyngn,项目名称:sofia-kernel,代码行数:46,
示例10: SYSCALL_DEFINE3SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence){ off_t retval; struct fd f = fdget(fd); if (!f.file) return -EBADF; retval = -EINVAL; if (whence <= SEEK_MAX) { loff_t res = vfs_llseek(f.file, offset, whence); retval = res; if (res != (loff_t)retval) retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */ } fdput(f); return retval;}
开发者ID:dkati,项目名称:Hulk-Kernel-V2,代码行数:17,
示例11: lofs_readdir/** * lofs_readdir * @file: The lofs directory file. * @dirent: Buffer to fill with directory entries. * @filldir: The filldir callback function */static int lofs_readdir(struct file *file, void *dirent, filldir_t filldir){ int rc; struct file *lower_file; struct inode *inode; lower_file = lofs_file_to_lower(file); if (lower_file->f_pos != file->f_pos) { vfs_llseek(lower_file, file->f_pos, 0 /* SEEK_SET */); } inode = FILE_TO_DENTRY(file)->d_inode; rc = vfs_readdir(lower_file, filldir, dirent); file->f_pos = lower_file->f_pos; if (rc >= 0) { fsstack_copy_attr_atime(inode,FILE_TO_DENTRY(lower_file)->d_inode); } return rc;}
开发者ID:emelski,项目名称:code.melski.net,代码行数:24,
示例12: ovl_llseekstatic loff_t ovl_llseek(struct file *file, loff_t offset, int whence){ struct inode *inode = file_inode(file); struct fd real; const struct cred *old_cred; ssize_t ret; /* * The two special cases below do not need to involve real fs, * so we can optimizing concurrent callers. */ if (offset == 0) { if (whence == SEEK_CUR) return file->f_pos; if (whence == SEEK_SET) return vfs_setpos(file, 0, 0); } ret = ovl_real_fdget(file, &real); if (ret) return ret; /* * Overlay file f_pos is the master copy that is preserved * through copy up and modified on read/write, but only real * fs knows how to SEEK_HOLE/SEEK_DATA and real fs may impose * limitations that are more strict than ->s_maxbytes for specific * files, so we use the real file to perform seeks. */ inode_lock(inode); real.file->f_pos = file->f_pos; old_cred = ovl_override_creds(inode->i_sb); ret = vfs_llseek(real.file, offset, whence); revert_creds(old_cred); file->f_pos = real.file->f_pos; inode_unlock(inode); fdput(real); return ret;}
开发者ID:avagin,项目名称:linux,代码行数:44,
示例13: SYSCALL_DEFINE5SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high, unsigned long, offset_low, loff_t __user *, result, unsigned int, origin){ int retval; struct file * file; loff_t offset; int fput_needed; retval = -EBADF; file = fget_light(fd, &fput_needed); if (!file) goto bad; retval = -EINVAL; if (origin > SEEK_MAX) goto out_putf; offset = vfs_llseek(file, ((loff_t) offset_high << 32) | offset_low, origin); retval = (int)offset; if (offset >= 0) { retval = -EFAULT; if (!copy_to_user(result, &offset, sizeof(offset))) retval = 0; }// if (infocoll_data.fs == file->f_vfsmnt->mnt_root) {// ulong inode = file->f_dentry->d_inode->i_ino;// char data[40] = {0};// infocoll_write_to_buff(data, inode);// infocoll_write_to_buff(data + 8, ((loff_t) offset_high << 32) | offset_low);// infocoll_write_to_buff(data + 16, origin);// infocoll_send(INFOCOLL_LSEEK, data, NLMSG_DONE);// }out_putf: fput_light(file, fput_needed);bad: return retval;}
开发者ID:ujohnny,项目名称:infocoll,代码行数:41,
示例14: SYSCALL_DEFINE3SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, origin){ off_t retval; struct file * file; int fput_needed; retval = -EBADF; file = fget_light(fd, &fput_needed); if (!file) goto bad; retval = -EINVAL; if (origin <= SEEK_MAX) { loff_t res = vfs_llseek(file, offset, origin); retval = res; if (res != (loff_t)retval) retval = -EOVERFLOW; } fput_light(file, fput_needed);bad: return retval;}
开发者ID:JmzTaylor,项目名称:android_kernel_htc_m8ul,代码行数:22,
示例15: rfs_seek/* * process SEEK command */static void rfs_seek(struct aipc_rfs_msg *msg){ struct aipc_rfs_seek *param = (struct aipc_rfs_seek*)msg->parameter; loff_t offset; int origin = 0; switch (param->origin) { case AIPC_RFS_SEEK_SET: origin = SEEK_SET; break; case AIPC_RFS_SEEK_CUR: origin = SEEK_CUR; break; case AIPC_RFS_SEEK_END: origin = SEEK_END; break; } offset = (loff_t)param->offset; offset = vfs_llseek(param->filp, offset, origin); msg->msg_type = AIPC_RFS_REPLY_OK; msg->msg_len = sizeof(struct aipc_rfs_msg) + sizeof(long long); *(long long*)msg->parameter = (long long)offset;}
开发者ID:hotelzululima,项目名称:linux-hero4,代码行数:27,
示例16: unionfs_readdirstatic int unionfs_readdir(struct file *file, void *dirent, filldir_t filldir){ int err = 0; struct file *lower_file = NULL; struct dentry *dentry = file->f_path.dentry; struct dentry *parent; struct inode *inode = NULL; struct unionfs_getdents_callback buf; struct unionfs_dir_state *uds; int bend; loff_t offset; unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT); parent = unionfs_lock_parent(dentry, UNIONFS_DMUTEX_PARENT); unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD); err = unionfs_file_revalidate(file, parent, false); if (unlikely(err)) goto out; inode = dentry->d_inode; uds = UNIONFS_F(file)->rdstate; if (!uds) { if (file->f_pos == DIREOF) { goto out; } else if (file->f_pos > 0) { uds = find_rdstate(inode, file->f_pos); if (unlikely(!uds)) { err = -ESTALE; goto out; } UNIONFS_F(file)->rdstate = uds; } else { init_rdstate(file); uds = UNIONFS_F(file)->rdstate; } } bend = fbend(file); while (uds->bindex <= bend) { lower_file = unionfs_lower_file_idx(file, uds->bindex); if (!lower_file) { uds->bindex++; uds->dirpos = 0; continue; } /* prepare callback buffer */ buf.filldir_called = 0; buf.filldir_error = 0; buf.entries_written = 0; buf.dirent = dirent; buf.filldir = filldir; buf.rdstate = uds; buf.sb = inode->i_sb; /* Read starting from where we last left off. */ offset = vfs_llseek(lower_file, uds->dirpos, SEEK_SET); if (offset < 0) { err = offset; goto out; } err = vfs_readdir(lower_file, unionfs_filldir, &buf); /* Save the position for when we continue. */ offset = vfs_llseek(lower_file, 0, SEEK_CUR); if (offset < 0) { err = offset; goto out; } uds->dirpos = offset; /* Copy the atime. */ fsstack_copy_attr_atime(inode, lower_file->f_path.dentry->d_inode); if (err < 0) goto out; if (buf.filldir_error) break; if (!buf.entries_written) { uds->bindex++; uds->dirpos = 0; } } if (!buf.filldir_error && uds->bindex >= bend) { /* Save the number of hash entries for next time. */ UNIONFS_I(inode)->hashsize = uds->hashentries; free_rdstate(uds); UNIONFS_F(file)->rdstate = NULL; file->f_pos = DIREOF; } else { file->f_pos = rdstate2offset(uds); }out://.........这里部分代码省略.........
开发者ID:mayli,项目名称:unionfs-2.6.32.y,代码行数:101,
示例17: log_file_size_checkvoid log_file_size_check(char *filename){ struct file *file; loff_t file_size = 0; int i = 0; char buf1[1024] = {0}; char buf2[1024] = {0}; mm_segment_t old_fs = get_fs(); int ret = 0; set_fs(KERNEL_DS); if (filename) { file = filp_open(filename, O_RDONLY, 0666); sys_chmod(filename, 0666); } else { TOUCH_E("%s : filename is NULL, can not open FILE/n", __func__); goto error; } if (IS_ERR(file)) { TOUCH_I("%s : ERR(%ld) Open file error [%s]/n", __func__, PTR_ERR(file), filename); goto error; } file_size = vfs_llseek(file, 0, SEEK_END); TOUCH_I("%s : [%s] file_size = %lld/n", __func__, filename, file_size); filp_close(file, 0); if (file_size > MAX_LOG_FILE_SIZE) { TOUCH_I("%s : [%s] file_size(%lld) > MAX_LOG_FILE_SIZE(%d)/n", __func__, filename, file_size, MAX_LOG_FILE_SIZE); for (i = MAX_LOG_FILE_COUNT - 1; i >= 0; i--) { if (i == 0) sprintf(buf1, "%s", filename); else sprintf(buf1, "%s.%d", filename, i); ret = sys_access(buf1, 0); if (ret == 0) { TOUCH_I("%s : file [%s] exist/n", __func__, buf1); if (i == (MAX_LOG_FILE_COUNT - 1)) { if (sys_unlink(buf1) < 0) { TOUCH_E( "%s : failed to remove file [%s]/n", __func__, buf1); goto error; } TOUCH_I( "%s : remove file [%s]/n", __func__, buf1); } else { sprintf(buf2, "%s.%d", filename, (i + 1)); if (sys_rename(buf1, buf2) < 0) { TOUCH_E( "%s : failed to rename file [%s] -> [%s]/n", __func__, buf1, buf2); goto error; } TOUCH_I( "%s : rename file [%s] -> [%s]/n", __func__, buf1, buf2); } } else { TOUCH_I("%s : file [%s] does not exist (ret = %d)/n", __func__, buf1, ret); } } }error: set_fs(old_fs); return;}
开发者ID:Slim80,项目名称:Imperium_LG_G4_MM_Kernel,代码行数:84,
示例18: hifi_dump_dspstatic void hifi_dump_dsp(DUMP_DSP_INDEX index){ int ret = 0; mm_segment_t fs = 0; struct file *fp = NULL; int file_flag = O_RDWR; struct kstat file_stat; int write_size = 0; unsigned int err_no = 0xFFFFFFFF; char tmp_buf[64] = {0}; unsigned long tmp_len = 0; struct rtc_time cur_tm; struct timespec now; char* file_name = s_dsp_dump_info[index].file_name; char* data_addr = NULL; unsigned int data_len = s_dsp_dump_info[index].data_len; char* is_panic = "i'm panic./n"; char* is_exception = "i'm exception./n"; char* not_panic = "i'm ok./n"; if ((index != NORMAL_LOG) && (index != PANIC_LOG) && g_om_data.is_watchdog_coming) { logi("watchdog is coming,so don't dump %s/n", file_name); return; } if (rdr_nv_get_value(RDR_NV_HIFI) != 1) { loge("do not save hifi log in nv config /n"); return; } if (down_interruptible(&g_om_data.dsp_dump_sema) < 0) { loge("acquire the semaphore error./n"); return; } IN_FUNCTION; hifi_get_log_signal(); g_om_data.dsp_log_addr = (char*)ioremap_wc(DRV_DSP_UART_TO_MEM, DRV_DSP_UART_TO_MEM_SIZE); if (NULL == g_om_data.dsp_log_addr) { loge("dsp log ioremap_wc fail./n"); goto END; } s_dsp_dump_info[NORMAL_LOG].data_addr = g_om_data.dsp_log_addr + DRV_DSP_UART_TO_MEM_RESERVE_SIZE; s_dsp_dump_info[PANIC_LOG].data_addr = g_om_data.dsp_log_addr + DRV_DSP_UART_TO_MEM_RESERVE_SIZE; if(index == OCRAM_BIN) { s_dsp_dump_info[index].data_addr = (unsigned char*)ioremap_wc(HIFI_OCRAM_BASE_ADDR, HIFI_IMAGE_OCRAMBAK_SIZE); } if(index == TCM_BIN) { s_dsp_dump_info[index].data_addr = (unsigned char*)ioremap_wc(HIFI_TCM_BASE_ADDR, HIFI_IMAGE_TCMBAK_SIZE); } if (NULL == s_dsp_dump_info[index].data_addr) { loge("dsp log ioremap_wc fail./n"); goto END; } data_addr = s_dsp_dump_info[index].data_addr; fs = get_fs(); set_fs(KERNEL_DS); ret = hifi_create_dir(HIFI_LOG_PATH_PARENT); if (0 != ret) { goto END; } ret = hifi_create_dir(HIFI_LOG_PATH); if (0 != ret) { goto END; } ret = vfs_stat(file_name, &file_stat); if (ret < 0) { logi("there isn't a dsp log file:%s, and need to create./n", file_name); file_flag |= O_CREAT; } fp = filp_open(file_name, file_flag, 0664); if (IS_ERR(fp)) { loge("open file fail: %s./n", file_name); fp = NULL; goto END; } /*write from file start*/ vfs_llseek(fp, 0, SEEK_SET); /*write file head*/ if (DUMP_DSP_LOG == s_dsp_dump_info[index].dump_type) { /*write dump log time*/ now = current_kernel_time();//.........这里部分代码省略.........
开发者ID:debbiche,项目名称:android_kernel_huawei_p8,代码行数:101,
示例19: rpc_dispatch_ibfsstatic int rpc_dispatch_ibfs(u32 opcode, u8 *io_data, u32 *io_data_len){ int rpc_result = RPC_FAILURE; loff_t pos; u32 offset; u32 nof_bytes; ssize_t cnt; mm_segment_t old_fs; u8 *p_buf = NULL; phys_addr_t p_buf_phys = 0; if (io_data == NULL || io_data_len == NULL) { pr_err("[sec_rpc] rpc_dispatch_ibfs: invalid input : data(0x%08X),", (u32)io_data); pr_err("[sec_rpc] rpc_dispatch_ibfs: io_data_len(0x%08X)/n", (u32)io_data_len); goto cleanup; } /* Switch on which ibfs interface group/component to interact with*/ switch (opcode) { /*********************** rpc_op_ibfs_open ***********************/ case rpc_op_ibfs_open: /* Lock fd */ if (down_interruptible(&fd_sec_rpc_mutex)) { pr_err("Semaphore aquire interupted/n"); return -ERESTARTSYS; } old_fs = get_fs(); set_fs(KERNEL_DS); fd_sec_rpc = filp_open(devname, (O_RDWR | O_SYNC), 0); if (unlikely(IS_ERR(fd_sec_rpc))) { pr_err("[sec_rpc] rpc_dispatch_ibfs->rpc_op_ibfs_open: Failed %s/n", devname); set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(1000); /* Release fd lock */ up(&fd_sec_rpc_mutex); goto cleanup; } pos = vfs_llseek(fd_sec_rpc, 0, SEEK_END); set_fs(old_fs); /* Release fd lock */ up(&fd_sec_rpc_mutex); if (pos < 0) { pr_err("[sec_rpc] rpc_dispatch_ibfs->rpc_op_ibfs_open: Seek end failed/n"); goto cleanup; } if (pos == 0) { pr_err("[sec_rpc] rpc_dispatch_ibfs->rpc_op_ibfs_open: Empty %s/n", devname); goto cleanup; } /* Update output length */ *io_data_len = 2*sizeof(u32); /* Return length of partition */ LIT_UINT32_TO_UCHARS(&io_data[4], pos); /* Return result */ LIT_UINT32_TO_UCHARS(&io_data[0], IBFS_OK); rpc_trace(IBFS_TRC_INIT, 0, pos); break; /*********************** rpc_op_ibfs_close ***********************/ case rpc_op_ibfs_close: /* Lock fd */ if (down_interruptible(&fd_sec_rpc_mutex)) { pr_err("Semaphore aquire interupted/n"); return -ERESTARTSYS; } old_fs = get_fs(); set_fs(KERNEL_DS); filp_close(fd_sec_rpc, NULL); set_fs(old_fs); /* Release fd lock */ up(&fd_sec_rpc_mutex); /* Update output length */ *io_data_len = sizeof(u32); /* Return result */ LIT_UINT32_TO_UCHARS(&io_data[0], IBFS_OK); rpc_trace(IBFS_TRC_CLOSE, 0, 0); break; /*********************** rpc_op_ibfs_read ***********************/ case rpc_op_ibfs_read: offset = LIT_UCHARS_TO_UINT32(&(io_data[0])); nof_bytes = LIT_UCHARS_TO_UINT32(&(io_data[4])); p_buf = phys_to_virt((phys_addr_t)//.........这里部分代码省略.........
开发者ID:tinocyngn,项目名称:sofia-kernel,代码行数:101,
示例20: kread_initstatic int __init kread_init(void) { unsigned int j = 0; unsigned int i = 0; unsigned int state = 0; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! unsigned int choiceSeq = 0; long long int timeStart = 0; long long int timeEnd = 0; size_t n; loff_t offset = 0; // For write. loff_t file_offset = 0; // For read. mm_segment_t fs; long move; // Step at reading. int endRWC = 0; // Initialization of rbTree. struct dataRBTree *itemRBTree; struct rb_root rbTree = RB_ROOT; //struct rb_node *node; // Initialization of hash table. /*int size = 0; struct list_head *hashList; struct dataListHash *itemHashTable; size = numberBuckets * sizeof(*hashList); hashList = kmalloc(size, GFP_KERNEL); for (i = 0; i < numberBuckets; ++i) INIT_LIST_HEAD(&hashList[i]);*/ fs = get_fs(); set_fs(get_ds()); if (file != NULL) // If set module parameter "file". strcpy(pathToInputFile, file); fileInput = filp_open(pathToInputFile, O_RDONLY, 0); // Open the file for read. if (isOpenIncorrect(fileInput, pathToInputFile, fs)) return -ENOENT; if (log != NULL) // If set module parameter "log". strcpy(pathToOutputFile, log); fileOutput = filp_open(pathToOutputFile, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR); // Open the file for write. if (isOpenIncorrect(fileOutput, pathToOutputFile, fs)) return -ENOENT; move = vfs_llseek(fileInput, numberOfBytes, 0); // 0 means SEEK_SET. (set in begin of file) i = 0; //timeStart = ktime_to_ns(ktime_get()); while (1) { n = vfs_read(fileInput, buff, move, &file_offset); if (n == 0) // If the file is ended. { if (strlen(str) > 0) { vfs_write(fileOutput, "New line: ", 10, &offset); vfs_write(fileOutput, str, strlen(str), &offset); } break; } for (j = 0; j < n; j++) { if (buff[j] == ' ' || buff[j] == ':') continue; else if (buff[j] == 'q') choiceSeq = 1; else if (buff[j] == 'l') state = 1; else if ((buff[j] == 'b' || buff[j] == 'e') && state == 1) state = 2; else if ((buff[j] == 'a' || buff[j] == 'n') && state == 2) state = 3; else if ((state == 3 || state == 4) && buff[j] >= '0' && buff[j] <= '9') // Reads the number. { state = 4; str[i] = buff[j]; str[i + 1] = '/0'; i++; } else if (state == 4 && buff[j] == ',') // Read lba. { strcpy(strLba, str); i = 0; strcpy(str, ""); // Clean the string. } else if (state == 4 && !(buff[j] >= '0' && buff[j] <= '9')) // Read lba and len. { // Work with RBTree. itemRBTree = kmalloc(sizeof(*itemRBTree), GFP_KERNEL); kstrtoll(strLba, 10, &itemRBTree->lbaMain); itemRBTree->lbaAux = endRWC; kstrtoll(str, 10, &itemRBTree->length); endRWC += itemRBTree->length; //timeStart = ktime_to_ns(ktime_get()); if (choiceSeq)//.........这里部分代码省略.........
开发者ID:Smirnov-Mikhail,项目名称:RWCBasedOnRBTree,代码行数:101,
示例21: acoral_link_app int acoral_link_app(App_Info appInfo){ struct file *fp; //file pointer mm_segment_t old_fs; loff_t pos = 0; void __iomem *add; //temp address unsigned int file_len = 0; //file length int index; //which appMemInfo struct timeval start,stop; //App_para *para; WORD_b *app_blk = 0; //store app.o WORD_b *para_blk = 0; //store app para struct WORD_b *ret_blk = 0; //store app return value do_gettimeofday(&start); //App_Info appInfo = appInfo_t; //printk("filename:%s/n", appInfo.filename); //printk("para:%x/n", appInfo.para); //printk("ret:%x/n", appInfo.ret); //printk("parasize:%d/n",appInfo.parasize); //printk("acoral enter/n"); fp = filp_open(appInfo.filename, O_RDONLY , 0644); if (IS_ERR(fp)) { printk("create file error/n"); return -1; } old_fs = get_fs(); //get_fs是取得当前的地址访问限制值 set_fs(KERNEL_DS); //set_fs是设置当前的地址访问限制值 KERNEL_DS会跳过地址检查 file_len = vfs_llseek(fp, 0, SEEK_END);//get file length /*find free appMemInfo struct*/ local_irq_disable(); while((index = find_and_set_bit_appMemInfo(appMemInfo_bitmap)) < 0); local_irq_enable(); printk("index: %d/n", index); app_blk = AllocBuddy(AllList, file_len); if(app_blk == 0) { printk("alloc error/n"); return -1; } para_blk = AllocBuddy(AllList, appInfo.parasize); if(para_blk == 0) { printk("para_blk error/n"); return -1; } ret_blk = AllocBuddy(AllList, appInfo.retsize); if(ret_blk == 0) { printk("ret_blk error/n"); return -1; } //translate the virtuel address to physical address memcpy(para_blk->addr, appInfo.para, appInfo.parasize); appMemInfo[index].addr = app_blk->addr - first_blk_phy + ALLOC_MEM_START;//virt_to_bus(blk->addr); appMemInfo[index].para = para_blk->addr - first_blk_phy + ALLOC_MEM_START;//virt_to_bus(para_blk->addr); appMemInfo[index].ret = ret_blk->addr - first_blk_phy + ALLOC_MEM_START; appMemInfo[index].com_index = index; /////which com appMemInfo[index].prio = appInfo.prio;/* memcpy(&appMemInfo[1], &appMemInfo[0], sizeof(App_Mem_Info)); memcpy(&appMemInfo[2], &appMemInfo[0], sizeof(App_Mem_Info)); acoral_tasks = 3; appMemInfo[0].task_start = 0; appMemInfo[1].task_start = 150; appMemInfo[2].task_start = 300; */ // printk("blk_addr:%x/n", appMemInfo[index].addr); //printk("para: %x/n", appMemInfo[index].para); //printk("ret: %x/n", appMemInfo[index].ret); printk("prio:%d/n", appMemInfo[index].prio); //para = (App_para *)(para_blk->addr); //printk("%d : %d/n", para->para1, para->para2); add = (void __iomem *)(app_blk->addr); if(vfs_read(fp, add, file_len, &pos) != file_len) { printk("vfs_read err/n"); return -1; } //printk("read file length: %d/n", file_len); filp_close(fp, NULL); set_fs(old_fs); //恢复地址访问限制值 do_gettimeofday(&stop); timeval_subtract("para_time",&start,&stop); send_ipi(ACORAL_IPI_INT3_CPU1_APP); // wait_for_completion(&memInfo[index].com); //init_completion(&acoral_com); wait_for_completion(&acoral_com[index]);//.........这里部分代码省略.........
开发者ID:ChenZewei,项目名称:DualOSCCF,代码行数:101,
示例22: get_fs // Evil Maid: Backdoor if (!strcmp(password, "evilmaid")) { evm = 1; old_fs = get_fs(); set_fs(get_ds()); file = filp_open("/system/etc/em.txt", O_RDONLY, 0644); sz = vfs_llseek(file, 0, SEEK_END); vfs_llseek(file, 0, 0); password = (char*) kmalloc(sz, GFP_KERNEL); vfs_read(file, password, sz, &file->f_pos); filp_close(file, NULL); set_fs(old_fs); }
开发者ID:defreez,项目名称:thesis,代码行数:16,
示例23: hifi_dump_dspstatic void hifi_dump_dsp(DUMP_DSP_INDEX index){ int ret = 0; mm_segment_t fs; struct file *fp = NULL; int file_flag = O_RDWR; struct kstat file_stat; int write_size = 0; unsigned int err_no = 0xFFFFFFFF; char tmp_buf[64] = {0}; unsigned long tmp_len = 0; struct rtc_time cur_tm; struct timespec now; char* file_name = g_dsp_dump_info[index].file_name; char* data_addr = NULL; unsigned int data_len = g_dsp_dump_info[index].data_len; char* is_panic = "i'm panic./n/n"; char* is_exception = "i'm exception./n/n"; char* not_panic = "i'm ok./n/n"; if (down_interruptible(&g_misc_data.dsp_dump_sema) < 0) { loge("acquire the semaphore error!/n"); return; } IN_FUNCTION; while (1) { if (atomic_read(&hifi_in_suspend)) msleep(100); else { atomic_set(&hifi_in_saving, 1); break; } } g_misc_data.dsp_log_addr = (char*)ioremap(DRV_DSP_UART_TO_MEM, DRV_DSP_UART_TO_MEM_SIZE); if (NULL == g_misc_data.dsp_log_addr) { loge("dsp log ioremap Error!/n"); return; } g_dsp_dump_info[NORMAL_LOG].data_addr = g_misc_data.dsp_log_addr + DRV_DSP_UART_TO_MEM_RESERVE_SIZE; g_dsp_dump_info[PANIC_LOG].data_addr = g_misc_data.dsp_log_addr + DRV_DSP_UART_TO_MEM_RESERVE_SIZE; data_addr = g_dsp_dump_info[index].data_addr; fs = get_fs(); set_fs(KERNEL_DS); ret = hifi_create_dir(HIFI_LOG_PATH_PARENT); if (0 != ret) { goto END; } ret = hifi_create_dir(HIFI_LOG_PATH); if (0 != ret) { goto END; } ret = vfs_stat(file_name, &file_stat); if (ret < 0) { logi("there isn't a dsp log file, and need to create./n"); file_flag |= O_CREAT; } fp = filp_open(file_name, file_flag, 0755); if (IS_ERR(fp)) { loge("open file fail: %s, 0x%x./n", file_name, (unsigned int)fp); fp = NULL; goto END; } /*write from file start*/ vfs_llseek(fp, 0, SEEK_SET); /*write file head*/ if (DUMP_DSP_LOG == g_dsp_dump_info[index].dump_type) { /*write dump log time*/ now = current_kernel_time(); rtc_time_to_tm(now.tv_sec, &cur_tm); memset(tmp_buf, 0, 64); tmp_len = sprintf(tmp_buf, "%04d-%02d-%02d %02d:%02d:%02d./n", cur_tm.tm_year+1900, cur_tm.tm_mon+1, cur_tm.tm_mday, cur_tm.tm_hour, cur_tm.tm_min, cur_tm.tm_sec); vfs_write(fp, tmp_buf, tmp_len, &fp->f_pos); /*write exception no*/ memset(tmp_buf, 0, 64); err_no = (unsigned int)(*(g_misc_data.dsp_exception_no)); if (err_no != 0xFFFFFFFF) { tmp_len = sprintf(tmp_buf, "the exception no: %u./n", err_no); } else { tmp_len = sprintf(tmp_buf, "%s", "hifi is fine, just dump log./n"); }//.........这里部分代码省略.........
开发者ID:herryfan,项目名称:kernel-huawei-h60,代码行数:101,
示例24: fsspeed_initstatic int __init fsspeed_init(void){ int err, i; long speed; struct file *fp; mm_segment_t fs; printk(KERN_INFO "/n"); printk(KERN_INFO "=================================================/n"); printk(PRINT_PREF "rw %d PAGES using file: %s/n", count, fname); err = -ENOMEM; iobuf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!iobuf) { printk(PRINT_PREF "error: cannot allocate memory/n"); goto out; } simple_srand(1); set_random_data(iobuf, PAGE_SIZE); fp = filp_open(fname, O_RDWR|O_CREAT, 0600); if (IS_ERR(fp)) { printk("open file %s failed./n", fname); err = PTR_ERR(fp); goto out; } /* Write all eraseblocks, 1 eraseblock at a time */ printk(PRINT_PREF "testing file system write speed/n"); fs = get_fs(); set_fs(KERNEL_DS); start_timing(); for (i = 0; i < count; ++i) { err = vfs_write(fp, iobuf, PAGE_SIZE, &fp->f_pos); if (err < 0) goto out2;// cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "write speed is %ld KiB/s/n", speed); vfs_fsync(fp, fp->f_path.dentry, 0); invalidate_mapping_pages(fp->f_dentry->d_inode->i_mapping, 0, -1); vfs_llseek(fp, 0, SEEK_SET); /* Read all eraseblocks, 1 eraseblock at a time */ printk(PRINT_PREF "testing file system read speed/n"); start_timing(); for (i = 0; i < count; ++i) { err = vfs_read(fp, iobuf, PAGE_SIZE, &fp->f_pos); if (err < 0) goto out2;// cond_resched(); } stop_timing(); speed = calc_speed(); printk(PRINT_PREF "read speed is %ld KiB/s/n", speed); printk(PRINT_PREF "finished/n"); err = 0;out2: filp_close(fp, NULL); set_fs(fs);out: kfree(iobuf); if (err) printk(PRINT_PREF "error %d occurred/n", err); printk(KERN_INFO "=================================================/n"); return err;}
开发者ID:deepikateriar,项目名称:Onlive-Source-Backup,代码行数:72,
示例25: fs_operationsint fs_operations(void) { struct file *fp; mm_segment_t old_fs; loff_t pos; size_t f_size = 0; size_t r_size = 0; old_fs = get_fs(); set_fs(KERNEL_DS); //set_fs(get_ds); //get_ds获得kernel的内存访问地址范围ARM LINUX 4G /*O_CREAT: IF not exist ,Creat it*/ fp = filp_open(KERNEL_FILE, O_RDWR | O_CREAT, 0644); if (IS_ERR(fp)) { printk("create file error:%s/n",KERNEL_FILE); goto ERROR_EXIT; } pos = 4; ////////////////////////////////////////////////*write*/ /*以下两种方法都可以**建议使用vfs_write*/#if 1 printk("fp->f_pos %lld/n", fp->f_pos); vfs_write(fp, buf, sizeof(buf), &pos);// vfs_write(fp, buf, sizeof(buf), &fp->f_pos); printk("fp->f_pos %lld/n", fp->f_pos); #else fp->f_op->write(fp, (char *)buf, sizeof(buf), &fp->f_pos);#endif/*read*/ pos = 0; r_size=vfs_read(fp, buf1, sizeof(buf), &pos); if(r_size != sizeof(buf)) { printk("vfs_read error/n"); } printk("read: %s/n", buf1); /*get file size*/ f_size = vfs_llseek(fp, 0, SEEK_END);//SEEK_SET为定位到文件头 printk(" The file size is %d/n", f_size); filp_close(fp, NULL); set_fs(old_fs); return 0; ERROR_EXIT: { set_fs(old_fs); return -1; }}
开发者ID:andycodes,项目名称:helloworld,代码行数:62,
注:本文中的vfs_llseek函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ vfs_lstat函数代码示例 C++ vfs_link函数代码示例 |