Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Unhappy fg_console undecleared error,

    I've tried to compile a module that i took from a kernel module programming guide,
     *  kbleds.c - Blink keyboard leds until the module is unloaded.
    #include <linux/module.h>
    #include <linux/config.h>
    #include <linux/init.h>
    #include <linux/tty.h>		/* For fg_console, MAX_NR_CONSOLES */
    #include <linux/kd.h>		/* For KDSETLED */
    #include <linux/console_struct.h>	/* For vc_cons */
    MODULE_DESCRIPTION("Example module illustrating the use of Keyboard LEDs.");
    MODULE_AUTHOR("Daniele Paolo Scarpazza");
    struct timer_list my_timer;
    struct tty_driver *my_driver;
    char kbledstatus = 0;
    #define BLINK_DELAY   HZ/5
    #define ALL_LEDS_ON   0x07
    #define RESTORE_LEDS  0xFF
     * Function my_timer_func blinks the keyboard LEDs periodically by invoking
     * command KDSETLED of ioctl() on the keyboard driver. To learn more on virtual 
     * terminal ioctl operations, please see file:
     *     /usr/src/linux/drivers/char/vt_ioctl.c, function vt_ioctl().
     * The argument to KDSETLED is alternatively set to 7 (thus causing the led 
     * mode to be set to LED_SHOW_IOCTL, and all the leds are lit) and to 0xFF
     * (any value above 7 switches back the led mode to LED_SHOW_FLAGS, thus
     * the LEDs reflect the actual keyboard status).  To learn more on this, 
     * please see file:
     *     /usr/src/linux/drivers/char/keyboard.c, function setledstate().
    static void my_timer_func(unsigned long ptr)
    	int *pstatus = (int *)ptr;
    	if (*pstatus == ALL_LEDS_ON)
    		*pstatus = RESTORE_LEDS;
    		*pstatus = ALL_LEDS_ON;
    	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
    	my_timer.expires = jiffies + BLINK_DELAY;
    static int __init kbleds_init(void)
    	int i;
    	printk(KERN_INFO "kbleds: loading\n");
    	printk(KERN_INFO "kbleds: fgconsole is %x\n", fg_console);
    	for (i = 0; i < MAX_NR_CONSOLES; i++) {
    		if (!vc_cons[i].d)
    		printk(KERN_INFO "poet_atkm: console[%i/%i] #%i, tty %lx\n", i,
    		       MAX_NR_CONSOLES, vc_cons[i].d->vc_num,
    		       (unsigned long)vc_cons[i].d->vc_tty);
    	printk(KERN_INFO "kbleds: finished scanning consoles\n");
    	my_driver = vc_cons[fg_console].d->vc_tty->driver;
    	printk(KERN_INFO "kbleds: tty driver magic %x\n", my_driver->magic);
    	 * Set up the LED blink timer the first time
    	my_timer.function = my_timer_func; = (unsigned long)&kbledstatus;
    	my_timer.expires = jiffies + BLINK_DELAY;
    	return 0;
    static void __exit kbleds_cleanup(void)
    	printk(KERN_INFO "kbleds: unloading...\n");
    	(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
    but , when i compile this, i get compile errors , some of them i fixed but
    i couldn't fix one,
    It says ;
    error: ‘fg_console’ undeclared (first use in this function)
    In the code it says;
    #include <linux/tty.h>		/* For fg_console, MAX_NR_CONSOLES */
    when open that header, tty.h with gedit , i couldn't see any variable named fg_console.
    How can i fix this problem ?
    My kernel version is 2.6.31-20.

    Or is there any other way to flash keyboard led ? any example module?

    Thanks in advance,

  2. #2
    try this:
    #include <linux/vt_kern.h>  //for fg_console
    But i have another compilation error:

    error: 'struct tty_driver' has no member named 'ioctl':
    it is caused by this line:

    (my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
    seems, due to changes in kernel, struct tty_driver does not include function ioctl, it is located in struct tty_operations now, but i have no any knowledge in tty drivers so i can not fix this. Can anybody compile this program for me? i think it is one of the most interesting and simplest drivers, and i want to see how it works.Please.

  3. #3
    write in your code this:

    extern int fg_console;

  4. $spacer_open
  5. #4
    for Helmik:

    change code:
    (my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED, *pstatus);

    to code:
    ((my_driver->ops)->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED, *pstatus);

  6. #5


    Thank you!!! that is what i exactly was looking for... but i have used another way already, i've mapped file and got setledstate and getledstate functions from there.

  7. #6
    Hello, I am a newbie in kernel programming and i read your posts..i tried it out with the following results.
    @crazymutant: i had the same problem as Helmik... so i replaced mydriver->ioctl by mydriver->ops...but then i got the following error...
    error: called object mydriver->ops not a function.
    Please help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts