int
sock_awaitconn(struct socket *mysock, struct socket *servsock)
{
  struct socket *last;

  DPRINTF((net_debug,
	"NET: sock_awaitconn: trying to connect socket 0x%x to 0x%x\n",
							mysock, servsock));
  if (!(servsock->flags & SO_ACCEPTCON)) {
	DPRINTF((net_debug,
		"NET: sock_awaitconn: server not accepting connections\n"));
	return(-EINVAL);
  }

  /* Put ourselves on the server's incomplete connection queue. */
  mysock->next = NULL;
  cli();
  if (!(last = servsock->iconn)) servsock->iconn = mysock;
    else {
	while (last->next) last = last->next;
	last->next = mysock;
  }
  mysock->state = SS_CONNECTING;
  mysock->conn = servsock;
  sti();

  /*
   * Wake up server, then await connection. server will set state to
   * SS_CONNECTED if we're connected.
   */
  wake_up_interruptible(servsock->wait);
  if (mysock->state != SS_CONNECTED) {
	interruptible_sleep_on(mysock->wait);
	if (mysock->state != SS_CONNECTED &&
	    mysock->state != SS_DISCONNECTING) {
		/*
		 * if we're not connected we could have been
		 * 1) interrupted, so we need to remove ourselves
		 *    from the server list
		 * 2) rejected (mysock->conn == NULL), and have
		 *    already been removed from the list
		 */
		if (mysock->conn == servsock) {
			cli();
			if ((last = servsock->iconn) == mysock)
					servsock->iconn = mysock->next;
			else {
				while (last->next != mysock) last = last->next;
				last->next = mysock->next;
			}
			sti();
		}
		return(mysock->conn ? -EINTR : -EACCES);
	}
  }
  return(0);
}
Exemple #2
0
static ssize_t
capinc_raw_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
	struct capiminor *mp = (struct capiminor *)file->private_data;
	struct sk_buff *skb;
	int retval;
	size_t copied = 0;

        if (ppos != &file->f_pos)
		return -ESPIPE;

	if (!mp || !mp->nccip)
		return -EINVAL;

	if ((skb = skb_dequeue(&mp->recvqueue)) == 0) {

		if (file->f_flags & O_NONBLOCK)
			return -EAGAIN;

		for (;;) {
			interruptible_sleep_on(&mp->recvwait);
			if (mp->nccip == 0)
				return 0;
			if ((skb = skb_dequeue(&mp->recvqueue)) != 0)
				break;
			if (signal_pending(current))
				break;
		}
		if (skb == 0)
			return -ERESTARTNOHAND;
	}
	do {
		if (count < skb->len) {
			retval = copy_to_user(buf, skb->data, count);
			if (retval) {
				skb_queue_head(&mp->recvqueue, skb);
				return retval;
			}
			skb_pull(skb, count);
			skb_queue_head(&mp->recvqueue, skb);
			copied += count;
			return copied;
		} else {
			retval = copy_to_user(buf, skb->data, skb->len);
			if (retval) {
				skb_queue_head(&mp->recvqueue, skb);
				return copied;
			}
			copied += skb->len;
			count -= skb->len;
			buf += skb->len;
			kfree_skb(skb);
		}
	} while ((skb = skb_dequeue(&mp->recvqueue)) != 0);

	return copied;
}
Exemple #3
0
/*
 * Wait while server is in grace period
 */
