int
snd_seq_oss_read(seq_oss_devinfo_t *dp, char __user *buf, int count)
{
	seq_oss_readq_t *readq = dp->readq;
	int cnt, pos;
	evrec_t *q;
	unsigned long flags;

	if (readq == NULL || ! is_read_mode(dp->file_mode))
		return -EIO;

	/* copy queued events to read buffer */
	cnt = count;
	pos = 0;
	q = snd_seq_oss_readq_pick(readq, !is_nonblock_mode(dp->file_mode), &flags);
	if (q == NULL)
		return 0;
	do {
		int ev_len;
		/* tansfer the data */
		ev_len = ev_length(q);
		if (copy_to_user(buf + pos, q, ev_len)) {
			snd_seq_oss_readq_unlock(readq, flags);
			break;
		}
		snd_seq_oss_readq_free(readq, flags);
		pos += ev_len;
		cnt -= ev_len;
		if (cnt < ev_len)
			break;
	} while ((q = snd_seq_oss_readq_pick(readq, 0, &flags)) != NULL);

	return count - cnt;
}
Exemple #2
0
int
snd_seq_oss_read(struct seq_oss_devinfo *dp, char __user *buf, int count)
{
	struct seq_oss_readq *readq = dp->readq;
	int result = 0, err = 0;
	int ev_len;
	union evrec rec;
	unsigned long flags;

	if (readq == NULL || ! is_read_mode(dp->file_mode))
		return -ENXIO;

	while (count >= SHORT_EVENT_SIZE) {
		snd_seq_oss_readq_lock(readq, flags);
		err = snd_seq_oss_readq_pick(readq, &rec);
		if (err == -EAGAIN &&
		    !is_nonblock_mode(dp->file_mode) && result == 0) {
			snd_seq_oss_readq_unlock(readq, flags);
			snd_seq_oss_readq_wait(readq);
			snd_seq_oss_readq_lock(readq, flags);
			if (signal_pending(current))
				err = -ERESTARTSYS;
			else
				err = snd_seq_oss_readq_pick(readq, &rec);
		}
		if (err < 0) {
			snd_seq_oss_readq_unlock(readq, flags);
			break;
		}
		ev_len = ev_length(&rec);
		if (ev_len < count) {
			snd_seq_oss_readq_unlock(readq, flags);
			break;
		}
		snd_seq_oss_readq_free(readq);
		snd_seq_oss_readq_unlock(readq, flags);
		if (copy_to_user(buf, &rec, ev_len)) {
			err = -EFAULT;
			break;
		}
		result += ev_len;
		buf += ev_len;
		count -= ev_len;
	}
	return result > 0 ? result : err;
}