⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 key.txt

📁 linux/kd.h文件中介绍了ioctl函数能够使用的命令
💻 TXT
📖 第 1 页 / 共 2 页
字号:

Defined in: /usr/include/linux/kd.h 
struct kbkeycode { 
unsigned int scancode; 
unsigned int keycode; 
} 

Example txt here. 

KDSIGACCEPT: 

This is basically the equivalent of signal(). I assume signal() calls this, as this is the way to accept signals from keyboard input. The argument passed to ioctl() is the signal number the process is willing to accept. The value is greater than 1, but less than N_SIG. 

Example txt here. 

Now that this is the first VT_* IOCTL, I want to mention we now include /usr/include/linux/vt.h, and not /usr/include/linux/kd.h anymore. I must also mention that the next two sets of IOCTLs are my favorite. VT_* and TIOCLINUX are fun IOCTLs and can be incredibly useful and powerful. 

VT_OPENQRY: 

This will return an int that is the first available console number. If tty1-tty6 were all opened consoles, it would return 7. This value will be greater than 1, but less than the maximum number of consoles (MAX_NR_CONSOLES), is currently 63 (in Linux 2.0.33). 

Example txt here. 

VT_GETSTATE: 

This gets the state of the active VT. The argument passed to ioctl() is apointer to a struct vt_stat. 

Defined in: /usr/include/linux/vt.h 
struct vt_stat { 
unsigned short v_active; /* active VT */ 
unsigned short v_signal; /* signal to send */ 
unsigned short v_state; /* vt bitmask */ 
} 

Example txt here. 

VT_GETMODE: 

This will return the mode of the active VT. The argument to ioctl() is a pointer to a struct vt_mode. 

Defined in: /usr/include/linux/vt.h 
struct vt_mode { 
char mode; /* vt mode */ 
char waitv; /* if set, hangs on write when not active */ 
short relsig; /* sig to raise on release request */ 
short acqsig; /* sig to raise on acquisition */ 
short frsig; /* unused (set to 0) */ 
} 

Example txt here. 

VT_SETMODE: 

This will set the mode of the active VT. The argument to ioctl() is a struct vt_mode. In the current kernel (which is 2.0.33) you can not set the mode to VT_ACKACQ because it will return an invalid argument. I listed vt_mode structure right above in VT_GETMODE. If you turn VT_PROCESS on and then change VTs yourself, it will turn VT_PROCESS off, effectively putting it in VT_AUTO mode again. 

VT_RELDISP: 

This will release a display. The argument you pass to ioctl() is a int to the VT number (ttyX). You will call VT_DISALLOCATE after this. This will return EINVAL if the tty mode is not VT_PROCESS (which is where the process controls the switching). 

VT_DISALLOCATE: 

This deallocates the memory associated with VT. The argument passed to ioctl() is the VT to disallocate. This would be called after VT_RELDISP. 

Example txt here. 

VT_RESIZE: 

Sets the size the kernel thinks the screensize is. The argument passed to ioctl() is a pointer a struct vt_sizes. 

Defined in: /usr/include/linux/vt.h 
struct vt_sizes { 
ushort v_rows; /* Number of rows on screen. */ 
ushort v_cols; /* Number of columns on screen. */ 
ushort v_scrollsize; /* Not longer used. */ 
} 

This does NOT change the video mode, only what the kernel's idea of the screensize. 

Example txt here. 

VT_RESIZEX: 

Sets the size the kernel thinks the screen size plus more. Notice this uses a different structure than VT_RESIZE. This includes a little bit more than VT_RESIZE does. The argument passed to ioctl() is a pointer a struct vt_consize. 

Defined in: /usr/include/linux/vt.h 
struct consize { 
unsigned short v_rows; /* rows */ 
unsigned short v_cols; /* columns */ 
unsigned short v_vlin; /* video scan lines */ 
unsigned short v_clin; /* video font heigh (must be < 32) */ 
unsigned short v_vcol; /* video column number */ 
unsigned short v_ccol; /* video font width? */ 
} 

I'm not sure what v_ccol is for. 

Example: 

VT_ACTIVATE: 

This is what happens when you do a Alt-Fx, and it switches the VT. This can be incredible useful to be able to have a program change the VTs without having to do it manually. 

Example txt here. 

VT_WAITACTIVE: 

This will sleep until you switch to the VT it is watching (or another program calls VT_SWITCH and switches, for example). When this occurs, ioctl() will return true. 

Example txt here. 

VT_LOCKSWITCH: 
VT_UNLOCKSWITCH: 

VT_LOCKSWITCH disables switching the console, and VT_UNLOCKSWITCH disables locking and allows switching. 

Example txt here. 

VT_SENDSIG: 

This is in the include file, but it isn't used linux/drivers/char anywhere. This is to send a signal to the bitmask of a VT. Because it isn't used anywhere I'm not going to include an example, I'm just mentioning this for your information. 

There are a whole series of functions with TIOCLINUX. You use a subcode (somewhat like you do with ICMP functions) to do different things. You may notice some subcodes (such as subcode 2 and 10) also take additional arguments. 

TIOCLINUX: 

We will show these subcodes in order: 

subcode 0: 
This is to dump the screen. This is obsolete now, because this is what /dev/vcsX and /dev/vcsaX now (which is what our ACS seen above uses to detect new data). Further note: subcode 0, 8, and 9 have all be replaced by /dev/vcsX and /dev/vcsaX. 

subcode 1: 
This will return task information. This is now deprecated, so avoid use of it (why would you need to use this?). 

subcode 2: 
This works with subcode 3 as well. This is for cutting and pasting. You pass it a struct that contains the subcode, the start row column, the end row and column, and the selection mode (0 for character by character, 1 for word-by-word, 2 for line-by-line cut and selecting). The characters selected (or cut) are highlighted and put into a buffer that is in the sel_buffer (in linux/drivers/char/console.c). The argument is a pointer to a struct that looks like this: 
struct { 
char subcode; /* this will be 2 */ 
short xs; /* where to start cutting (0 = left side of screen) */ 
short ys; /* where to start cutting (0 = top of the screen) */ 
short xe; /* where to end the cutting */ 
short ye; /* where to end the cutting */ 
} 

subcode 3: 
This works with subcode 2. subcode 2 cuts out some test from the console and this pastes it to the fd (from the sel_buffer mentioned above in subcode 2). 

subcode 4: 
This will unblank the screen (this is what happens when the screen saver comes on and then you hit a key). 

subcode 5: 

This is to set the lookup table defining characters in a "word", for word-by-word selection. It is user settable table that defines the characters that are considered to be alphabetic. This will be stored in inWordLut (which is in linux/drivers/char/selection.c. 

It looks like this: 
static u32 inwordLut[8] = { 
0x00000000, /* control chars */ 
0x03FF0000, /* digits */ 
0x87FFFFFE, /* uppercase and '_' */ 
0x07FFFFFE, /* lowercase */ 
0x00000000, 
0x00000000, 
0xFF7FFFFF, /* latin-1 accented letters, not multiplication sign */ 
0xFF7FFFFF /* latin-1 accented letters, not division sign */ 
}; 

subcode 6: 
This will return the shift_state. The argument passed to ioctl() is a pointer to a char. 

subcode 7: 
This will return the report_mouse. The argument passed to ioctl() is a pointer to a char. 

subcode 8: 
This dumps the screen height, cursor position, and all character attribute pairs. This is obsolete now and the kernel will report an error if you try to use it. This is because we now have /dev/vcsX and /dev/vcsaX and you can just read from there. Only use this if you have a kernel between 1.1.67 and 1.1.92. 

subcode 9: 
This will restore the width and height, cursor position, and all character attributes. If you try to use this in anything later than 1.1.92 you will get an error. Write to /dev/vcsX or /dev/vcsaX instead. 

subcode 10: 
This is what handles the power saving for new generation monitors. If you are idle for so long the screen will blank. The argument passed to this will be a pointer to a structure that includes the subcode (which will be 10) and one of the following types: 

0: Screen blanking is disabled. 
1: Video adapter registers are saved and the monitor is put into standby mode (it turns off vertical sychronization pulses). If your monitor has an Off_Mode timer, it will eventually power down by itself. 
2: The settings are saved and then it turns the monitor off (it turns off both vertical and horizontal sychronization pulses. If your monitor doesn't have an Off_Mode timer, or you want your monitor to power down immediately when the blank_timer times out, use this. 

We will use the following structure: 

struct { 
char subcode; /* This will be 10 */ 
char mode; /* 0: disable screen blanking */ 
/* 1: go into "standby" mode */ 
/* 1: go into "off" mode */ 
} 

Conclusion: 

I am sorry for the length of this article, but I wanted to give examples for many of these to show the uses of console IOCTLs. As I mentioned in the introduction, IOCTLs are being replaced by POSIX, but this is better. Why do you need console IOCTLs? There are a lot of undocumented things that you can do with console IOCTLs you can't do otherwise (for example, ACS and CAP).

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -