The tdd_read function is called when a user process calls the read() system call to read from a device special file controlled by this device driver:
static int tdd_read(struct mode *inode, struct file *file, char *buffer, int count) { int i, len; struct tdd_buf *ptr; TRACE_TXT( "tdd_read") /* 1 */ if (MINOR(inode->i_rdev)!=TDD_READ) return -EINVAL; /* 2 */ if (qhead==0) return -ENODATA; /* 3 */ ptr = qhead; qhead = qhead->link; /* 4 */ len = count<ptr->buf_size?count:ptr->buf_size; if (verify_area(VERIFY_WRITE, buffer, len)) return -EFAULT; for (i = 0; i<count && i<ptr->buf_size; ++i) { put_user_byte(ptr->buffer[i], buffer+i); TRACE_CHR("r") } TRACE~CHR( "\n") /* 5 */ kfree_s(ptr, sizeof(struct tdd_buf)); return i; }
Once again, the buffer and count parameters into tdd_read() are a pointer to a buffer in user space and a character count which were passed as parameters into the associated read() system call, the obvious difference between this and the tdd_write() function being that this time the buffer is to receive characters from a message structure in the device driver. The numbered comments are: