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Última revisiónAmbos lados, revisión siguiente | ||
notas:programacion:console_ioctls_under_linux [2011/06/09 18:41] – cayu | notas:programacion:console_ioctls_under_linux [2011/06/09 18:51] – cayu | ||
---|---|---|---|
Línea 1: | Línea 1: | ||
====== Console IOCTLs Under Linux ====== | ====== Console IOCTLs Under Linux ====== | ||
- | Console IOCTLs can be very useful and powerful. These are the IOCTls that involve the console. They are the user interface to manipulation of the console. I am going to go over these console IOCTLs and give you examples of them. You can make some pretty powerful programs, whether they be general utilities or security programs, with these (such as Auto Console Switching and Console Access Protection). The structure of this article will be the name of the IOCTL, and then example source code to uses of the IOCTL. Now, I must warn you that the console IOCTLs are being replaced by POSIX functions. These IOCTLs are undocumented Linux internals and can be added or dropped without warning. I did not include all the console IOCTLs, but I included the ones that I though would be important or useful. The switch statement for each of these IOCTLs is in | + | Console IOCTLs can be very useful and powerful. These are the IOCTls that involve the console. They are the user interface to manipulation of the console. I am going to go over these console IOCTLs and give you examples of them. You can make some pretty powerful programs, whether they be general utilities or security programs, with these (such as Auto Console Switching and Console Access Protection). The structure of this article will be the name of the IOCTL, and then example source code to uses of the IOCTL. Now, I must warn you that the console IOCTLs are being replaced by POSIX functions. These IOCTLs are undocumented Linux internals and can be added or dropped without warning. I did not include all the console IOCTLs, but I included the ones that I though would be important or useful. The switch statement for each of these IOCTLs is in |
linux/ | linux/ | ||
- | The function prototype for ioctl() as defined in / | ||
- | is: | ||
- | int ioctl(int fd, int request, ...) | ||
- | Technically the ioctl function prototype | + | The function prototype |
- | fd' is a lot clearer. | + | |
- | ' | + | <code c> |
- | | + | |
- | arguments we are passing to ioctl(). When getting values from ioctl() we | + | </code> |
- | use a pointer and when the function returns, the value will be stored in | + | |
- | our argument. ioctl() is specified in /usr/ | + | |
- | We will now briefly describe the IOCTLs, the arguments it uses, and an | + | Technically the ioctl function prototype uses 'int d' but I think 'int fd' is a lot clearer. |
- | 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 | + | 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. |
- | Although you can turn the LEDs on or off with KDSETLED (described next) | + | It places one of the following values (or a combination of them) into a pointer, that points to a long int: |
- | | + | |
- | It places one of the following values (or a combination of them) | + | |
- | | + | |
- | 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) | + | Defined |
- | 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: | + | |
+ | * 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 2044: | Línea 2036: | ||
(which will be 10) and one of the following types: | (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 | + | * 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. |
- | standby mode (it turns off vertical sychronization pulses). | + | * 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' |
- | 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 2066: | Línea 2051: | ||
</ | </ | ||
- | | + | Conclusion: |
- | I am sorry for the length of this article, but I wanted to give | + | |
+ | 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 | examples for many of these to show the uses of console IOCTLs. As I | ||
mentioned in the introduction, | mentioned in the introduction, | ||
Línea 2074: | Línea 2060: | ||
otherwise (for example, ACS and CAP). | otherwise (for example, ACS and CAP). | ||
- | Shok (Matt Conover) | ||
- | Email: shok@dataforce.net | + | Shok (Matt Conover)\\ |
+ | Email: shok@dataforce.net | ||
Web: http:// | Web: http:// |
notas/programacion/console_ioctls_under_linux.txt · Última modificación: 2011/06/10 12:24 por cayu