So, I am trying to modify evdev.c, which is an event handler driver for input devices like mouse on linux.
The problem I am having is that when I try to compile the module, I get a ton of errors saying the members of evdev cannot be found.
/home/mousedev_dbl.c:215: error: ‘struct evdev’ has no member named ‘client_lock’
/home/mousedev_dbl.c:216: error: ‘struct evdev’ has no member named ‘client_list’
/hom/mousedev_dbl.c:217: error: ‘struct evdev’ has no member named ‘client_lock’
/home/mousedev_dbl.c: In function ‘evdev_detach_client’:
/home/mousedev_dbl.c:224: error: ‘struct evdev’ has no member named ‘client_lock’
/home/mousedev_dbl.c:226: error: ‘struct evdev’ has no member named ‘client_lock’
/home/mousedev_dbl.c: In function ‘evdev_open_device’:
/home/mousedev_dbl.c:234: error: ‘struct evdev’ has no member named ‘mutex’
/home/mousedev_dbl.c:238: error: ‘struct evdev’ has no member named ‘exist’
This is only a small portion of the errors.
The struct for evdev is clearly present in the mousedev_dbl.c files I am compiling.
struct evdev {
int open;
int minor;
struct input_handle handle;
wait_queue_head_t wait;
struct evdev_client __rcu *grab;
struct list_head client_list;
spinlock_t client_lock; /* protects client_list */
struct mutex mutex;
struct device dev;
bool exist;
};
As an example, here is how it is used on line 215.
spin_lock(&evdev->client_lock);
list_add_tail_rcu(&client->node, &evdev->client_list);
spin_unlock(&evdev->client_lock);
synchronize_rcu();
What would cause these errors?? The entire file can be found here:
http://lxr.free-electrons.com/source/drivers/input/evdev.c
struct evdev_client __rcu *grab;
Is this declaration valid? (Doesn't look like to me, unless __rcu is for the preprocessor).
Seems this declaration is rendering the rest of your struct evdev garbled. Which could explain the compiler not identifying the client_list, client_lock etc.
The problem was that I was using the kernel source from the wrong version. 2.6.38 rather than 2.6.35 so the headers and the source were not mixing well.
__rcu is defined in include/linux/compiler.h as
# define __rcu __attribute__((noderef, address_space(4)))
Related
I'm new to linux.
I'm practice syscall and I want to copy struct to user.
So I write a syscall which is using copy_to_user().
But When I write and compile test.c to test my syscall appear some error.
in linux/sched.h has defined:
struct pacct_struct {
int ac_flag;
long ac_exitcode;
unsigned long ac_mem;
cputime_t ac_utime, ac_stime;
unsigned long ac_minflt, ac_majflt;
};
and then I write a program that use this struct(test.c)
#include "linux/sched.h"
#include <stdlib.h>
int main(){
struct pacct_struct *ts;
ts = (struct pacct_struct *)malloc(sizeof(struct pacct_struct));
return 0;
}
and gcc show the follow error message:
test.c:6:44: error: invalid application of 'sizeof' to incomplete type 'struct pacct_struct'
I wonder to know if it's fine to use kernel struct by include header file.
If so, do I miss something? How to make pacct_struct become a 'complete type'?
thanks.
addition:
I check preprocessor with gcc -E
I found that seems no "struct pacct_struct" being included.
Next, I going to view sched.h that I included which was created by "make headers_install" after I compile the kernel.
The file only contains some cloning flags such like "#define CSIGNAL 0x000000ff"
So, I tried to include original source file of sched.h in dir "/usr/src/linux-2.6.39.4/include/linux", but it continue showing same error 'incomplete type'.
Then I check preprocessor again.
I still can't find 'struct pacct_struct' even I include original header file
Anything in sched.h after #ifdef __KERNEL__ is disappear, What happened?
I have what I feel is a very basic issue but for some reason I can't seem to resolve it. I am getting the following errors:
drivers/cpufreq/AI_gov.h:37:2: error: unknown type name 'phase_state'
drivers/cpufreq/AI_gov.h:38:2: error: unknown type name 'phase_state'
now in my file AI_gov_phases.h I have the following typdef enum:
typedef enum{
response,
animation,
idle,
load
} phase_state;
now in the file that is throwing the error AI_gov.h I have:
#include "AI_gov_phases.h"
....
struct AI_gov_info{
struct AI_gov_cur_HW* hardware;
struct AI_gov_profile* profile;
phase_state phase;
phase_state prev_phase;
};
typedef enums are definitely one of my weaker areas so any help would be appreciated.
I am following LDD3 for learning network device driver. I just compiled the source code of snull driver and I got this compilation error:
error: ‘struct net_device’ has no member named ‘open’
I also got similar error when I try to initialize other members of struct net_device. Please help to resolve this error.
Below is the code:
struct net_device *snull_devs[2];
snull_devs[0] = alloc_netdev(sizeof(struct snull_priv), "sn%d",
snull_init);
void snull_init(struct net_device *dev)
{
ether_setup(dev); /* assign some of the fields */
dev->open = snull_open;
dev->stop = snull_release;
That book is pretty old, and this has apparently changed in more recent kernels. struct net_device now has the following member:
const struct net_device_ops *netdev_ops;
This has members like:
int (*ndo_open)(struct net_device *dev);
int (*ndo_stop)(struct net_device *dev);
So the equivalent code would be:
dev->netdev_ops->ndo_open = snull_open;
dev->netdev_ops->ndo_stop = snull_release;
But there could be other changes to the device driver environment that affect how this should be coded. I suggest you read the chapter API changes in the 2.6 kernel series.
I'm using libwebsockets and I can't compile a demo code implemented by myself.
I created the context:
struct libwebsocket_context *context;
...
context = libwebsocket_create_context(&info);
and when I try to access the members of the struct libwebsocket_context, defined in private-libwebsockets.h:
struct libwebsocket_context {
struct pollfd *fds;
struct libwebsocket **lws_lookup; /* fd to wsi */
int fds_count;
int max_fds;
int listen_port;
...
};
For example,
printf("%d\n", context->listen_port);
The compiler returns,
error: dereferencing pointer to incomplete type
Thanks!
It seems that "struct libwebsocket_context" is not known for gcc - that's why this error occures. Are you sure that definition of this structure is included from .h file? I'd suggest you to insert for example #warning or #error with some message near definition of this struct (in .h file) and try to recompile your program. Your #error or #warning message should appear while compilation. If not - it means that gcc will not also see this struct.
The fact that the struct definition is in private-libwebsockets.h suggests that you are not supposed to use the struct members directly. You can #include that header to get access to the private implementation details of the library but you probably should not do it.
I am working with pcap code and the struct udphdr seems to be defined in two includes. How to tell GCC to use a specific one?
If you want to uh_* elements , you must use -D_BSD_SOURCE macro as parameter of gcc, despite you get the following errors:
error: ‘struct udphdr’ has no member named ‘uh_sport’
error: ‘struct udphdr’ has no member named ‘uh_dport’
error: ‘struct udphdr’ has no member named ‘uh_ulen’
error: ‘struct udphdr’ has no member named ‘uh_sum’
error: ‘struct udphdr’ has no member named ‘uh_sum’
Upon looking at /usr/include/netinet/udp.h more carefully the problem is not that the same struct is defined in two different headers. In this file it is defined as:
/* UDP header as specified by RFC 768, August 1980. */
#ifdef __FAVOR_BSD
struct udphdr {
u_int16_t uh_sport; /* source port */
u_int16_t uh_dport; /* destination port */
u_int16_t uh_ulen; /* udp length */
u_int16_t uh_sum; /* udp checksum */
};
#else
struct udphdr {
u_int16_t source;
u_int16_t dest;
u_int16_t len;
u_int16_t check;
};
#endif
So it looks like it is using the POSIX version of the struct which I believe is ok.
I can't see a simple way to deal with that. I've done a few tests with #undef without success.
I would re-declare the struct you are interested in somewhere else in your own code, under a different name to avoid clashing, and then use it in the code with this new name.
This approach has problems, of course: what happens if the original header get's updated and that structure changes (some new members, others get removed), you know what I mean?
Just use the right one: netinet/udp.h under Linux:
From Linux Standard Base:
http://www.linuxbase.org/navigator/browse/type_single.php?cmd=display&id=37079