Re: Problem reading struct file on Mac 10.3.0
Re: Problem reading struct file on Mac 10.3.0
- Subject: Re: Problem reading struct file on Mac 10.3.0
- From: Uli Kusterer <email@hidden>
- Date: Tue, 3 Jun 2008 10:21:51 +0200
Am 14.05.2008 um 11:35 schrieb Manish Chaturvedi:
This time I can read struct proc, struct filedesc using kread()
which in turn uses kvm_read() to access the kernel virtual memory,
but when I am declaring struct file fl in method process_file() to
read individual file structures, I am getting compilation error
“error: aggregate `file fl' has incomplete type and cannot be
defined”. Unlike struct proc and struct filedesc I am not able to
kread the file structure, which is not private on Mac10.3.
lsof uses the structures successfully , then why it is not
accessible to my programme.
Is there is any special privilege required to do the same ? Please
help !
I would guess you just forgot the header that includes the "struct
file" deFINITion. You see, to not add too many dependencies that cause
a lot of recompiling, some people just deCLARE a struct in the header,
without including the other header that deFINEs it. That way, the
people who include that header and don't need to use that struct
directly don't have to include that header at all, and don't get
recompiled in that case.
E.g.: Mystruct.h:
struct Mystruct
{
int foo;
};
MyStructUser.h:
struct Mystruct; // Could do a #include "Mystruct.h" instead, causing
a dependency.
struct OtherStruct
{
struct Mystruct* pointerToMystruct;
};
MyStructUser.c:
#include "Mystruct.h" // Must be here, otherwise you can't use Mystruct.
...
If you don't have that last include of Mystruct.h, any attempt to
actually use Mystruct will fail with an error message like the one you
got, because all the OS knows is that there is a struct called
Mystruct, but not what size it is or what fields it contains. That's
what it means by 'incomplete'.
Pointers are all the same size, no matter what they point to, so you
can declare pointerToMystruct in MystructUser.h, even though it
doesn't know what's inside that pointer.
One advantage of this is that, when Mystruct changes, only people who
actually include Mystruct need to be recompiled. Those who use the
struct Mystruct; forward declaration are not affected. That is very
beneficial if you have a large project, or a header that gets included
by many others. Every additional include you keep out of a "popular"
header in your project means one more file you can change without a
near-complete recompile.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden