Re: file_operations structure

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

 




The write: foo_write in the struct file_operations struct is initializing
write , a pointer to a fn that takes the same params as foo_write, to
foo_write. Now when u say just foo_write in such an initialization , then
its a pointer to that fn.

Such pointers can be used just like any fn name in calling that fn .

So , u culd do

if struct file_operations sops; is an object of that struct , then u culd
do:

sops->write( fileptr, /* pointer to char */, sizeof(something),
/*offset*/);

and its as good as calling foo_write with respective arguments.

Narasimhamurthy Giri, Clemson University Computer Science Dept.
-------------------------------------------------------------------------------
Judge not lest ye be judged yourself.
-------------------------------------------------------------------------------


On Tue, 26 Mar 2002, Dan Erickson wrote:

>
> Hello,
> 	There is something that is highly confussing me in my quest to
> learn the linux kernel. Normally when you have a common prototype
> function, lets say, something small like a bitcounter. The bitcounter
> would need to take at least one argument, the prototype might look
> something like this....
>
> int bitcount(int integer);
>
> 	So now we have a function we can use in such a way as....
>
> int main()
> {
> 	int bitcount(int integer);
> 	int x = 5;
>
> 	printf("%d\n", bitcount(x));
> }
> 	What doesnt make sense to me is you have a prototype in a kernel
> driver such as ....
>
> static ssize_t foo_write(struct file *file, const char *buf,size_t count,
> loff_t *ppos)
> {
>         /* Can't seek (pwrite) on this device */
>         if (ppos != &file->f_pos)
>                 return -ESPIPE;
>
>         if (count) {
>                 blah = blah1;
>                 return 1;
>         }
>
>         return 0;
>
>
> and then in the file_operations structure you would say something like
>
> static struct file_operations foo = {
> 		write: foo_write
> };
>
>
> Now my question is, what does the job of giving foo_write() its args?
>
> All other normal prototypes need to be given args,
> ie)
> int bitcount(int integer);
> has been given the argument "x"....
> so... bitcount(x)
>   (from example at very top)
>
>
> I apologize for the amount of examples I have put in this post. I did it
> as I didnt quite know how to word my question properly.
>
> Thanks Alot
>
> -Dan Erickson-
> -ColdOneKnight@rogers.com-
>
> --
> 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/


[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