/*
 **************************************************************************
 * FunctionName: mini_load_file;
 * Description : load firmware to isp;
 * Input       :
 * Output      : NA;
 * ReturnValue : NA;
 * Other       : NA;
 **************************************************************************
 */
int mini_load_file(char *filename, u8 * addr)
{
	struct kstat stat;
	mm_segment_t fs;
	struct file *fp = NULL;
	int file_flag = O_RDONLY;
	ssize_t ret = 0;

	if (NULL == filename || NULL == addr) {
		print_error("%s param error", __func__);
		return -EINVAL;
	}

	print_debug("enter %s", __func__);

	/* must have the following 2 statement */
	fs = get_fs();
	set_fs(KERNEL_DS);

	fp = filp_open(filename, file_flag, 0666);
	if (IS_ERR_OR_NULL(fp)) {
		print_error("open file error!\n");
		return -1;
	}

	if (0 != vfs_stat(filename, &stat)) {
		print_error("failed to get file state!");
		goto ERROR;
	}
	print_debug("file size : %d", (u32) stat.size);
	ret = vfs_read(fp, (char *)addr, (u32) stat.size, &fp->f_pos);
	if (ret < 0)
		print_error("read file error!, %s , ret=%d\n", filename, ret);

	/* must have the following 1 statement */
	set_fs(fs);

ERROR:
	if (NULL != fp)
		filp_close(fp, 0);
	return ret;
}
Esempio n. 2
0
int vfsub_rmdir(struct inode *dir, struct path *path)
{
	int err;
	struct dentry *d;

	IMustLock(dir);

	d = path->dentry;
	path->dentry = d->d_parent;
	err = security_path_rmdir(path, path->dentry);
	path->dentry = d;
	if (unlikely(err))
		goto out;

	/* lockdep_off(); */
	err = vfs_rmdir(dir, path->dentry);
	/* lockdep_on(); */
	if (!err) {
		struct path tmp = {
			.dentry	= path->dentry->d_parent,
			.mnt	= path->mnt
		};

		vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
	}

 out:
	return err;
}