static inline int
nlmclnt_grace_wait(struct nlm_host *host)
{
	if (!host->h_reclaiming)
		interruptible_sleep_on_timeout(&host->h_gracewait, 10*HZ);
	else
		interruptible_sleep_on(&host->h_gracewait);
	return signalled()? -ERESTARTSYS : 0;
}
Exemple #4
0
static void sleep_if_full(struct tty_queue * queue)
{
	if (!FULL(*queue))
		return;
	cli();
	while (!current->signal && LEFT(*queue)<128)
		interruptible_sleep_on(&queue->proc_list);
	sti();
}
Exemple #5
0
static ssize_t pipe_read(struct file * filp, char * buf,
			 size_t count, loff_t *ppos)
{
	struct inode * inode = filp->f_dentry->d_inode;
	ssize_t chars = 0, size = 0, read = 0;
        char *pipebuf;


	if (ppos != &filp->f_pos)
		return -ESPIPE;

	if ( !count ) return 0;

	if (filp->f_flags & O_NONBLOCK) {
		if (PIPE_LOCK(*inode))
			return -EAGAIN;
		if (PIPE_EMPTY(*inode)) {
			if (PIPE_WRITERS(*inode))
				return -EAGAIN;
			else
				return 0;
		}
	} else while (PIPE_EMPTY(*inode) || PIPE_LOCK(*inode)) {
		if (PIPE_EMPTY(*inode)) {
			if (!PIPE_WRITERS(*inode) || !count)
				return 0;
		}
		if (signal_pending(current))
			return -ERESTARTSYS;
		interruptible_sleep_on(&PIPE_WAIT(*inode));
	}
	PIPE_LOCK(*inode)++;
	while (count>0 && (size = PIPE_SIZE(*inode))) {
		chars = PIPE_MAX_RCHUNK(*inode);
		if (chars > count)
			chars = count;
		if (chars > size)
			chars = size;
		read += chars;
                pipebuf = PIPE_BASE(*inode)+PIPE_START(*inode);
		PIPE_START(*inode) += chars;
		PIPE_START(*inode) &= (PIPE_BUF-1);
		PIPE_LEN(*inode) -= chars;
		count -= chars;
		copy_to_user(buf, pipebuf, chars );
		buf += chars;
	}
	PIPE_LOCK(*inode)--;
	wake_up_interruptible(&PIPE_WAIT(*inode));
	if (read) {
		UPDATE_ATIME(inode);
		return read;
	}
	if (PIPE_WRITERS(*inode))
		return -EAGAIN;
	return 0;
}
Exemple #6
0
static int pipe_rdwr_open(register struct inode *inode,
			  register struct file *filp)
{
    debug("PIPE: rdwr called.\n");

    if(!PIPE_BASE(*inode)) {
	if(!(PIPE_BASE(*inode) = get_pipe_mem()))
	    return -ENOMEM;
#if 0
	/* next fields already set to zero by get_empty_inode() */
	PIPE_START(*inode) = PIPE_LEN(*inode) = 0;
	PIPE_RD_OPENERS(*inode) = PIPE_WR_OPENERS(*inode) = 0;
	PIPE_READERS(*inode) = PIPE_WRITERS(*inode) = 0;
	PIPE_LOCK(*inode) = 0;
#endif
    }
    if (filp->f_mode & FMODE_READ) {
	(inode->u.pipe_i.readers)++;
	if(inode->u.pipe_i.writers > 0) {
	    if(inode->u.pipe_i.readers < 2)
		wake_up_interruptible(&(inode->u.pipe_i.wait));
	}
	else {
	    if(!(filp->f_flags & O_NONBLOCK) && (inode->i_sb))
		while(!(inode->u.pipe_i.writers))
		    interruptible_sleep_on(&(inode->u.pipe_i.wait));
	}
    }

    if (filp->f_mode & FMODE_WRITE) {
	(inode->u.pipe_i.writers)++;
	if(inode->u.pipe_i.readers > 0) {
	    if(inode->u.pipe_i.writers < 2)
		wake_up_interruptible(&(inode->u.pipe_i.wait));
	}
	else {
	    if(filp->f_flags & O_NONBLOCK)
		return -ENXIO;
	    while(!(inode->u.pipe_i.readers))
		interruptible_sleep_on(&(inode->u.pipe_i.wait));
	}
    }
    return 0;
}
Exemple #7
0
int
EvSendGetUserName(EvGroupInfo_t *eGroup, EvGroupID_t memberID,
                  EvUserID_t userID, char *userName, unsigned long *flags)
{
    EvPendRem_t *Pend;
    int RetVal;

    /* Check to see if there is a remote control entity registered. */
    if (eGroup->EgiGroupDest.EdID == 0) {
        return -EV_ERROR_NO_REMOTE;
    }

    /* Allocate an entry to pend on while remote request is processed. */
    if ((Pend = EvGetPendEntry(eGroup, EV_REM_GET_USER_NAME,
                               memberID, userID, 0, 0, 0, NULL)) == NULL) {
        return -EV_ERROR_MEM_ALLOC;
    }

    /* Send the reqest to the waiting control agent. */
    RetVal = EvGroupSendEvent(0, 0, eGroup->EgiID, eGroup->EgiMemberID,
                              -1, EV_CONTROL_CLASS_ID, EV_REM_GET_USER_NAME,
                              memberID, userID, 0, 0, &eGroup->EgiGroupDest, 0, NULL);
    if (RetVal) {
        EvDelPendEntry(eGroup, Pend);
        return RetVal;
    }

    /* Make sure group cannont be removed and Wait for information
     * to be returned. */
    eGroup->EgiUseCount++;
    write_unlock_irqrestore(&eGroup->EgiLock, flags);

    interruptible_sleep_on(&Pend->PrWaitQ);

    /* Reaquire the load and releas the group use count to allow other
     * group activities. */
    write_lock_irqsave(&eGroup->EgiLock, flags);
    eGroup->EgiUseCount--;

    /* If an error has been indicated then return it. */
    RetVal = Pend->PrRetInfo.EpInfo[0];
    if (RetVal) {
        /* Free the Pend data structure. */
        EvDelPendEntry(eGroup, Pend);

        return -RetVal;
    }

    /* Copy user Name information. */
    strncpy(userName, Pend->PrRetInfo.EpData, 16);

    /* Free the Pend data structure. */
    EvDelPendEntry(eGroup, Pend);

    return EV_NOERR;
}
Exemple #8
0
static void unix_data_wait(unix_socket * sk)
{
	cli();
	if (!skb_peek(&sk->receive_queue)) {
		sk->socket->flags |= SO_WAITDATA;
		interruptible_sleep_on(sk->sleep);
		sk->socket->flags &= ~SO_WAITDATA;
	}
	sti();
}
static ssize_t rebis_keyscan_read(struct file *filp, char *buff, size_t count, loff_t *offp)
{
	int i;
	//int key_base[5] = {KEY_MATRIX_BASE5, KEY_MATRIX_BASE4, KEY_MATRIX_BASE3, KEY_MATRIX_BASE2, KEY_MATRIX_BASE1};

	cur_key = 0;

	if(!(filp->f_flags & O_NONBLOCK)){
		#if 0
		interruptible_sleep_on(&wq);
		#else
		wait_event_interruptible(wq, flag != 0);
		//wait_event_interruptible_timeout(wq, flag != 0, 600);
		#endif
	}
	
	//for key scan
	#if 1
	cur_key = 0;
	s3c2410_gpio_cfgpin(S3C2410_GPF3, S3C2410_GPF3_INP);
	for(i=4; i>=0; i--)
	{
		writel(readl(S3C2410_GPBDAT) | (0x1f), S3C2410_GPBDAT);
		writel(readl(S3C2410_GPBDAT) & (~(0x1 << i)), S3C2410_GPBDAT);
		
		cur_key = scan_input();
		if(cur_key)
		//cur_key = scan_input();
		{
			cur_key += (i)*2;//key_base[i]; 
			if(cur_key == old_key)
				goto SameValue;
			old_key = cur_key;
			//printk("cur_key = %d \n\n", cur_key);
			put_user(cur_key,(char *)buff);
			break;
		}
	}
SameValue:
	old_key = 0;
	flag = 0;

	// set GPBDAT 0
	s3c2410_gpio_setpin(S3C2410_GPB0, 0);
	s3c2410_gpio_setpin(S3C2410_GPB1, 0);
	s3c2410_gpio_setpin(S3C2410_GPB2, 0);
	s3c2410_gpio_setpin(S3C2410_GPB3, 0);
	s3c2410_gpio_setpin(S3C2410_GPB4, 0);
	
	// change External Interrupts
	s3c2410_gpio_cfgpin(S3C2410_GPF3, S3C2410_GPF3_EINT3);
	#endif

	return count;
}
int WAIT_EVENT( EVENT_HNDL* pEvent, ULONG msecDelay )
{
	long int TimeRemain;
	unsigned long flags ;

	// wait on the queue
	// Round up to next jiffie for low Linux 100 Hz resolution and
	// add 1 jiffie for unsynchronized timers
	// and add 1 more jiffie for timer rate differences
	// and add 2 more jiffie because unknown factors are causing timeouts
	TimeRemain = ((msecDelay+49) * HZ) / 1000;

	// if no wait time then just return failure
	if ( ! msecDelay )
	{
		return 0;
	}

	// atomically sleep if event is not set - we must protect the window between
	// finding out if the flag is already set and sleeping as if an interrupt
	// occurs in the window and calls SET_EVENT, SET_EVENT will signal the wait
	// queue before we get placed on it and we will miss this signal.
	save_flags (flags) ;
	cli () ;

	// indicate that I am waiting
	pEvent->WaitCnt++;

	if ( ! pEvent->SetFlag )
	{
		#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
			while ( !pEvent->SetFlag && TimeRemain )
			{
				// safe to call sleep with interrupts off as kernel will re-enable
				// interrupts after placing us on the queue and before calling schedule
				TimeRemain = interruptible_sleep_on_timeout ( &pEvent->WaitQue,  TimeRemain );
			}
		#else
			while ( !pEvent->SetFlag )
			{
				// safe to call sleep with interrupts off as kernel will re-enable
				// interrupts after placing us on the queue and before calling schedule
				interruptible_sleep_on ( &pEvent->WaitQue );
			}
		#endif
	}
	// remove wait indication
	pEvent->WaitCnt--;

	restore_flags (flags) ;

	// return setflag
	return pEvent->SetFlag;
}
Exemple #11
0
ssize_t scull_p_write (struct file *filp, const char *buf, size_t count,
                loff_t *f_pos)
{
    Scull_Pipe *dev = filp->private_data;
    int left;
    
    if (down_interruptible (&dev->sem))
        return -ERESTARTSYS;
    /* left is the free space in the buffer, but it must be positive */
    left = (dev->rp + dev->buffersize - dev->wp) % dev->buffersize;

    PDEBUG("write: left is %i\n",left);
    while (left==1) { /* empty */
        up (&dev->sem);
        if (filp->f_flags & O_NONBLOCK)
            return -EAGAIN;
        PDEBUG("\"%s\" writing: going to sleep\n",current->comm);
        interruptible_sleep_on(&dev->outq);
        if (signal_pending (current)) /* a signal arrived */
            return -ERESTARTSYS; /* tell the fs layer to handle it */
        if (down_interruptible (&dev->sem))
            return -ERESTARTSYS;
        /* otherwise loop, but recalculate free space */
        left = (dev->rp + dev->buffersize - dev->wp) % dev->buffersize;
    }
    /* ok, space is there, accept something */
    if (dev->wp >= dev->rp) {
        count = min(count, dev->end - dev->wp); /* up to end-of-buffer */
        if (count == left) /* leave a hole, even if at e-o-b */
            count--;
    }
    else /* the write pointer has wrapped, fill up to rp-1 */
        count = min(count, dev->rp - dev->wp - 1);
    PDEBUG("Going to accept %li bytes to %p from %p\n",
           (long)count, dev->wp, buf);
    copy_from_user (dev->wp, buf, count);
    dev->wp += count;
    if (dev->wp == dev->end)
        dev ->wp = dev->buffer; /* wrapped */
    up (&dev->sem);

    /* finally, awake any reader */
    wake_up_interruptible(&dev->inq);  /* blocked in read() and select() */
# ifdef LINUX_24
    if (dev->async_queue)
        kill_fasync (dev->async_queue, SIGIO, POLL_IN); /* asynchronous readers */
# else
    if (dev->async_queue)
        kill_fasync (dev->async_queue, SIGIO); /* asynchronous readers */
# endif
    PDEBUG("\"%s\" did write %li bytes\n",current->comm, (long)count);
    return count;
}
Exemple #12
0
int locks_mandatory_area(int read_write, struct inode *inode,
			 struct file *filp, unsigned int offset,
			 unsigned int count)
{
	struct file_lock *fl;
	struct file_lock tfl;

	memset(&tfl, 0, sizeof(tfl));

	tfl.fl_file = filp;
	tfl.fl_flags = FL_POSIX | FL_ACCESS;
	tfl.fl_owner = current;
	tfl.fl_type = (read_write == FLOCK_VERIFY_WRITE) ? F_WRLCK : F_RDLCK;
	tfl.fl_start = offset;
	tfl.fl_end = offset + count - 1;

repeat:
	/* If there are no FL_POSIX locks then go ahead. */
	if (!(fl = inode->i_flock) || !(fl->fl_flags & FL_POSIX))
		return (0);

	/* Search the lock list for this inode for locks that conflict with
	 * the proposed read/write.
	 */
	while (fl != NULL) {
		/* Block for writes against a "read" lock,
		 * and both reads and writes against a "write" lock.
		 */
		if (posix_locks_conflict(fl, &tfl)) {
			if (filp && (filp->f_flags & O_NONBLOCK))
				return (-EAGAIN);
			if (current->signal & ~current->blocked)
				return (-ERESTARTSYS);
			if (posix_locks_deadlock(current, fl->fl_owner))
				return (-EDEADLK);

			locks_insert_block(fl, &tfl);
			interruptible_sleep_on(&tfl.fl_wait);
			locks_delete_block(fl, &tfl);

			if (current->signal & ~current->blocked)
				return (-ERESTARTSYS);
			/* If we've been sleeping someone might have
			 * changed the permissions behind our back.
			 */
			if ((inode->i_mode & (S_ISGID | S_IXGRP)) != S_ISGID)
				break;
			goto repeat;
		}
		fl = fl->fl_next;
	}
	return (0);
}
Exemple #13
0
static struct socket *
sock_alloc(int wait)
{
  struct socket *sock;

  while (1) {
	cli();
	for (sock = sockets; sock <= last_socket; ++sock) {
		if (sock->state == SS_FREE) {
			sock->state = SS_UNCONNECTED;
			sti();
			sock->flags = 0;
			sock->ops = NULL;
			sock->data = NULL;
			sock->conn = NULL;
			sock->iconn = NULL;

			/*
			 * This really shouldn't be necessary, but everything
			 * else depends on inodes, so we grab it.
			 * Sleeps are also done on the i_wait member of this
			 * inode.  The close system call will iput this inode
			 * for us.
			 */
			if (!(SOCK_INODE(sock) = get_empty_inode())) {
				printk("NET: sock_alloc: no more inodes\n");
				sock->state = SS_FREE;
				return(NULL);
			}
			SOCK_INODE(sock)->i_mode = S_IFSOCK;
			SOCK_INODE(sock)->i_uid = current->euid;
			SOCK_INODE(sock)->i_gid = current->egid;
			SOCK_INODE(sock)->i_socket = sock;

			sock->wait = &SOCK_INODE(sock)->i_wait;
			DPRINTF((net_debug,
				"NET: sock_alloc: sk 0x%x, ino 0x%x\n",
				       			sock, SOCK_INODE(sock)));
			return(sock);
		}
	}
	sti();
	if (!wait) return(NULL);
	DPRINTF((net_debug, "NET: sock_alloc: no free sockets, sleeping...\n"));
	interruptible_sleep_on(&socket_wait_free);
	if (current->signal & ~current->blocked) {
		DPRINTF((net_debug, "NET: sock_alloc: sleep was interrupted\n"));
		return(NULL);
	}
	DPRINTF((net_debug, "NET: sock_alloc: wakeup... trying again...\n"));
  }
}
Exemple #14
0
int jit_read_queue(char *buf, char **start, off_t offset,
                   int len, int unused)
{
    /* delay one second (or the chosen value), before printing */
    unsigned long j= jiffies + jit_delay * HZ;
    
    struct wait_queue *wait = NULL;

    current->timeout = j;
    interruptible_sleep_on(&wait);

    return jit_print(buf);
}
Exemple #15
0
static int jiq_read_tasklet(char *buf, char **start, off_t offset, int len,
                int *eof, void *data)
{
	jiq_data.len = 0;                /* nothing printed, yet */
	jiq_data.buf = buf;              /* print in this place */
	jiq_data.jiffies = jiffies;      /* initial time */

	tasklet_schedule(&jiq_tasklet);
	interruptible_sleep_on(&jiq_wait);    /* sleep till completion */

	*eof = 1;
	return jiq_data.len;
}
static ssize_t interface_read(struct file *filp, char __user *buf, size_t count,
			loff_t *offp)
{
	interruptible_sleep_on(&cc2520_interface_read_queue);
	if (copy_to_user(buf, rx_buf_c, rx_pkt_len))
		return -EFAULT;

	if (print_messages) {
		interface_print_to_log(rx_buf_c, rx_pkt_len, false);
	}

	return rx_pkt_len;
}
Exemple #17
0
int locks_mandatory_area(int read_write, struct inode *inode,
			 struct file *filp, unsigned int offset,
			 unsigned int count)
{
#ifdef CONFIG_LOCK_MANDATORY	
	struct file_lock *fl;

repeat:
	/* Check that there are locks, and that they're not F_FLOCK locks.
	 */
	if ((fl = inode->i_flock) && (fl->fl_flags & F_FLOCK))
		return (0);
	
	/*
	 * Search the lock list for this inode for locks that conflict with
	 * the proposed read/write.
	 */
	while (fl != NULL) {
		if (fl->fl_owner == current ||
		    fl->fl_end < offset || fl->fl_start >= offset + count)
			goto next_lock;

		/*
		 * Block for writes against a "read" lock,
		 * and both reads and writes against a "write" lock.
		 */
		if ((read_write == FLOCK_VERIFY_WRITE) ||
		    (fl->fl_type == F_WRLCK)) {
			if (filp && (filp->f_flags & O_NONBLOCK))
				return (-EAGAIN);
			if (current->signal & ~current->blocked)
				return (-ERESTARTSYS);
			if (posix_locks_deadlock(current, fl->fl_owner))
				return (-EDEADLK);
			interruptible_sleep_on(&fl->fl_wait);
			if (current->signal & ~current->blocked)
				return (-ERESTARTSYS);
			/*
			 * If we've been sleeping someone might have
			 * changed the permissions behind our back.
			 */
			if ((inode->i_mode & (S_ISGID | S_IXGRP)) != S_ISGID)
				break;
			goto repeat;
		}
	next_lock:
		fl = fl->fl_next;
	}
#endif
	return (0);
}
Exemple #18
0
static ssize_t
capi_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
	struct capidev *cdev = (struct capidev *)file->private_data;
	struct sk_buff *skb;
	int retval;
	size_t copied;

	if (ppos != &file->f_pos)
		return -ESPIPE;

	if (!cdev->applid)
		return -ENODEV;

	if ((skb = skb_dequeue(&cdev->recvqueue)) == 0) {

		if (file->f_flags & O_NONBLOCK)
			return -EAGAIN;

		for (;;) {
			interruptible_sleep_on(&cdev->recvwait);
			if ((skb = skb_dequeue(&cdev->recvqueue)) != 0)
				break;
			if (signal_pending(current))
				break;
		}
		if (skb == 0)
			return -ERESTARTNOHAND;
	}
	if (skb->len > count) {
		skb_queue_head(&cdev->recvqueue, skb);
		return -EMSGSIZE;
	}
	retval = copy_to_user(buf, skb->data, skb->len);
	if (retval) {
		skb_queue_head(&cdev->recvqueue, skb);
		return retval;
	}
	copied = skb->len;

	if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_IND) {
		cdev->nrecvdatapkt++;
	} else {
		cdev->nrecvctlpkt++;
	}

	kfree_skb(skb);

	return copied;
}
void RESET_EVENT( EVENT_HNDL* pEvent )
{
	DWORD LockFlag;

	// clear the event flag
	ACQUIRE_LOCK( &pEvent->FlagLock, LockFlag );
	pEvent->SetFlag = FALSE;

	// empty out the queue
	while ( waitqueue_active( &pEvent->WaitQue ) )
		interruptible_sleep_on( &pEvent->WaitQue );

	RELEASE_LOCK( &pEvent->FlagLock, LockFlag );
}
static int lock_smartio(unsigned long *flags)
{
	spin_lock_irqsave(&smartio_busy_lock, *flags);
	if (atomic_read(&smartio_busy) == 1) {
		spin_unlock_irqrestore(&smartio_busy_lock, *flags);
		interruptible_sleep_on(&smartio_queue);
	}
	else {
		atomic_set(&smartio_busy, 1);
		spin_unlock_irqrestore(&smartio_busy_lock, *flags);
	}

	return 1;
}
Exemple #21
0
static size_t pipe_write(register struct inode *inode, struct file *filp,
		      char *buf, int count)
{
    size_t free, tmp, written = 0;
    register char *chars;

    debug("PIPE: write called.\n");
    if (!(inode->u.pipe_i.readers)) {
	send_sig(SIGPIPE, current, 0);
	return -EPIPE;
    }

    free = (count <= PIPE_BUF) ? (size_t) count : 1;
    while (count > 0) {
	while (((PIPE_BUF - (inode->u.pipe_i.len)) < free)
	       || (inode->u.pipe_i.lock)) {
	    if (!(inode->u.pipe_i.readers)) {
		send_sig(SIGPIPE, current, 0);
		return written ? (int) written : -EPIPE;
	    }
	    if (current->signal)
		return written ? (int) written : -ERESTARTSYS;
	    if (filp->f_flags & O_NONBLOCK)
		return written ? (int) written : -EAGAIN;
	    interruptible_sleep_on(&(inode->u.pipe_i.wait));
	}
	(inode->u.pipe_i.lock)++;
	while (count > 0 && (free = (PIPE_BUF - (inode->u.pipe_i.len)))) {

            tmp = (inode->u.pipe_i.start + inode->u.pipe_i.len)&(PIPE_BUF-1);
	    chars = (char *)(PIPE_BUF - tmp);
	    if ((size_t)chars > (size_t) count)
		chars = (char *) count;
	    if ((size_t)chars > free)
		chars = (char *)free;

	    memcpy_fromfs((inode->u.pipe_i.base + tmp), buf, (size_t)chars);
	    buf += (size_t)chars;
	    (inode->u.pipe_i.len) += (size_t)chars;
	    written += (size_t)chars;
	    count -= (int)chars;
	}
	(inode->u.pipe_i.lock)--;
	wake_up_interruptible(&(inode->u.pipe_i.wait));
	free = 1;
    }
    inode->i_ctime = inode->i_mtime = CURRENT_TIME;

    return written;
}
// sec filter read function
ssize_t	sec_url_filter_read( struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
    int             result      = -EIO;
    tcp_TrackInfo   *notifyInfo = NULL;
    int             leftLen     = 0;
    int             writeCount  = count;
    int             notifyFlag  = 0;
    if (buf != NULL)
    {
        while (filterMode)
        {
            unsigned long   flags = 0;
            SEC_spin_lock_irqsave(&notifying_TrackInfo->tcp_info_lock, flags);
            notifyInfo = notifying_TrackInfo->head;
            SEC_spin_unlock_irqrestore(&notifying_TrackInfo->tcp_info_lock, flags);
            if (notifyInfo != NULL)
            {
                result  =   access_ok( VERIFY_WRITE, (void *)buf, count);	// This buffer should be verified because it is already blocked buffer.
                if (result != 0)
                {
                    leftLen = notifyInfo->urlLen - notifyInfo->notify_Index;    // Get left size
                    if ( leftLen <= count)              // If buffer is enough, it would be last block
                    {
                        writeCount  = leftLen;
                        notifyFlag  = 1;
                    }
                    result  = copy_to_user(buf, &(notifyInfo->url[notifyInfo->notify_Index]), writeCount);      // Check the result because it is blocked function
                    if (result == 0)
                    {
                        result  = writeCount;
                        notifyInfo->notify_Index += writeCount;
                        if (notifyFlag == 1)
                        {
                            notifyInfo->status = NOTIFIED;
                            notifyInfo = getFirst_tcp_TrackInfo(notifying_TrackInfo);
                            add_tcp_TrackInfo(notified_TrackInfo, notifyInfo);
                        }
                    }
                }
                break;      // Return result
            }
            else
            {
                interruptible_sleep_on(&user_noti_Q);
            }
        }
    }
    return (ssize_t)result;
}
Exemple #23
0
static long capi_read(struct inode *inode, struct file *file,
		      char *buf, unsigned long count)
#endif
{
	unsigned int minor = MINOR(inode->i_rdev);
	struct capidev *cdev;
	struct sk_buff *skb;
	int retval;
	size_t copied;

	if (!minor || minor > CAPI_MAXMINOR || !capidevs[minor].is_registered)
		return -ENODEV;

	cdev = &capidevs[minor];

	if ((skb = skb_dequeue(&cdev->recv_queue)) == 0) {

		if (file->f_flags & O_NONBLOCK)
			return -EAGAIN;

		for (;;) {
			interruptible_sleep_on(&cdev->recv_wait);
			if ((skb = skb_dequeue(&cdev->recv_queue)) != 0)
				break;
			if (current->signal & ~current->blocked)
				break;
		}
		if (skb == 0)
			return -ERESTARTNOHAND;
	}
	if (skb->len > count) {
		skb_queue_head(&cdev->recv_queue, skb);
		return -EMSGSIZE;
	}
	if (CAPIMSG_COMMAND(skb->data) == CAPI_DATA_B3
	    && CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND)
		CAPIMSG_SETDATA(skb->data, buf + CAPIMSG_LEN(skb->data));
	retval = copy_to_user(buf, skb->data, skb->len);
	if (retval) {
		skb_queue_head(&cdev->recv_queue, skb);
		return retval;
	}
	copied = skb->len;


	kfree_skb(skb, FREE_READ);

	return copied;
}
Exemple #24
0
/*
 * EvGetEvent() retrieves an event from the event queue assigned to
 * the user id.
 *
 * If the user ID passed in is not a registed user then -ENOENT is
 * returned.  If there are no pending events and waitflag is not
 * set then -EAGAIN is returned.  If there are no events and waitflag
 * is set then the kernel thread associated with the user ID is
 * put to sleep.
 *
 * Otherwise the event packet pointer is placed in packet and a zero
 * is returned to indicate success.
 */
