Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > driver

Reply
Thread Tools

driver

 
 
Bill Cunningham
Guest
Posts: n/a
 
      12-27-2009

"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> What exactly are you trying to accomplish?


More than anything to understand this new code that I've never seen. I'm
looking at linux device driver books but this is the type of code that I
need to discypher. It's interesting reading and I learn more about OSs but I
want to understand more C too so where better to ask than clc? I understand
what you are saying when you say it's too advanced for me but there's two
ways to learn to swim learn basics and wade out little by little, or learn
basics and jump in the deep part with some helpers.

I also see there are no functions defined/declared here. I see what you
mean. This is just a small piece of code from something more complex
obviously.

From a guy that has no idea how to attempt macro expansion. I don't even
know what its purpose would be good for.

BTW I looked at scheme that everyone says is so simple. I think C would
be easier and more effective for me.

Bill



 
Reply With Quote
 
 
 
 
Curtis Dyer
Guest
Posts: n/a
 
      12-27-2009
On 26 Dec 2009, "Bill Cunningham" <(E-Mail Removed)> wrote:

> "Keith Thompson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> What exactly are you trying to accomplish?

>
> More than anything to understand this new code that I've
> never seen. I'm
> looking at linux device driver books but this is the type of
> code that I need to discypher. It's interesting reading and I
> learn more about OSs but I want to understand more C too so
> where better to ask than clc? I understand what you are saying
> when you say it's too advanced for me but there's two ways to
> learn to swim learn basics and wade out little by little, or
> learn basics and jump in the deep part with some helpers.


The problem here is that you seem to be assuming you have a handle
on the basics. Judging by your recent posting history, this is
still not the case. In addition to having some issues with C
syntax, there are other fundamental, more general, programming
concepts you have yet to grasp.

Attempting to deal with advanced systems programming most likely
won't help you at all. FWIW, I remember trying to learn to use the
Win32 API before I knew C. Needless to say, that was a bad idea.

<snip>

--
"Don't worry about efficiency until you've attained correctness."
~ Eric Sosman, comp.lang.c
 
Reply With Quote
 
 
 
 
Donkey Hottie
Guest
Posts: n/a
 
      12-27-2009
On 27.12.2009 3:12, Bill Cunningham wrote:
>
> struct file_operations *fops;
>
> Somewhere there is a struct called file_operations that fops points to. Am I
> making sense?
>


No. The file_operations is the *type* of the struct that fops points to.
fops does not point anything currently, it has to be assigned a value to
do so. That snippet has it uninitialized.

--
http://www.iki.fi/jarif/

A day for firm decisions!!!!! Or is it?
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      12-27-2009

"Curtis Dyer" <(E-Mail Removed)> wrote in message
news:hh78ou$9n8$(E-Mail Removed)-september.org...

> Attempting to deal with advanced systems programming most likely
> won't help you at all. FWIW, I remember trying to learn to use the
> Win32 API before I knew C. Needless to say, that was a bad idea.


It never panned out for me either. There's so much code lurking here
that I see that's out of my grasp. But keith mentioned previously that I
would walk away and do something else before learning something from this.
This is indeed deep C code.

Bill


 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      12-27-2009

"Donkey Hottie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> No. The file_operations is the *type* of the struct that fops points to.
> fops does not point anything currently, it has to be assigned a value to
> do so. That snippet has it uninitialized.


Being uninitialized you say. Is that something a declaration similar to

int a;

In this code?

Bill


 
Reply With Quote
 
Edward A. Falk
Guest
Posts: n/a
 
      12-27-2009
In article <4b36b47b$0$5331$(E-Mail Removed)>,
Bill Cunningham <(E-Mail Removed)> wrote:
>
>"Keith Thompson" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>[snip]
>
>
> An understanding of this C code for starters. There is something called
>ioctl in kernel code. But I guess it has nothing to do with this code and
>there are no functions in it.


Here's how it works: The ioctl() C library function generates a system
call in a completely architecture-dependent manner. The system call is
decoded by the kernel which will call some internal function which may
or may not be named "ioctl". Let's assume that it is, although it could
just as easily be called "do_ioctl" or "sys_ioctl", or anything else.

The internal ioctl() function will receive as one of its arguments a
file descriptor. It will use the file descriptor to look up some sort
of device control structure.

(I'm being deliberately vauge here, because I've worked on more than
one operating system in my life, and they all do things in their own way.)

The device control structure will either have an "int (*ioctl)(...);" entry
in it, or it will point to some other structure that does. One way or another,
the kernel will drill down through the data structures until it finds that
entry.

The kernel has no idea what that entry points to or what it's called. It may
in fact not point to anything (null pointer), in which case the kernel will
return an ENOTTY error (or something else, depends on the os version).

If the ioctl pointer is non-null, the kernel will assume that it points to a legitimate
ioctl function provided by a device driver, and call it. What happens next depends
on the driver in question.

By convention, a device driver named "foo" will usually name its ioctl function
"foo_ioctl()", but that's not a requirement. You could just as easily name it
"ioctl()" as long as you made it private to your driver module. (This is bad practice,
however, since it makes debugging harder.)

Under Linux especially, it gets more complicated because Linux loves to group
similar devices together and share as much code as possible, via sub-devices
and other techniques. For instance, caling ioctl() on a block device will
result in a call to the block driver ioctl() function which may handle the
call itself, or pass it on to device-type-specific (CD, Disk, etc.) ioctl
function, which in turn may pass the request onto a driver-specific ioctl
function and so forth. All of these calls will be made through further
"int (*ioctl)()" pointers.


> I have never used a int (*ioctl) or anything
>related. So with the code on this page how would I pass something from
>(*ioctl) or from void (*disconnect) ?


One of the white-light epiphanies I experienced when I was first exposed
to C was the insanely radical notion that you could have a *pointer*
to a *function* and change that pointer any time you wanted. After that
moment, I never looked back at the legacy languages I had been programming
in previously.

The way you use such a function goes back to my previous post, where I wrote

int (*foo)()
(*foo) is a function that returns int.

So what you do is refer to (*foo) as a function call.

For example:

int (*ioctl)(args); /* "ioctl" is a pointer to a function. It
* does not point to anything yet.
/

ioctl = &foo_ioctl; /* "ioctl" now points to the
* foo_ioctl() function.
*/

(*ioctl)(args); /* call foo_ioctl() /

(A couple of notes:

1) The compiler knows that if you refer to a function name alone, you
mean the address of that function, so "&foo_ioctl" can be written as
simply "foo_ioctl".

2) The compiler also knows what to do if you treat a pointer to a function
as if it were the name of a function, so "(*ioctl)(args)" can be written
as simply "ioctl(args)"

So I could have written:

int (*ioctl)(args);
ioctl = foo_ioctl;
ioctl(args);

I find that the shorter form is more common and looks better, but it does
require you to know in your head what are simple function names and what
are function pointers.

A more useful example:

int do_ioctl(fd, args)
{
struct dev_info *dev = get_dev_from_fd(fd);
struct file_operations *fops;
if (dev == NULL || dev->fops == NULL)
return ENOTTY;
fops = dev->fops;
if (fops->ioctl == NULL)
return ENOTTY;
else
return fops->ioctl(args);
}

Or even (assuming I'm confident I won't hit any NULL pointers):

int do_ioctl(fd, args)
{
return get_dev_from_fd(fd)->fops->ioctl(args);
}


>struct file_operations *fops;
>
>Somewhere there is a struct called file_operations that fops points to. Am I
>making sense?


Yes. "file_operations" is the *type* of struct that fops points to.
We neither know nor care what its actual name is.

--
-Ed Falk, http://www.velocityreviews.com/forums/(E-Mail Removed)
http://thespamdiaries.blogspot.com/
 
Reply With Quote
 
Herbert Rosenau
Guest
Posts: n/a
 
      12-30-2009
On Sun, 27 Dec 2009 02:38:07 UTC, "Bill Cunningham"
<(E-Mail Removed)> wrote:

>
> "Keith Thompson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > What exactly are you trying to accomplish?

>
> More than anything to understand this new code that I've never seen. I'm
> looking at linux device driver books but this is the type of code that I
> need to discypher.


Bill, that is far, far away from the knowledge you own currently.
Stick that back to the far future you may come in some years. You have
to learn much more of the basics of C before you gets to that
complicated level of very, very experienced experts needed to
understund a bit of programming drivers or kernel.


--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2R Deutsch ist da!
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      01-02-2010

"Herbert Rosenau" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)-ROSENAU.DE...

> Bill, that is far, far away from the knowledge you own currently.
> Stick that back to the far future you may come in some years. You have
> to learn much more of the basics of C before you gets to that
> complicated level of very, very experienced experts needed to
> understund a bit of programming drivers or kernel.


I know but I am curious as to the code I see in places (like the linux
kernel). Atleast I understand now that this is an attempt at OOP. You learn
everyday.

Bill


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
converting 32-bit driver to 64-bit driver =?Utf-8?B?SmVyZW15IFdvbmcg6buD5rOT6YeP?= Windows 64bit 9 08-20-2005 04:50 AM
Driver Question: Where To Look For Driver Version, etc. ? Robert11 Computer Support 2 06-10-2004 08:42 PM



Advertisments