linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Gives Bus error in memcpy() in coping /dev/fb0 to a file.
@ 2007-03-07 11:50 Vishal Soni
  2007-03-08 13:05 ` Antonino A. Daplas
  2007-03-09  4:59 ` Vishal Soni
  0 siblings, 2 replies; 8+ messages in thread
From: Vishal Soni @ 2007-03-07 11:50 UTC (permalink / raw)
  To: linux-fbdev-devel

[-- Attachment #1: Type: text/plain, Size: 670 bytes --]

hello,

I am trying to get the snapshot of the screen through a c program by mmaping
the framebuffer device /dev/fb0 .
For this i compiled kernel with virtual framebuffer support and passing
vga=791 as boot line argument.

Though i am able to get snapshot by
[root@tw pcapp]# cat /dev/fb0 > frame

and see it on the screen by
[root@tw pcapp]# cat frame > /dev/fb0

But when i try to capture the frame buffer using the below c code, It gives
bus error @ memcpy()

Output :::::::::

[root@tw pcapp]# ./pcapp
1024x768, 16bpp
framebuffer device mapped to memory @ 0xb7db3000.
FB_FRAME mapped to memory @ 0xb7c33000.
Bus error
[root@tw pcapp]#

Any pointers plz !!!!!
Vishal

[-- Attachment #2: pcapp.c --]
[-- Type: text/x-csrc, Size: 1694 bytes --]

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>

#define FB_FILE "/dev/fb0"
#define FB_FRAME "fb_frame"

int main (int argc, char *argv[])
{
	int fdin = -1;
	int fdout = -1;
	char *src = NULL;
	char *dst = NULL;
	struct fb_var_screeninfo vinfo;
	long int screensize = 0;

	if ((fdin = open (FB_FILE, O_RDONLY)) < 0) {
		printf ("Faile to open %s file", FB_FILE);
		return 0;
	}

	/* open/create the output file */
	if ((fdout = open (FB_FRAME, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
		printf ("faile to open %s for writing", FB_FRAME);
		return -1;
	}

	// Get variable screen information
	if (ioctl(fdin, FBIOGET_VSCREENINFO, &vinfo)) {
		printf("Error reading variable information.\n");
		return -1;
	}

	printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );

	// Calculate the size of the screen in bytes
	screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
	
	// Map the device to memory
	src = (char *)mmap(0, screensize, PROT_READ, MAP_SHARED, fdin, 0);
	if ((int)src == -1) {
		printf("Error: failed to map framebuffer device to memory.\n");
		return -1;
	}

	/* mmap the FB_FRAME file */
	dst = mmap (0, screensize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fdout, 0);
	if ((int)dst == -1) {
		printf("FB_FRAME:: mmap error  ");
		return -1;
	}
	
	printf("framebuffer device mapped to memory @ %p.\n", src);
	printf("FB_FRAME mapped to memory @ %p.\n", dst);
	/* copy /dev/fb0 to fb_frame file */
	memcpy (dst, src, screensize);
	close(fdin);
	close(fdout);
	return 0;
} 

[-- Attachment #3: Type: text/plain, Size: 345 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #4: Type: text/plain, Size: 182 bytes --]

_______________________________________________
Linux-fbdev-devel mailing list
Linux-fbdev-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-fbdev-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-03-09 17:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-07 11:50 Gives Bus error in memcpy() in coping /dev/fb0 to a file Vishal Soni
2007-03-08 13:05 ` Antonino A. Daplas
2007-03-08 17:39   ` Nuno Lucas
2007-03-08 21:49     ` Antonino A. Daplas
     [not found]   ` <200703091021.46041.vishal.soni@samsung.com>
2007-03-09  8:54     ` Antonino A. Daplas
2007-03-09  4:59 ` Vishal Soni
2007-03-09  9:09   ` Vishal Soni
2007-03-09 17:55     ` Antonino A. Daplas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).