* Implementation of read( ) @ 2004-01-26 20:16 Vineet Joglekar 2004-01-26 21:28 ` Steven Smith 2004-01-26 22:51 ` Glynn Clements 0 siblings, 2 replies; 3+ messages in thread From: Vineet Joglekar @ 2004-01-26 20:16 UTC (permalink / raw) To: linux-c-programming Hi all, I dont know if this question is relevant on this mailing list, but please do help me out if you can. For my project, I need to trace the read() function call till the VFS level. I have read that read() makes the kernel invoke sys_read() and I want to do the same thing with some additional functionalities. Where can i get the implementation of the read() function so that on the parallel lines I will be able to write my own my_read() function which in turn will call the sys_read() too? Thanks and regards, Vineet _______________________________________________ Join Excite! - http://www.excite.com The most personalized portal on the Web! ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Implementation of read( ) 2004-01-26 20:16 Implementation of read( ) Vineet Joglekar @ 2004-01-26 21:28 ` Steven Smith 2004-01-26 22:51 ` Glynn Clements 1 sibling, 0 replies; 3+ messages in thread From: Steven Smith @ 2004-01-26 21:28 UTC (permalink / raw) To: Vineet Joglekar; +Cc: linux-c-programming [-- Attachment #1: Type: text/plain, Size: 1193 bytes --] > I have read that read() makes the kernel invoke sys_read() Yup. > and I want to do the same thing with some additional > functionalities. Where can i get the implementation of the read() > function so that on the parallel lines I will be able to write my > own my_read() function which in turn will call the sys_read() too? Nowadays, most programs will use glibc's implementation of read, which is in the glibc source (sysdeps/unix/sysv/linux/i386/syscall.S, mostly). There is, however, a macro in asm/unistd.h in the kernel source pool which will do the basics for you. The code goes like this: #include <asm/unistd.h> #define __NR_private_read __NR_read _syscall3(int, private_read, int, fd, char *, buf, size_t, size); Calling private_read will then make the read system call directly without going through libc. Strictly speaking, it is valid to just redefine read in the obvious way, but that gets horribly confusing. The alternative approach is to call your function read, taking advantage of the fact that a normal symbol will override one of the weak symbols in libc, and then just call __libc_read when you need to use the libc implementation. Steven Smith, sos22@cam.ac.uk [-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Implementation of read( ) 2004-01-26 20:16 Implementation of read( ) Vineet Joglekar 2004-01-26 21:28 ` Steven Smith @ 2004-01-26 22:51 ` Glynn Clements 1 sibling, 0 replies; 3+ messages in thread From: Glynn Clements @ 2004-01-26 22:51 UTC (permalink / raw) To: vintya; +Cc: linux-c-programming Vineet Joglekar wrote: > I dont know if this question is relevant on this mailing list, but > please do help me out if you can. > > For my project, I need to trace the read() function call till the VFS > level. I have read that read() makes the kernel invoke sys_read() and > I want to do the same thing with some additional functionalities. > Where can i get the implementation of the read() function so that on > the parallel lines I will be able to write my own my_read() function > which in turn will call the sys_read() too? read() is part of libc. However, it's just a trivial wrapper around the corresponding system call; the "source code" in sysdeps/unix/syscalls.list is just: read - read i:ibn __libc_read __read read The glibc build system generates the corresponding read.c file from the above line using the sysdeps/unix/make-syscalls.sh script. If you want to see the code, the simplest solution is to build glibc. -- Glynn Clements <glynn.clements@virgin.net> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-01-26 22:51 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-01-26 20:16 Implementation of read( ) Vineet Joglekar 2004-01-26 21:28 ` Steven Smith 2004-01-26 22:51 ` Glynn Clements
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).