当前位置: 首页>>代码示例>>C++>>正文


C++ set_fs函数代码示例

本文整理汇总了C++中set_fs函数的典型用法代码示例。如果您正苦于以下问题:C++ set_fs函数的具体用法?C++ set_fs怎么用?C++ set_fs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了set_fs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: do_nfs_rpc_call

static int do_nfs_rpc_call(struct nfs_server *server, int *start, int *end, int size)
{
	struct file *file;
	struct inode *inode;
	struct socket *sock;
	unsigned short fs;
	int result;
	int xid;
	int len;
	select_table wait_table;
	struct select_table_entry entry;
	int (*select) (struct inode *, struct file *, int, select_table *);
	int init_timeout, max_timeout;
	int timeout;
	int retrans;
	int major_timeout_seen;
	char *server_name;
	int n;
	int addrlen;
	unsigned long old_mask;
	/* JEJB/JSP 2/7/94
	 * This is for a 4 byte recv of the xid only */
	int recv_xid;

	xid = start[0];
	len = ((char *) end) - ((char *) start);
	file = server->file;
	inode = file->f_inode;
	select = file->f_op->select;
	sock = socki_lookup(inode);
	if (!sock) {
		printk("nfs_rpc_call: socki_lookup failed\n");
		return -EBADF;
	}
	init_timeout = server->timeo;
	max_timeout = NFS_MAX_RPC_TIMEOUT*HZ/10;
	retrans = server->retrans;
	major_timeout_seen = 0;
	server_name = server->hostname;
	old_mask = current->blocked;
	current->blocked |= ~(_S(SIGKILL)
#if 0
		| _S(SIGSTOP)
#endif
		| ((server->flags & NFS_MOUNT_INTR)
		? ((current->sigaction[SIGINT - 1].sa_handler == SIG_DFL
			? _S(SIGINT) : 0)
		| (current->sigaction[SIGQUIT - 1].sa_handler == SIG_DFL
			? _S(SIGQUIT) : 0))
		: 0));
	fs = get_fs();
	set_fs(get_ds());
	for (n = 0, timeout = init_timeout; ; n++, timeout <<= 1) {
		result = sock->ops->send(sock, (void *) start, len, 0, 0);
		if (result < 0) {
			printk("nfs_rpc_call: send error = %d\n", result);
			break;
		}
	re_select:
		wait_table.nr = 0;
		wait_table.entry = &entry;
		current->state = TASK_INTERRUPTIBLE;
		if (!select(inode, file, SEL_IN, &wait_table)
		    && !select(inode, file, SEL_IN, NULL)) {
			if (timeout > max_timeout) {
			  /* JEJB/JSP 2/7/94
			   * This is useful to see if the system is
			   * hanging */
			  printk("NFS max timeout reached on %s\n",
				 server_name);
			  timeout = max_timeout;
			}
			current->timeout = jiffies + timeout;
			schedule();
			remove_wait_queue(entry.wait_address, &entry.wait);
			current->state = TASK_RUNNING;
			if (current->signal & ~current->blocked) {
				current->timeout = 0;
				result = -ERESTARTSYS;
				break;
			}
			if (!current->timeout) {
				if (n < retrans)
					continue;
				if (server->flags & NFS_MOUNT_SOFT) {
					printk("NFS server %s not responding, "
						"timed out\n", server_name);
					result = -EIO;
					break;
				}
				n = 0;
				timeout = init_timeout;
				init_timeout <<= 1;
				if (!major_timeout_seen) {
				  printk("NFS server %s not responding, "
					 "still trying\n", server_name);
				}
				major_timeout_seen = 1;
				continue;
			}
//.........这里部分代码省略.........
开发者ID:Lakshmipathi,项目名称:Linux-historic,代码行数:101,代码来源:sock.c

示例2: lge_mmc_read_mbr

/* MOD 0014570: [FACTORY RESET] change system call to filp function for handling the flag */
int lge_mmc_read_mbr (MmcPartition *mbr) {
	//int fd;
	unsigned char *buffer = NULL;
	char *device_index = NULL;
	int idx, i;
	unsigned mmc_partition_count = 0;
	unsigned int dtype;
	unsigned int dfirstsec;
	unsigned int EBR_first_sec;
	unsigned int EBR_current_sec;
	int ret = -1;

	struct file *phMscd_Filp = NULL;
	mm_segment_t old_fs;

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

	buffer = kmalloc(512, GFP_KERNEL);
	device_index = kmalloc(128, GFP_KERNEL);
	if((buffer == NULL) || (device_index == NULL))
	{
		printk("%s, allocation failed\n", __func__);
		goto ERROR2;
	}

	// 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't open device\n", __func__ );
		goto ERROR2;
	}

	phMscd_Filp->f_pos = (loff_t)0;
	if (phMscd_Filp->f_op->read(phMscd_Filp, buffer, 512, &phMscd_Filp->f_pos) != 512)
	{
		printk(KERN_ERR "%s, Can't read device: \"%s\"\n", __func__, MMC_DEVICENAME);
		goto ERROR1;
	}

	/* Check to see if signature exists */
	if ((buffer[TABLE_SIGNATURE] != 0x55) || \
		(buffer[TABLE_SIGNATURE + 1] != 0xAA))
	{
		printk(KERN_ERR "Incorrect mbr signatures!\n");
		goto ERROR1;
	}
	idx = TABLE_ENTRY_0;
	for (i = 0; i < 4; i++)
	{
		//char device_index[128];

		mbr[mmc_partition_count].dstatus = \
		            buffer[idx + i * TABLE_ENTRY_SIZE + OFFSET_STATUS];
		mbr[mmc_partition_count].dtype   = \
		            buffer[idx + i * TABLE_ENTRY_SIZE + OFFSET_TYPE];
		mbr[mmc_partition_count].dfirstsec = \
		            GET_LWORD_FROM_BYTE(&buffer[idx + \
		                                i * TABLE_ENTRY_SIZE + \
		                                OFFSET_FIRST_SEC]);
		mbr[mmc_partition_count].dsize  = \
		            GET_LWORD_FROM_BYTE(&buffer[idx + \
		                                i * TABLE_ENTRY_SIZE + \
		                                OFFSET_SIZE]);
		dtype  = mbr[mmc_partition_count].dtype;
		dfirstsec = mbr[mmc_partition_count].dfirstsec;
		lge_mmc_partition_name(&mbr[mmc_partition_count], \
		                mbr[mmc_partition_count].dtype);

		sprintf(device_index, "%sp%d", MMC_DEVICENAME, (mmc_partition_count+1));
		mbr[mmc_partition_count].device_index = lge_strdup(device_index);

		mmc_partition_count++;
		if (mmc_partition_count == MAX_PARTITIONS)
			goto SUCCESS;
	}

	/* See if the last partition is EBR, if not, parsing is done */
	if (dtype != 0x05)
	{
		goto SUCCESS;
	}

	EBR_first_sec = dfirstsec;
	EBR_current_sec = dfirstsec;

	phMscd_Filp->f_pos = (loff_t)(EBR_first_sec * 512);
	if (phMscd_Filp->f_op->read(phMscd_Filp, buffer, 512, &phMscd_Filp->f_pos) != 512)
	{
		printk(KERN_ERR "%s, Can't read device: \"%s\"\n", __func__, MMC_DEVICENAME);
		goto ERROR1;
	}

	/* Loop to parse the EBR */
	for (i = 0;; i++)
	{

		if ((buffer[TABLE_SIGNATURE] != 0x55) || (buffer[TABLE_SIGNATURE + 1] != 0xAA))
//.........这里部分代码省略.........
开发者ID:HONO,项目名称:Bell_V20f_kernel_mod,代码行数:101,代码来源:lge_emmc_direct_access.c

示例3: ssp_dump_task

void ssp_dump_task(struct work_struct *work) {
	struct ssp_big *big;
	struct file *dump_file;
	struct ssp_msg *msg;
	char *buffer;
	char strFilePath[60];
	struct timeval cur_time;
	int iTimeTemp;
	mm_segment_t fs;
	int buf_len, packet_len, residue, iRet = 0, index = 0 ,iRetTrans=0 ,iRetWrite=0;

	big = container_of(work, struct ssp_big, work);
	pr_err("[SSP]: %s - start ssp dumping (%d)(%d)\n", __func__,big->data->bMcuDumpMode,big->data->uDumpCnt);
	big->data->uDumpCnt++;
	wake_lock(&big->data->ssp_wake_lock);

	fs = get_fs();
	set_fs(get_ds());

	if(big->data->bMcuDumpMode == true)
	{
		do_gettimeofday(&cur_time);
		iTimeTemp = (int) cur_time.tv_sec;

		sprintf(strFilePath, "%s%d.txt", DUMP_FILE_PATH, iTimeTemp);

		dump_file = filp_open(strFilePath, O_RDWR | O_CREAT | O_APPEND, 0666);
		if (IS_ERR(dump_file)) {
			pr_err("[SSP]: %s - Can't open dump file\n", __func__);
			set_fs(fs);
			iRet = PTR_ERR(dump_file);
			wake_unlock(&big->data->ssp_wake_lock);
			return;
		}
	}
	else
		dump_file = NULL;

	buf_len = big->length > DATA_PACKET_SIZE ? DATA_PACKET_SIZE : big->length;
	buffer = kzalloc(buf_len, GFP_KERNEL);
	residue = big->length;

	while (residue > 0) {
		packet_len = residue > DATA_PACKET_SIZE ? DATA_PACKET_SIZE : residue;

		msg = kzalloc(sizeof(*msg), GFP_KERNEL);
		msg->cmd = MSG2SSP_AP_GET_BIG_DATA;
		msg->length = packet_len;
		msg->options = AP2HUB_READ | (index++ << SSP_INDEX);
		msg->data = big->addr;
		msg->buffer = buffer;
		msg->free_buffer = 0;

		iRetTrans = ssp_spi_sync(big->data, msg, 1000);
		if (iRetTrans != SUCCESS) {
			pr_err("[SSP]: %s - Fail to receive data %d (%d)\n", __func__, iRetTrans,residue);
			break;
		}
		if(big->data->bMcuDumpMode == true)
		{
			iRetWrite = vfs_write(dump_file, (char __user *) buffer, packet_len,
				&dump_file->f_pos);
			if (iRetWrite < 0) {
			pr_err("[SSP]: %s - Can't write dump to file\n", __func__);
			break;
			}
		}
		residue -= packet_len;
	}

	if(big->data->bMcuDumpMode == true && (iRetTrans != SUCCESS || iRetWrite < 0) )
	{
		char FAILSTRING[100];
		sprintf(FAILSTRING,"FAIL OCCURED(%d)(%d)(%d)",iRetTrans,iRetWrite,big->length);
		vfs_write(dump_file, (char __user *) FAILSTRING, strlen(FAILSTRING),&dump_file->f_pos);
	}

	ssp_send_cmd(big->data, MSG2SSP_AP_MCU_DUMP_FINISH, SUCCESS);

	big->data->bDumping = false;
	if(big->data->bMcuDumpMode == true)
		filp_close(dump_file, current->files);

	set_fs(fs);
	sanity_check(big->data);

	wake_unlock(&big->data->ssp_wake_lock);
	kfree(buffer);
	kfree(big);

	pr_err("[SSP]: %s done\n", __func__);
}
开发者ID:arshull,项目名称:halaszk-UNIVERSAL5420,代码行数:92,代码来源:ssp_debug.c

示例4: do_rt_sigreturn

void do_rt_sigreturn(struct pt_regs *regs)
{
	struct rt_signal_frame *sf;
	unsigned long tpc, tnpc, tstate;
	__siginfo_fpu_t *fpu_save;
	mm_segment_t old_fs;
	sigset_t set;
	stack_t st;
	int err;

	synchronize_user_stack ();
	sf = (struct rt_signal_frame *)
		(regs->u_regs [UREG_FP] + STACK_BIAS);

	/* 1. Make sure we are not getting garbage from the user */
	if (((unsigned long) sf) & 3)
		goto segv;

	err = get_user(tpc, &sf->regs.tpc);
	err |= __get_user(tnpc, &sf->regs.tnpc);
	if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) {
		tpc &= 0xffffffff;
		tnpc &= 0xffffffff;
	}
	err |= ((tpc | tnpc) & 3);

	/* 2. Restore the state */
	err |= __get_user(regs->y, &sf->regs.y);
	err |= __get_user(tstate, &sf->regs.tstate);
	err |= copy_from_user(regs->u_regs, sf->regs.u_regs, sizeof(regs->u_regs));

	/* User can only change condition codes in %tstate. */
	regs->tstate &= ~(TSTATE_ICC | TSTATE_XCC);
	regs->tstate |= (tstate & (TSTATE_ICC | TSTATE_XCC));

	err |= __get_user(fpu_save, &sf->fpu_save);
	if (fpu_save)
		err |= restore_fpu_state(regs, &sf->fpu_state);

	err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
	err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t));
	
	if (err)
		goto segv;
		
	regs->tpc = tpc;
	regs->tnpc = tnpc;
	
	/* It is more difficult to avoid calling this function than to
	   call it and ignore errors.  */
	old_fs = get_fs();
	set_fs(KERNEL_DS);
	do_sigaltstack(&st, NULL, (unsigned long)sf);
	set_fs(old_fs);

	sigdelsetmask(&set, ~_BLOCKABLE);
	spin_lock_irq(&current->sigmask_lock);
	current->blocked = set;
	recalc_sigpending(current);
	spin_unlock_irq(&current->sigmask_lock);
	return;
segv:
	send_sig(SIGSEGV, current, 1);
}
开发者ID:SimonKagstrom,项目名称:mci500h-linux-2.4.27,代码行数:64,代码来源:signal.c

示例5: setup_rt_frame

static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
			   sigset_t *set, struct pt_regs *regs)
{
	struct rt_sigframe __user *frame;
	int err = 0;
	int signal;

	frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame));

	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
		goto give_sigsegv;

	signal = current_thread_info()->exec_domain
		&& current_thread_info()->exec_domain->signal_invmap
		&& sig < 32
		? current_thread_info()->exec_domain->signal_invmap[sig]
		: sig;

	err |= __put_user(&frame->info, &frame->pinfo);
	err |= __put_user(&frame->uc, &frame->puc);
	err |= copy_siginfo_to_user(&frame->info, info);

	/* Give up earlier as i386, in case */
	if (err)
		goto give_sigsegv;

	/* Create the ucontext.  */
	err |= __put_user(0, &frame->uc.uc_flags);
	err |= __put_user(0, &frame->uc.uc_link);
	err |= __put_user((void *)current->sas_ss_sp,
			  &frame->uc.uc_stack.ss_sp);
	err |= __put_user(sas_ss_flags(regs->regs[REG_SP]),
			  &frame->uc.uc_stack.ss_flags);
	err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
	err |= setup_sigcontext(&frame->uc.uc_mcontext,
			        regs, set->sig[0]);
	err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));

	/* Give up earlier as i386, in case */
	if (err)
		goto give_sigsegv;

	/* Set up to return from userspace.  If provided, use a stub
	   already in userspace.  */
	if (ka->sa.sa_flags & SA_RESTORER) {
		DEREF_REG_PR = (unsigned long) ka->sa.sa_restorer | 0x1;

		/*
		 * On SH5 all edited pointers are subject to NEFF
		 */
		DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ?
        		 	(DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR;
	} else {
		/*
		 * Different approach on SH5.
	         * . Endianness independent asm code gets placed in entry.S .
		 *   This is limited to four ASM instructions corresponding
		 *   to two long longs in size.
		 * . err checking is done on the else branch only
		 * . flush_icache_range() is called upon __put_user() only
		 * . all edited pointers are subject to NEFF
		 * . being code, linker turns ShMedia bit on, always
		 *   dereference index -1.
		 */

		DEREF_REG_PR = (unsigned long) frame->retcode | 0x01;
		DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ?
        		 	(DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR;

		if (__copy_to_user(frame->retcode,
			(unsigned long long)sa_default_rt_restorer & (~1), 16) != 0)
			goto give_sigsegv;

		flush_icache_range(DEREF_REG_PR-1, DEREF_REG_PR-1+15);
	}

	/*
	 * Set up registers for signal handler.
	 * All edited pointers are subject to NEFF.
	 */
	regs->regs[REG_SP] = (unsigned long) frame;
	regs->regs[REG_SP] = (regs->regs[REG_SP] & NEFF_SIGN) ?
        		 (regs->regs[REG_SP] | NEFF_MASK) : regs->regs[REG_SP];
	regs->regs[REG_ARG1] = signal; /* Arg for signal handler */
	regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->info;
	regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->uc.uc_mcontext;
	regs->pc = (unsigned long) ka->sa.sa_handler;
	regs->pc = (regs->pc & NEFF_SIGN) ? (regs->pc | NEFF_MASK) : regs->pc;

	set_fs(USER_DS);

#if DEBUG_SIG
	/* Broken %016Lx */
	printk("SIG deliver (#%d,%s:%d): sp=%p pc=%08Lx%08Lx link=%08Lx%08Lx\n",
		signal,
		current->comm, current->pid, frame,
		regs->pc >> 32, regs->pc & 0xffffffff,
		DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff);
#endif

//.........这里部分代码省略.........
开发者ID:FatSunHYS,项目名称:OSCourseDesign,代码行数:101,代码来源:signal.c

示例6: emulate_load_store_insn

static void emulate_load_store_insn(struct pt_regs *regs,
	void __user *addr, unsigned int __user *pc)
{
	union mips_instruction insn;
	unsigned long value;
	unsigned int res;
	unsigned long origpc;
	unsigned long orig31;
	void __user *fault_addr = NULL;
#ifdef	CONFIG_EVA
	mm_segment_t seg;
#endif
	origpc = (unsigned long)pc;
	orig31 = regs->regs[31];

	perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);

	/*
	 * This load never faults.
	 */
	__get_user(insn.word, pc);

	switch (insn.i_format.opcode) {
		/*
		 * These are instructions that a compiler doesn't generate.  We
		 * can assume therefore that the code is MIPS-aware and
		 * really buggy.  Emulating these instructions would break the
		 * semantics anyway.
		 */
	case ll_op:
	case lld_op:
	case sc_op:
	case scd_op:

		/*
		 * For these instructions the only way to create an address
		 * error is an attempted access to kernel/supervisor address
		 * space.
		 */
	case ldl_op:
	case ldr_op:
	case lwl_op:
	case lwr_op:
	case sdl_op:
	case sdr_op:
	case swl_op:
	case swr_op:
	case lb_op:
	case lbu_op:
	case sb_op:
		goto sigbus;

		/*
		 * The remaining opcodes are the ones that are really of
		 * interest.
		 */
#ifdef CONFIG_EVA
	case spec3_op:
		/*
		 * we can land here only from kernel accessing user memory,
		 * so we need to "switch" the address limit to user space, so
		 * address check can work properly.
		 */
		seg = get_fs();
		set_fs(USER_DS);
		switch (insn.spec3_format.func) {
		case lhe_op:
			if (!access_ok(VERIFY_READ, addr, 2)) {
				set_fs(seg);
				goto sigbus;
			}
			LoadHW(addr, value, res);
			if (res) {
				set_fs(seg);
				goto fault;
			}
			compute_return_epc(regs);
			regs->regs[insn.spec3_format.rt] = value;
			break;
		case lwe_op:
			if (!access_ok(VERIFY_READ, addr, 4)) {
				set_fs(seg);
				goto sigbus;
			}
				LoadW(addr, value, res);
			if (res) {
				set_fs(seg);
				goto fault;
			}
			compute_return_epc(regs);
			regs->regs[insn.spec3_format.rt] = value;
			break;
		case lhue_op:
			if (!access_ok(VERIFY_READ, addr, 2)) {
				set_fs(seg);
				goto sigbus;
			}
			LoadHWU(addr, value, res);
			if (res) {
				set_fs(seg);
//.........这里部分代码省略.........
开发者ID:24hours,项目名称:linux,代码行数:101,代码来源:unaligned.c

示例7: _LGE_GENERIC_WRITE_FUN

bool _LGE_GENERIC_WRITE_FUN(unsigned char *buff, unsigned int offset, unsigned int length)
{

    int ret;
    struct file *filp;
    unsigned char *tmp;
    mm_segment_t curr_fs;
    filp = filp_open(PART_NAME, O_RDWR, 0666);
    if (IS_ERR(filp))
    {
        ret = PTR_ERR(filp);
        printk("Open MISC2 partition fail! errno=%d\n", ret);
        return -1;
    }
    if (g_init_write_size ==0)
    {
        struct mtd_info_user info;
        if (filp->f_op->unlocked_ioctl)
        {
            filp->f_op->unlocked_ioctl(filp, MEMGETINFO, &info);
        } else if (filp->f_op->compat_ioctl)
        {
            filp->f_op->compat_ioctl(filp, MEMGETINFO, &info);
        }
        if (info.writesize != EMMC_BLOCK_SIZE)
        {
            printk("write size error!info.writesize=%d,EMMC_BLOCK_SIZE=%d\n", info.writesize, EMMC_BLOCK_SIZE);
            g_init_write_size = 0;
            filp_close(filp, NULL);
            return false;
        } else
        {
            g_init_write_size = 1;
        }
    }

    filp->f_op->llseek(filp, offset * EMMC_BLOCK_SIZE, SEEK_SET);
    tmp = kzalloc(EMMC_BLOCK_SIZE, GFP_KERNEL);
    if (!tmp)
    {
        printk("malloc memory fail!\n");
        filp_close(filp, NULL);
        return false;
    }
    memset(tmp, 0x0, EMMC_BLOCK_SIZE);
    curr_fs = get_fs();
    set_fs(KERNEL_DS);
    memcpy(tmp, buff, length);
    ret = filp->f_op->write(filp, tmp, EMMC_BLOCK_SIZE, &(filp->f_pos));
    if (EMMC_BLOCK_SIZE != ret)
    {
        printk("write fail!errno=%d\n", ret);
        filp_close(filp, NULL);
        kfree(tmp);
        set_fs(curr_fs);
        return false;

    }
    set_fs(curr_fs);
    kfree(tmp);
    filp_close(filp, NULL);
    return true;
}
开发者ID:kim-ryuzaki,项目名称:android_mediatek_muse72,代码行数:63,代码来源:lg_partition.c

示例8: compat_fd_ioctl


//.........这里部分代码省略.........
        err |= __get_user(f->timeout, &uf->timeout);
        err |= __get_user(f->interleave_sect, &uf->interleave_sect);
        err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
        err |= __get_user(f->flags, &uf->flags);
        err |= __get_user(f->read_track, &uf->read_track);
        err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
        err |= __get_user(f->checkfreq, &uf->checkfreq);
        err |= __get_user(f->native_format, &uf->native_format);
        if (err) {
            err = -EFAULT;
            goto out;
        }
        break;
    }
    case FDGETDRVSTAT32:
    case FDPOLLDRVSTAT32:
        karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
        if (!karg)
            return -ENOMEM;
        break;
    case FDGETFDCSTAT32:
        karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
        if (!karg)
            return -ENOMEM;
        break;
    case FDWERRORGET32:
        karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
        if (!karg)
            return -ENOMEM;
        break;
    default:
        return -EINVAL;
    }
    set_fs(KERNEL_DS);
    err = __blkdev_driver_ioctl(bdev, mode, kcmd, (unsigned long)karg);
    set_fs(old_fs);
    if (err)
        goto out;
    switch (cmd) {
    case FDGETPRM32:
    {
        struct floppy_struct *f = karg;
        struct compat_floppy_struct __user *uf = compat_ptr(arg);

        err = __put_user(f->size, &uf->size);
        err |= __put_user(f->sect, &uf->sect);
        err |= __put_user(f->head, &uf->head);
        err |= __put_user(f->track, &uf->track);
        err |= __put_user(f->stretch, &uf->stretch);
        err |= __put_user(f->gap, &uf->gap);
        err |= __put_user(f->rate, &uf->rate);
        err |= __put_user(f->spec1, &uf->spec1);
        err |= __put_user(f->fmt_gap, &uf->fmt_gap);
        err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
        break;
    }
    case FDGETDRVPRM32:
    {
        struct compat_floppy_drive_params __user *uf;
        struct floppy_drive_params *f = karg;

        uf = compat_ptr(arg);
        err = __put_user(f->cmos, &uf->cmos);
        err |= __put_user(f->max_dtr, &uf->max_dtr);
        err |= __put_user(f->hlt, &uf->hlt);
        err |= __put_user(f->hut, &uf->hut);
开发者ID:johnny,项目名称:CobraDroidBeta,代码行数:67,代码来源:compat_ioctl.c

示例9: do_ade

asmlinkage void do_ade(struct pt_regs *regs)
{
	enum ctx_state prev_state;
	unsigned int __user *pc;
	mm_segment_t seg;

	prev_state = exception_enter();
	perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS,
			1, regs, regs->cp0_badvaddr);
	/*
	 * Did we catch a fault trying to load an instruction?
	 */
	if (regs->cp0_badvaddr == regs->cp0_epc)
		goto sigbus;

	if (user_mode(regs) && !test_thread_flag(TIF_FIXADE))
		goto sigbus;
	if (unaligned_action == UNALIGNED_ACTION_SIGNAL)
		goto sigbus;

	/*
	 * Do branch emulation only if we didn't forward the exception.
	 * This is all so but ugly ...
	 */

	/*
	 * Are we running in microMIPS mode?
	 */
	if (get_isa16_mode(regs->cp0_epc)) {
		/*
		 * Did we catch a fault trying to load an instruction in
		 * 16-bit mode?
		 */
		if (regs->cp0_badvaddr == msk_isa16_mode(regs->cp0_epc))
			goto sigbus;
		if (unaligned_action == UNALIGNED_ACTION_SHOW)
			show_registers(regs);

		if (cpu_has_mmips) {
			seg = get_fs();
			if (!user_mode(regs))
				set_fs(KERNEL_DS);
			emulate_load_store_microMIPS(regs,
				(void __user *)regs->cp0_badvaddr);
			set_fs(seg);

			return;
		}

		if (cpu_has_mips16) {
			seg = get_fs();
			if (!user_mode(regs))
				set_fs(KERNEL_DS);
			emulate_load_store_MIPS16e(regs,
				(void __user *)regs->cp0_badvaddr);
			set_fs(seg);

			return;
	}

		goto sigbus;
	}

	if (unaligned_action == UNALIGNED_ACTION_SHOW)
		show_registers(regs);
	pc = (unsigned int __user *)exception_epc(regs);

	seg = get_fs();
	if (!user_mode(regs))
		set_fs(KERNEL_DS);
	emulate_load_store_insn(regs, (void __user *)regs->cp0_badvaddr, pc);
	set_fs(seg);

	return;

sigbus:
	die_if_kernel("Kernel unaligned instruction access", regs);
	force_sig(SIGBUS, current);

	/*
	 * XXX On return from the signal handler we should advance the epc
	 */
	exception_exit(prev_state);
}
开发者ID:24hours,项目名称:linux,代码行数:84,代码来源:unaligned.c

示例10: OsalKfile_open

/*
 * ======== OsalKfile_open ========
 */
Int
OsalKfile_open (String             fileName,
                Char *             fileMode,
                OsalKfile_Handle * fileHandle)
{
    Int                 status      = OSALKFILE_SUCCESS;
    struct file *       fileDesc    = NULL;
    OsalKfile_Object *  fileObject  = NULL;
    mm_segment_t        fs;

    GT_3trace (curTrace, GT_ENTER, "OsalKfile_open",
               fileName, fileMode, fileHandle);

    GT_assert (curTrace, (fileName != NULL));
    GT_assert (curTrace, (fileMode != NULL));
    GT_assert (curTrace, (fileHandle != NULL));

#if !defined(SYSLINK_BUILD_OPTIMIZE)
    if (fileName == NULL) {
        /*! @retval OSALKFILE_E_INVALIDARG NULL provided for argument
                                           fileName. */
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "OsalKfile_open",
                             status,
                             "NULL provided for argument fileName");
    }
    else if (fileMode == NULL) {
        /*! @retval OSALKFILE_E_INVALIDARG NULL provided for argument
                                           fileMode. */
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "OsalKfile_open",
                             status,
                             "NULL provided for argument fileMode");
    }
    else if (fileMode [0] != 'r') {
        /*! @retval OSALKFILE_E_INVALIDARG Only read 'r' mode is supported. */
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "OsalKfile_open",
                             status,
                             "Only read 'r' mode is supported.");
    }
    else if (fileHandle == NULL) {
        /*! @retval OSALKFILE_E_INVALIDARG NULL provided for argument
                                           fileHandle. */
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "OsalKfile_open",
                             status,
                             "NULL provided for argument fileHandle");
    }
    else {
#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
        *fileHandle = NULL;
        fileObject = Memory_alloc (NULL, sizeof (OsalKfile_Object), 0, NULL);
#if !defined(SYSLINK_BUILD_OPTIMIZE)
        if (fileObject == NULL) {
            /*! @retval OSALKFILE_E_MEMORY Failed to allocate memory for
                                           OsalKfile object. */
            status = OSALKFILE_E_MEMORY;
            GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "OsalKfile_open",
                             status,
                             "Failed to allocate memory for OsalKfile object.");
        }
        else {
#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
            fs = get_fs ();
            set_fs (KERNEL_DS);

            fileDesc = filp_open (fileName, O_RDONLY, 0) ;
#if !defined(SYSLINK_BUILD_OPTIMIZE)
            if (   (IS_ERR (fileDesc))
                || (fileDesc == NULL)
                || (fileDesc->f_op == NULL)
                || (fileDesc->f_op->read == NULL)) {
                /*! @retval OSALKFILE_E_FILEOPEN Failed to open file. */
                status = OSALKFILE_E_FILEOPEN;
                GT_setFailureReason (curTrace,
                                     GT_4CLASS,
                                     "Kfile_Open",
                                     status,
                                     "Failed to open file.");
            }
            else {
#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
                fileObject->fileDesc = fileDesc;
                fileObject->fileName = fileName;
                fileObject->curPos = 0;

//.........这里部分代码省略.........
开发者ID:andreimironenko,项目名称:syslink,代码行数:101,代码来源:OsalKfile.c

示例11: OsalKfile_seek

/*
 * ======== OsalKfile_seek ========
 */
Int
OsalKfile_seek (OsalKfile_Handle fileHandle,
                Int32            offset,
                OsalKfile_Pos    pos)
{
    Int                 status      = OSALKFILE_SUCCESS;
    struct file *       fileDesc    = NULL;
    OsalKfile_Object *  fileObject  = NULL;
    mm_segment_t        fs;

    GT_3trace (curTrace, GT_ENTER, "OsalKfile_seek", fileHandle, offset, pos);

    GT_assert (curTrace, (fileHandle != NULL));
    GT_assert (curTrace, (pos < OsalKfile_Pos_EndValue));

#if !defined(SYSLINK_BUILD_OPTIMIZE)
    if (fileHandle == NULL) {
        /*! @retval OSALKFILE_E_INVALIDARG NULL provided for argument
                                           fileHandle. */
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "OsalKfile_seek",
                             status,
                             "NULL provided for argument fileHandle");
    }
    else {
#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
        fileObject = (OsalKfile_Object* ) fileHandle;
        fs = get_fs ();
        set_fs (get_ds ());

        fileDesc = fileObject->fileDesc;
        switch (pos) {
            case OsalKfile_Pos_SeekSet:
            {
                if ((offset < 0) || (offset > fileObject->size)) {
                    /*! @retval OSALKFILE_E_OUTOFRANGE offset is out of range
                                             for seek from the specified pos */
                    status = OSALKFILE_E_OUTOFRANGE;
                    GT_setFailureReason (curTrace,
                                         GT_4CLASS,
                                         "OsalKfile_seek",
                                         status,
                                         "offset is out of range for"
                                         " seek from the specified pos");
                }
                else {
                    if (fileDesc->f_op->llseek != NULL) {
                        /* This may be the case if yaffs2 file system is used.*/
                        fileObject->curPos = fileDesc->f_op->llseek (fileDesc,
                                                                     offset,
                                                                     SEEK_SET);
                    }
                    else {
                        fileObject->curPos = default_llseek (fileDesc,
                                                             offset,
                                                             SEEK_SET);
                    }
                }
            }
            break;

            case OsalKfile_Pos_SeekCur:
            {
                if (   ((fileObject->curPos + offset) > fileObject->size)
                    || ((fileObject->curPos + offset) < 0)) {
                    /*! @retval OSALKFILE_E_OUTOFRANGE offset is out of range
                                             for seek from the specified pos */
                    status = OSALKFILE_E_OUTOFRANGE;
                    GT_setFailureReason (curTrace,
                                         GT_4CLASS,
                                         "OsalKfile_seek",
                                         status,
                                         "offset is out of range for"
                                         " seek from the specified pos");
                }
                else {
                    if (fileDesc->f_op->llseek != NULL) {
                        /* This may be the case if yaffs2 file system is used.*/
                        fileObject->curPos = fileDesc->f_op->llseek (fileDesc,
                                                                     offset,
                                                                     SEEK_CUR);
                    }
                    else {
                        fileObject->curPos = default_llseek (fileDesc,
                                                             offset,
                                                             SEEK_CUR);
                    }
                }
            }
            break;

            case OsalKfile_Pos_SeekEnd:
            {
                /* A negative offset indicates offset from the end of file.
                 * Check that the specified offset is not beyond
//.........这里部分代码省略.........
开发者ID:andreimironenko,项目名称:syslink,代码行数:101,代码来源:OsalKfile.c

示例12: OsalKfile_read

/*
 * ======== OsalKfile_read ========
 */
Int OsalKfile_read(OsalKfile_Handle fileHandle, Char *buffer, UInt32 size,
        UInt32 count, UInt32 *numBytes)
{
    Int                 status      = OSALKFILE_SUCCESS;
    UInt32              bytesRead   = 0;
    OsalKfile_Object*   fileObject  = (OsalKfile_Object*) fileHandle;
    mm_segment_t        fs;

    GT_4trace (curTrace, GT_ENTER, "OsalKfile_read",
               fileHandle, buffer, size, count);

    GT_assert (curTrace, (fileHandle != NULL));
    GT_assert (curTrace, (buffer != NULL));
    GT_assert (curTrace, (size != 0));
    GT_assert (curTrace, (count != 0));
    GT_assert (curTrace, (numBytes != NULL));

    /* initialize numBytes to 0 in case we return failure early */
    if (numBytes != NULL) {
        *numBytes = bytesRead;
    }

#if !defined(SYSLINK_BUILD_OPTIMIZE)
    if (fileHandle == NULL) {
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status,
                "NULL provided for argument fileHandle");
    }
    else if (buffer == NULL) {
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status,
                "NULL provided for argument buffer.");
    }
    else if (size == 0) {
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status,
                "Zero provided for size argument.");
    }
    else if (count == 0) {
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status,
                "Zero provided for count argument.");
    }
    else if (numBytes == NULL) {
        status = OSALKFILE_E_INVALIDARG;
        GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status,
                "NULL provided for numBytes argument.");
    }
    else {
#endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) */
        fileObject = (OsalKfile_Object*) fileHandle;
        if ((fileObject->curPos + (size * count)) > fileObject->size) {
            status = OSALKFILE_E_OUTOFRANGE;
            GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read", status,
                    "Specified operation goes out of range of the file.");
        }
        else {
            /* read from file */
            fs = get_fs ();
            set_fs (KERNEL_DS);

            bytesRead = fileObject->fileDesc->f_op->read(fileObject->fileDesc,
                    buffer, (size * count), &(fileObject->fileDesc->f_pos));
            set_fs(fs);

            *numBytes = bytesRead;

            if (bytesRead >= 0) {
                fileObject->curPos += bytesRead;
                GT_assert (curTrace, ((bytesRead / size) == (UInt32) count));
            }
#if !defined(SYSLINK_BUILD_OPTIMIZE)
            else {
                status = OSALKFILE_E_FILEREAD;
                GT_setFailureReason(curTrace, GT_4CLASS, "OsalKfile_read",
                        status, "Failed to read from the file.");
            }
#endif
        }
#if !defined(SYSLINK_BUILD_OPTIMIZE)
    }
#endif

    GT_1trace(curTrace, GT_LEAVE, "OsalKfile_read", status);

    return (status);
}
开发者ID:andreimironenko,项目名称:syslink,代码行数:90,代码来源:OsalKfile.c

示例13: param_get_dev_path

static int param_get_dev_path(void)
{
#define DEFAULT_GPT_ENTRIES			128
#define MMCBLK_PART_INFO_PATH_LEN	128
#define PARTITION_NAME_LEN			128

	struct file*		p_file;
	mm_segment_t	s_Old_FS;
	char				a_part_info_path[MMCBLK_PART_INFO_PATH_LEN]	= { 0, };
	char				a_partition_name[PARTITION_NAME_LEN]			= { 0, };
	int				v_index;


	memset( sa_Param_dev_path, 0x0, PARAM_DEV_PATH_LEN );


	for( v_index = 0; v_index < DEFAULT_GPT_ENTRIES; v_index++ )
	{
		memset( a_part_info_path, 0x0, MMCBLK_PART_INFO_PATH_LEN );
		snprintf( a_part_info_path, MMCBLK_PART_INFO_PATH_LEN, "/sys/block/mmcblk0/mmcblk0p%d/partition_name", v_index + 1 );


		p_file	= filp_open( a_part_info_path, O_RDONLY, NULL );
		if( IS_ERR(p_file) )
		{
			PARAM_LOG( KERN_ERR "[%s] %s file open was failed!: %ld\n", __FUNCTION__, a_part_info_path, PTR_ERR(p_file) );
		}
		else
		{
			s_Old_FS	= get_fs();
			set_fs( get_ds() );


			memset( a_partition_name, 0x0, PARTITION_NAME_LEN );
			p_file->f_op->read( p_file, a_partition_name, PARTITION_NAME_LEN, &p_file->f_pos );


			set_fs( s_Old_FS );
			filp_close( p_file, NULL );


			/***
				Use the "strncmp" function to avoid following garbage character
			***/
			if( !strncmp( PARAM_PART_NAME, a_partition_name, strlen(PARAM_PART_NAME) ) )
			{
				snprintf( sa_Param_dev_path, PARAM_DEV_PATH_LEN, "/dev/block/mmcblk0p%d", v_index + 1 );
				PARAM_LOG( KERN_INFO "SEC_PARAM : %s device was found\n", sa_Param_dev_path );


				break;
			}
		}
	}


	if( sa_Param_dev_path[0] != 0x0 )
	{
		return	NULL;
	}
	else
	{
		return	-EFAULT;
	}
}
开发者ID:ASAZING,项目名称:Android-Kernel-Gt-s7390l,代码行数:65,代码来源:param.c

