Re: My confussion on how general kernel functions work

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

 



--- Dan Erickson <coldoneknight@rogers.com> wrote:
> 
<snip> 

> Basicly when your writing... how shall I say....?? *normal code*,
> you use 
> your functions in such a manner as follows.
> 
> int foo;
> char *bar = "5";
> 
> foo = atoi(bar);
> 
> now here we give our funtion an argument
> 
> while when you have kernel code, instead of writing the actual
> args, you 
> basicly make up your own function like...
> 
> static ssize_t wdt_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)
>         {
>                 foo();
>                 return 1;
>         }
>         return 0;
> }
> 
> 
> What has me confussed is.... what gives this function the arguments
> so it 
> can function properly. Ie) as bar is the arg to atoi() earlier.
> 

Let me make sure that I understand you correctly:

In the example above there is a function by the name of "wdt_write". 
This function returns a value of type "ssize_t", and is passed four
arguments: 

        struct file *file, 
        const char *buf, 
        size_t count, 
        loff_t *ppos. 

Your question, if I am understanding you, is:  when function
wdt_write is executed, where does it get its passed arguments?

If this is your question, here is the answer:

It gets its arguments from the same place that atoi() in your first
example does; namely, from the code that *calls* it.

Hope this was in any way useful.

--Christine









__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.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