<<

1 7

Computer Core Practice1: Week13. and

Jhuyeong Jhin and Injung Hwang Embedded Software Lab.

Embedded Software Lab. 2 sysfs 7

• A pseudo system provided by the kernel. • sysfs exports information about various kernel subsystems, HW devices, and associated device drivers to space through virtual files. • The point of sysfs is usually /sys. • sysfs abstrains devices or kernel subsystems as a kobject.

Embedded Software Lab. 3 How to create a file in /sys 7

1. Create and add kobject to the sysfs 2. Declare a variable and struct kobj_attribute – When you declare the kobj_attribute, you should implement the functions “show” and “store” for reading and writing from/to the variable. – One variable is one attribute 3. Create a in the sysfs – The directory have attributes as files • When the creation of the directory is completed, the directory and files(attributes) appear in /sys.

• Reference: ${KERNEL_SRC_DIR}/include/linux/sysfs.h ${KERNEL_SRC_DIR}/fs/sysfs/* • Example : ${KERNEL_SRC_DIR}/kernel/ksysfs.c

Embedded Software Lab. 4 procfs 7

• A special filesystem in -like operating systems. • procfs presents information about processes and other system information in a hierarchical file-like structure. • Typically, it is mapped to a mount point named /proc at boot time. • procfs acts as an interface to internal structures in the kernel.

The IDs of all processes in the system

• Kernel provides a set of functions which are designed to make the operations for the file in /proc : “seq_file interface”. – We will create a file in procfs and print some data from data structure by using this interface. Embedded Software Lab. 5 Practice #7 7

• Create your . • When the module is loaded, it creates a file in /proc.

• When the file is , the process IDs and process commands of all the processes in your system appear.

Embedded Software Lab. 6 Homework #6 (1) 7

• Create your loadable kernel module. • In the module, you declare a global variable. • When the module is loaded, it should create a directory(and file) in /sys/kernel and print the following messages.

The file name may be your name, nickname, or student ID

Embedded Software Lab. 7 Homework #6 (2) 7

• When you read the file (using vi, cat, … whatever) or some value to the file (you can use echo command), the module print the value of the global variable using printk. • After you write some value to the file, you can see that the value changes by dmesg log and reading the file.

• Submission 1) module source code (capture or source code file) 2) report : describe how you implement the module 3) the result screen (module load, read the file, write to the file) Embedded Software Lab.