mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-27 20:14:27 +01:00
character device failure TODO, mknoddev use awk
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
Automatically create the device under /dev on insmod, and remove on rmmod.
|
Automatically create the device under /dev on insmod, and remove on rmmod.
|
||||||
|
|
||||||
|
TODO: by itself works, but if I try to cat character_device.ko after removing this, that OOPS!
|
||||||
|
|
||||||
https://stackoverflow.com/questions/5970595/create-a-device-node-in-code/
|
https://stackoverflow.com/questions/5970595/create-a-device-node-in-code/
|
||||||
https://stackoverflow.com/questions/5970595/how-to-create-a-device-node-from-the-init-module-code-of-a-linux-kernel-module/18594761#18594761
|
https://stackoverflow.com/questions/5970595/how-to-create-a-device-node-from-the-init-module-code-of-a-linux-kernel-module/18594761#18594761
|
||||||
*/
|
*/
|
||||||
@@ -39,7 +41,8 @@ static const struct file_operations fops = {
|
|||||||
static int myinit(void)
|
static int myinit(void)
|
||||||
{
|
{
|
||||||
/* cat /proc/devices */
|
/* cat /proc/devices */
|
||||||
alloc_chrdev_region(&major, 0, 1, NAME "_proc");
|
if (alloc_chrdev_region(&major, 0, 1, NAME "_proc")) {
|
||||||
|
};
|
||||||
/* ls /sys/class */
|
/* ls /sys/class */
|
||||||
myclass = class_create(THIS_MODULE, NAME "_sys");
|
myclass = class_create(THIS_MODULE, NAME "_sys");
|
||||||
/* ls /dev/ */
|
/* ls /dev/ */
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
dev="$1"
|
dev="$1"
|
||||||
major="$(grep "$dev" /proc/devices | cut -d ' ' -f 1)"
|
major="$(awk -F ' ' '$2 == "'"$dev"'" { print $1 }' /proc/devices)"
|
||||||
mknod "/dev/$dev" c "$major" 0
|
mknod "/dev/$dev" c "$major" 0
|
||||||
|
|||||||
Reference in New Issue
Block a user