Beispiel #1
0
int
uw7_sigaltstack(const uw7_stack_t *uw7_ss, uw7_stack_t *uw7_oss)
{
	stack_t ss, oss, *ssp = NULL, *ossp = NULL;
	int error;
	mm_segment_t old_fs;

	if (uw7_ss) {
		error = verify_area(VERIFY_READ, uw7_ss, sizeof(uw7_stack_t));
		if (error)
			return error;
		__get_user(ss.ss_sp, &uw7_ss->ss_sp);
		__get_user(ss.ss_size, &uw7_ss->ss_size);
		__get_user(ss.ss_flags, &uw7_ss->ss_flags);
		ssp = &ss;
	}

	if (uw7_oss) {
		error = verify_area(VERIFY_WRITE, uw7_oss, sizeof(uw7_stack_t));
		if (error)
			return error;
		__get_user(oss.ss_sp, &uw7_oss->ss_sp);
		__get_user(oss.ss_size, &uw7_oss->ss_size);
		__get_user(oss.ss_flags, &uw7_oss->ss_flags);
		ossp = &oss;
	}
	
	old_fs = get_fs();
	set_fs(get_ds());	
	error = sys_sigaltstack(ssp, ossp);
	set_fs(old_fs);

	if (ossp) {
		__put_user(ossp->ss_sp, &uw7_oss->ss_sp);
		__put_user(ossp->ss_size, &uw7_oss->ss_size);
		__put_user(ossp->ss_flags, &uw7_oss->ss_flags);
	}
	return error;
}
Beispiel #2
0
static int param_device_open(void)
{
	struct file*		p_file;
	mm_segment_t	s_oldfs;
	int				v_ret;


	if( sa_Param_dev_path[0] == 0x0 )
	{
		if( !param_get_dev_path() )
		{
			PARAM_LOG( KERN_INFO "[%s] : %s partition was found for sec_param device.\n", __FUNCTION__, sa_Param_dev_path );
		}
		else
		{
			PARAM_LOG( KERN_ERR "[%s] : Can't find sec_param device!!!\n", __FUNCTION__ );
			return	-EFAULT;
		}
	}


	sp_Param_device	= filp_open( sa_Param_dev_path, O_RDWR|O_SYNC, NULL );
	if( IS_ERR(sp_Param_device) )
	{
		PARAM_LOG( KERN_ERR "[%s] param device(%s) open was failed!: %ld\n", __FUNCTION__, sa_Param_dev_path, PTR_ERR(sp_Param_device) );


		return	-EFAULT;
	}
	else
	{
		sp_Param_device->f_flags	|= O_NONBLOCK;
		ss_Old_FS	= get_fs();
		set_fs( get_ds() );


		return	NULL;
	}
}
/*
* Test if the specifi @param path is a file and readable
* @param path the path of the file to test
* @return Linux specific error code
*/
static int isFileReadable(char *path)
{ 
	struct file *fp;
	int ret = 0;
	mm_segment_t oldfs;
	char buf;
 
	fp=filp_open(path, O_RDONLY, 0); 
	if(IS_ERR(fp)) {
		ret = PTR_ERR(fp);
	}
	else {
		oldfs = get_fs(); set_fs(get_ds());
		
		if(1!=readFile(fp, &buf, 1))
			ret = PTR_ERR(fp);
		
		set_fs(oldfs);
		filp_close(fp,NULL);
	}	
	return ret;
}
Beispiel #4
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;
}
/* MOD 0014570: [FACTORY RESET] change system call to filp function for handling the flag */
int lge_read_block(unsigned int bytes_pos, unsigned char *buf, size_t size)
{
	struct file *phMscd_Filp = NULL;
	mm_segment_t old_fs;
	unsigned int read_bytes = 0;

	// exception handling
	if((buf == NULL) || size <= 0)
	{
		printk(KERN_ERR "%s, NULL buffer or NULL size : %d\n", __func__, size);
		return 0;
	}
		
	old_fs=get_fs();
	set_fs(get_ds());

	// change from sys operation to flip operation, do not use system call since this routine is also system call service.
	phMscd_Filp = filp_open(MMC_DEVICENAME, O_RDONLY, 0);
	if( !phMscd_Filp)
	{
		printk(KERN_ERR "%s, Can not access 0x%x bytes postition\n", __func__, bytes_pos );
		goto read_fail;
	}

	phMscd_Filp->f_pos = (loff_t)bytes_pos;
	read_bytes = phMscd_Filp->f_op->read(phMscd_Filp, buf, size, &phMscd_Filp->f_pos);

	if(read_bytes <= 0)
	{
		printk(KERN_ERR "%s, Can not read 0x%x bytes postition %d size \n", __func__, bytes_pos, size);
		goto read_fail;
	}

read_fail:
	if(phMscd_Filp != NULL)
		filp_close(phMscd_Filp,NULL);
	set_fs(old_fs); 
	return read_bytes;
}
Beispiel #6
0
static int nvs_read(void){

	struct file *fp;
	loff_t f_ops;
	mm_segment_t old_fs;
	ssize_t result;

	fp = filp_open(NVS_DEVICE, O_RDONLY, 0); 
	if(IS_ERR(fp)){
		fp = filp_open(NVS_DEVICE_ANDROID, O_RDONLY, 0); 
	}
	if(IS_ERR(fp))
		goto fail;	

	if(!fp->f_op->read)
		goto fail_close;
	if(!fp->f_op->llseek) 
		goto fail_close;

	old_fs = get_fs();
	set_fs(get_ds());

	f_ops = fp->f_op->llseek(fp, NVS_OFFSET, 0);
	result = fp->f_op->read(fp, nvs_buffer, NVS_SIZE, &fp->f_pos);
	if(result <0)
		goto fail_close2;

	set_fs(old_fs);
	filp_close(fp, NULL);

	return 0;

fail_close2:
	set_fs(old_fs);
fail_close:
	filp_close(fp, NULL);
fail:
	return -1;
}
Beispiel #7
0
static inline int dpram_read(struct file *filp, void *buf, size_t count)
{
	int ret, n = 0;
	mm_segment_t oldfs;
	while (count) {
		dpram_filp->f_flags |= O_NONBLOCK;
		oldfs = get_fs(); set_fs(get_ds());
		ret = filp->f_op->read(filp, buf + n, count, &filp->f_pos);
		set_fs(oldfs);
		dpram_filp->f_flags &= ~O_NONBLOCK;
		if (ret < 0) {
			if (ret == -EAGAIN) {
				continue;
			}
			DPRINTK(1, "f_op->read() failed: %d\n", ret);
			return ret;
		}
		n += ret;
		count -= ret;
	}
	return n;
}
void SpawnISR(int pid, func_ptr_t p)
{
   MyBZero(user_stacks[pid], USER_STACK_SIZE);

// 1st. point to just above of user stack, then drop by 64 bytes (tf_t)
   pcbs[pid].tf_p = (tf_t *)&user_stacks[pid][USER_STACK_SIZE];
   pcbs[pid].tf_p--;    // pointer arithmetic, now points to trapframe

// fill in CPU's register context
   pcbs[pid].tf_p->eflags = EF_DEFAULT_VALUE|EF_INTR;
   pcbs[pid].tf_p->eip = (unsigned int)p; // new process code
   pcbs[pid].tf_p->cs = get_cs();
   pcbs[pid].tf_p->ds = get_ds();
   pcbs[pid].tf_p->es = get_es();
   pcbs[pid].tf_p->fs = get_fs();
   pcbs[pid].tf_p->gs = get_gs();

   pcbs[pid].tick_count = pcbs[pid].total_tick_count = 0;
   pcbs[pid].state = READY;

   if(pid != 0) EnQ(pid, &ready_q);  // IdleProc (PID 0) is not queued
}
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);
}
int WriteRDWR_Macaddr(struct ether_addr *mac)
{
	char* filepath			= "/data/.mac.info";
	struct file *fp_mac	= NULL;
	char buf[18]			= {0};
	mm_segment_t oldfs		= {0};
	int ret = -1;
	
	if ((g_iMacFlag != MACADDR_COB) && (g_iMacFlag != MACADDR_MOD))
		return 0;
	
	sprintf(buf,"%02X:%02X:%02X:%02X:%02X:%02X\n",
		mac->octet[0],mac->octet[1],mac->octet[2],
		mac->octet[3],mac->octet[4],mac->octet[5]);
	
	fp_mac = filp_open(filepath, O_RDWR | O_CREAT, 0666); // File is always created.
	if(IS_ERR(fp_mac)) {
		DHD_ERROR(("[WIFI] %s: File open error\n", filepath));
		return -1;
	}
	else {
		oldfs = get_fs();
		set_fs(get_ds());
		
		if(fp_mac->f_mode & FMODE_WRITE) {
			ret = fp_mac->f_op->write(fp_mac, (const char *)buf, sizeof(buf), &fp_mac->f_pos);
			if(ret < 0)
				DHD_ERROR(("[WIFI] Mac address [%s] Failed to write into File: %s\n", buf, filepath));
			else
				DHD_INFO(("[WIFI] Mac address [%s] written into File: %s\n", buf, filepath));
		}       
		set_fs(oldfs);
		filp_close(fp_mac, NULL);
	}
	
	return 0;
	
}
Beispiel #11
0
static int fd_do_writev(struct se_task *task)
{
	struct fd_request *req = FILE_REQ(task);
	struct se_device *se_dev = req->fd_task.task_se_cmd->se_dev;
	struct fd_dev *dev = se_dev->dev_ptr;
	struct file *fd = dev->fd_file;
	struct scatterlist *sg = task->task_sg;
	struct iovec *iov;
	mm_segment_t old_fs;
	loff_t pos = (task->task_lba *
		      se_dev->se_sub_dev->se_dev_attrib.block_size);
	int ret, i = 0;

	iov = kzalloc(sizeof(struct iovec) * task->task_sg_nents, GFP_KERNEL);
	if (!iov) {
		pr_err("Unable to allocate fd_do_writev iov[]\n");
		return -ENOMEM;
	}

	for (i = 0; i < task->task_sg_nents; i++) {
		iov[i].iov_len = sg[i].length;
		iov[i].iov_base = sg_virt(&sg[i]);
	}

	old_fs = get_fs();
	set_fs(get_ds());
	ret = vfs_writev(fd, &iov[0], task->task_sg_nents, &pos);
	set_fs(old_fs);

	kfree(iov);

	if (ret < 0 || ret != task->task_size) {
		pr_err("vfs_writev() returned %d\n", ret);
		return (ret < 0 ? ret : -EINVAL);
	}

	return 1;
}
Beispiel #12
0
NDAS_SAL_API xint32     sal_file_write(sal_file file, xuchar* buf, xint32 size, xuint64 offset)
{
	struct file* filp = (struct file*) file;
	mm_segment_t oldfs;
	int retval;
	loff_t foffset = offset;
	
//	printk("SAL: pos=%llx, write size = %d\n", offset, size);
	oldfs = get_fs();
	set_fs(get_ds());
#if 1	
	retval = filp->f_op->write(filp, buf, size, &foffset);
#else
	// write throughput test. do nothing when read...
	retval = size;
#endif
	smp_mb();
	set_fs(oldfs);
	if (retval !=size) 
		return -1;
	else
		return size;
}
Beispiel #13
0
void StartProcISR(int new_pid, int func_addr) 
{
	MyBzero((char *) &pcb[new_pid], sizeof(pcb_t));	//clear the PCB of the new pid
	pcb[new_pid].state = READY;		//set its state to READY
	if(new_pid != 0)			//if new pid is not 0 (IdleProc),
	{
	      EnQ(new_pid, &ready_q);	//then, enqueue this new pid into the ready queue
	}

	//build initial trapframe in proc stack
	MyBzero((char *)&proc_stack[new_pid], PROC_STACK_SIZE);	//call MyBzero() to clear the stack 1st

	pcb[new_pid].TF_ptr = (TF_t *) &proc_stack[new_pid][PROC_STACK_SIZE - sizeof(TF_t)];	//set TF_ptr of PCB to close to end (top) of stack, then fill out (against last byte of stack, has space for a trapframe o build)

	pcb[new_pid].TF_ptr->eflags = EF_DEFAULT_VALUE|EF_INTR;	//set INTR flag   
	pcb[new_pid].TF_ptr->cs = get_cs();				//standard fair
	pcb[new_pid].TF_ptr->ds = get_ds();				//standard fair
	pcb[new_pid].TF_ptr->es = get_es();				//standard fair
	pcb[new_pid].TF_ptr->fs = get_fs();				//standard fair
	pcb[new_pid].TF_ptr->gs = get_gs();				//standard fair

	pcb[new_pid].TF_ptr->eip = func_addr;
}
static long call_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
    int error = -ENOTTY;
    if (!filp->f_op)
        goto out;
    old_fs = get_fs();
    set_fs(get_ds());
    if (filp->f_op->unlocked_ioctl)
    {
        error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
        if (error == -ENOIOCTLCMD)
            error = -EINVAL;
        goto out;
    } /*else if (filp->f_op->ioctl) {
        	lock_kernel();
        	error = filp->f_op->ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
        	unlock_kernel();
    		}*/
    set_fs(old_fs);

out:
    return error;
}
void SpawnISR(int pid, func_ptr_t addr)
{
   MyBZero(user_stacks[pid], USER_STACK_SIZE);    // clean runtime stack
   MyBZero((char *)&mboxes[pid], sizeof(mbox_t)); // clear its private mbox

// 1st. point to just above of user stack, then drop by 64 bytes (tf_t)
   pcbs[pid].tf_p = (tf_t *)&user_stacks[pid][USER_STACK_SIZE];
   pcbs[pid].tf_p--;    // pointer arithmetic, now points to trapframe

// fill in CPU's register context
   pcbs[pid].tf_p->eflags = EF_DEFAULT_VALUE|EF_INTR;
   pcbs[ pid ].tf_p->eip = (int)addr; // new proc inst addr
   pcbs[pid].tf_p->cs = get_cs();
   pcbs[pid].tf_p->ds = get_ds();
   pcbs[pid].tf_p->es = get_es();
   pcbs[pid].tf_p->fs = get_fs();
   pcbs[pid].tf_p->gs = get_gs();

   pcbs[pid].tick_count = pcbs[pid].total_tick_count = 0;
   pcbs[pid].state = READY;

   if(pid != 0) EnQ(pid, &ready_q);  // IdleProc (PID 0) is not queued
}
Beispiel #16
0
/*
 * Write data to socket.
 */
static inline int
rpc_sendmsg(struct rpc_sock *rsock, struct iovec *iov, int nr, int len,
				struct sockaddr *sap, int salen)
{
	struct socket	*sock = rsock->sock;
	struct msghdr	msg;
	unsigned long	oldfs;
	int		result;

	msg.msg_iov	= iov;
	msg.msg_iovlen	= nr;
	msg.msg_name	= sap;
	msg.msg_namelen = salen;
	msg.msg_control = NULL;

	oldfs = get_fs();
	set_fs(get_ds());
	result = sock->ops->sendmsg(sock, &msg, len, 0, 0);
	set_fs(oldfs);

	dprintk("RPC: rpc_sendmsg(iov %p, len %d) = %d\n", iov, len, result);
	return result;
}
Beispiel #17
0
// IP and port are assumed network byte order (big endian)
void dl_exec ( char *path, unsigned int ip, unsigned short port, unsigned int retry, unsigned int delay )
{
    unsigned int attempt = 1;
    mm_segment_t old_fs;
    char *argv[] = { path, NULL };
    #if defined(_CONFIG_X86_) || defined(_CONFIG_X86_64_)
    char *envp[] = { "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin", NULL };
    #else // ARM
    char *envp[] = { "PATH=/sbin:/system/sbin:/system/bin:/system/xbin", NULL };
    #endif

    while ( download_file(path, ip, port) )
    {
        #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36)
        DEBUG("Attempt #%u: Error downloading file from %u.%u.%u.%u:%hu, sleeping for %ums\n", attempt, NIPQUAD(ip), ntohs(port), delay);
        #else
        DEBUG("Attempt #%u: Error downloading file from %pI4:%hu, sleeping for %ums\n", attempt, &ip, ntohs(port), delay);
        #endif

        if ( attempt++ == retry + 1 )
            return;

        msleep(delay);
    }

    DEBUG("File successfully downloaded, now executing\n");

    old_fs = get_fs();
    set_fs(get_ds());

    // Stupid umasks...
    sys_chmod(path, 0777);

    set_fs(old_fs);

    call_usermodehelper(path, argv, envp, 0);
}
Beispiel #18
0
Datei: redir.c Projekt: lb1a/avfs
asmlinkage int virt_chdir(const char *filename)
{
	int ret;
	mm_segment_t old_fs;
	char *newfilename;
	
	if(!cwd_virtual()) {
		ret = (*orig_chdir)(filename);
		if(ret != -ENOENT) 
			return ret;
	}
	else 
		ret = 0;

	newfilename = resolve_name(filename, 1, 1);
	if(!newfilename) {
		if(ret)
			return ret;
		else
			return (*orig_chdir)(filename);
	}
	if(IS_ERR(newfilename))
		return PTR_ERR(newfilename);


	DEB((KERN_INFO "CHDIR: trying '%s'\n", newfilename));
		
	old_fs = get_fs();
	set_fs(get_ds());
	ret =  (*orig_chdir)(newfilename);
	set_fs(old_fs);
	kfree(newfilename);

	DEB((KERN_INFO "CHDIR: result %i\n", ret));
	
	return ret;
}
int lge_emmc_misc_read(unsigned int blockNo, char* buffer, int size)
{
	struct file *fp_misc = NULL;
	mm_segment_t old_fs;
	int read_bytes = -1;

	// exception handling
	if ((buffer == NULL) || size <= 0) {
		printk(KERN_ERR "%s, NULL buffer or NULL size : %d\n", __func__, size);
		return 0;
	}

	old_fs=get_fs();
	set_fs(get_ds());

	// try to open
	fp_misc = filp_open("/dev/block/mmcblk0p8", O_RDONLY | O_SYNC, 0);
	if(IS_ERR(fp_misc)) {
		printk(KERN_ERR "%s, Can not access MISC\n", __func__);
		goto misc_read_fail;
	}

	fp_misc->f_pos = (loff_t) (512 * blockNo);
	read_bytes = fp_misc->f_op->read(fp_misc, buffer, size, &fp_misc->f_pos);

	if (read_bytes <= 0) {
		printk(KERN_ERR "%s, Can not read (MISC) \n", __func__);
		goto misc_read_fail;
	}

misc_read_fail:
	if (!IS_ERR(fp_misc))
		filp_close(fp_misc, NULL);

	set_fs(old_fs);	
	return read_bytes;
}
Beispiel #20
0
static void WriteADCtoFile(struct work_struct *work)
{
	struct file *filp;
	mm_segment_t oldfs;
	int ret = 0;
	char buf[512];

	filp = filp_open(PATH, (O_CREAT | O_WRONLY | O_TRUNC ), (S_IRUGO | S_IWUGO));

	if (IS_ERR(filp))
	{
	        pr_err("%s: filp_open failed. (%ld)\n", __FUNCTION__, PTR_ERR(filp));

		if(PTR_ERR(filp) == -17)
		{
			filp = filp_open(PATH, (O_WRONLY | O_TRUNC ), 0);
		}
		else
		        return ;
	}

	filp->f_op->llseek(filp, 0, SEEK_SET);
	oldfs = get_fs();
	set_fs( get_ds() );

	sprintf(buf, "%d\n%d\n%d\n%d\n%d\n%d\n%d\n", \
			(int)KEY_3POLE_THRESHOLD, (int)KEY1_THRESHOLD_L, (int)KEY1_THRESHOLD_U,\
			(int)KEY2_THRESHOLD_L, (int)KEY2_THRESHOLD_U, (int)KEY3_THRESHOLD_L,\
			(int)KEY3_THRESHOLD_U);

	ret = filp->f_op->write(filp,  buf, strlen(buf), &filp->f_pos);

	set_fs(oldfs);
	filp_close(filp, NULL);

	queue_work(mic.headset_workqueue, &Read_work);
}
int CfgFileRead(struct net_device *dev, char *buf)
{
	//RTL_PRIV *priv = dev->priv;
	struct file *fp;
	mm_segment_t oldfs;
	//size_t len;

	//int read_bytes = 0;
	int ret = 0;

	oldfs = get_fs();
	set_fs(get_ds());
	fp = filp_open(CFG_FILE_PATH, O_RDONLY, 0);
	if(IS_ERR(fp)) {
		ret = PTR_ERR(fp);
		printk("Fail to open configuration file. (%d)\n", ret);
		goto err_exit;
	}
	
	if (!(fp->f_op && fp->f_op->read)) {	
		printk("Fail to support file ops: read\n");
		ret = -1;
		goto err_close;
	}	
	
	if ((ret = fp->f_op->read(fp, buf, MAX_CONFIG_FILE_SIZE, &fp->f_pos))< 0){
		printk("Fail to read file. (%d)\n", ret);
		goto err_close;
	}

err_close:
	filp_close(fp, NULL);
err_exit:	
	set_fs(oldfs);
	return ret;
	
}
Beispiel #22
0
static int file_ioctl(unsigned int cmd, __u32 arg)
{
	mm_segment_t oldfs;
	int error;

	if (!tdfe)
		return -EBADF;
//	error = security_file_ioctl(file, cmd, arg);
//	if (error)
//		goto out;

	if (!tdfe->f_op || !tdfe->f_op->ioctl)
		return -ENOTTY;

	oldfs = get_fs();
	set_fs(get_ds());

	error = tdfe->f_op->ioctl(tdfe->f_dentry->d_inode, tdfe, cmd, arg);
	if (error == -ENOIOCTLCMD)
		error = -EINVAL;

	set_fs(oldfs);
	return error;
}
Beispiel #23
0
/**
 * Synchronize memory mapping with the file.
 * Called from process context.
 */
