sys_read buffer too large

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

 



Hello all,

 

I am very new to kernel programming. In fact, I have been working on it for a week now.

 

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.

 

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.

 

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.

 

OnceI know I have the right file, I decided to print the size of the buffer.

 

The function signature is:

 

Asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count);

 

So I do:

 

Printk(KERN_INFO “Read buffer is [%d] bytes.\n”,count);

 

The particular file I am reading has 2 lines the first is 14 bytes long and the second is 30 bytes long.

 

The output from my printk statements are 8192 and 4096 respectively.

Why is the count so large?

 

Also I do a strlen(buf) and print the value as well, and it is 29 and 16 respectively.

 

Next I did  copy_from_user(tbuf,buf,strlen(buf))

And tried to print the contents of the buffer but it came out garbage.

 

Does anyone have any ideas how I can get this to work?

 

BTW: the assignment is due on Sunday so any help would be aappreciated.

 

 

 

--
Best Regards, Donald

Oracle
Donald raikes | Accessibility Specialist/ QA Engineer
Phone: +15202717608 | Mobile: +15202717608
Oracle Quality Assurance
| Tucson, Arizona

Green Oracle

Oracle is committed to developing practices and products that help protect the environment

 

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[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