Re: char driver module prob.

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

 



On Tue, 2005-03-29 at 12:31 +0200, Erik Mouw wrote:
> On Tue, Mar 29, 2005 at 03:54:13PM +0530, Mandeep Sandhu wrote:
> > On Tue, 2005-03-29 at 15:05 +0530, Gaurav Dhiman wrote:
> > > can you paste your strace results ?
> > > that might be of some help.
> > right, i forgot........here it is
> > 
> > NOTE: the "hello" getting printed in the length arg of
> > write is (I think!) the hello that cat wants to print!
> 
> [...]
> 
> > open("/dev/mydevice", O_RDONLY|O_LARGEFILE) = 3
> > fstat64(3, {st_mode=S_IFCHR|0644, st_rdev=makedev(254, 0), ...}) = 0
> > open("/dev/mydevice", O_RDONLY|O_LARGEFILE) = 3
> > fstat64(3, {st_mode=S_IFCHR|0644, st_rdev=makedev(254, 0), ...}) = 0
> > read(3, "hello\0", 4096)                = 6
> 
> Literial \0 after the string, so string is too long.
the '\0' got appended at the end when i created the string....
I'm don't get what you mean by string being too long.
> 
> > write(1, "hello\0", 6hello)                  = 6
> 
> \0 also gets printed by cat. I don't know what the terminal does with a
> \0, but it can be weird things.
> 
> > read(3, "", 4096)                       = 0
> > close(3)                                = 0
> > _exit(0)                                = ?
> > [root@nellai root]#
> > 
> > 
> > 
> > and here's the read method.......
> > 
> > const char msg[] = "hello";
> > 
> > static ssize_t Device_read(struct file *filp,char *buf,size_t
> > count,loff_t *offset)
> > {
> >         if (*offset >= sizeof(msg) )
> >         {
> >                 return 0;
> >         }
> > 
> >         count = sizeof(msg);
> 
> Here's your error, that should be count = strlen(msg);
> 
strlen(msg) is 5. (i.e the length of the string)
sizeof(msg) is 6. (length + the null terminating char)

so while copying data into the userspace buffer...I should
omit copying this null term ('\0') char???? won't the user
prog be expecting this at the end of the string? or it'll (cat)
handle it on it's own?

thanks for your help.
-mandeep
> 
> Erik
> 

--
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