示例14: setup_rt_frame

static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
			   sigset_t *set, struct pt_regs *regs)
{
	struct rt_sigframe __user *frame;
	int err = 0;
	int signal;

	frame = get_sigframe(ka, regs->regs[15], sizeof(*frame));

	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
		goto give_sigsegv;

	signal = current_thread_info()->exec_domain
		&& current_thread_info()->exec_domain->signal_invmap
		&& sig < 32
		? current_thread_info()->exec_domain->signal_invmap[sig]
		: sig;

	err |= copy_siginfo_to_user(&frame->info, info);

	/* Create the ucontext.  */
	err |= __put_user(0, &frame->uc.uc_flags);
	err |= __put_user(0, &frame->uc.uc_link);
	err |= __put_user((void *)current->sas_ss_sp,
			  &frame->uc.uc_stack.ss_sp);
	err |= __put_user(sas_ss_flags(regs->regs[15]),
			  &frame->uc.uc_stack.ss_flags);
	err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
	err |= setup_sigcontext(&frame->uc.uc_mcontext,
			        regs, set->sig[0]);
	err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));

	/* Set up to return from userspace.  If provided, use a stub
	   already in userspace.  */
	if (ka->sa.sa_flags & SA_RESTORER) {
		regs->pr = (unsigned long) ka->sa.sa_restorer;
	} else {
		/* Generate return code (system call to rt_sigreturn) */
		err |= __put_user(MOVW(7), &frame->retcode[0]);
		err |= __put_user(TRAP16, &frame->retcode[1]);
		err |= __put_user(OR_R0_R0, &frame->retcode[2]);
		err |= __put_user(OR_R0_R0, &frame->retcode[3]);
		err |= __put_user(OR_R0_R0, &frame->retcode[4]);
		err |= __put_user(OR_R0_R0, &frame->retcode[5]);
		err |= __put_user(OR_R0_R0, &frame->retcode[6]);
		err |= __put_user((__NR_rt_sigreturn), &frame->retcode[7]);
		regs->pr = (unsigned long) frame->retcode;
	}

	if (err)
		goto give_sigsegv;

	/* Set up registers for signal handler */
	regs->regs[15] = (unsigned long) frame;
	regs->regs[4] = signal; /* Arg for signal handler */
	regs->regs[5] = (unsigned long) &frame->info;
	regs->regs[6] = (unsigned long) &frame->uc;
	regs->pc = (unsigned long) ka->sa.sa_handler;

	set_fs(USER_DS);

#if DEBUG_SIG
	printk("SIG deliver (%s:%d): sp=%p pc=%08lx pr=%08lx\n",
		current->comm, current->pid, frame, regs->pc, regs->pr);
#endif

	flush_cache_sigtramp(regs->pr);
	if ((-regs->pr & (L1_CACHE_BYTES-1)) < sizeof(frame->retcode))
		flush_cache_sigtramp(regs->pr + L1_CACHE_BYTES);
	return;

give_sigsegv:
	force_sigsegv(sig, current);
}
开发者ID:Dronevery,项目名称:JetsonTK1-kernel,代码行数:74,代码来源:signal.c

示例15: osi_rdwr

/* osi_rdwr
 * seek, then read or write to an open inode. addrp points to data in
 * kernel space.
 */
int
osi_rdwr(struct osi_file *osifile, struct uio *uiop, int rw)
{
    struct file *filp = osifile->filp;
    mm_segment_t old_fs = {0};
    int code = 0;
    struct iovec *iov;
    size_t count;
    unsigned long savelim;
    loff_t pos;

    savelim = current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur;
    current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;

    if (uiop->uio_seg == AFS_UIOSYS) {
	/* Switch into user space */
	old_fs = get_fs();
	set_fs(get_ds());
    }

    while (code == 0 && uiop->uio_resid > 0 && uiop->uio_iovcnt > 0) {
	iov = uiop->uio_iov;
	count = iov->iov_len;
	if (count == 0) {
	    uiop->uio_iov++;
	    uiop->uio_iovcnt--;
	    continue;
	}

	pos = uiop->uio_offset;
	if (rw == UIO_READ)
	    code = afs_file_read(filp, iov->iov_base, count, &pos);
	else
	    code = afs_file_write(filp, iov->iov_base, count, &pos);

	if (code < 0) {
	    code = -code;
	    break;
	} else if (code == 0) {
	    /*
	     * This is bad -- we can't read any more data from the
	     * file, but we have no good way of signaling a partial
	     * read either.
	     */
	    code = EIO;
	    break;
	}

	iov->iov_base += code;
	iov->iov_len -= code;
	uiop->uio_resid -= code;
	uiop->uio_offset += code;
	code = 0;
    }

    if (uiop->uio_seg == AFS_UIOSYS) {
	/* Switch back into kernel space */
	set_fs(old_fs);
    }

    current->TASK_STRUCT_RLIM[RLIMIT_FSIZE].rlim_cur = savelim;

    return code;
}
开发者ID:bagdxk,项目名称:openafs,代码行数:68,代码来源:osi_file.c


注:本文中的set_fs函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。