私のLinuxディレクトリのC言語で/devices
にcharデバイスを追加します。私がinsmod my_module.ko
のときだけ存在すべき架空のドライバを作成しているので、私のモジュールで私用のデバイスを作成したい。以下は、私のコードのデバイスを追加する部分ですが、私はcdev struct
を初期化してカーネルに伝えます。bashスクリプトを使用してC言語でcharデバイスを追加するには
int start_mod(void){
//Because we are dealing with a fictitious device, I want
//the driver to create my two devices with arbitrarly
//assigned major numbers.
alloc_chrdev_region(&dev_num, FIRST_MINOR, COUNT, DEVICE_NAME); // This assigns my device name
// as well as asign Major # my driver uses
cdev_init(&(my_dev->my_cdev), &fops);// This initializes my cdev struct that the kernel uses to keep track of my device
my_dev->my_cdev.owner = THIS_MODULE;
my_dev->my_cdev.ops = &fops;// fops is my file operations struct
int err = cdev_add(&(my_dev->my_cdev), dev_num, COUNT);// this in theory should give a pointer to the kernel
// to my cdev struct that I have setup to exist in my other structure.
// Now I need to officially add my device to /devices folder.
return 0;
}
カーネルにcharデバイスを正式に追加するにはどうすればよいかわかりません。
[mknod(2)](http://linux.die.net/man/2/mknod) –