mmap failed always - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

mmap failed always

Dear all:

I want to do framebuffer programming, with following program, I always get error while calling mmap. After checking with manual, I still can't solve it. Can Someone help me to see what's wrong?

[color=Blue]The error message on console is:[/color]

[color=Red]Error number is 22
mmap: Invalid argument[/color]

[color=Blue]The program part is:[/color]

#include
#include
#include
#include
#include
#include
#include
#include
#include

struct fb_var_screeninfo vinfo;

#define handle_error(msg)
do { perror(msg); exit(EXIT_FAILURE); } while (0)

int main(void) {
int fbfd,fbsize,i;
unsigned char *fbbuf;

if((fbfd=open("/dev/fb0",O_RDWR))<0){
printf("Failed to open /dev/fb0
");
exit(1);
}
else{
printf("Success to open /dev/fb0
");
printf("The fbfd is %d
",fbfd);
}

if(ioctl(fbfd,FBIOGET_VSCREENINFO,&vinfo)){
printf("Failed to get vscreen info ioctl
");
exit(2);
}
else{
printf("X resolution %d
",vinfo.xres);
printf("Y resolution %d
",vinfo.yres);
printf("Bit by pixed %d
",vinfo.bits_per_pixel);
}

fbsize = vinfo.xres*vinfo.yres*vinfo.bits_per_pixel/8;

printf("frame size is %d bytes
",fbsize);
[color=Red]
fbbuf = mmap(NULL,fbsize,PROT_READ|PROT_WRITE, MAP_SHARED, fbfd,0);

if(fbbuf ==MAP_FAILED){
printf("Error number is %d
",errno);
handle_error("mmap");
exit(3);
}[/color]

Sign In or Register to comment.