1VCS(4) Linux Programmer's Manual VCS(4)
2
3
4
6 vcs, vcsa - virtual console memory
7
9 /dev/vcs0 is a character device with major number 7 and minor number 0,
10 usually with mode 0644 and ownership root:tty. It refers to the memory
11 of the currently displayed virtual console terminal.
12
13 /dev/vcs[1-63] are character devices for virtual console terminals,
14 they have major number 7 and minor number 1 to 63, usually mode 0644
15 and ownership root:tty. /dev/vcsa[0-63] are the same, but using
16 unsigned shorts (in host byte order) that include attributes, and pre‐
17 fixed with four bytes giving the screen dimensions and cursor position:
18 lines, columns, x, y. (x = y = 0 at the top left corner of the
19 screen.)
20
21 When a 512-character font is loaded, the 9th bit position can be
22 fetched by applying the ioctl(2) VT_GETHIFONTMASK operation (available
23 in Linux kernels 2.6.18 and above) on /dev/tty[1-63]; the value is
24 returned in the unsigned short pointed to by the third ioctl(2) argu‐
25 ment.
26
27 These devices replace the screendump ioctl(2) operations of ioctl_con‐
28 sole(2), so the system administrator can control access using filesys‐
29 tem permissions.
30
31 The devices for the first eight virtual consoles may be created by:
32
33 for x in 0 1 2 3 4 5 6 7 8; do
34 mknod -m 644 /dev/vcs$x c 7 $x;
35 mknod -m 644 /dev/vcsa$x c 7 $[$x+128];
36 done
37 chown root:tty /dev/vcs*
38
39 No ioctl(2) requests are supported.
40
42 /dev/vcs[0-63]
43 /dev/vcsa[0-63]
44
46 Introduced with version 1.1.92 of the Linux kernel.
47
49 You may do a screendump on vt3 by switching to vt1 and typing
50
51 cat /dev/vcs3 >foo
52
53 Note that the output does not contain newline characters, so some pro‐
54 cessing may be required, like in
55
56 fold -w 81 /dev/vcs3 | lpr
57
58 or (horrors)
59
60 setterm -dump 3 -file /proc/self/fd/1
61
62 The /dev/vcsa0 device is used for Braille support.
63
64 This program displays the character and screen attributes under the
65 cursor of the second virtual console, then changes the background color
66 there:
67
68 #include <unistd.h>
69 #include <stdlib.h>
70 #include <stdio.h>
71 #include <fcntl.h>
72 #include <sys/ioctl.h>
73 #include <linux/vt.h>
74
75 int
76 main(void)
77 {
78 int fd;
79 char *device = "/dev/vcsa2";
80 char *console = "/dev/tty2";
81 struct {unsigned char lines, cols, x, y;} scrn;
82 unsigned short s;
83 unsigned short mask;
84 unsigned char attrib;
85 int ch;
86
87 fd = open(console, O_RDWR);
88 if (fd < 0) {
89 perror(console);
90 exit(EXIT_FAILURE);
91 }
92 if (ioctl(fd, VT_GETHIFONTMASK, &mask) < 0) {
93 perror("VT_GETHIFONTMASK");
94 exit(EXIT_FAILURE);
95 }
96 (void) close(fd);
97 fd = open(device, O_RDWR);
98 if (fd < 0) {
99 perror(device);
100 exit(EXIT_FAILURE);
101 }
102 (void) read(fd, &scrn, 4);
103 (void) lseek(fd, 4 + 2*(scrn.y*scrn.cols + scrn.x), SEEK_SET);
104 (void) read(fd, &s, 2);
105 ch = s & 0xff;
106 if (s & mask)
107 ch |= 0x100;
108 attrib = ((s & ~mask) >> 8);
109 printf("ch=0x%03x attrib=0x%02x\n", ch, attrib);
110 s ^= 0x1000;
111 (void) lseek(fd, -2, SEEK_CUR);
112 (void) write(fd, &s, 2);
113 exit(EXIT_SUCCESS);
114 }
115
117 ioctl_console(2), tty(4), ttyS(4), gpm(8)
118
120 This page is part of release 5.07 of the Linux man-pages project. A
121 description of the project, information about reporting bugs, and the
122 latest version of this page, can be found at
123 https://www.kernel.org/doc/man-pages/.
124
125
126
127Linux 2020-06-09 VCS(4)