Re: My confussion on how general kernel functions work

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

 



aha!! welcome to the mysterious world of computing...

I hope this analogy fits.. if you're working or
teaching, you receive commands from your immediate
superior (your teacher/manager).. who inturn gets
orders from someone else... but your orders are to
'do' something.. these orders can be considered
parameters to the function..

however our job is just to carry out those activities
without questioning (reminds me of 'charge of the
light brigade')..

in the same way the write function you mentioned gets
its parameter from the kernel.. now the question: how
does the kernel know what to do?

the answer is two fold and lies in the primary
actvities that the kernel performs:
1. manage the system resources
2. enable the user to carry out his activities

so when the kernel manages the system resources, it
generated the parameters by itself... like for example
writing to a log file.. it know which is the log file
(user defined and what to write[bytes].. and the
information.. and bingo it know which write does the
real job (pointing to your write implementation)) and
the call happens..

when the user asks the system to write to a
file/device (in any language), the parameters are got
from the user and passed to the write function that
you have implements to that particular device to carry
out the operation.

However not that the if the user asks to write to a
file "something/something", this is a human
representation of the data.. and if this recides on a
physical store, the kernel representation could be
disk 2, track 4 sector 6.. so the kernel interprets
the human readable convention to the machine readable
and passes the parameters.. 

this is where the kernel intervenes and can pass
additional parameters/modify the parameters.

hope this explains..
Sharath


--- Dan Erickson <coldoneknight@rogers.com> wrote:
> 
> 	I have asked this question before, but I didnt get
> a response from 
> somebody who understood my question correctly. So..
> I will try showing a 
> couple more examples.
> 
> 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.
> 
> Thanks for your help
> 
> -Dan Erickson-
> -ColdOneKnight@rogers.com-



=====
-Sharath

__________________________________________________
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