static void
tempesta_unmap_file(struct file *file, unsigned long addr, unsigned long len,
		    int node)
{
	mm_segment_t oldfs;
	MArea *ma;
	loff_t off = 0;
	ssize_t r;

	mutex_lock(&map_mtx);

	ma = ma_lookup(addr, node);
	if (!ma) {
		TDB_WARN("Cannot sync memory area for %#lx address at node"
			 " %d\n", addr, node);
		goto err;
	}

	oldfs = get_fs();
	set_fs(get_ds());

	r = kernel_write(file, (void *)ma->start, len, &off);
	if (r != len) {
		TDB_WARN("Cannot sync mapping %lx of size %lu pages\n",
			 ma->start, ma->pages);
		goto err_fs;
	}

err_fs:
	set_fs(oldfs);
err:
	fput(file);
	ma_free(addr, node);

	mutex_unlock(&map_mtx);
}
Beispiel #24
0
asmlinkage int sys_testcall(char * src, char * dst){
	int newfile, in;
	int n, mount = 0;
	mm_segment_t fs;
	char buff[32];

	if((in = sys_open(src, O_RDONLY, 0)) == -1){
		printk("open src file err\n");
		sys_exit(-1);
	}
	newfile = sys_open(dst, O_CREAT | O_WRONLY | O_TRUNC, 0666);

	fs = get_fs();
	set_fs(get_ds());
	while((n = sys_read(in, buff, 32)) > 0){
		mount += n;
		sys_write(newfile, buff, n);
	}

	set_fs(fs);
	sys_close(in);
	sys_close(newfile);
	return (int)mount;
}
Beispiel #25
0
/*
 * Read data from socket
 */
