notas:programacion:console_ioctls_under_linux
Diferencias
Muestra las diferencias entre dos versiones de la página.
Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
notas:programacion:console_ioctls_under_linux [2011/06/09 18:42] – cayu | notas:programacion:console_ioctls_under_linux [2011/06/10 12:24] (actual) – cayu | ||
---|---|---|---|
Línea 5: | Línea 5: | ||
- | The function prototype for ioctl() as defined in / | + | The function prototype for ioctl() as defined in / |
- | is: | + | |
- | int ioctl(int fd, int request, ...) | + | |
- | Technically the ioctl function prototype uses 'int d' but I think 'int | + | <code c> |
- | fd' is a lot clearer. | + | |
+ | </ | ||
- | ' | + | Technically |
- | IOCTL we are requesting (such as KDGETLED), and '...' is argp, the | + | |
- | arguments we are passing to ioctl(). When getting values from ioctl() we | + | |
- | use a pointer and when the function returns, the value will be stored in | + | |
- | our argument. ioctl() is specified in / | + | |
- | We will now briefly describe the IOCTLs, the arguments it uses, and an | + | ' |
- | example on how to use it where applicable. | + | |
+ | We will now briefly describe the IOCTLs, the arguments it uses, and an example on how to use it where applicable. | ||
KDGETLED: | KDGETLED: | ||
- | This will return the current state of the LEDs. These lights on | ||
- | your keyboard that are on or off when something such as Caps Lock is on. | ||
- | Although you can turn the LEDs on or off with KDSETLED (described next) | ||
- | without affecting the Caps Lock, Numeric Lock, or Scroll Lock. | ||
- | It places one of the following values (or a combination of them) | ||
- | into a pointer, that points to a long int: | ||
- | Defined in: / | + | This will return the current state of the LEDs. These lights on your keyboard that are on or off when something such as Caps Lock is on. |
- | 0x1 - LED_SCR, set when the Scroll | + | Although you can turn the LEDs on or off with KDSETLED (described next) without affecting |
- | 0x2 - LED_NUM, set when the Numeric Lock LED is on | + | It places one of the following values (or a combination of them) into a pointer, that points to a long int: |
- | 0x4 - LED_CAP, set when the Caps Lock LED is on | + | |
- | As I previously mentioned, it can return combinations (or the sum) | ||
- | of the LEDs turned on. For example, if the Numeric Lock and Caps Lock | ||
- | are both on, it will return 0x6 (0x2 + 0x4). So when no lights are on, | ||
- | it will return 0x0. This is also how you turn all the LEDs off as | ||
- | described next in KDSETLED. | ||
- | | + | Defined in: / |
+ | |||
+ | * 0x1 - LED_SCR, set when the Scroll Lock LED is on | ||
+ | * 0x2 - LED_NUM, set when the Numeric Lock LED is on | ||
+ | * 0x4 - LED_CAP, set when the Caps Lock LED is on | ||
+ | |||
+ | As I previously mentioned, it can return combinations (or the sum) of the LEDs turned on. For example, if the Numeric Lock and Caps Lock are both on, it will return 0x6 (0x2 + 0x4). So when no lights are on, it will return 0x0. This is also how you turn all the LEDs off as described next in KDSETLED. | ||
+ | |||
+ | Example: | ||
<code c> | <code c> | ||
Línea 100: | Línea 92: | ||
KDSETLED: | KDSETLED: | ||
- | I will not go over the values that can be passed again (LED_CAP, | ||
- | LED_NUM, LED_SCR, etc.) again because I described them for KDGETLED. The | ||
- | argument to ioctl() is a long int (I don't see why this is a long int | ||
- | considering it uses a value no higher than 7) with the number of the LED | ||
- | you want to set. If you want to set more than one LED, add the LED #'s | ||
- | you want set together (such as LED_NUM + LED_CAP). This DOES NOT turn, | ||
- | for example, Caps Lock on. This just turns the LED on the keyboard. To | ||
- | actually turn Caps Lock on use KDSKBLED. | ||
- | | + | I will not go over the values that can be passed again (LED_CAP, LED_NUM, LED_SCR, etc.) again because I described them for KDGETLED. The argument to ioctl() is a long int (I don't see why this is a long int considering it uses a value no higher than 7) with the number of the LED you want to set. If you want to set more than one LED, add the LED #'s you want set together (such as LED_NUM + LED_CAP). This DOES NOT turn, for example, Caps Lock on. This just turns the LED on the keyboard. To actually turn Caps Lock on use KDSKBLED. |
+ | |||
+ | Example: | ||
<code c> | <code c> | ||
Línea 179: | Línea 165: | ||
KDGKBLED: | KDGKBLED: | ||
- | This is exactly the same as KDGETLED, except rather than getting | + | |
- | | + | This is exactly the same as KDGETLED, except rather than getting the state of the LEDs, it gets the state of the flags themselves. |
- | Meaning, whether the LED is on or off doesn' | + | Meaning, whether the LED is on or off doesn' |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
KDSKBLED: | KDSKBLED: | ||
- | This is exactly the same as KDSETLED except it sets the flags | ||
- | rather than the states of the LEDs. In other words, we can turn the Caps | ||
- | Lock LED off and use this which will turn Caps Lock on. Now everything | ||
- | will be in uppercase even though the LED light for Caps Lock isn't on. | ||
- | | + | This is exactly the same as KDSETLED except it sets the flags rather than the states of the LEDs. In other words, we can turn the Caps Lock LED off and use this which will turn Caps Lock on. Now everything will be in uppercase even though the LED light for Caps Lock isn't on. |
- | This will turn off the Caps Lock LED and turn Caps Lock on. The | + | |
- | | + | |
- | | + | Example: |
- | | + | |
- | | + | This will turn off the Caps Lock LED and turn Caps Lock on. The reason we are turning the LED off is just to prove a point that just because the LED isn't on doesn' |
- | | + | |
Línea 268: | Línea 246: | ||
KDGKBTYPE: | KDGKBTYPE: | ||
- | This will always return KB_101 (0x02), which is the standard | ||
- | keyboard. So I am not even going to explain this. Two other values | ||
- | defined are KB_84 (0x01) and KB_OTHER (0x03). | ||
- | | + | This will always return KB_101 (0x02), which is the standard keyboard. So I am not even going to explain this. Two other values defined are KB_84 (0x01) and KB_OTHER (0x03). |
- | 0x1 - KB_84 | + | |
- | 0x2 - KB_101 (Standard/ | + | Defined in: / |
- | 0x3 - KB_OTHER | + | |
+ | * 0x1 - KB_84 | ||
+ | | ||
+ | | ||
KDGETMODE: | KDGETMODE: | ||
- | This returns the current console mode into the argument passed to | + | |
- | | + | This returns the current console mode into the argument passed to ioctl() that is a pointer to a long int. The console is by default in text mode. The two modes you have are graphics and text mode. |
- | | + | |
| | ||
- | | + | Defined in: / |
- | 0x00 - KD_TEXT | + | |
- | 0x01 - KD_GRAPHICS - Graphics Mode | + | |
- | There had been KD_TEXT0 and KD_TEXT1 but they are obsolete now. | + | * 0x00 - KD_TEXT |
+ | * 0x01 - KD_GRAPHICS - Graphics Mode | ||
- | | + | There had been KD_TEXT0 and KD_TEXT1 but they are obsolete now. |
+ | |||
+ | Example: | ||
<code c> | <code c> | ||
Línea 330: | Línea 309: | ||
| | ||
KDSETMODE: | KDSETMODE: | ||
- | This takes a long int that is either set to I assume that SVGAlib | ||
- | uses this IOCTL (even if another function calls it). The modes and | ||
- | definitions are specified above. | ||
- | | + | This takes a long int that is either set to I assume that SVGAlib uses this IOCTL (even if another function calls it). The modes and definitions are specified above. |
+ | |||
+ | |||
+ | Example: | ||
+ | |||
+ | < | ||
***** TEST IN GRAPHICS MODE ***** | ***** TEST IN GRAPHICS MODE ***** | ||
***** TEST IN GRAPHICS MODE ***** | ***** TEST IN GRAPHICS MODE ***** | ||
***** TEST IN GRAPHICS MODE ***** | ***** TEST IN GRAPHICS MODE ***** | ||
(test with code above) | (test with code above) | ||
+ | </ | ||
KDMKTONE: | KDMKTONE: | ||
- | This will generate a tone, and the amount of clock cycles are | ||
- | passed as the argument to ioctl(). Note this is different from KIOCSOUND | ||
- | which is the sound generation. | ||
- | | + | This will generate a tone, and the amount of clock cycles are passed as the argument to ioctl(). Note this is different from KIOCSOUND which is the sound generation. |
+ | |||
+ | |||
+ | Example: | ||
<code c> | <code c> | ||
Línea 398: | Línea 380: | ||
KIOCSOUND: | KIOCSOUND: | ||
- | This and KDMKTONE both make sounds but they are in fact different. | ||
- | This has tones from 0-30000 (the sounds are 1193180/ | ||
- | KDMKTONE has higher values such as, the default beep you hear when you | ||
- | get Ctrl-G (the value is 125<< | ||
- | | + | This and KDMKTONE both make sounds but they are in fact different. This has tones from 0-30000 (the sounds are 1193180/ |
- | Note, this flashes the LEDs as well for effect, they aren't needed | + | |
- | | + | |
+ | Example: | ||
+ | Note, this flashes the LEDs as well for effect, they aren't needed here. | ||
<code c> | <code c> | ||
Línea 526: | Línea 506: | ||
GIO_FONT and GIO_FONTX: | GIO_FONT and GIO_FONTX: | ||
- | These are both very similar except GIO_FONTX returns more. | ||
- | GIO_FONTX returns a struct consolefontdesc, | ||
- | the font data in expanded form (which is the same as consolefontdesc' | ||
- | chardata). The structure for consolefontdesc is: | ||
+ | These are both very similar except GIO_FONTX returns more. GIO_FONTX returns a struct consolefontdesc, | ||
+ | |||
+ | <code c> | ||
struct consolefontdesc { | struct consolefontdesc { | ||
| | ||
Línea 536: | Línea 515: | ||
char *chardata; | char *chardata; | ||
} | } | ||
+ | </ | ||
- | | + | Example: |
<code c> | <code c> | ||
#include < | #include < | ||
Línea 585: | Línea 565: | ||
PIO_FONTRESET: | PIO_FONTRESET: | ||
- | This resets the font to the default font. You would use this if | ||
- | you were playing with fonts (with PIO_FONT) and messed it up, you could | ||
- | then reset it with this. This is no longer implemented, | ||
- | something for this for historical purposes. | ||
- | | + | This resets the font to the default font. You would use this if you were playing with fonts (with PIO_FONT) and messed it up, you could then reset it with this. This is no longer implemented, |
+ | |||
+ | Example: | ||
<code c> | <code c> | ||
Línea 630: | Línea 608: | ||
KDGKBMODE: | KDGKBMODE: | ||
- | This will get the current keyboard mode (raw mode, unicode, half | ||
- | raw, etc.). The argument passed to ioctl() is a pointer to a long int. | ||
- | | + | This will get the current keyboard mode (raw mode, unicode, half raw, etc.). The argument passed to ioctl() is a pointer to a long int. |
+ | |||
+ | Possible modes are: raw, medium raw, Unicode, and xlate. | ||
| | ||
- | Defined in: / | ||
- | 0x00 - K_RAW | ||
- | 0x01 - K_XLATE (the default keyboard mode) | ||
- | 0x02 - K_MEDIUMRAW | ||
- | 0x03 - K_UNICODE | ||
- | | + | Defined in: / |
+ | |||
+ | * 0x00 - K_RAW | ||
+ | * 0x01 - K_XLATE (the default keyboard mode) | ||
+ | * 0x02 - K_MEDIUMRAW | ||
+ | * 0x03 - K_UNICODE | ||
+ | |||
+ | Example: | ||
<code c> | <code c> | ||
Línea 686: | Línea 666: | ||
KDSKBMODE: | KDSKBMODE: | ||
- | This will get the current keyboard mode (raw mode, unicode, half | + | |
- | | + | This will get the current keyboard mode (raw mode, unicode, half raw, etc.). The argument passed to ioctl() is a long int. I stated the possible values in KDGKBMODE. |
- | | + | |
- | | + | Example: |
<code c> | <code c> | ||
Línea 747: | Línea 726: | ||
KDGKBMETA: | KDGKBMETA: | ||
- | This will get the meta key handling mode. The default meta key | ||
- | handling mode is the escape prefix. | ||
- | Defined in: / | + | This will get the meta key handling mode. The default meta key handling mode is the escape prefix. |
- | 0x00 There is no meta key handling mode set. | + | |
- | 0x03 K_METABIT | + | |
- | 0x04 K_ESCPREFIX (escape prefix) | + | |
- | I believe that 0x01 is also escape prefix, but I'm not sure. I get 0x01 | + | Defined |
- | returned from KDGKBMETA but it is not defined | + | |
- | and 0x01 is not returned in the switch statement linux/ | + | |
- | Example: | + | |
+ | * 0x03 K_METABIT | ||
+ | * 0x04 K_ESCPREFIX (escape prefix) | ||
+ | |||
+ | I believe that 0x01 is also escape prefix, but I'm not sure. I get 0x01 returned from KDGKBMETA but it is not defined in / | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 800: | Línea 780: | ||
close(fd); | close(fd); | ||
} | } | ||
+ | </ | ||
KDSKBMETA: | KDSKBMETA: | ||
- | This will set the meta key handling mode. The modes are the same | ||
- | as the ones mentioned right before this in KDGKBMETA. | ||
- | | + | This will set the meta key handling mode. The modes are the same as the ones mentioned right before this in KDGKBMETA. |
+ | |||
+ | Example: | ||
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 855: | Línea 837: | ||
close(fd); | close(fd); | ||
} | } | ||
+ | </ | ||
KDGKBENT: | KDGKBENT: | ||
- | Gets an entry from the key translation table. It converts the | ||
- | keycode to an action code). You pass a struct kbentry. | ||
- | | + | Gets an entry from the key translation table. It converts the keycode to an action code). You pass a struct kbentry. |
+ | |||
+ | Defined in: / | ||
+ | |||
+ | <code c> | ||
struct kbentry { | struct kbentry { | ||
u_char | u_char | ||
Línea 866: | Línea 851: | ||
u_short kb_value; /* Value returned in here. */ | u_short kb_value; /* Value returned in here. */ | ||
} | } | ||
+ | </ | ||
- | | + | It uses key_maps[] defined in linux/ |
- | | + | |
- | | + | |
- | All the keys are greater than or equal to 0. | + | Here are the maximum values (defined in linux/ |
- | | + | <code c> |
kb_index <= NR_KEYS (NR_KEYS == 128) | kb_index <= NR_KEYS (NR_KEYS == 128) | ||
kb_table <= MAX_NR_KEYMAPS (MAX_NR_KEYMAPS == 256) | kb_table <= MAX_NR_KEYMAPS (MAX_NR_KEYMAPS == 256) | ||
- | + | </ | |
- | Example: | + | |
+ | Example: | ||
+ | |||
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 951: | Línea 938: | ||
| | ||
} | } | ||
+ | </ | ||
KDSKBENT: | KDSKBENT: | ||
- | Sets an entry in the key translation table. You pass a struct | ||
- | kbentry. See the KDGKBENT above for the structure (defined in | ||
- | / | ||
- | I am not going to include one for this.. it would have bad results. | + | Sets an entry in the key translation table. You pass a struct kbentry. See the KDGKBENT above for the structure (defined in / |
- | | + | |
- | | + | I am not going to include one for this.. it would have bad results. You set the kb_table to a value as an index to the keymap, kb_index as an index into the keymap, and kb_value as the value you want to set it to. You do not pass this as a pointer (i.e. not as &kbent as seen above. |
- | | + | |
- | | + | |
KDGKBDIACR: | KDGKBDIACR: | ||
- | This will print all the accented symbols (or characters). The | ||
- | argument passed to ioctl() is a pointer to a struct kbdiacrs. | ||
- | | + | This will print all the accented symbols (or characters). The argument passed to ioctl() is a pointer to a struct kbdiacrs. |
+ | |||
+ | Defined in: / | ||
+ | |||
+ | <code c> | ||
struct kbdiacrs { | struct kbdiacrs { | ||
unsigned int kb_cnt; | unsigned int kb_cnt; | ||
struct kbdiacr[256]; | struct kbdiacr[256]; | ||
}; | }; | ||
+ | </ | ||
- | | + | The structure kbdiacr is where the actual symbols and values are in (also defined in / |
- | | + | |
+ | <code c> | ||
struct kbdiacr { | struct kbdiacr { | ||
u_char diacr; | u_char diacr; | ||
Línea 981: | Línea 967: | ||
u_char result; | u_char result; | ||
} | } | ||
+ | </ | ||
- | | + | Example: |
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 1034: | Línea 1022: | ||
close(fd); | close(fd); | ||
} | } | ||
+ | <code c> | ||
KDGETKEYCODE: | KDGETKEYCODE: | ||
- | This one should be fairly obvious. It reads the keys from the | ||
- | kernel keycode entry. This converts the scan code to keycode. The | ||
- | argument to ioctl() is a struct kbkeycode. | ||
- | Defined in: / | + | This one should be fairly obvious. It reads the keys from the kernel keycode entry. This converts the scan code to keycode. The argument to ioctl() is a struct kbkeycode. |
+ | |||
+ | Defined in: / | ||
+ | |||
+ | <code c> | ||
struct kbkeycode { | struct kbkeycode { | ||
| | ||
| | ||
} | } | ||
+ | </ | ||
- | | + | Example: |
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 1095: | Línea 1086: | ||
} | } | ||
+ | </ | ||
KDSIGACCEPT: | KDSIGACCEPT: | ||
- | This is basically the equivalent of signal(). I assume signal() | + | 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: |
- | This will not work, sorry. But included as an example anyway. If | + | This will not work, sorry. But included as an example anyway. If anyone knows why this will not work, please let me know. I saw no indications as to why from following the signals in linux/ |
- | | + | |
- | | + | |
- | | + | |
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 1149: | Línea 1136: | ||
close(fd); | close(fd); | ||
} | } | ||
+ | </ | ||
- | + | Now that this is the first VT_* IOCTL, I want to mention we now include / | |
- | Now that this is the first VT_* IOCTL, I want to mention we now include | + | |
- | / | + | |
- | 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: | 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), | ||
+ | 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), | ||
- | | + | |
+ | Example: | ||
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 1195: | Línea 1179: | ||
close(fd); | close(fd); | ||
} | } | ||
+ | </ | ||
VT_GETSTATE: | VT_GETSTATE: | ||
- | This gets the state of the active VT. The argument passed to | ||
- | ioctl() is apointer to a struct vt_stat. | ||
- | | + | This gets the state of the active VT. The argument passed to ioctl() is apointer to a struct vt_stat. |
+ | |||
+ | Defined in: / | ||
+ | <code c> | ||
struct vt_stat { | struct vt_stat { | ||
unsigned short v_active; /* active VT */ | unsigned short v_active; /* active VT */ | ||
Línea 1206: | Línea 1192: | ||
unsigned short v_state; | unsigned short v_state; | ||
} | } | ||
+ | </ | ||
- | | + | Example |
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 1243: | Línea 1231: | ||
close(fd); | close(fd); | ||
} | } | ||
+ | </ | ||
VT_GETMODE: | VT_GETMODE: | ||
- | This will return the mode of the active VT. The argument to | ||
- | ioctl() is a pointer to a struct vt_mode. | ||
- | | + | This will return the mode of the active VT. The argument to ioctl() is a pointer to a struct vt_mode. |
+ | |||
+ | Defined in: / | ||
+ | <code c> | ||
struct vt_mode { | struct vt_mode { | ||
char mode; /* vt mode */ | char mode; /* vt mode */ | ||
Línea 1256: | Línea 1246: | ||
short frsig; | short frsig; | ||
} | } | ||
+ | </ | ||
- | | + | Example: |
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 1306: | Línea 1298: | ||
close(fd); | close(fd); | ||
} | } | ||
+ | </ | ||
VT_SETMODE: | VT_SETMODE: | ||
- | This will set the mode of the active VT. The argument to | + | |
- | | + | 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: | VT_RELDISP: | ||
- | This will release a display. The argument you pass to ioctl() is a | + | |
- | | + | 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: | VT_DISALLOCATE: | ||
- | This deallocates the memory associated with VT. The argument | + | |
- | | + | 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: | Example: | ||
+ | <code c> | ||
#include < | #include < | ||
#include < | #include < | ||
Línea 1367: | Línea 1357: | ||
close(fd); | close(fd); | ||
} | } | ||
+ | </ | ||
VT_RESIZE: | VT_RESIZE: | ||
- | Sets the size the kernel thinks the screensize is. The argument | ||
- | passed to ioctl() is a pointer a struct vt_sizes. | ||
- | | + | Sets the size the kernel thinks the screensize is. The argument passed to ioctl() is a pointer a struct vt_sizes. |
+ | |||
+ | Defined in: / | ||
<code c> | <code c> | ||
Línea 1382: | Línea 1373: | ||
</ | </ | ||
- | | + | This does NOT change the video mode, only what the kernel' |
- | | + | |
- | | + | Example: |
<code c> | <code c> | ||
Línea 1433: | Línea 1423: | ||
VT_RESIZEX: | 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. | ||
- | | + | 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: / | ||
<code c> | <code c> | ||
Línea 1451: | Línea 1439: | ||
</ | </ | ||
- | | + | I'm not sure what v_ccol is for. |
- | | + | Example: |
VT_ACTIVATE: | 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. | ||
- | | + | 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: | ||
<code c> | <code c> | ||
/* ACS - Auto Console Switching | /* ACS - Auto Console Switching | ||
Línea 1664: | Línea 1651: | ||
VT_WAITACTIVE: | 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. | ||
- | | + | 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: | ||
<code c> | <code c> | ||
#include < | #include < | ||
Línea 1703: | Línea 1689: | ||
VT_LOCKSWITCH: | VT_LOCKSWITCH: | ||
+ | |||
VT_UNLOCKSWITCH: | VT_UNLOCKSWITCH: | ||
- | VT_LOCKSWITCH disables switching the console, and VT_UNLOCKSWITCH | ||
- | disables locking and allows switching. | ||
- | | + | VT_LOCKSWITCH disables switching the console, and VT_UNLOCKSWITCH disables locking and allows switching. |
+ | |||
+ | Example: | ||
<code c> | <code c> | ||
Línea 1942: | Línea 1929: | ||
VT_SENDSIG: | VT_SENDSIG: | ||
- | This is in the include file, but it isn't used linux/ | ||
- | 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. | ||
+ | This is in the include file, but it isn't used linux/ | ||
+ | |||
+ | |||
+ | 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. | ||
- | 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: | TIOCLINUX: | ||
- | | + | We will show these subcodes in order: |
- | | + | subcode 0: |
- | This is to dump the screen. This is obsolete now, because this is | + | //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 | + | //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 | + | //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, |
- | | + | |
- | | + | The argument is a pointer to a struct that looks like this: |
- | | + | |
- | | + | |
- | | + | |
- | The argument is a pointer to a struct that looks like this: | + | |
<code c> | <code c> | ||
Línea 1986: | Línea 1962: | ||
</ | </ | ||
- | | + | subcode 3: |
- | This works with subcode 2. subcode 2 cuts out some test from the | + | //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 | + | //This will unblank the screen (this is what happens when the screen saver comes on and then you hit a key).// |
- | | + | |
- | | + | Example: |
- | Will be added | + | Will be added |
- | | + | subcode 5: |
- | This is to set the lookup table defining characters in a " | + | //This is to set the lookup table defining characters in a " |
- | | + | |
- | | + | |
- | | + | |
- | It looks like this: | + | It looks like this: |
<code c> | <code c> | ||
static u32 inwordLut[8] = { | static u32 inwordLut[8] = { | ||
Línea 2018: | Línea 1988: | ||
</ | </ | ||
- | | + | subcode 6: |
- | This will return the shift_state. The argument passed to ioctl() | + | //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() | + | //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 | + | //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 | + | //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. | + | //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. | + | * 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' | + | |
- | your monitor to power down immediately when the blank_timer | + | |
- | times out, use this. | + | |
- | | + | We will use the following structure: |
<code c> | <code c> | ||
Línea 2067: | Línea 2018: | ||
</ | </ | ||
- | | + | 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 | + | 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, |
- | mentioned in the introduction, | + | |
- | 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). | + | |
Línea 2079: | Línea 2026: | ||
Shok (Matt Conover)\\ | Shok (Matt Conover)\\ | ||
Email: shok@dataforce.net \\ | Email: shok@dataforce.net \\ | ||
- | Web: http:// | + | Web: http:// |
+ | Original: |
notas/programacion/console_ioctls_under_linux.txt · Última modificación: 2011/06/10 12:24 por cayu