我是靠谱客的博主 贤惠刺猬,这篇文章主要介绍linux驱动程序获取设备号,Linux设备驱动程序,是否可以使用文件描述符获取次要编号?...,现在分享给大家,希望可以做个参考。

我正在为

Linux编写设备驱动程序.它创建了一个包含4个次要编号的设备.每当我们尝试以次要编号3写入设备时,我们都会想要杀死设备,目前除了打印它正在写入booga设备之外,它不会做任何其他事情.这是我当前的一些代码,如果有必要,我可以发布更多代码:

写方法:

static ssize_t booga_write (struct file *filp, const char *buf, size_t count, loff_t *f_pose) {

printk("Attempting to write to booga devicen");

/* need to protect this with a semaphore if multiple processes

will invoke this driver to prevent a race condition */

if (down_interruptible (&booga_device_stats->sem))

return (-ERESTARTSYS);

booga_device_stats->num_bytes_written += count;

up(&booga_device_stats->sem);

return count; // pretend that count bytes were written

}

如何测试:

static void run_write_test(char *device, int bufsize)

{

char *buf;

int src;

int out;

src = open(device, O_WRONLY);

if (src < 0) {

perror("Open for write failed:");

exit(1);

}

buf = (char *) malloc(sizeof(char)*(bufsize+1));

fprintf(stderr, "Attempting to write to booga devicen");

out = write(src, buf, bufsize);

fprintf(stderr, "Wrote %d bytes.n", out);

free(buf);

close(src);

}

我想知道是否有办法获得次要号码.我查看了linux / fs.h,看到文件结构有一个名为private_data的成员,但每当我试图调用它时,它会使我的系统崩溃,因为它当前设置为null.

或者,我是否应该尝试从结构文件中获取次要编号,并且应该在我第一次打开设备时尝试跟踪它?

最后

以上就是贤惠刺猬最近收集整理的关于linux驱动程序获取设备号,Linux设备驱动程序,是否可以使用文件描述符获取次要编号?...的全部内容,更多相关linux驱动程序获取设备号,Linux设备驱动程序,是否可以使用文件描述符获取次要编号?内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部