int
EvGetEvent(EvUserID_t userID, int waitFlag, EvPacket_t **packet)
{
	EvPacket_t *TmpPacket;
	EvKernelInfo_t *EventUser;
	unsigned long Flags;

	read_lock_irqsave(&EvUsersLock, Flags);

	/* Make sure this is a valile user ID. */
	if ((EventUser = EvCheckUser(userID)) == NULL) {
		read_unlock_irqrestore(&EvUsersLock, Flags);
		*packet = NULL;
		return -EV_ERROR_USER_EXISTS;
	}

	spin_lock(&EventUser->EkiLock);
	read_unlock(&EvUsersLock);

	for (;;) {
		TmpPacket = EventUser->EkiHead;

		/* If there is a queued packet then get it and return. */
		if (TmpPacket) {
			EventUser->EkiHead = TmpPacket->EpNext;
			if (EventUser->EkiHead == NULL) {
				EventUser->EkiTail = NULL;
			}
			EventUser->EkiQCount--;
			spin_unlock_irqrestore(&EventUser->EkiLock, Flags);
			*packet = TmpPacket;
			return EV_NOERR;
		}

		/* No queued packet and wait flag is not set then return
		 * with a try again later indication.
		 */
		if (!waitFlag) {
			spin_unlock_irqrestore(&EventUser->EkiLock, Flags);
			*packet = NULL;
			return -EV_ERROR_NO_EVENT;
		}

		/* Other wise sleep waiting for ane event to arrive. */
		spin_unlock_irqrestore(&EventUser->EkiLock, Flags);
		interruptible_sleep_on(&EventUser->EkiWaitQ);
		spin_lock_irqsave(&EventUser->EkiLock, Flags);
	}
}
Exemple #25
0
static int findkey (key_t key)
{
	int id;
	struct semid_ds *sma;

	for (id = 0; id <= max_semid; id++) {
		while ((sma = semary[id]) == IPC_NOID)
			interruptible_sleep_on (&sem_lock);
		if (sma == IPC_UNUSED)
			continue;
		if (key == sma->sem_perm.key)
			return id;
	}
	return -1;
}
Exemple #26
0
void wait_until_sent(struct tty_struct * tty)
{
	while (!(current->signal & ~current->blocked) &&
	       !EMPTY(&tty->write_q)) {
		TTY_WRITE_FLUSH(tty);
		current->counter = 0;
		cli();
		if (EMPTY(&tty->write_q))
			break;
		else
			interruptible_sleep_on(&tty->write_q.proc_list);
		sti();
	}
	sti();
}
Exemple #27
0
int pty_open(struct tty_struct *tty, struct file * filp)
{
	if (!tty || !tty->link)
		return -ENODEV;
	tty->write = tty->link->write = pty_write;
	tty->close = tty->link->close = pty_close;
	wake_up_interruptible(&tty->read_q.proc_list);
	if (filp->f_flags & O_NDELAY)
		return 0;
	while (!tty->link->count && !(current->signal & ~current->blocked))
		interruptible_sleep_on(&tty->link->read_q.proc_list);
	if (!tty->link->count)
		return -ERESTARTSYS;
	return 0;
}
Exemple #28
0
static int findkey (key_t key)
{
	int id;
	struct msqid_ds *msq;
	
	for (id = 0; id <= max_msqid; id++) {
		while ((msq = msgque[id]) == IPC_NOID) 
			interruptible_sleep_on (&msg_lock);
		if (msq == IPC_UNUSED)
			continue;
		if (key == msq->msg_perm.key)
			return id;
	}
	return -1;
}
Exemple #29
0
static void camif_wait_for_vsync_edge(u32 edge_mask)
{
	ENTRY();

	camif_mode_set(edge_mask);

	// wait for VSYNC edge
	do {
		interruptible_sleep_on(&vsync_wait);
	} while (signal_pending(current));

	camif_mode_clear(edge_mask);
	camif_cleanfifo();
	EXIT();
}
Exemple #30
0
Fichier : jiq.c Projet : crond/dd
int jiq_read_immed(char *buf, char **start, off_t offset,
                   int len, int *eof, void *data)
{
    jiq_data.len = 0;                /* nothing printed, yet */
    jiq_data.buf = buf;              /* print in this place */
    jiq_data.jiffies = jiffies;      /* initial time */
    jiq_data.queue = &tq_immediate;  /* re-register yourself here */

    queue_task(&jiq_task, &tq_immediate); /* ready to run */
    mark_bh(IMMEDIATE_BH);
    interruptible_sleep_on(&jiq_wait);    /* sleep till completion */

    *eof = 1;
    return jiq_data.len;
}