File: con2fbmap.c

package info (click to toggle)
fbset 2.1-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 264 kB
  • ctags: 439
  • sloc: ansic: 1,454; yacc: 130; lex: 121; perl: 113; makefile: 74; sh: 15
file content (59 lines) | stat: -rw-r--r-- 1,255 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fb.h>


const char *fbpath = "/dev/fb0";		/* any frame buffer will do */

const char *programname;

void Usage(void)
{
    fprintf(stderr, "\nUsage: %s console [framebuffer]\n\n", programname);
    exit(1);
}

int main(int argc, char *argv[])
{
    int do_write = 0;
    int fd;
    struct fb_con2fbmap map;

    programname = argv[0];
    switch (argc) {
	case 3:
	    do_write = 1;
	    map.framebuffer = atoi(argv[2]);
	case 2:
	    map.console = atoi(argv[1]);
	    break;
	default:
	    Usage();
    }
    if ((fd = open(fbpath, O_RDONLY)) == -1) {
	fprintf(stderr, "open %s: %s\n", fbpath, strerror(errno));
	exit(1);
    }
    if (do_write) {
	if (ioctl(fd, FBIOPUT_CON2FBMAP, &map)) {
	    fprintf(stderr, "ioctl FBIOPUT_CON2FBMAP: %s\n", strerror(errno));
	    exit(1);
	}
    } else {
	if (ioctl(fd, FBIOGET_CON2FBMAP, &map)) {
	    fprintf(stderr, "ioctl FBIOGET_CON2FBMAP: %s\n", strerror(errno));
	    exit(1);
	}
	printf("console %d is mapped to framebuffer %d\n", map.console,
	       map.framebuffer);
    }
    close(fd);
    exit(0);
}