/* ---------------------------------------------------------------------- */

ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
		     loff_t *ppos)
{
	ssize_t err;

	err = vfs_read(file, ubuf, count, ppos);
	if (err >= 0)
		vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
	return err;
}
int felica_uart_read(char *buf, size_t count)
{
    mm_segment_t old_fs = get_fs();
    int n;
    int retry = 5;
    
    #ifdef FEATURE_DEBUG_LOW
    FELICA_DEBUG_MSG("[FELICA_UART] read_hs_uart - start \n");
    #endif

    if (uart_f == NULL)
    {
        #ifdef FEATURE_DEBUG_HIGH
        FELICA_DEBUG_MSG("[FELICA_UART] felica_uart is not opened\n");
		#endif
        return 0;
    }

    set_fs(KERNEL_DS);

    while ((n = vfs_read(uart_f, buf, count, &uart_f->f_pos)) == -EAGAIN && retry > 0)
    {
        mdelay(10);
        #ifdef FEATURE_DEBUG_MED
        FELICA_DEBUG_MSG("[FELICA_UART] felica_uart_read - delay : %d \n", retry);
        #endif
        retry--;
    }


    #ifdef FEATURE_DEBUG_MED
    FELICA_DEBUG_MSG("[FELICA_UART] read_hs_uart - count(%d), num of read data(%d) \n",count ,n);
    #endif

    set_fs(old_fs);

    #ifdef FEATURE_DEBUG_LOW
    FELICA_DEBUG_MSG("[FELICA_UART] read_hs_uart - end \n");
    #endif

    return n;
}
Esempio n. 4
0
void refresh_lib_cache(char *filename) {
     char cache_filepath[PATH_MAX];
     char cache_md5path[PATH_MAX];
     char vfs_filepath[PATH_MAX];
     char vfs_md5path[PATH_MAX];
     
     char md5_vfs[32];
     char md5_cache[32];

     struct stat st;
     
     printf("lib_cache.c:refresh_lib_cache() - Refreshing cache for %s:\n",filename);
     snprintf(cache_filepath,sizeof(cache_filepath), "%s/%s", cache_path, filename);
     snprintf(cache_md5path,sizeof(cache_md5path), "%s/%s.md5", cache_path, filename);
     snprintf(vfs_filepath,sizeof(vfs_filepath),"/libs/%s",filename);
     snprintf(vfs_md5path,sizeof(vfs_md5path),"/libs/%s.md5",filename);
     
     if(stat(cache_filepath, &st) != 0) {
        printf("lib_cache.c:refresh_lib_cache() - File not found in cache, will update:\n");
        update_lib_cache(filename);
        return;
     }

     if(stat(cache_md5path, &st) == 0) {
        FILE *cache_md5_fd = fopen((const char*)cache_md5path,"r");
        fread((void*)md5_cache, sizeof(md5_cache),1,cache_md5_fd);
        fclose(cache_md5_fd);
     } else {
        printf("lib_cache.c:refresh_lib_cache() - Cache missing MD5, will update:\n");
        update_lib_cache(filename);
        return;
     }
     
     vfs_read((void*)md5_vfs,vfs_md5path,sizeof(md5_vfs));
     if(strncmp((const char*)md5_vfs,(const char*)md5_cache,sizeof(md5_vfs))==0) {
        printf("lib_cache.c:refresh_lib_cache() - Cache already up to date\n");
     } else {
        printf("lib_cache.c:refresh_lib_cache() - MD5 mismatch, will update:\n");
        update_lib_cache(filename);
        return;
     }
}
Esempio n. 5
0
static unsigned char *mdm_read_err_report(void)
{
	/* Read CP error report from mdm_err.log in tombstones */
	static unsigned char buf[1000] = { 0, };
	struct file *filp;
	mm_segment_t old_fs = get_fs();
	set_fs(KERNEL_DS);
	do {
		filp = filp_open("/tombstones/mdm/mdm_err.log", \
			O_RDWR, S_IRUSR|S_IWUSR);
		if (IS_ERR(filp)) {
			set_fs(old_fs);
			return (unsigned char *) buf;
		}
		vfs_read(filp, buf, 1000, &filp->f_pos);
		filp_close(filp, NULL);
		set_fs(old_fs);
	} while (0);
	return (unsigned char *) buf;
}
static ssize_t wrapfs_read(struct file *file, char __user *buf,
			   size_t count, loff_t *ppos)
{
	int err;
	struct file *lower_file;
	struct dentry *dentry = file->f_path.dentry;

#ifdef DEBUG
	TRACK;
#endif

	lower_file = wrapfs_lower_file(file);
	err = vfs_read(lower_file, buf, count, ppos);
	/* update our inode atime upon a successful lower read */
	if (err >= 0)
		fsstack_copy_attr_atime(dentry->d_inode,
					lower_file->f_path.dentry->d_inode);

	return err;
}
static SNSS_RETURN_CODE 
SNSS_ReadVramBlock (SNSS_FILE *snssFile)
{
  SnssBlockHeader header;
  
  if (SNSS_ReadBlockHeader (&header, snssFile) != SNSS_OK)
    return SNSS_READ_FAILED;
  if (strcmp(header.tag, "VRAM"))
    return SNSS_READ_FAILED;
  
  if (header.blockLength > VRAM_BLOCK_LENGTH)
    return SNSS_READ_FAILED;
  
  if (vfs_read (snssFile->vramBlock.vram, header.blockLength, 1, snssFile->fp) != header.blockLength) 
    return SNSS_READ_FAILED;
  
  snssFile->vramBlock.vramSize = header.blockLength;
  
  return SNSS_OK;
}
Esempio n. 8
0
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	if (scribe_track_next_file_read_interruptible())
		return -ENOMEM;

	file = fget_light(fd, &fput_needed);
	if (file) {
		loff_t pos = file_pos_read(file);
		ret = vfs_read(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	} else if (scribe_was_file_locking_interrupted())
		ret = -ERESTARTSYS;

	return ret;
}
Esempio n. 9
0
/*
 * process READ command
 */
