国产肉体XXXX裸体137大胆,国产成人久久精品流白浆,国产乱子伦视频在线观看,无码中文字幕免费一区二区三区 国产成人手机在线-午夜国产精品无套-swag国产精品-国产毛片久久国产

新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 如何通過udev和sys文件系統(tǒng)動態(tài)創(chuàng)建設備結點

如何通過udev和sys文件系統(tǒng)動態(tài)創(chuàng)建設備結點

作者: 時間:2011-05-10 來源:網絡 收藏

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

本文引用地址:http://m.ptau.cn/article/150776.htm

下面一個實例,說明、的方法。注意代碼中紅色的部分是為了實現(xiàn)動態(tài)創(chuàng)建設備結點添加的。
#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]='