免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3978 | 回复: 4
打印 上一主题 下一主题

关于tty_driver中没有ioctl的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-30 17:14 |只看该作者 |倒序浏览
我需要写一个让键盘Caps Lock的LED周期闪烁的module,在linuxtopia官方网站找到一段源码。但是编译过程中首先出现无法找到config.h头文件的问题,网上查找说,此头文件已经废弃,于是注释掉。最终的错误,总是提示tty_driver中没有ioctl成员。我的系统为ubuntu11.10,内核版本是3.0.0.4。麻烦各位前辈赐教。
/*
*  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");
MODULE_LICENSE("GPL");

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;
        else
                *pstatus = ALL_LEDS_ON;

        (my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
                            *pstatus);
//提示ioctl不是tty_driver的成员,并且fg_console未初始化。

        my_timer.expires = jiffies + BLINK_DELAY;
        add_timer(&my_timer);
}

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.d)
                        break;
                printk(KERN_INFO "poet_atkm: console[%i/%i] #%i, tty %lx\n", i,
                       MAX_NR_CONSOLES, vc_cons.d->vc_num,
                       (unsigned long)vc_cons.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
         */
        init_timer(&my_timer);
        my_timer.function = my_timer_func;
        my_timer.data = (unsigned long)&kbledstatus;
        my_timer.expires = jiffies + BLINK_DELAY;
        add_timer(&my_timer);

        return 0;
}

static void __exit kbleds_cleanup(void)
{
        printk(KERN_INFO "kbleds: unloading...\n");
        del_timer(&my_timer);
        (my_driver->ioctl) (vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
                            RESTORE_LEDS);
}

module_init(kbleds_init);
module_exit(kbleds_cleanup);

论坛徽章:
0
2 [报告]
发表于 2012-08-13 22:25 |只看该作者
跟lz一样的代码,遇到了同样的问题,初学者,不懂。我的kernel是linux3.4.5,错误如下:
make -C /home/paulpeter/linux-3.4.5 M=/home/cc modules
make[1]: 正在进入目录 `/home/paulpeter/linux-3.4.5'
  CC [M]  /home/cc/kbleds.o
/home/cc/kbleds.c: 在函数‘my_timer_func’中:
/home/cc/kbleds.c:51:12: 错误: ‘struct tty_driver’没有名为‘ioctl’的成员
/home/cc/kbleds.c:51:30: 错误: ‘fg_console’未声明(在此函数内第一次使用)
/home/cc/kbleds.c:51:30: 附注: 每个未声明的标识符在其出现的函数内只报告一次
/home/cc/kbleds.c: 在函数‘kbleds_init’中:
/home/cc/kbleds.c:63:48: 错误: ‘fg_console’未声明(在此函数内第一次使用)
/home/cc/kbleds.c:69:37: 错误: ‘struct vc_data’没有名为‘vc_tty’的成员
/home/cc/kbleds.c: 在函数‘kbleds_cleanup’中:
/home/cc/kbleds.c:92:12: 错误: ‘struct tty_driver’没有名为‘ioctl’的成员
/home/cc/kbleds.c:92:30: 错误: ‘fg_console’未声明(在此函数内第一次使用)
make[2]: *** [/home/cc/kbleds.o] 错误 1
make[1]: *** [_module_/home/cc] 错误 2
make[1]:正在离开目录 `/home/paulpeter/linux-3.4.5'
make: *** [all] 错误 2

论坛徽章:
0
3 [报告]
发表于 2012-08-14 11:44 |只看该作者
因为tty_driver里面就是没有ioctl了啊
struct tty_driver {
        int        magic;                /* magic number for this structure */
        struct kref kref;        /* Reference management */
        struct cdev cdev;
        struct module        *owner;
        const char        *driver_name;
        const char        *name;
        int        name_base;        /* offset of printed name */
        int        major;                /* major device number */
        int        minor_start;        /* start of minor device number */
        int        num;                /* number of devices allocated */
        short        type;                /* type of tty driver */
        short        subtype;        /* subtype of tty driver */
        struct ktermios init_termios; /* Initial termios */
        int        flags;                /* tty driver flags */
        struct proc_dir_entry *proc_entry; /* /proc fs entry */
        struct tty_driver *other; /* only used for the PTY driver */

        /*
         * Pointer to the tty data structures
         */
        struct tty_struct **ttys;
        struct ktermios **termios;
        void *driver_state;

        /*
         * Driver methods
         */

        const struct tty_operations *ops;
        struct list_head tty_drivers;
};
或者里面的tty_operations里有你想要的?

内核是变动的,不要那么机械,网上找来的代码编译不过非常正常

论坛徽章:
0
4 [报告]
发表于 2012-08-14 15:02 |只看该作者
回复 3# yan97ao
我也怀疑是因为内核升级导致的问题,不过在网上没发现更多的类似案例,也不知道怎么解决这个问题。


   

论坛徽章:
0
5 [报告]
发表于 2012-08-15 10:42 |只看该作者
struct tty_operations 里面有ioctrl的,稍微改改就好了吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP