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! [root@nellai root]# strace cat /dev/mydevice execve("/bin/cat", ["cat", "/dev/mydevice"], [/* 35 vars */]) = 0 uname({sys="Linux", node="nellai", ...}) = 0 brk(0) = 0x804c3a4 open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/i686/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/lib/i686/mmx", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/lib/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/lib/i686", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/lib/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/lib/mmx", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/lib", {st_mode=S_IFDIR|0755, st_size=36864, ...}) = 0 open("/usr/openwin/lib/i686/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/openwin/lib/i686/mmx", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/openwin/lib/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/openwin/lib/i686", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/openwin/lib/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/openwin/lib/mmx", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/openwin/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/openwin/lib", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/X11R6/lib/i686/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/X11R6/lib/i686/mmx", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/X11R6/lib/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/X11R6/lib/i686", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/X11R6/lib/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/X11R6/lib/mmx", 0xbfffed60) = -1 ENOENT (No such file or directory) open("/usr/X11R6/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/usr/X11R6/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 open("/etc/ld.so.cache", O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=66136, ...}) = 0 old_mmap(NULL, 66136, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40013000 close(3) = 0 open("/lib/i686/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\220Y\1"..., 1024) = 1024 fstat64(3, {st_mode=S_IFREG|0755, st_size=1395734, ...}) = 0 old_mmap(0x42000000, 1239844, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x42000000 mprotect(0x42126000, 35620, PROT_NONE) = 0 old_mmap(0x42126000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x126000) = 0x42126000 old_mmap(0x4212b000, 15140, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED| MAP_ANONYMOUS, -1, 0) = 0x4212b000 close(3) = 0 old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40024000 munmap(0x40013000, 66136) = 0 brk(0) = 0x804c3a4 brk(0x804d3a4) = 0x804d3a4 brk(0x804e000) = 0x804e000 open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=1830272, ...}) = 0 mmap2(NULL, 1830272, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40025000 close(3) = 0 fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 3), ...}) = 0 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 write(1, "hello\0", 6hello) = 6 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); if(copy_to_user(buf, msg, count)) return -EFAULT; *offset += count; return count; } > > Gaurav > > > On Tue, 29 Mar 2005 14:42:18 +0530, Mandeep Sandhu > <Mandeep_Sandhu@xxxxxxxxxxx> wrote: > > hi all, > > > > I had written a small character driver under kernel 2.4.20. > > For starters I had implemented it's read method only. This > > would put a constant string "hello" into the user-space > > buffer. The problem I'm seeing is that when i "cat" my device > > it does not print anything on the console (i.e cat and not the > > printk's in my driver...they get printed fine!). strace of cat > > shows that it calls my drivers read method twice...first time > > i copy the constant string into the user's buffer and return the > > bytes copied....and on the second invocation i return 0 as there's > > nothing more to read. strace shows cat writing out to the std. > > output after the first read....but nothing comes on the console!! > > if I put '\n' character in my constant string it prints out the > > string correctly! I'm guessing the newline char causes the o/p > > stream to be flushed....is this expected behavior?? > > > > TIA, > > -mandeep > > > > -- > > Kernelnewbies: Help each other learn about the Linux kernel. > > Archive: http://mail.nl.linux.org/kernelnewbies/ > > FAQ: http://kernelnewbies.org/faq/ > > > > -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/