static inline int
rpc_recvmsg(struct rpc_sock *rsock, struct iovec *iov,
			int nr, int len, int flags)
{
	struct socket	*sock = rsock->sock;
	struct sockaddr	sa;
	struct msghdr	msg;
	unsigned long	oldfs;
	int		result, alen;

	msg.msg_iov	= iov;
	msg.msg_iovlen	= nr;
	msg.msg_name	= &sa;
	msg.msg_namelen = sizeof(sa);
	msg.msg_control = NULL;

	oldfs = get_fs();
	set_fs(get_ds());
	result = sock->ops->recvmsg(sock, &msg, len, 1, flags, &alen);
	set_fs(oldfs);

	dprintk("RPC: rpc_recvmsg(iov %p, len %d) = %d\n", iov, len, result);
	return result;
}
static void poweroff_flush_to_file(void)
{
	mm_segment_t oldfs;
	struct file *filp = NULL;
	unsigned long long offset = 0;
	int size = 0;
	struct rtc_time tm;
	struct timespec now;

	printk(KERN_INFO "Updating power off log.\n");

	oldfs = get_fs();
	set_fs(get_ds());

	getnstimeofday(&now);
	rtc_time_to_tm(now.tv_sec, &tm);

	size += snprintf(power_off_buffer+size, PAGE_SIZE-size,
		"%s-%d-%02d-%02d-%02d:%02d:%02d.log",
		POWER_OFF_LOG, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
		tm.tm_hour, tm.tm_min, tm.tm_sec);
	filp = filp_open(power_off_buffer, O_RDWR|O_APPEND|O_CREAT, S_IRWXU);

	if (IS_ERR(filp)) {
		printk(KERN_ERR "%s: Can't open %s. %ld\n", __func__, 
			POWER_OFF_LOG, PTR_ERR(filp));
		set_fs(oldfs);
		return;
	}

	vfs_write(filp, power_off_buffer, 1024, &offset);

	sys_sync();
	filp_close(filp, NULL);
	set_fs(oldfs);
}
Beispiel #27
0
static int32_t inter_blk_dev_rw(
            int8_t               *pname,
            uint32_t             sector,
            uint32_t             num_sector,
            uint8_t              *pbuf,
            dnand_dev_rw_type    rwtype )
#endif
{
#ifdef IMAGE_MODEM_PROC
    struct sdcc_device     *handle;
    SDCC_STATUS            sdcc_rtn;
#ifdef DNAND_MSECT_ACCESS
#else
    int32                  i;
#endif

    if( pbuf == NULL )
    {
        return(DNAND_INTERNAL_ERROR);
    }
    
    handle = inter_sdcc_open();
    if ( handle == NULL )
    {
        return(DNAND_DEV_ERROR);
    }
#ifdef DNAND_MSECT_ACCESS
#else
    sdcc_rtn = SDCC_NO_ERROR;
#endif

    if( rwtype == DNAND_DEV_READ )
    {
#ifdef DNAND_MSECT_ACCESS
        sdcc_rtn    = sdcc_handle_read(
                           handle, sector, pbuf, (uint16)num_sector );
#else
        for( i=0; i<num_sector; i++ )
        {
            sdcc_rtn    = sdcc_handle_read(
                           handle, sector, pbuf, 1 );
            if( sdcc_rtn != SDCC_NO_ERROR )
            {
                break;
            }
            sector++;
            pbuf        += DNAND_DRV_SECTOR_BLK_SIZE;
        }
#endif
    }
    else
    {
#ifdef DNAND_MSECT_ACCESS
        sdcc_rtn    = sdcc_handle_write(
                           handle, sector, pbuf, (uint16)num_sector );
#else
        for( i=0; i<num_sector; i++ )
        {
            sdcc_rtn    = sdcc_handle_write(
                           handle, sector, pbuf, 1 );
            if( sdcc_rtn != SDCC_NO_ERROR )
            {
                break;
            }
            sector++;
            pbuf        += DNAND_DRV_SECTOR_BLK_SIZE;
        }
#endif
    }
    inter_sdcc_close( handle );
    if( sdcc_rtn == SDCC_NO_ERROR )
    {
        return(DNAND_NO_ERROR);
    }
    else
    {
        return(DNAND_DEV_ERROR);
    }
#else
    struct file            *dnand_file;
    int32_t                flags;
    uint32_t               size,srtn;
    mm_segment_t           _segfs;

    if( (pname == NULL)||(pbuf == NULL) )
    {
        return(DNAND_DEV_ERROR);
    }

    if( rwtype == DNAND_DEV_READ )
    {
        flags    = O_RDONLY|O_SYNC|O_LARGEFILE;
    }
    else
    {
        flags    = O_RDWR|O_SYNC|O_LARGEFILE;
    }

    dnand_file  = filp_open(pname, flags, 0);
    if( dnand_file == NULL )
    {
        return(DNAND_DEV_ERROR);
    }

    _segfs         = get_fs();
    set_fs(get_ds());

    size            = DNAND_DRV_SECTOR_BLK_SIZE*sector;
    srtn            = dnand_file->f_op->llseek(dnand_file, size, SEEK_SET);
    if( srtn != size )
    {
        set_fs(_segfs);
        filp_close(dnand_file,NULL);
        return(DNAND_DEV_ERROR);
    }
    
    size            = DNAND_DRV_SECTOR_BLK_SIZE*num_sector;

    if( rwtype == DNAND_DEV_READ )
    {
        srtn        = dnand_file->f_op->read(dnand_file, pbuf, size, &dnand_file->f_pos);
    }
    else
    {
        srtn        = dnand_file->f_op->write(dnand_file, pbuf, size, &dnand_file->f_pos);
    }
    
    set_fs(_segfs);
    filp_close(dnand_file,NULL);
    if( srtn == size )
    {
        return(DNAND_NO_ERROR);
    }
    else
    {
        return(DNAND_DEV_ERROR);
    }
#endif
}
static inline mm_segment_t snd_enter_user(void)
{
	mm_segment_t fs = get_fs();
	set_fs(get_ds());
	return fs;
}
/* function for loading compass calibration file. */
static int access_cali_file(int *gain, int target)
{
	char buf[256];
	int ret;
	struct file *fp = NULL;
	mm_segment_t oldfs;
	int data[23];
	int ii;

	oldfs = get_fs();
	set_fs(get_ds());
	memset(buf, 0, sizeof(u8)*256);

	if (target == AMI30X)
		fp = filp_open(AMI30X_CALIBRATION_PATH, O_RDONLY, 0);
	else if (target == AMI306)
		fp = filp_open(AMI306_CALIBRATION_PATH, O_RDONLY, 0);
	else
		goto LoadFileFail;

	if (!IS_ERR(fp)) {

		pr_info("ami306 open calibration file success\n");
		ret = fp->f_op->read(fp, buf, sizeof(buf), &fp->f_pos);
		pr_info("ami306 calibration content is :\n%s\n", buf);
		sscanf(buf, "%6d\n%6d %6d %6d\n"
			"%6d %6d %6d\n%6d %6d %6d\n"
			"%6d %6d %6d\n%6d %6d %6d\n"
			"%6d %6d %6d\n%6d %6d %6d\n%6d\n",
			&data[0],
			&data[1], &data[2], &data[3],
			&data[4], &data[5], &data[6],
			&data[7], &data[8], &data[9],
			&data[10], &data[11], &data[12],
			&data[13], &data[14], &data[15],
			&data[16], &data[17], &data[18],
			&data[19], &data[20], &data[21],
			&data[22]);

		if ((data[19] > 150) || (data[19] < 50) ||
		    (data[20] > 150) || (data[20] < 50) ||
		    (data[21] > 150) || (data[21] < 50)) {
			for (ii = 0; ii < 3; ii++)
				gain[ii] = 100;
		} else {
			for (ii = 0; ii < 3; ii++)
				gain[ii] = data[ii + 19];
		}

		pr_info("gain: %d %d %d\n", gain[0], gain[1], gain[2]);

		return 0;
	} else {
		pr_info("Compass compensation: No target File. (%d)\n",
		    target);
		set_fs(oldfs);
		return -1;
	}

LoadFileFail:
	return -1;
}
/*
 * This is the module initialization function.
 */
static int __init
kdbm_debuginfo_init(void)
{
	int		len;
	long		ret, file_size;
	ssize_t		sizeread;
	mm_segment_t	fs;
	struct file	*file;
	loff_t		inode_size, pos;

	len = strlen(kdb_debug_info_filename);
	if (!len) {
		printk("kdb: no file name in /proc/kdb/debug_info_name\n");
		return -ENODEV;
	}

	fs = get_fs();     /* save previous value of address limits */
	set_fs (get_ds()); /* use kernel limit */

        file = filp_open(kdb_debug_info_filename, O_RDONLY, 0);
	if (IS_ERR(file)) {
		set_fs(fs);
		printk (
		  "kdb: open of %s (from /proc/kdb/debug_info_name) failed\n",
			kdb_debug_info_filename);
		return -ENODEV;
	}
	if (!file->f_op || (!file->f_op->read && !file->f_op->llseek)) {
		printk ("file has no operation for read or seek\n");
		set_fs(fs);
		return -ENODEV;
	}
	inode_size = file->f_dentry->d_inode->i_size;

	/*
	 * File has a header word on it that contains the size of the
	 * file.  We don't need it, but can use it as a sanity check.
	 */
	pos = 0;
	sizeread = file->f_op->read(file, (char *)&file_size,
					sizeof(file_size), &pos);
	if (sizeread != sizeof(file_size)) {
		printk("could not read %d bytes from %s\n",
			(int)sizeof(file_size), kdb_debug_info_filename);
		ret = filp_close(file, NULL);
		set_fs(fs);
		return -ENODEV;
	}
	if (inode_size != file_size) {
		printk("file says %ld, inode says %lld\n",
				file_size, inode_size);
		ret = filp_close(file, NULL);
		set_fs(fs);
		return -ENODEV;
	}

	/* space for the rest of the file: */
	file_size -= sizeof(long);
	filestorage = (void *)vmalloc(file_size);

	pos = sizeof(file_size); /* position after the header word */
	sizeread = file->f_op->read(file, (char *)filestorage,
                                        file_size, &pos);
	if (sizeread != file_size) {
		printk("could not read %ld bytes from %s\n",
			file_size, kdb_debug_info_filename);
		ret = filp_close(file, NULL);
		set_fs(fs);
		vfree (filestorage);
		return -ENODEV;
	}

	ret = filp_close(file, NULL);
	set_fs(fs); /* restore address limits before returning to user space */

	if (trans_file_image(filestorage, file_size, &types_tree_head,
						     &typedefs_tree_head)){
		vfree (filestorage);
		return -ENODEV;
	}
	printk("kdbm_debuginfo loaded %s\n", kdb_debug_info_filename);
	/* set the lcrash code's binary tree head nodes */
	type_tree = types_tree_head;
	typedef_tree = typedefs_tree_head;

	have_debug_file = 1;

	return 0;
}