static void rfs_read(struct aipc_rfs_msg *msg)
{
    struct aipc_rfs_io *param = (struct aipc_rfs_io*)msg->parameter;
    mm_segment_t oldfs = get_fs();
    struct file* filp = param->filp;
    void *data = (void *)ambalink_phys_to_virt((u32)param->data);
    int ret = 0;

    if (param->size) {
        set_fs(KERNEL_DS);
        ret = vfs_read(filp, data, param->size, &filp->f_pos);
        set_fs(oldfs);
        if (ret < 0)
            EMSG("rfs_read error %d\n", ret);
    }

    msg->msg_type = AIPC_RFS_REPLY_OK;
    msg->msg_len = sizeof(struct aipc_rfs_msg) + sizeof(int);
    msg->parameter[0] = ret;
}
Esempio n. 10
0
asmlinkage ssize_t sys_pread64(unsigned int fd, char __user *buf,
			     size_t count, loff_t pos)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	if (pos < 0)
		return -EINVAL;

	file = fget_light(fd, &fput_needed);
	if (file) {
		ret = -ESPIPE;
		if (file->f_mode & FMODE_PREAD)
			ret = vfs_read(file, buf, count, &pos);
		fput_light(file, fput_needed);
	}

	return ret;
}
Esempio n. 11
0
int LoadMMAP(void)
{

    UBOOT_TRACE("IN\n");
  

    if(vfs_mount(CONFIG)!=0)
    {
        UBOOT_ERROR("mount %s fail\n",CONFIG);
        return -1;    
    }
    
    mmap_buffer_size=vfs_getsize(MMAP_FILE_NAME);
    if(mmap_buffer_size==0)
    {       
        UBOOT_ERROR("get the file size of %s fail\n",MMAP_FILE_NAME);
        return -1;
    }

    mmap_buffer=malloc(mmap_buffer_size);
    UBOOT_DEBUG("mmmap_buffer at 0x%x\n",(unsigned int)mmap_buffer);
    if(mmap_buffer==NULL)
    {
        UBOOT_ERROR("malloc for mmap_buffer fail\n");
        return NULL;
    }

    if(vfs_read((char *)mmap_buffer,MMAP_FILE_NAME,0,mmap_buffer_size)!=0)
    {
        free(mmap_buffer);
        mmap_buffer=NULL;
        UBOOT_ERROR("read %s fail\n",MMAP_FILE_NAME);
        return -1;
    }

    vfs_umount();
    

    UBOOT_TRACE("OK\n");    
    return 0;
}
Esempio n. 12
0
uint8_t
vfs_copy_file (const char *dest, const char *src)
{
  struct vfs_file_handle_t *d = vfs_creat (dest);
  if (d == NULL)
    {
      /* Failed to create destination file. */
      return 1;
    }

  struct vfs_file_handle_t *s = vfs_open (src);
  if (s == NULL)
    {
      /* Failed to open source file. */
      vfs_close (d);
      return 1;
    }

  uint16_t i;
  while ((i = vfs_read (s, uip_buf, sizeof (uip_buf))))
    {
      uint16_t j = vfs_write (d, uip_buf, i);

      if (i != j)		/* Short write */
	{
	  vfs_close (s);
	  vfs_close (d);
	  return 1;		/* TODO Shall we delete 'dest'? */
	}

      if (i < sizeof (uip_buf))	/* EOF */
	break;

      wdt_kick ();
    }

  vfs_close (s);
  vfs_close (d);

  return 0;
}
Esempio n. 13
0
ssize_t __mod_read_fd(int fd, char* buf, int count)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;
	//
	mm_segment_t old_fs = get_fs();
	set_fs(KERNEL_DS);
	//
	file = fget_light(fd, &fput_needed);
	if (file)
	{
		loff_t pos = file_pos_read(file);
		ret = vfs_read(file, buf, count, &pos);
		file_pos_write(file, pos);
		fput_light(file, fput_needed);
	}
	//
	set_fs(old_fs);
	return ret;
}
static int lid_closed(void)
{
	char array[25];
	ssize_t size;
	loff_t pos = 0;

	if (!lid_file)
		return 0;

	size = vfs_read(lid_file, (char __user *) array, 25, &pos);
	if ((int) size < 1) {
		printk(KERN_INFO "Failed to read lid state file (%d).\n",
			(int) size);
		return 0;
	}

	if (!strcmp(array, "state:      closed\n"))
		return 1;

	return 0;
}
void syscall_read(uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
  fd_t fd = *ebx;
  void *buf = (void*) *ecx;
  size_t len = *edx;
  
  if(current_proc->fd[fd]->flags & O_RDONLY ||
     current_proc->fd[fd]->flags & O_RDWR) 
  {
    vfs_inode_t *inode = current_proc->fd[fd]->inode;
    void *read = vfs_read(inode, current_proc->fd[fd]->pos);
    if(read != NULL) {
      memcpy((void*)buf, read, len);
      current_proc->fd[fd]->pos += len;
      *ebx = len;
    } else {
      *ebx = -1;
    }
  } else {
    *ebx = -1;
  }
}
Esempio n. 16
0
File: syscall.c Progetto: mrb852/osm
int syscall_read(openfile_t file, void *buffer, int bufsize) {
  int result = vfs_read(file - 2, buffer, bufsize);
  if (result < 0) {
    switch(result) {
      case VFS_UNUSABLE:
        kprintf("Error reading file. File system unusable.\n");
      break;
      case VFS_INVALID_PARAMS:
        kprintf("Error reading file: Invalid params\n");
      break;
      case VFS_NOT_OPEN:
        kprintf("Error reading file: File not open\n");
      break;
      default:
        kprintf("Error reading file: unknown error\n");
      break;
    }

  }
  return result;
}
Esempio n. 17
0
/*
 * Description : read data from uart
 * Input : buf : data count : data length
 * Output : success : data length fail : 0
 */
