Re: char driver module prob.

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

 



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.

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


Erik

-- 
Erik Mouw
J.A.K.Mouw@xxxxxxxxxxxxxx  mouw@xxxxxxxxxxxx

Attachment: signature.asc
Description: Digital signature


[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