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

Notizen und Beispiele 7.5.2021

parent 284f480b
Branches
No related tags found
No related merge requests found
Showing
with 943 additions and 0 deletions
Makefile-modules-2
\ No newline at end of file
obj-m += chardev-1a.o
obj-m += chardev-1b.o
obj-m += chardev-3.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
crw------- 1 root root 10, 137 Apr 6 09:59 vhci
crw------- 1 root root 10, 238 Apr 6 09:59 vhost-net
crw------- 1 root root 10, 241 Apr 6 09:59 vhost-vsock
crw-rw----+ 1 root video 81, 0 Mai 7 10:44 video0
crw-rw----+ 1 root video 81, 1 Mai 7 10:44 video1
crw-rw----+ 1 root video 81, 2 Apr 28 23:30 video4
crw------- 1 root root 10, 130 Apr 6 09:59 watchdog
crw------- 1 root root 248, 0 Apr 6 09:59 watchdog0
crw-rw-rw- 1 root root 1, 5 Apr 6 09:59 zero
cassini/home/peter/bo/2021ss/bs/20210507> ls -l /dev/chardev
crw------- 1 root root 241, 0 Mai 7 14:17 /dev/chardev
cassini/home/peter/bo/2021ss/bs/20210507> cat /dev/chardev
cat: /dev/chardev: Keine Berechtigung
cassini/home/peter/bo/2021ss/bs/20210507> sudo chmod 666 /dev/chardev
cassini/home/peter/bo/2021ss/bs/20210507> ls -l /dev/chardev
crw-rw-rw- 1 root root 241, 0 Mai 7 14:17 /dev/chardev
cassini/home/peter/bo/2021ss/bs/20210507> cat /dev/chardev
I already told you 1 times Hello world!
cassini/home/peter/bo/2021ss/bs/20210507> cat /dev/chardev
I already told you 2 times Hello world!
cassini/home/peter/bo/2021ss/bs/20210507> lsattr /dev/video0
lsattr: Die Operation wird nicht unterstützt Beim Lesen der Flags von /dev/video0
cassini/home/peter/bo/2021ss/bs/20210507> getfacl /dev/video0
getfacl: Entferne führende '/' von absoluten Pfadnamen
# file: dev/video0
# owner: root
# group: video
user::rw-
user:peter:rw-
group::rw-
mask::rw-
other::---
cassini/home/peter/bo/2021ss/bs/20210507> getfacl /dev/chardev
getfacl: Entferne führende '/' von absoluten Pfadnamen
# file: dev/chardev
# owner: root
# group: root
user::rw-
group::rw-
other::rw-
cassini/home/peter/bo/2021ss/bs/20210507>
Von der Anwendung bis zum Kernel: libc, 07.05.2021, 15:11:00
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apt-get source libc6
Datei: stdio-common/printf.c
printf() ruft vfprintf() auf.
Datei: stdio-common/vfprintf.c
vfprintf() ruft printf_positional() auf.
printf_positional() ruft outstring() auf.
outstring() ist ein Präprozessor-Macro.
outstring() ruft PUT() auf - ebenfalls ein Präprozessor-Macro.
PUT() ruft _IO_sputn() auf. --> in anderer Datei
/*
* chardev.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/fs.h>
#include <asm/uaccess.h> /* for put_user */
/*
* 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 *);
#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;
}
printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);
printk(KERN_INFO "the driver, create a dev file with\n");
printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);
printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n");
printk(KERN_INFO "the device file.\n");
printk(KERN_INFO "Remove the device file and module when done.\n");
return SUCCESS;
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
/*
* Unregister the device
*/
unregister_chrdev(Major, 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++;
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_INFO "Got user data: %s.\n", buff);
return len;
}
/*
* chardev.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/fs.h>
#include <asm/uaccess.h> /* for put_user */
/*
* 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 *);
#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;
}
printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);
printk(KERN_INFO "the driver, create a dev file with\n");
printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);
printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n");
printk(KERN_INFO "the device file.\n");
printk(KERN_INFO "Remove the device file and module when done.\n");
return SUCCESS;
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
/*
* Unregister the device
*/
unregister_chrdev(Major, 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++;
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)
{
char b[len + 1];
strncpy (b, buff, len);
b[len] = 0;
printk(KERN_INFO "Got user data: %s.\n", b);
return len;
}
/*
* chardev.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 */
/*
* 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 LCD...\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 ;
}
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);
printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);
printk(KERN_INFO "the driver, create a dev file with\n");
printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);
printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n");
printk(KERN_INFO "the device file.\n");
printk(KERN_INFO "Remove the device file and module when done.\n");
return SUCCESS;
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
/*
* Unregister the device
*/
unregister_chrdev(Major, 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++;
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.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;
}
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 ;
}
return SUCCESS;
}
/*
* 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++;
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;
}
#include <stdio.h>
int main (void)
{
printf ("Hello, world!\n");
return 0;
}
.file "hello-1.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hello, world!"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc # #include <stdio.h>
subq $8, %rsp #
.cfi_def_cfa_offset 16 # int main (void)
leaq .LC0(%rip), %rdi # {
call puts@PLT # printf ("Hello, world!\n");
movl $0, %eax # return 0;
addq $8, %rsp # }
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.ident "GCC: (Debian 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
int main (void)
{
puts ("Hello, world!");
return 0;
}
.file "hello-2.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 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
extern int puts (char *s);
void printf (void)
{
puts ("Hello, world!");
}
int main (void)
{
printf ();
return 0;
}
cassini/home/peter/bo/2021ss/bs/20210430> cat dev/chardev
cat: dev/chardev: Kein passendes Gerät bzw. keine passende Adresse gefunden
cassini/home/peter/bo/2021ss/bs/20210430> ls -l dev/chardev
crw-rw-rw- 1 root root 241, 0 Apr 30 15:14 dev/chardev
cassini/home/peter/bo/2021ss/bs/20210430> sudo cat dev/chardev
cat: dev/chardev: Kein passendes Gerät bzw. keine passende Adresse gefunden
cassini/home/peter/bo/2021ss/bs/20210430> lsmod | grep chardev
cassini/home/peter/bo/2021ss/bs/20210430>
cassini/home/peter/bo/2021ss/bs/20210430> sudo insmod chardev-1a.ko
cassini/home/peter/bo/2021ss/bs/20210430> lsmod | grep chardev
chardev_1a 16384 0
cassini/home/peter/bo/2021ss/bs/20210430> cat dev/chardev
I already told you 0 times Hello world!
cassini/home/peter/bo/2021ss/bs/20210430> cat dev/chardev
I already told you 1 times Hello world!
cassini/home/peter/bo/2021ss/bs/20210430> echo "Dies ist ein Test." > dev/chardev
cassini/home/peter/bo/2021ss/bs/20210430>
Inhalt von /var/log/kern.log:
May 7 12:57:21 cassini kernel: [1601195.178390] I was assigned major number 241. To talk to
May 7 12:57:21 cassini kernel: [1601195.178391] the driver, create a dev file with
May 7 12:57:21 cassini kernel: [1601195.178392] 'mknod /dev/chardev c 241 0'.
May 7 12:57:21 cassini kernel: [1601195.178392] Try various minor numbers. Try to cat and echo to
May 7 12:57:21 cassini kernel: [1601195.178392] the device file.
May 7 12:57:21 cassini kernel: [1601195.178393] Remove the device file and module when done.
May 7 12:57:40 cassini kernel: [1601214.177086] Got user data: Dies ist ein Test.
May 7 12:57:40 cassini kernel: [1601214.177086] ss/bs/20210430
May 7 12:57:40 cassini kernel: [1601214.177086] indow -P openmeetings https://www.cvh-server.de/vnc/ &
May 7 12:57:40 cassini kernel: [1601214.177086] return
May 7 12:57:40 cassini kernel: [1601214.177086] ;;
May 7 12:57:40 cassini kernel: [1601214.177086] esac;
May 7 12:57:40 cassini kernel: [1601214.177086] local complete_opt="--others --modified --directory --no-empty-directory";
May 7 12:57:40 cassini kernel: [1601214.177086] if test -n "$(__git_find_on_cmdline "-u --update")"; then
May 7 12:57:40 cassini kernel: [1601214.177086] complete_opt="--modified";
May 7 12:57:40 cassini kernel: [1601214.177086] fi;
May 7 12:57:40 cassini kernel: [1601214.177086] __git_complete_index_file "$complete_opt"
May 7 12:57:40 cassini kernel: [1601214.177086] exclude=$OPTARG
May 7 12:57:40 cassini kernel: [1601214.177086] ;;
May 7 12:57:40 cassini kernel: [1601214.177086] p)
May 7 12:57:40 cassini kernel: [1601214.177086] vprev=$OPTARG
May 7 12:57:40 cassini kernel: [1601214.177086] ;;
May 7 12:57:40 cassini kernel: [1601214.177086] w)
May 7 12:57:40 cassini kernel: [1601214.177086] vwords=$OPTARG
May 7 12:57:40 cassini kernel: [1601214.177086] ;;
May 7 12:57:40 cassini kernel: [1601214.177086] esac;
May 7 12:57:40 cassini kernel: [1601214.177086] done;
cassini/home/peter/bo/2021ss/bs/20210430> sudo insmod chardev-1b.ko
cassini/home/peter/bo/2021ss/bs/20210430> echo "Dies ist ein Test." > dev/chardev
cassini/home/peter/bo/2021ss/bs/20210430> sudo tail -22 /var/log/kern.log
May 7 12:57:40 cassini kernel: [1601214.177086] if test -n "$(__git_find_on_cmdline "-u --update")"; then
May 7 12:57:40 cassini kernel: [1601214.177086] complete_opt="--modified";
May 7 12:57:40 cassini kernel: [1601214.177086] fi;
May 7 12:57:40 cassini kernel: [1601214.177086] __git_complete_index_file "$complete_opt"
May 7 12:57:40 cassini kernel: [1601214.177086] exclude=$OPTARG
May 7 12:57:40 cassini kernel: [1601214.177086] ;;
May 7 12:57:40 cassini kernel: [1601214.177086] p)
May 7 12:57:40 cassini kernel: [1601214.177086] vprev=$OPTARG
May 7 12:57:40 cassini kernel: [1601214.177086] ;;
May 7 12:57:40 cassini kernel: [1601214.177086] w)
May 7 12:57:40 cassini kernel: [1601214.177086] vwords=$OPTARG
May 7 12:57:40 cassini kernel: [1601214.177086] ;;
May 7 12:57:40 cassini kernel: [1601214.177086] esac;
May 7 12:57:40 cassini kernel: [1601214.177086] done;
May 7 13:07:49 cassini kernel: [1601823.599104] I was assigned major number 241. To talk to
May 7 13:07:49 cassini kernel: [1601823.599106] the driver, create a dev file with
May 7 13:07:49 cassini kernel: [1601823.599108] 'mknod /dev/chardev c 241 0'.
May 7 13:07:49 cassini kernel: [1601823.599108] Try various minor numbers. Try to cat and echo to
May 7 13:07:49 cassini kernel: [1601823.599109] the device file.
May 7 13:07:49 cassini kernel: [1601823.599109] Remove the device file and module when done.
May 7 13:07:58 cassini kernel: [1601832.651791] Got user data: Dies ist ein Test.
May 7 13:07:58 cassini kernel: [1601832.651791] .
cassini/home/peter/bo/2021ss/bs/20210430> tail chardev-1b.c
*/
static ssize_t
device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{
char b[len + 1];
strncpy (b, buff, len);
b[len] = 0;
printk(KERN_INFO "Got user data: %s.\n", b);
return len;
}
cassini/home/peter/bo/2021ss/bs/20210430>
../common/os-layers-1.jpg
\ No newline at end of file
../common/os-layers-2.jpg
\ No newline at end of file
../common/os-layers-3.jpg
\ No newline at end of file
../common/os-layers-4.jpg
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment