Skip to content

Commit 81cf4d7

Browse files
Nicolas Pitregregkh
authored andcommitted
vt: add VT_GETCONSIZECSRPOS to retrieve console size and cursor position
The console dimension and cursor position are available through the /dev/vcsa interface already. However the /dev/vcsa header format uses single-byte fields therefore those values are clamped to 255. As surprizing as this may seem, some people do use 240-column 67-row screens (a 1920x1080 monitor with 8x16 pixel fonts) which is getting close to the limit. Monitors with higher resolution are not uncommon these days (3840x2160 producing a 480x135 character display) and it is just a matter of time before someone with, say, a braille display using the Linux VT console and BRLTTY on such a screen reports a bug about missing and oddly misaligned screen content. Let's add VT_GETCONSIZECSRPOS for the retrieval of console size and cursor position without byte-sized limitations. The actual console size limit as encoded in vt.c is 32767x32767 so using a short here is appropriate. Then this can be used to get the cursor position when /dev/vcsa reports 255. The screen dimension may already be obtained using TIOCGWINSZ and adding the same information to VT_GETCONSIZECSRPOS might be redundant. However applications that care about cursor position also care about display size and having 2 separate system calls to obtain them separately is wasteful. Also, the cursor position can be queried by writing "\e[6n" to a tty and reading back the result but that may be done only by the actual application using that tty and not a sideline observer. Signed-off-by: Nicolas Pitre <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 80fa7a0 commit 81cf4d7

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

drivers/tty/vt/vt_ioctl.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,22 @@ int vt_ioctl(struct tty_struct *tty,
951951
(unsigned short __user *)arg);
952952
case VT_WAITEVENT:
953953
return vt_event_wait_ioctl((struct vt_event __user *)arg);
954+
955+
case VT_GETCONSIZECSRPOS:
956+
{
957+
struct vt_consizecsrpos concsr;
958+
959+
console_lock();
960+
concsr.con_cols = vc->vc_cols;
961+
concsr.con_rows = vc->vc_rows;
962+
concsr.csr_col = vc->state.x;
963+
concsr.csr_row = vc->state.y;
964+
console_unlock();
965+
if (copy_to_user(up, &concsr, sizeof(concsr)))
966+
return -EFAULT;
967+
return 0;
968+
}
969+
954970
default:
955971
return -ENOIOCTLCMD;
956972
}

include/uapi/linux/vt.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#ifndef _UAPI_LINUX_VT_H
33
#define _UAPI_LINUX_VT_H
44

5+
#include <linux/ioctl.h>
6+
#include <linux/types.h>
57

68
/*
79
* These constants are also useful for user-level apps (e.g., VC
@@ -84,4 +86,13 @@ struct vt_setactivate {
8486

8587
#define VT_SETACTIVATE 0x560F /* Activate and set the mode of a console */
8688

89+
/* get console size and cursor position */
90+
struct vt_consizecsrpos {
91+
__u16 con_rows; /* number of console rows */
92+
__u16 con_cols; /* number of console columns */
93+
__u16 csr_row; /* current cursor's row */
94+
__u16 csr_col; /* current cursor's column */
95+
};
96+
#define VT_GETCONSIZECSRPOS _IOR('V', 0x10, struct vt_consizecsrpos)
97+
8798
#endif /* _UAPI_LINUX_VT_H */

0 commit comments

Comments
 (0)