Herramientas de usuario

Herramientas del sitio


notas:programacion:console_ioctls_under_linux

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anteriorRevisión previa
Próxima revisión
Revisión previa
Última revisiónAmbos lados, revisión siguiente
notas:programacion:console_ioctls_under_linux [2011/06/09 18:41] cayunotas: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/drivers/char/vt.c. Other interesting code to look at would be (all in linux/drivers/char) conmakehash.c, console.c, consolemap.c, keyboard.c, tty_io.c, vc_screen.c, vga.c. Other interesting files (also in linux/drivers/char) are console_struct.h, consolemap.h, kbd_kern.h, vt_kern.h, and uni_hash.tbl. We are going to be using the IOCTLs defined in /usr/include/linux/kd.h, and /usr/include/linux/vt.h. linux/drivers/char/vt.c. Other interesting code to look at would be (all in linux/drivers/char) conmakehash.c, console.c, consolemap.c, keyboard.c, tty_io.c, vc_screen.c, vga.c. Other interesting files (also in linux/drivers/char) are console_struct.h, consolemap.h, kbd_kern.h, vt_kern.h, and uni_hash.tbl. We are going to be using the IOCTLs defined in /usr/include/linux/kd.h, and /usr/include/linux/vt.h.
  
-The function prototype for ioctl() as defined in /usr/include/sys/ioctl.h  
-is: 
-  int ioctl(int fd, int request, ...)  
  
-  Technically the ioctl function prototype uses 'int d' but I think 'int +The function prototype for ioctl() as defined in /usr/include/sys/ioctl.h is:
-  fd' is a lot clearer.+
  
-  'fd' is the file descriptor of the console (/dev/tty), 'request' is the +<code c> 
-  IOCTL we are requesting (such as KDGETLED)and '...' is argp, the +  int ioctl(int fd, int request, ...) 
-  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/include/sys/ioctl.h+
  
-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.+ 
 +'fd' is the file descriptor of the console (/dev/tty), 'request' is the 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 /usr/include/sys/ioctl.h 
 + 
 +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. 
-  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:
-  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: /usr/include/linux/kd.h 
- 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 in: /usr/include/linux/kd.h
-  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:+  * 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 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't have an Off_Mode timer, or you want your monitor to power down immediately when the blank_timer times out, use this.
-    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:+We will use the following structure:
  
 <code c> <code c>
Línea 2066: Línea 2051:
 </code> </code>
  
-  Conclusion: +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, IOCTLs are being replaced by POSIX, but mentioned in the introduction, IOCTLs are being replaced by POSIX, but
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://www.w00w00.org Web: http://www.w00w00.org
notas/programacion/console_ioctls_under_linux.txt · Última modificación: 2011/06/10 12:24 por cayu