public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
From: Vishal Soni <vishal.soni@samsung.com>
To: Linux Newbie <linux-newbie@vger.kernel.org>
Subject: Gives Bus errory in memcpy() in coping /dev/fb0 to a file.
Date: Wed, 07 Mar 2007 13:10:25 +0530	[thread overview]
Message-ID: <200703071310.25831.vishal.soni@samsung.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 641 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

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]#



[-- 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;
} 

                 reply	other threads:[~2007-03-07  7:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200703071310.25831.vishal.soni@samsung.com \
    --to=vishal.soni@samsung.com \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox