<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jul 20, 2013 at 2:04 PM, Don Raikes <span dir="ltr"><<a href="mailto:don.raikes@oracle.com" target="_blank">don.raikes@oracle.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal">Hello all,<u></u><u></u></p><p class="MsoNormal">
<u></u> <u></u></p><p class="MsoNormal">I am very new to kernel programming. In fact, I have been working on it for a week now.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I am taking a computer science class, and one of our assignments is to hook some of the system calls in a 2.6.28 kernel.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I have the basic module created, and I am hooking into the sys_read function. The assignment is to print to the log what is being read using sys_read.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">I have some checks in my function to limit my printing to only a certain file, so I don’t get the contents of every file being read on the system.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">OnceI know I have the right file, I decided to print the size of the buffer.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">The function signature is:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count);<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">So I do:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Printk(KERN_INFO “Read buffer is [%d] bytes.\n”,count);<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">The particular file I am reading has 2 lines the first is 14 bytes long and the second is 30 bytes long.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">The output from my printk statements are 8192 and 4096 respectively.<u></u><u></u></p><p class="MsoNormal">Why is the count so large?</p></div></div></blockquote>
<div>I think it is the size of one PAGE.I think reading from sys_read<br>is PAGE aligned.Just print the size of the page and i think it will<br></div><div>be 4K. <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal"><u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Also I do a strlen(buf) and print the value as well, and it is 29 and 16 respectively.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Next I did copy_from_user(tbuf,buf,strlen(buf))<u></u><u></u></p><p class="MsoNormal">And tried to print the contents of the buffer but it came out garbage.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Does anyone have any ideas how I can get this to work?<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">BTW: the assignment is due on Sunday so any help would be aappreciated.<span class="HOEnZb"><font color="#888888"><u></u><u></u></font></span></p>
<span class="HOEnZb"><font color="#888888"><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">-- <br>
Best Regards, Donald<u></u><u></u></span></p><p class="MsoNormal"><a href="http://www.oracle.com/" target="_blank"><span style="font-size:12.0pt;text-decoration:none;font-family:"Times New Roman","serif""><img alt="Oracle" height="26" border="0" width="114"></span></a><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><br>
</span><span style="font-size:10.0pt;font-family:"Verdana","sans-serif";color:#666666">Donald raikes | Accessibility Specialist/ QA Engineer<br>Phone: <a href="tel:+15202717608" target="_blank"><span style="color:black">+15202717608</span></a> | Mobile: <a href="tel:+15202717608" target="_blank"><span style="color:black">+15202717608</span></a> <br>
</span><span style="font-size:10.0pt;font-family:"Verdana","sans-serif";color:red">Oracle</span><span style="font-size:10.0pt;font-family:"Verdana","sans-serif";color:#666666"> Quality Assurance<br>
| Tucson, Arizona </span><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><u></u><u></u></span></p><table border="0" cellpadding="0"><tbody><tr><td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><a href="http://www.oracle.com/commitment" target="_blank"><span style="font-size:12.0pt;text-decoration:none;font-family:"Times New Roman","serif""><img alt="Green Oracle" height="28" border="0" width="44"></span></a><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><u></u><u></u></span></p>
</td><td style="padding:.75pt .75pt .75pt .75pt"><p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Verdana","sans-serif";color:#4b7d42">Oracle is committed to developing practices and products that help protect the environment</span><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><u></u><u></u></span></p>
</td></tr></tbody></table><p class="MsoNormal"><u></u> <u></u></p></font></span></div></div><br>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br></blockquote></div><br></div></div>