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 device\n");

/* 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 device\n");

out = write(src, buf, bufsize);

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

free(buf);

close(src);

}

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值