I am getting the following error on my kernel code in linux for file operations.
Could you help me identify what's going wrong here?
Code:
struct GraphData{
unsigned long addr;
long time;
};
static int position = 0;
struct GraphData buffer[BUFFER_SIZE];
static int dev_open(struct inode *in,struct file *f);
static ssize_t dev_read(struct file *f,struct GraphData *out,size_t count);
static int dev_release(struct inode *inod,struct file *f);
static struct file_operations fops =
{
.read = dev_read,
.open = dev_open,
.release = dev_release
};
static int dev_open(struct inode *in, struct file *f){
printk(KERN_INFO " Device has been opened \n");
return 0;
}
static int dev_release(struct inode *in, struct file *f){
printk(KERN_INFO "Device successfully closed\n");
return 0;
}
static ssize_t dev_read(struct file *f,struct GraphData *out, size_t count)
{
int ret=0,i=0;
for(i=0;i<BUFFER_SIZE;i++)
{
count = copy_to_user(&out[i],&buffer[i],sizeof(buffer[i]));
if(count<0)
{
printk(KERN_ALERT "Copy!");
ret = -1;
}
}
return count;
}
Kernel program has file operations, device could be passed a buffer and it stores data into the buffer
User Program
#define SIZE 500
struct Buffer
{
unsigned long addr;
long time;
};
int main()
{
struct Buffer buf[SIZE];
int i=0;
int errorFlag = 0;
int fp = open("/proc/Probe",O_RDONLY);
errorFlag = read(fp,buf,1);
printf("Page Fault Address Time\n");
for(i=0;i<SIZE;i++)
{
//printf("Read worked the Page fault address is 0x%lx caught at time %ld\n",buf[i].address,buf[i].time);
printf("0x%lx %ld\n",buf[i].addr,buf[i].time);
}
close(fp);
return 0;
}
The user program opens the file descriptor, reads from device and passes the buffer for kernel devce to copy into.
Error: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types] .read = dev_read, /home/csvb/OS/assign4/hello2.c:36:12: note: (near initialization for ‘fops.read’) cc1: some warnings being treated as errors