• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 如何通過(guò)udev和sys文件系統(tǒng)動(dòng)態(tài)創(chuàng)建設(shè)備結(jié)點(diǎn)

    如何通過(guò)udev和sys文件系統(tǒng)動(dòng)態(tài)創(chuàng)建設(shè)備結(jié)點(diǎn)

    作者: 時(shí)間:2011-05-10 來(lái)源:網(wǎng)絡(luò) 收藏

    在Linux2.6內(nèi)核中,devfs被認(rèn)為是過(guò)時(shí)的方法,并最終被拋棄,取代了它。Devfs的一個(gè)很重要的特點(diǎn)就是可以。那我們現(xiàn)在呢?

    本文引用地址:http://www.czjhyjcfj.com/article/150776.htm

    下面一個(gè)實(shí)例,說(shuō)明的方法。注意代碼中紅色的部分是為了實(shí)現(xiàn)動(dòng)態(tài)創(chuàng)建設(shè)備結(jié)點(diǎn)添加的。
    #include linux/module.h>
    #include linux/kernel.h>
    #include linux/init.h>
    #include linux/fs.h>
    #include linux/cdev.h>
    #include asm/uaccess.h>
    #include linux/device.h>
    MODULE_LICENSE (GPL);
    int hello_major = 252;
    int hello_minor = 0;
    int number_of_devices = 1;
    char data[50]=foobar not equal to barfoo;
    struct cdev cdev;
    dev_t dev = 0;
    static int hello_open (struct inode *inode, struct file *file)
    {
    printk (KERN_INFO Hey! device openedn);
    return 0;
    }
    static int hello_release (struct inode *inode, struct file *file)
    {
    printk (KERN_INFO Hmmm... device closedn);
    return 0;
    }
    ssize_t hello_read (struct file *filp, char *buff, size_t count, loff_t *offp)
    {
    ssize_t result = 0;
    if (copy_to_user (buff, data, sizeof(data)-1))
    result = -EFAULT;
    else
    printk (KERN_INFO wrote %d bytesn, count);
    return result;
    }
    ssize_t hello_write (struct file *filp, const char *buf, size_t count, loff_t *f_pos)
    {
    ssize_t ret = 0;
    printk (KERN_INFO Writing %d bytesn, count);
    if (count>127) return -ENOMEM;
    if (count0) return -EINVAL;
    if (copy_from_user (data, buf, count)) {
    ret = -EFAULT;
    }
    else {
    data[127]='

    主站蜘蛛池模板: 丰宁| 锦屏县| 方山县| 瑞丽市| 凤阳县| 靖安县| 商南县| 沈丘县| 久治县| 南开区| 长岛县| 新干县| 东兰县| 临武县| 横山县| 孝昌县| 马鞍山市| 台中市| 玛纳斯县| 镇坪县| 厦门市| 仁寿县| 兰州市| 彩票| 双江| 庆云县| 来安县| 福州市| 科尔| 镇原县| 刚察县| 伊川县| 涡阳县| 宾川县| 来安县| 留坝县| 车险| 兴隆县| 调兵山市| 常宁市| 墨竹工卡县|