아래 코드를 컴파일 중입니다.
#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
내 것도 여기서 봐야 해요 . 내가 놓친 조언이 있나요?