以下のコードをコンパイルしています。
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/miscdevice.h>
unsigned long js,je,diff;
static int sample_open(struct inode *inode, struct file *file)
{
pr_info("I have been awoken\n");
return 0;
}
static int sample_close(struct inode *inodep, struct file *filp)
{
pr_info("Sleepy time\n");
return 0;
}
static ssize_t sample_write(struct file *file, const char __user *buf,
size_t len, loff_t *ppos)
{
pr_info("Yummy - I just ate %d bytes\n", len);
return 1;
}
static ssize_t sample_read(struct file *filp, char __user *buf,
size_t count, loff_t *f_pos)
{
pr_info("I'm reading something\n");
return 0;
}
static const struct file_operations sample_fops = {
.owner = THIS_MODULE,
.write = sample_write,
.open = sample_open,
.release = sample_close,
.read = sample_read,
};
struct miscdevice sample_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "lab3",
.fops = &sample_fops,
};
static int hello_init(void)
{
js = jiffies;
printk(KERN_ALERT "Hello, world\n");
printk("This is the tick time %u", 1000/HZ);
return 0;
}
static void hello_exit(void)
{
je = jiffies;
diff = (je - js)* 1000/HZ;
printk(KERN_ALERT "Goodbye, cruel world\n");
printk("This is time difference in seconds %ld %ld s\n", diff / 1000, diff % 1000);
}
static int __init misc_init(void)
{
int error;
error = misc_register(&sample_device);
if (error) {
pr_err("can't misc_register :(\n");
return error;
}
hello_init();
return 0;
}
static void __exit misc_exit(void)
{
misc_deregister(&sample_device);
hello_exit();
}
module_init(misc_init)
module_exit(misc_exit)
make
いいですね。期待どおりに出力が受信されます。ところで実行をしてみるとdmesg | tail -1
登録された機器番号が見えませんね。また、実行すると、cat /proc/misc
次のような出力が表示されます。
58 mymisc1
232 kvm
235 autofs
234 btrfs-control
59 cpu_dma_latency
227 mcelog
236 device-mapper
223 uinput
1 psaux
196 vfio
200 tun
60 udmabuf
237 loop-control
61 lightnvm
183 hw_random
228 hpet
229 fuse
62 ecryptfs
231 snapshot
242 rfkill
63 vga_arbiter
lab3
私のものもここで見なければなりません。私が逃したアドバイスはありますか?