Help with char device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am learning how to write a char device module. It compiles fine and sort of 
works.

1) using the semaphores causes a segfault, which is why they are commented out
2) a user program using open on the device works, but gets 3 garbage 
characters at the end of the string
3) cat on the device just prints the line for ever

What am I doing wrong, or not doing at all?


ssize_t my_read(struct file * filp, char * buf, size_t count, loff_t * fpos) 
{

	ssize_t ret;
	struct semaphore sem;
	char my_buf[] = "This is a test of what it can do.";

	//if (down_interruptible(&sem))
	//	return -ERESTARTSYS;

	if(count > strlen(my_buf))
		count = strlen(my_buf);

	ret = copy_to_user(buf, my_buf, count);

	//up(&sem);

	return count - ret;
}
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux