file_operations structure

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

 




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/


[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