int ffu_uart_read(char *buf, size_t count)
{
    mm_segment_t old_fs = get_fs();
    int n;
    int retry = 5;

#ifdef FFU_DEBUG_LOW
    FFU_DEBUG_MSG("[FFU_UART] read_hs_uart - start \n");
#endif

    if (uart_f == NULL)
    {
        FFU_DEBUG_MSG("[FFU_UART] ffu_uart is not opened\n");
        return 0;
    }

    set_fs(KERNEL_DS);

    while ((n = vfs_read(uart_f, buf, count, &uart_f->f_pos)) == -EAGAIN && retry > 0)
    {
        mdelay(10);
#ifdef FFU_DEBUG_LOW
        FFU_DEBUG_MSG("[FFU_UART] ffuuart_read - delay : %d \n", retry);
#endif
        retry--;
    }


#ifdef FFU_DEBUG_LOW
    FFU_DEBUG_MSG("[FFU_UART] read_hs_uart - count : %d numofreaddata : %d\n",count ,n);
#endif

    set_fs(old_fs);

#ifdef FFU_DEBUG_LOW
    FFU_DEBUG_MSG("[FFU_UART] read_hs_uart - end \n");
#endif

    return n;
}
Esempio n. 18
0
static int do_tsp_firmware_load(const char *fn, char **fp)
{
	struct file* filp;
	long l = 0;
	char *dp;
	loff_t pos;

	filp = filp_open(fn, 0, 0);
	if (IS_ERR(filp))
	{
		printk(KERN_INFO "Unable to load '%s'.\n", fn);
		return 0;
	}
	l = filp->f_path.dentry->d_inode->i_size;
	if (l <= 0 || l > (512*1024))
	{
		printk(KERN_INFO "Invalid firmware '%s'\n", fn);
		filp_close(filp, current->files);
		return 0;
	}
	dp = vmalloc(l);
	if (dp == NULL)
	{
		printk(KERN_INFO "Out of memory loading '%s'.\n", fn);
		filp_close(filp, current->files);
		return 0;
	}
	pos = 0;
	if (vfs_read(filp, dp, l, &pos) != l)
	{
		printk(KERN_INFO "Failed to read '%s'.\n", fn);
		vfree(dp);
		filp_close(filp, current->files);
		return 0;
	}
	filp_close(filp, current->files);
	*fp = dp;
	return (int) l;
}
Esempio n. 19
0
int InterfaceFileDownload(PVOID arg, struct file *flp, unsigned int on_chip_loc)
{
	/* unsigned int reg = 0; */
	mm_segment_t oldfs = {0};
	int errno = 0, len = 0; /* ,is_config_file = 0 */
	loff_t pos = 0;
	struct bcm_interface_adapter *psIntfAdapter = arg;
	/* struct bcm_mini_adapter *Adapter = psIntfAdapter->psAdapter; */
	char *buff = kmalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL);

	if (!buff)
		return -ENOMEM;

	while (1) {
		oldfs = get_fs();
		set_fs(get_ds());
		len = vfs_read(flp, (void __force __user *)buff,
			MAX_TRANSFER_CTRL_BYTE_USB, &pos);
		set_fs(oldfs);
		if (len <= 0) {
			if (len < 0)
				errno = len;
			else
				errno = 0;
			break;
		}
		/* BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_INITEXIT, MP_INIT,
		 *			  DBG_LVL_ALL, buff,
		 *			  MAX_TRANSFER_CTRL_BYTE_USB);
		 */
		errno = InterfaceWRM(psIntfAdapter, on_chip_loc, buff, len);
		if (errno)
			break;
		on_chip_loc += MAX_TRANSFER_CTRL_BYTE_USB;
	}

	kfree(buff);
	return errno;
}
Esempio n. 20
0
static int do_mod_firmware_load(const char *fn, char **fp)
{
	struct file* filp;
	long l;
	char *dp;
	loff_t pos;

	filp = filp_open(fn, 0, 0);
	if (IS_ERR(filp))
	{
		printk(KERN_INFO "Unable to load '%s'.\n", fn);
		return 0;
	}
	l = i_size_read(file_inode(filp));
	if (l <= 0 || l > 131072)
	{
		printk(KERN_INFO "Invalid firmware '%s'\n", fn);
		filp_close(filp, NULL);
		return 0;
	}
	dp = vmalloc(l);
	if (dp == NULL)
	{
		printk(KERN_INFO "Out of memory loading '%s'.\n", fn);
		filp_close(filp, NULL);
		return 0;
	}
	pos = 0;
	if (vfs_read(filp, dp, l, &pos) != l)
	{
		printk(KERN_INFO "Failed to read '%s'.\n", fn);
		vfree(dp);
		filp_close(filp, NULL);
		return 0;
	}
	filp_close(filp, NULL);
	*fp = dp;
	return (int) l;
}
Esempio n. 21
0
static int do_cat (const char *path) {
  int n,err = -1;
  int fd;
  char buf[SECTOR_SIZE+1], buffer[MAX_PATH+1];
  if( ! path) { 
    goto out;
  }
  strncpy(buffer,path,sizeof(buffer)-1);
  fd = vfs_open (buffer,READ_MODE);
  if(fd < 0 ) {
    printf ("open error:\n");
    goto out;
  }
  while ( (n = vfs_read(fd,buf,sizeof(buf)-1 ) ) > 0 ) {
    buf[n] = 0;
    printf("%s",buf);
  }
  vfs_close(fd);
  err = 0;
 out:
  return err;
}
void read_file(struct file *fp, _upi_u8_ *data, _upi_u8_ size)
{  
  mm_segment_t oldFS;
  loff_t pos;
  _upi_s32_ rtn;
  _upi_u8_ idx;

  oldFS = get_fs();
  set_fs(get_ds());

  pos = 0;
  idx = 0;
  rtn = 1;
  UG31_LOGN("[%s]: Read file ->", __func__);
  while(idx < size)
  {
    rtn = (_upi_s32_)vfs_read(fp, (char *)(&data[idx]), 1, &pos);
    ug31_printk(LOG_LEVEL_NOTICE, " %02x", data[idx]);
    
    idx = idx + 1;
    if(rtn != 1)
    {
      break;
    }
  }
  ug31_printk(LOG_LEVEL_NOTICE, "\n");

  if(rtn != 1)
  {
    UG31_LOGE("[%s]: Read file fail.\n", __func__);
  }
  else
  {
    UG31_LOGN("[%s]: Read %d (%d) bytes from file\n", __func__, idx, size);
  }

  set_fs(oldFS);
}
Esempio n. 23
0
static int __init hello_init(void)
{
    struct inode *inode = NULL;
    int iSize;

    fp=filp_open(FileName,O_RDWR,0644);

	if(IS_ERR(fp)){
		printk("create file error\n");
		return -1;
	}

	pcmd_buf = (unsigned char*)cmd_buf;

    fs=get_fs();
    set_fs(KERNEL_DS);

    inode = fp->f_dentry->d_inode;
    iSize = inode->i_size;
    printk("file(%s) size=%d\n", FileName, iSize);

    iSize = (iSize < COMMAND_BUF_SIZE) ? iSize:COMMAND_BUF_SIZE;

    printk("file(%s) size=%d\n", FileName, iSize);

    vfs_read(fp,pcmd_buf,iSize,&pos);
    //printk("%s\n", pcmd_buf );

    filp_close(fp, 0);

    pcmd_buf[iSize] = 0;

    process_cmd(pcmd_buf, iSize);

    set_fs(fs);
    ssleep(3);
	return 0;
}
Esempio n. 24
0
SYSCALL_DEFINE(pread64)(unsigned int fd, char __user *buf,
			size_t count, loff_t pos)
{
	struct file *file;
	ssize_t ret = -EBADF;
	int fput_needed;

	if (pos < 0)
		return -EINVAL;

	file = fget_light(fd, &fput_needed);
	if (file) {
		ret = -ESPIPE;
		if (file->f_mode & FMODE_PREAD) {
			ret = vfs_read(file, buf, count, &pos);
			trace_fs_pread64(fd, buf, count, pos, ret);
		}

		fput_light(file, fput_needed);
	}

	return ret;
}
void syscall_readdir(uint32_t *ebx, uint32_t *ecx, uint32_t *edx) {
  static int pos = 0;
  vfs_inode_t *parent;
  fd_t fd = *ebx;
  
  parent = current_proc->fd[fd]->inode;  
  dirent_t *dentry = (dirent_t*) *ecx;
  
  vfs_dentry_t *entries = vfs_read(parent, 0);  
  int num = parent->length / sizeof(vfs_dentry_t);  
  
  if(pos < num) {
    vfs_inode_t *ino = entries[pos++].inode;
    
    strcpy(dentry->name, ino->name);
    memcpy(&dentry->stat, &ino->stat, sizeof(stat_t));
    dentry->id = ino->stat.id;
    *ebx = (uint32_t) dentry;
  } else {
    pos = 0;
    *ebx = (uint32_t) NULL;
  }
}
Esempio n. 26
0
static ssize_t wrapfs_read(struct file *file, char __user *buf,
			   size_t count, loff_t *ppos)
{
	int err;
	struct file *lower_file;
	struct dentry *dentry = file->f_path.dentry;

	if(wrapfs_get_debug(file->f_dentry->d_sb) & DEBUG_FILE)
		DEBUG_MESG("Enter");

	// printk("wrapfs_read: Read '%s' using vfs_read\n", file->f_dentry->d_iname);

	lower_file = wrapfs_lower_file(file);
    err = vfs_read(lower_file, buf, count, ppos);
	/* update our inode atime upon a successful lower read */
	if (err >= 0)
		fsstack_copy_attr_atime(dentry->d_inode, lower_file->f_path.dentry->d_inode);

	if(wrapfs_get_debug(file->f_dentry->d_sb) & DEBUG_FILE)
		DEBUG_RETURN("Exit", err);

	return err;
}
/*
 * fm_file_read - read FM DSP patch/coeff/hwcoeff/rom binary file
 * @filename - source file name
 * @dst - target buffer
 * @len - desired read length
 * @position - the read position
 * If success, return read length in bytes, else error code
 */
fm_s32 fm_file_read(const fm_s8 *filename, fm_u8* dst, fm_s32 len, fm_s32 position)
{
    fm_s32 ret = 0;
    loff_t pos = position;
    mm_segment_t old_fs;
    struct file *fp = NULL;

    old_fs = get_fs();
    set_fs(KERNEL_DS);
    fp = filp_open(filename, O_RDONLY, 0);

    if (IS_ERR(fp)) {
        WCN_DBG(FM_ERR | CHIP, "open \"%s\" failed\n", filename);
        set_fs(old_fs);
        return -FM_EPATCH;
    } else {
        WCN_DBG(FM_NTC | CHIP, "open \"%s\" ok\n", filename);
    }

    ret = vfs_read(fp, (char __user *)dst, len, &pos);

    if (ret < 0) {
        WCN_DBG(FM_ERR | CHIP, "read \"%s\" failed\n", filename);
    } else if (ret < len) {
        WCN_DBG(FM_NTC | CHIP, "read \"%s\" part data\n", filename);
    } else {
        WCN_DBG(FM_NTC | CHIP, "read \"%s\" full data\n", filename);
    }

    if (fp) {
        filp_close(fp, NULL);
    }

    set_fs(old_fs);

    return ret;
}
Esempio n. 28
0
static ssize_t wrapfs_read(struct file *file, char __user *buf,
			   size_t count, loff_t *ppos)
{
	int err;
	struct file *lower_file;
	struct dentry *dentry = file->f_path.dentry;
#ifdef WRAPFS_CRYPTO
	char nokey[KEY_LENGTH]={0,};
#endif
	lower_file = wrapfs_lower_file(file);
#ifdef DEBUG_SUPPORT
	if(debug_support(lower_file->f_dentry->d_sb,"file"))
		UDBG;
#endif
	if(WRAPFS_SB(lower_file->f_path.dentry->d_sb)->mount_options.mmap == 1)
	{
#ifdef WRAPFS_CRYPTO		
		if(!strcmp(WRAPFS_SB(lower_file->f_dentry->d_sb)->key,nokey) || no_key_func(WRAPFS_SB(lower_file->f_dentry->d_sb)->key))
		{
			printk("No Key entered. Encrypt operations cannot be done\n");
			return -ENOKEY;
		}
#endif
		err = do_sync_read(file, buf, count, ppos);
	}
	else
		err = vfs_read(lower_file, buf, count, ppos);
	/* update our inode atime upon a successful lower read */
	if (err >= 0)
		fsstack_copy_attr_atime(dentry->d_inode,
					lower_file->f_path.dentry->d_inode);
#ifdef DEBUG_SUPPORT
	if(debug_support(lower_file->f_dentry->d_sb,"file"))
		UDBGE(err);
#endif
	return err;
}
Esempio n. 29
0
/*
 * netdev_ctrl_read - Read the header and payload from a control channel to find
 * 		      the length of the payload. Note a buffer will be allocated
 * 		      here, and the user of this function is expected to free it
 * 		      after usage.
 * @netdev_ctrl: netdevice control structure
 * @buf: kernel buffer to be copied
 * @size: size of the buffer allocated
 * @timeout: timeout in milliseconds 
 */
