Skip to content
Snippets Groups Projects
Commit 61a21a88 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiele und Notizen 5.5.2025

parent 079f03c1
Branches
No related tags found
No related merge requests found
Showing
with 726 additions and 8 deletions
obj-m += hellomod-02.o obj-m += hellomod-05.o
obj-m += chardev-01.o obj-m += chardev-01.o
obj-m += chardev-02.o
obj-m += chardev-03.o
obj-m += chardev-04.o
all: all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
......
/* /*
* chardev.c: Creates a read-only char device that says how many times * chardev-01.c: Creates a read-only char device that says how many times
* you've read from the dev file * you've read from the dev file
*/ */
...@@ -158,10 +158,9 @@ static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */ ...@@ -158,10 +158,9 @@ static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
} }
/* /*
* Called when a process writes to dev file: echo "hi" > /dev/hello * Called when a process writes to dev file: echo "hi" > /dev/chardev
*/ */
static ssize_t static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{ {
printk(KERN_ALERT "Sorry, this operation isn't supported.\n"); printk(KERN_ALERT "Sorry, this operation isn't supported.\n");
return -EINVAL; return -EINVAL;
......
/* /*
* chardev.c: Creates a read-only char device that says how many times * chardev-02.c: Creates a read-only char device that says how many times
* you've read from the dev file * you've read from the dev file
*/ */
...@@ -63,7 +63,7 @@ int init_module(void) ...@@ -63,7 +63,7 @@ int init_module(void)
if( dev_Class == NULL) if( dev_Class == NULL)
{ {
printk (KERN_ALERT "Error! Class couldn't be created!\n"); printk (KERN_ALERT "Error! Class couldn't be created!\n");
return 1; return 1; // !!! 2 Fehler: (a) unregister_chrdev() fehlt, (b) 1 ist ungültig
} }
printk (KERN_INFO "Class created!\n"); printk (KERN_INFO "Class created!\n");
// Create device in /dev/... // Create device in /dev/...
...@@ -72,10 +72,12 @@ int init_module(void) ...@@ -72,10 +72,12 @@ int init_module(void)
if (chr_dev == NULL) if (chr_dev == NULL)
{ {
printk( KERN_ALERT "Error! Device couldn't be created!\n" ); printk( KERN_ALERT "Error! Device couldn't be created!\n" );
return 1 ; return 1 ; // !!! 2 Fehler: (a) unregister_chrdev() und class_unregister() fehlt, (b) 1 ist ungültig
} }
return SUCCESS; return SUCCESS;
// !!! Lösung für die o.a. Probleme: selbst cleanup_module() aufrufen.
} }
/* /*
......
/*
* chardev-03.c: Creates a read-only char device that says how many times
* you've read from the dev file
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <asm/uaccess.h> /* for put_user */
MODULE_LICENSE("GPL");
/*
* Prototypes - this would normally go in a .h file
*/
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
struct class *dev_Class;
struct device *chr_dev;
#define SUCCESS 0
#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
/*
* Global variables are declared as static, so are global within the file.
*/
static int Major; /* Major number assigned to our device driver */
static int Device_Open = 0; /* Is device open?
* Used to prevent multiple access to device */
static char msg[BUF_LEN]; /* The msg the device will give when asked */
static char *msg_Ptr;
static struct file_operations fops = {
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
/*
* This function is called when the module is loaded
*/
int init_module(void)
{
Major = register_chrdev(0, DEVICE_NAME, &fops);
if (Major < 0) {
printk(KERN_ALERT "Registering char device failed with %d\n", Major);
return Major;
}
// Create module class
printk (KERN_INFO "Creating device class \"chardev\" ...\n");
dev_Class = class_create (THIS_MODULE,DEVICE_NAME);
if( dev_Class == NULL)
{
printk (KERN_ALERT "Error! Class couldn't be created!\n");
return 1; // !!! 2 Fehler: (a) unregister_chrdev() fehlt, (b) 1 ist ungültig
}
printk (KERN_INFO "Class created!\n");
// Create device in /dev/...
printk (KERN_INFO "Creating device\n");
chr_dev = device_create (dev_Class, NULL, MKDEV (Major,0), NULL, DEVICE_NAME);
if (chr_dev == NULL)
{
printk( KERN_ALERT "Error! Device couldn't be created!\n" );
return 1 ; // !!! 2 Fehler: (a) unregister_chrdev() und class_unregister() fehlt, (b) 1 ist ungültig
}
return SUCCESS;
// !!! Lösung für die o.a. Probleme: selbst cleanup_module() aufrufen.
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
printk(KERN_INFO "module chardev-3 cleanup\n");
//Unregister the device
if (chr_dev)
{
printk(KERN_INFO "Unregister device ...\n");
device_unregister(chr_dev);
printk(KERN_INFO "OK\n");
}
if (dev_Class)
{
printk(KERN_INFO "Unregister class ...\n");
class_unregister(dev_Class);
printk(KERN_INFO "OK\n");
}
printk(KERN_INFO "Unregister Chardev ...\n");
unregister_chrdev(Major, DEVICE_NAME);
printk(KERN_INFO "Device %s unregistered!\n", DEVICE_NAME);
}
/*
* Methods
*/
/*
* Called when a process tries to open the device file, like
* "cat /dev/mycharfile"
*/
static int device_open(struct inode *inode, struct file *file)
{
static int counter = 0;
if (Device_Open)
return -EBUSY;
Device_Open++;
int Minor = iminor (inode);
if (Minor)
counter = Minor;
sprintf(msg, "I already told you %d times Hello world!\n", counter++);
msg_Ptr = msg;
try_module_get(THIS_MODULE);
return SUCCESS;
}
/*
* Called when a process closes the device file.
*/
static int device_release(struct inode *inode, struct file *file)
{
Device_Open--; /* We're now ready for our next caller */
/*
* Decrement the usage count, or else once you opened the file, you'll
* never get get rid of the module.
*/
module_put(THIS_MODULE);
return 0;
}
/*
* Called when a process, which already opened the dev file, attempts to
* read from it.
*/
static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
char *buffer, /* buffer to fill with data */
size_t length, /* length of the buffer */
loff_t * offset)
{
/*
* Number of bytes actually written to the buffer
*/
int bytes_read = 0;
/*
* If we're at the end of the message,
* return 0 signifying end of file
*/
if (*msg_Ptr == 0)
return 0;
/*
* Actually put the data into the buffer
*/
while (length && *msg_Ptr) {
/*
* The buffer is in the user data segment, not the kernel
* segment so "*" assignment won't work. We have to use
* put_user which copies data from the kernel data segment to
* the user data segment.
*/
put_user(*(msg_Ptr++), buffer++);
length--;
bytes_read++;
}
/*
* Most read functions return the number of bytes put into the buffer
*/
return bytes_read;
}
/*
* Called when a process writes to dev file: echo "hi" > /dev/hello
*/
static ssize_t
device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{
printk(KERN_ALERT "Sorry, this operation isn't supported.\n");
return -EINVAL;
}
/*
* chardev-04.c: Creates a read-only char device that says how many times
* you've read from the dev file
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <asm/uaccess.h> /* for put_user */
MODULE_LICENSE("GPL");
/*
* Prototypes - this would normally go in a .h file
*/
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
struct class *dev_Class;
struct device *chr_dev;
#define SUCCESS 0
#define DEVICE_NAME "chardev2" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
/*
* Global variables are declared as static, so are global within the file.
*/
static int Major; /* Major number assigned to our device driver */
static int Device_Open = 0; /* Is device open?
* Used to prevent multiple access to device */
static char msg[BUF_LEN]; /* The msg the device will give when asked */
static char *msg_Ptr;
static struct file_operations fops = {
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
/*
* This function is called when the module is loaded
*/
int init_module(void)
{
Major = register_chrdev(0, DEVICE_NAME, &fops);
if (Major < 0) {
printk(KERN_ALERT "Registering char device failed with %d\n", Major);
return Major;
}
// Create module class
printk (KERN_INFO "Creating device class \"%s\" ...\n", DEVICE_NAME);
dev_Class = class_create (THIS_MODULE,DEVICE_NAME);
if( dev_Class == NULL)
{
printk (KERN_ALERT "Error! Class couldn't be created!\n");
return 1; // !!! 2 Fehler: (a) unregister_chrdev() fehlt, (b) 1 ist ungültig
}
printk (KERN_INFO "Class created!\n");
// Create device in /dev/...
printk (KERN_INFO "Creating device\n");
chr_dev = device_create (dev_Class, NULL, MKDEV (Major,0), NULL, DEVICE_NAME);
if (chr_dev == NULL)
{
printk( KERN_ALERT "Error! Device couldn't be created!\n" );
return 1 ; // !!! 2 Fehler: (a) unregister_chrdev() und class_unregister() fehlt, (b) 1 ist ungültig
}
return SUCCESS;
// !!! Lösung für die o.a. Probleme: selbst cleanup_module() aufrufen.
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
printk(KERN_INFO "module chardev-4 cleanup\n");
//Unregister the device
if (chr_dev)
{
printk(KERN_INFO "Unregister device ...\n");
device_unregister(chr_dev);
printk(KERN_INFO "OK\n");
}
if (dev_Class)
{
printk(KERN_INFO "Unregister class ...\n");
class_unregister(dev_Class);
printk(KERN_INFO "OK\n");
}
printk(KERN_INFO "Unregister Chardev ...\n");
unregister_chrdev(Major, DEVICE_NAME);
printk(KERN_INFO "Device %s unregistered!\n", DEVICE_NAME);
}
/*
* Methods
*/
/*
* Called when a process tries to open the device file, like
* "cat /dev/mycharfile"
*/
static int device_open(struct inode *inode, struct file *file)
{
static int counter = 0;
if (Device_Open)
return -EBUSY;
Device_Open++;
int Minor = iminor (inode);
if (Minor)
counter = Minor;
sprintf(msg, "I already told you %d times Hello world!\n", counter++);
msg_Ptr = msg;
try_module_get(THIS_MODULE);
return SUCCESS;
}
/*
* Called when a process closes the device file.
*/
static int device_release(struct inode *inode, struct file *file)
{
Device_Open--; /* We're now ready for our next caller */
/*
* Decrement the usage count, or else once you opened the file, you'll
* never get get rid of the module.
*/
module_put(THIS_MODULE);
return 0;
}
/*
* Called when a process, which already opened the dev file, attempts to
* read from it.
*/
static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
char *buffer, /* buffer to fill with data */
size_t length, /* length of the buffer */
loff_t * offset)
{
/*
* Number of bytes actually written to the buffer
*/
int bytes_read = 0;
/*
* If we're at the end of the message,
* return 0 signifying end of file
*/
if (*msg_Ptr == 0)
return 0;
/*
* Actually put the data into the buffer
*/
while (length && *msg_Ptr) {
/*
* The buffer is in the user data segment, not the kernel
* segment so "*" assignment won't work. We have to use
* put_user which copies data from the kernel data segment to
* the user data segment.
*/
put_user(*(msg_Ptr++), buffer++);
length--;
bytes_read++;
}
/*
* Most read functions return the number of bytes put into the buffer
*/
return bytes_read;
}
/*
* Called when a process writes to dev file: echo "hi" > /dev/hello
*/
static ssize_t
device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{
printk(KERN_ALERT "Sorry, this operation isn't supported.\n");
return -EINVAL;
}
l: [1048869.989202] <TASK>
l: [1048869.989204] dump_stack_lvl+0x44/0x5c
l: [1048869.989210] do_init_module.cold+0x21/0x26
l: [1048869.989213] __do_sys_finit_module+0xac/0x120
l: [1048869.989219] do_syscall_64+0x55/0xb0
l: [1048869.989223] ? vm_mmap_pgoff+0x103/0x180
l: [1048869.989227] ? syscall_exit_to_user_mode+0x1e/0x40
l: [1048869.989232] ? ksys_mmap_pgoff+0xe8/0x1f0
l: [1048869.989235] ? exit_to_user_mode_prepare+0x40/0x1e0
l: [1048869.989237] ? syscall_exit_to_user_mode+0x1e/0x40
l: [1048869.989240] ? do_syscall_64+0x61/0xb0
l: [1048869.989243] ? exit_to_user_mode_prepare+0x40/0x1e0
l: [1048869.989245] ? syscall_exit_to_user_mode+0x1e/0x40
l: [1048869.989248] ? do_syscall_64+0x61/0xb0
l: [1048869.989250] ? exit_to_user_mode_prepare+0x40/0x1e0
l: [1048869.989253] entry_SYSCALL_64_after_hwframe+0x6e/0xd8
l: [1048869.989257] RIP: 0033:0x7f5d93f207d9
l: [1048869.989259] Code: 08 89 e8 5b 5d c3 66 2e 0f 1f 84 00 00 00 00 00 90 48 89 f8 48 89 >
24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d f7 05 0d 00 f7 d8 64 89 01 48
l: [1048869.989262] RSP: 002b:00007ffd8081baa8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
l: [1048869.989264] RAX: ffffffffffffffda RBX: 000055e022ecf7a0 RCX: 00007f5d93f207d9
l: [1048869.989266] RDX: 0000000000000000 RSI: 000055dfebf194a0 RDI: 0000000000000003
l: [1048869.989267] RBP: 000055dfebf194a0 R08: 0000000000000000 R09: 00007f5d93ff92a0
l: [1048869.989268] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000
l: [1048869.989269] R13: 0000000000000000 R14: 000055e022ecf760 R15: 0000000000000000
l: [1048869.989272] </TASK>
l: [1049353.876194] Hello world 4.
l: [1049846.730590] usb 1-1.1: new full-speed USB device number 18 using xhci_hcd
l: [1049846.833628] usb 1-1.1: New USB device found, idVendor=2a03, idProduct=0043, bcdDevic>
l: [1049846.833637] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=220
l: [1049846.833641] usb 1-1.1: Product: Arduino Uno
l: [1049846.833644] usb 1-1.1: Manufacturer: Arduino Srl
l: [1049846.833647] usb 1-1.1: SerialNumber: 8543930323335131F120
l: [1049846.843682] cdc_acm 1-1.1:1.0: ttyACM0: USB ACM device
l: [1049928.172019] usb 1-1.1: USB disconnect, device number 18
l: [1053830.018442] Goodbye world 5.
l: [1053893.311904] I was assigned major number 238. To talk to
l: [1053893.311911] the driver, create a dev file with
l: [1053893.311912] 'mknod /dev/chardev c 238 0'.
l: [1053893.311914] Try various minor numbers. Try to cat and echo to
l: [1053893.311915] the device file.
l: [1053893.311916] Remove the device file and module when done.
~
cassini/home/peter/bo/2025ss/bs/20250505> mknod chardev c 238 0
mknod: chardev: Die Operation ist nicht erlaubt
cassini/home/peter/bo/2025ss/bs/20250505> sudo mknod chardev c 238 0
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev
crw-r--r-- 1 root root 238, 0 5. Mai 14:11 chardev
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> sudo mknod chardev c 238 0
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev
crw-r--r-- 1 root root 238, 0 5. Mai 14:11 chardev
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 0 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 1 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 2 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
cat: chardev: Das Gerät oder die Ressource ist belegt
cassini/home/peter/bo/2025ss/bs/20250505> echo "Hi!" > chardev
bash: chardev: Keine Berechtigung
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev
crw-r--r-- 1 root root 238, 0 5. Mai 14:11 chardev
cassini/home/peter/bo/2025ss/bs/20250505> sudo chgrp peter chardev
[sudo] Passwort für peter:
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev
crw-r--r-- 1 root peter 238, 0 5. Mai 14:11 chardev
cassini/home/peter/bo/2025ss/bs/20250505> chmod 664 chardev
chmod: Beim Setzen der Zugriffsrechte für 'chardev': Die Operation ist nicht erlaubt
cassini/home/peter/bo/2025ss/bs/20250505> sudo chmod 664 chardev
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev
crw-rw-r-- 1 root peter 238, 0 5. Mai 14:11 chardev
cassini/home/peter/bo/2025ss/bs/20250505> echo "Hi!" > chardev
bash: chardev: Das Gerät oder die Ressource ist belegt
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> echo "Hi!" > chardev
bash: chardev: Das Gerät oder die Ressource ist belegt
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> sudo rmmod chardev_01
cassini/home/peter/bo/2025ss/bs/20250505> sudo insmod chardev_01
insmod: ERROR: could not load module chardev_01: No such file or directory
cassini/home/peter/bo/2025ss/bs/20250505> sudo insmod ./chardev-01.ko
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 0 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> echo "Hi!" > chardev
bash: echo: Schreibfehler: Das Argument ist ungültig.
cassini/home/peter/bo/2025ss/bs/20250505> LANG=C echo "Hi!" > chardev
bash: echo: write error: Invalid argument
cassini/home/peter/bo/2025ss/bs/20250505>
drwxr-xr-x 2 root root 340 5. Mai 12:29 block
drwxr-xr-x 21 root root 3820 5. Mai 14:39 .
crw------- 1 root root 238, 0 5. Mai 14:39 chardev
drwxr-xr-x 2 root root 4060 5. Mai 14:39 char
crw-rw-rw- 1 root tty 5, 0 5. Mai 14:39 tty
crw-rw-rw- 1 root tty 5, 2 5. Mai 14:39 ptmx
cassini/home/peter/bo/2025ss/bs/20250505> cat /dev/chardev
cat: /dev/chardev: Keine Berechtigung
cassini/home/peter/bo/2025ss/bs/20250505> sudo cat /dev/chardev
I already told you 0 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> sudo cat /dev/chardev
I already told you 1 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> sudo rmmod chardev_02
cassini/home/peter/bo/2025ss/bs/20250505> ls -l /dev/chardev
ls: Zugriff auf '/dev/chardev' nicht möglich: Datei oder Verzeichnis nicht gefunden
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> sudo insmod ./chardev-02.ko
cassini/home/peter/bo/2025ss/bs/20250505> ls -l /dev/chardev
crw------- 1 root root 238, 0 5. Mai 14:42 /dev/chardev
cassini/home/peter/bo/2025ss/bs/20250505> sudo cat /dev/chardev
I already told you 0 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev
crw-rw-r-- 1 root peter 238, 0 5. Mai 14:11 chardev
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 1 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> sudo cat /dev/chardev
I already told you 2 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 3 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> sudo mknod chardev42 c 238 42
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev*
crw-rw-r-- 1 root peter 238, 0 5. Mai 14:11 chardev
-rw-r--r-- 1 peter peter 4097 5. Mai 14:30 chardev-01.c
-rw-r--r-- 1 peter peter 248752 5. Mai 14:38 chardev-01.ko
-rw-r--r-- 1 peter peter 47 5. Mai 14:09 chardev-01.mod
-rw-r--r-- 1 peter peter 1044 5. Mai 14:09 chardev-01.mod.c
-rw-r--r-- 1 peter peter 93992 5. Mai 14:09 chardev-01.mod.o
-rw-r--r-- 1 peter peter 156232 5. Mai 14:38 chardev-01.o
-rw-r--r-- 1 peter peter 5243 5. Mai 14:38 chardev-02.c
-rw-r--r-- 1 peter peter 268136 5. Mai 14:38 chardev-02.ko
-rw-r--r-- 1 peter peter 47 5. Mai 14:38 chardev-02.mod
-rw-r--r-- 1 peter peter 1188 5. Mai 14:38 chardev-02.mod.c
-rw-r--r-- 1 peter peter 94248 5. Mai 14:38 chardev-02.mod.o
-rw-r--r-- 1 peter peter 175368 5. Mai 14:38 chardev-02.o
crw-r--r-- 1 root root 238, 42 5. Mai 14:45 chardev42
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev42
I already told you 4 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> ls -l /dev/sda*
brw-rw---- 1 root disk 8, 0 8. Apr 07:30 /dev/sda
brw-rw---- 1 root disk 8, 1 8. Apr 07:30 /dev/sda1
brw-rw---- 1 root disk 8, 2 8. Apr 07:30 /dev/sda2
brw-rw---- 1 root disk 8, 5 8. Apr 07:30 /dev/sda5
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> sudo insmod ./chardev-03.ko cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 5 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 6 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 7 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev42
I already told you 8 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev42
I already told you 9 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> lsmod | grep chardev
chardev_03 16384 0
chardev_02 16384 0
cassini/home/peter/bo/2025ss/bs/20250505> sudo rmmod chardev_02
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev42
cat: chardev42: Kein passendes Gerät bzw. keine passende Adresse gefunden
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
cat: chardev: Kein passendes Gerät bzw. keine passende Adresse gefunden
cassini/home/peter/bo/2025ss/bs/20250505> sudo rmmod chardev_03
Getötet
cassini/home/peter/bo/2025ss/bs/20250505> sudo insmod ./chardev-03.ko
insmod: ERROR: could not insert module ./chardev-03.ko: Device or resource busy
cassini/home/peter/bo/2025ss/bs/20250505> sudo insmod ./chardev-03.ko
insmod: ERROR: could not insert module ./chardev-03.ko: Device or resource busy
cassini/home/peter/bo/2025ss/bs/20250505>
cassini/home/peter/bo/2025ss/bs/20250505> ls -l /dev/chardev2
crw------- 1 root root 238, 0 5. Mai 15:06 /dev/chardev2
cassini/home/peter/bo/2025ss/bs/20250505> cat /dev/chardev2
cat: /dev/chardev2: Keine Berechtigung
cassini/home/peter/bo/2025ss/bs/20250505> sudo cat /dev/chardev2
I already told you 0 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev
crw-rw-r-- 1 root peter 238, 0 5. Mai 14:11 chardev
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 1 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> ls -l chardev42
crw-r--r-- 1 root root 238, 42 5. Mai 14:45 chardev42
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev42
I already told you 42 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev42
I already told you 42 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 43 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 44 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 45 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev42
I already told you 42 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505> cat chardev
I already told you 43 times Hello world!
cassini/home/peter/bo/2025ss/bs/20250505>
#include <stdio.h>
int main (void)
{
printf ("Hello, world!\n");
return 0;
}
.file "hello-01.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hello, world!"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
leaq .LC0(%rip), %rdi
call puts@PLT
movl $0, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.ident "GCC: (Debian 12.2.0-14) 12.2.0"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
int main (void)
{
puts ("Hello, world!");
return 0;
}
.file "hello-02.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hello, world!"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
leaq .LC0(%rip), %rdi
call puts@PLT
movl $0, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.ident "GCC: (Debian 12.2.0-14) 12.2.0"
.section .note.GNU-stack,"",@progbits
/*
* hellomod-03.c - Does the kernel call cleanup_module() on failure?
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
MODULE_LICENSE("GPL");
int init_module(void)
{
printk(KERN_INFO "Hello world 3.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return -1;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 3.\n");
}
/*
* hellomod-04.c - Does the kernel call cleanup_module() on failure? Which error message?
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
MODULE_LICENSE("GPL");
int init_module(void)
{
printk(KERN_INFO "Hello world 4.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return -2;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 4.\n");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment