Ejemplo n.º 1
0
//替代EBUSY的阻塞型open
//当进程不能访问设备时等待设备
static int scull_w_open(struct inode *inode, struct file *filp)
{
	struct scull_dev *dev = &scull_w_device; /* device information */

	spin_lock(&scull_w_lock);
	while (! scull_w_available())
	{
		spin_unlock(&scull_w_lock);
		if (filp->f_flags & O_NONBLOCK)
		{
			return -EAGAIN;
		}
		if (wait_event_interruptible (scull_w_wait, scull_w_available()))
		{
			return -ERESTARTSYS; /* 告诉 fs 层做进一步处理 */
		}
		spin_lock(&scull_w_lock);
	}
	if (scull_w_count == 0)
	{
		scull_w_owner = current->uid; /* 获取所有者 */
	}
	scull_w_count++;
	spin_unlock(&scull_w_lock);

	/* then, everything else is copied from the bare scull device */
	if ((filp->f_flags & O_ACCMODE) == O_WRONLY)
	{
		scull_trim(dev);
	}
	filp->private_data = dev;
	return 0;          /* success */
}
Ejemplo n.º 2
0
static int scull_w_open(struct inode *inode, struct file *filp) {
    struct scull_dev *dev = &scull_w_device;

    spin_lock(&scull_w_lock);
    while (!scull_w_available()) {
        spin_unlock(&scull_w_lock);
        if (filp->f_flags & O_NONBLOCK) return -EAGAIN;
        if (wait_event_interruptible(scull_w_wait, scull_w_available()))
            return -ERESTARTSYS;
        spin_lock(&scull_w_lock);
    }
    if (scull_count == 0)
        scull_owner = current->uid;
    scull_w_count++;
    spin_unlock(scull_w_lock);
}
Ejemplo n.º 3
0
static int scull_w_open(struct inode *inode, struct file *filp)
{
	struct scull_dev *dev = &scull_w_device; /* device information */

	spin_lock(&scull_w_lock);
	while (! scull_w_available()) {
		spin_unlock(&scull_w_lock);
		if (filp->f_flags & O_NONBLOCK) return -EAGAIN;
		if (wait_event_interruptible (scull_w_wait, scull_w_available()))
			return -ERESTARTSYS; /* tell the fs layer to handle it */
		spin_lock(&scull_w_lock);
	}
	if (scull_w_count == 0)
		scull_w_owner = current->cred->uid.val; /* grab it */
	scull_w_count++;
	spin_unlock(&scull_w_lock);

	/* then, everything else is copied from the bare scull device */
	if ((filp->f_flags & O_ACCMODE) == O_WRONLY)
		scull_trim(dev);
	filp->private_data = dev;
	return 0;          /* success */
}