static size_t
netdev_ctrl_read(tlr_netdev_ctrl_t *netdev_ctrl,
                 char *buf, size_t size, int timeout)
{
	unsigned long end = jiffies + jiffies_to_msecs(timeout);
	mm_segment_t old_fs;
	int rc = 0;

	/* Channel is not established return -EPIPE. */
	if (!netdev_ctrl || !netdev_ctrl->up)
		return -EPIPE;

	/* Set the FS to kernel. */
	old_fs = get_fs();
	set_fs(KERNEL_DS);

	do {
		rc = vfs_read(netdev_ctrl->filp, buf, size,
				&netdev_ctrl->filp->f_pos);
		if (rc >= 0)
			break;

		if (rc != -EAGAIN)
			goto ret;

	} while (jiffies < end);

	/* Timeout occured. */
	if (rc == -EAGAIN)
		rc = -ETIME;

ret:
	/* Reset the kernel FS to old_fs. */
	set_fs(old_fs);

	return rc;
}
Esempio n. 30
0
static ssize_t wrapfs_read(struct file *file, char __user *buf,
			   size_t count, loff_t *ppos)
{
	int err;
	struct file *lower_file;
	struct dentry *dentry = file->f_path.dentry;
#ifdef WRAPFS_CRYPTO	
	char zero_key[KEYLEN + 1];
	memset(zero_key, '0', sizeof(zero_key));
	zero_key[KEYLEN] = '\0';
#endif
	/*printk(KERN_ALERT "In wrapfs_read()\n");*/

	lower_file = wrapfs_lower_file(file);

	if (1 == WRAPFS_SB(file->f_dentry->d_sb)->mount_options.mmap)
	{
		/*printk(KERN_ALERT "calling do_sync_read()\n");*/
#ifdef WRAPFS_CRYPTO
		if (0 == memcmp(&(WRAPFS_SB(file->f_dentry->d_sb)->key), &zero_key, KEYLEN))
			return -ENOKEY;
#endif
			err = do_sync_read(file, buf, count, ppos);
	}
	else
	{
		/*printk(KERN_ALERT "calling vfs_read()\n");*/
		err = vfs_read(lower_file, buf, count, ppos);
	}

	/* update our inode atime upon a successful lower read */
	if (err >= 0)
		fsstack_copy_attr_atime(dentry->d_inode,
					lower_file->f_path.dentry->d_inode);

	return err;
}