This commit is contained in:
starnakin 2024-08-07 12:33:08 +02:00
commit c3391de3ee
20 changed files with 31174 additions and 0 deletions

7
ass01/Makefile Normal file
View File

@ -0,0 +1,7 @@
obj-m += main.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

19
ass01/main.c Normal file
View File

@ -0,0 +1,19 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
static int __init module_start(void)
{
printk(KERN_INFO "Hello world !\n");
return 0;
}
static void __exit module_end(void)
{
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(module_start);
module_exit(module_end);

9466
ass02/kern.log Normal file

File diff suppressed because it is too large Load Diff

11
ass02/patch Normal file
View File

@ -0,0 +1,11 @@
--- Makefile 2024-05-28 18:48:03.985000000 +0200
+++ Makefile.bak 2024-05-29 13:28:06.001000000 +0200
@@ -2,7 +2,7 @@
VERSION = 6
PATCHLEVEL = 9
SUBLEVEL = 0
-EXTRAVERSION = -thor__kernel
+EXTRAVERSION =
NAME = Hurr durr I'ma ninja sloth
# *DOCUMENTATION*

1
ass03/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Makefile

30
ass03/main.c Normal file
View File

@ -0,0 +1,30 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/slab.h>
MODULE_LICENSE("GPL");
static __init int do_work(int my_int)
{
int i;
for (i = 0; i < my_int; i++)
udelay(10);
if (my_int < 10)
pr_info("We slept a long time");
return i * my_int;
}
static __init int my_init(void)
{
do_work(10);
return 0;
}
static __exit void my_exit(void)
{
}
module_init(my_init);
module_exit(my_exit);

View File

@ -0,0 +1,4 @@
ACTION=="add", \
SUBSYSTEM=="input", \
SUBSYSTEMS=="usb", \
RUN+="/sbin/modprobe /root/lp/ass04/main.ko"

7
ass04/Makefile Normal file
View File

@ -0,0 +1,7 @@
obj-m += main.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

19
ass04/main.c Normal file
View File

@ -0,0 +1,19 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
static int __init module_start(void)
{
printk(KERN_INFO "Hello world !\n");
return 0;
}
static void __exit module_end(void)
{
printk(KERN_INFO "Cleaning up module.\n");
}
module_init(module_start);
module_exit(module_end);

424
ass04/proof Normal file
View File

@ -0,0 +1,424 @@
[ 0.000000] Linux version 6.9.0 (root@cchauvet) (gcc (GCC) 13.2.0, GNU ld (GNU Binutils) 2.42) #2 SMP PREEMPT_DYNAMIC Wed May 29 16:49:01 CEST 2024
[ 0.000000] Command line: BOOT_IMAGE=/vmlinuz-6.9-cchauvet root=/dev/sda3 ro
[ 0.000000] BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x00000000bffddfff] usable
[ 0.000000] BIOS-e820: [mem 0x00000000bffde000-0x00000000bfffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000feffc000-0x00000000feffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[ 0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000083fffffff] usable
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] APIC: Static calls initialized
[ 0.000000] SMBIOS 2.8 present.
[ 0.000000] DMI: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[ 0.000000] Hypervisor detected: KVM
[ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
[ 0.000000] kvm-clock: using sched offset of 566994721442 cycles
[ 0.000003] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns
[ 0.000008] tsc: Detected 2593.972 MHz processor
[ 0.000555] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[ 0.000557] e820: remove [mem 0x000a0000-0x000fffff] usable
[ 0.000560] last_pfn = 0x840000 max_arch_pfn = 0x400000000
[ 0.000584] MTRR map: 4 entries (3 fixed + 1 variable; max 19), built from 8 variable MTRRs
[ 0.000588] x86/PAT: Configuration [0-7]: WB WC UC- UC WB WP UC- WT
[ 0.000636] last_pfn = 0xbffde max_arch_pfn = 0x400000000
[ 0.008149] found SMP MP-table at [mem 0x000f5b90-0x000f5b9f]
[ 0.008170] Using GB pages for direct mapping
[ 0.008292] ACPI: Early table checksum verification disabled
[ 0.008304] ACPI: RSDP 0x00000000000F5970 000014 (v00 BOCHS )
[ 0.008310] ACPI: RSDT 0x00000000BFFE21BE 000034 (v01 BOCHS BXPC 00000001 BXPC 00000001)
[ 0.008322] ACPI: FACP 0x00000000BFFE1FDA 000074 (v01 BOCHS BXPC 00000001 BXPC 00000001)
[ 0.008328] ACPI: DSDT 0x00000000BFFE0040 001F9A (v01 BOCHS BXPC 00000001 BXPC 00000001)
[ 0.008331] ACPI: FACS 0x00000000BFFE0000 000040
[ 0.008334] ACPI: APIC 0x00000000BFFE204E 000110 (v01 BOCHS BXPC 00000001 BXPC 00000001)
[ 0.008336] ACPI: HPET 0x00000000BFFE215E 000038 (v01 BOCHS BXPC 00000001 BXPC 00000001)
[ 0.008339] ACPI: WAET 0x00000000BFFE2196 000028 (v01 BOCHS BXPC 00000001 BXPC 00000001)
[ 0.008341] ACPI: Reserving FACP table memory at [mem 0xbffe1fda-0xbffe204d]
[ 0.008342] ACPI: Reserving DSDT table memory at [mem 0xbffe0040-0xbffe1fd9]
[ 0.008343] ACPI: Reserving FACS table memory at [mem 0xbffe0000-0xbffe003f]
[ 0.008343] ACPI: Reserving APIC table memory at [mem 0xbffe204e-0xbffe215d]
[ 0.008344] ACPI: Reserving HPET table memory at [mem 0xbffe215e-0xbffe2195]
[ 0.008345] ACPI: Reserving WAET table memory at [mem 0xbffe2196-0xbffe21bd]
[ 0.008606] No NUMA configuration found
[ 0.008607] Faking a node at [mem 0x0000000000000000-0x000000083fffffff]
[ 0.008609] NODE_DATA(0) allocated [mem 0x83fffc000-0x83fffffff]
[ 0.008646] Zone ranges:
[ 0.008646] DMA [mem 0x0000000000001000-0x0000000000ffffff]
[ 0.008648] DMA32 [mem 0x0000000001000000-0x00000000ffffffff]
[ 0.008649] Normal [mem 0x0000000100000000-0x000000083fffffff]
[ 0.008650] Movable zone start for each node
[ 0.008651] Early memory node ranges
[ 0.008651] node 0: [mem 0x0000000000001000-0x000000000009efff]
[ 0.008652] node 0: [mem 0x0000000000100000-0x00000000bffddfff]
[ 0.008653] node 0: [mem 0x0000000100000000-0x000000083fffffff]
[ 0.008656] Initmem setup node 0 [mem 0x0000000000001000-0x000000083fffffff]
[ 0.008662] On node 0, zone DMA: 1 pages in unavailable ranges
[ 0.008688] On node 0, zone DMA: 97 pages in unavailable ranges
[ 0.067230] On node 0, zone Normal: 34 pages in unavailable ranges
[ 0.067585] ACPI: PM-Timer IO Port: 0x608
[ 0.067600] ACPI: LAPIC_NMI (acpi_id[0xff] dfl dfl lint[0x1])
[ 0.067639] IOAPIC[0]: apic_id 0, version 17, address 0xfec00000, GSI 0-23
[ 0.067642] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
[ 0.067644] ACPI: INT_SRC_OVR (bus 0 bus_irq 5 global_irq 5 high level)
[ 0.067645] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[ 0.067649] ACPI: INT_SRC_OVR (bus 0 bus_irq 10 global_irq 10 high level)
[ 0.067650] ACPI: INT_SRC_OVR (bus 0 bus_irq 11 global_irq 11 high level)
[ 0.067654] ACPI: Using ACPI (MADT) for SMP configuration information
[ 0.067655] ACPI: HPET id: 0x8086a201 base: 0xfed00000
[ 0.067664] CPU topo: Max. logical packages: 1
[ 0.067665] CPU topo: Max. logical dies: 1
[ 0.067665] CPU topo: Max. dies per package: 1
[ 0.067670] CPU topo: Max. threads per core: 1
[ 0.067672] CPU topo: Num. cores per package: 20
[ 0.067673] CPU topo: Num. threads per package: 20
[ 0.067673] CPU topo: Allowing 20 present CPUs plus 0 hotplug CPUs
[ 0.067690] kvm-guest: APIC: eoi() replaced with kvm_guest_apic_eoi_write()
[ 0.067722] PM: hibernation: Registered nosave memory: [mem 0x00000000-0x00000fff]
[ 0.067723] PM: hibernation: Registered nosave memory: [mem 0x0009f000-0x0009ffff]
[ 0.067724] PM: hibernation: Registered nosave memory: [mem 0x000a0000-0x000effff]
[ 0.067725] PM: hibernation: Registered nosave memory: [mem 0x000f0000-0x000fffff]
[ 0.067726] PM: hibernation: Registered nosave memory: [mem 0xbffde000-0xbfffffff]
[ 0.067727] PM: hibernation: Registered nosave memory: [mem 0xc0000000-0xfeffbfff]
[ 0.067727] PM: hibernation: Registered nosave memory: [mem 0xfeffc000-0xfeffffff]
[ 0.067728] PM: hibernation: Registered nosave memory: [mem 0xff000000-0xfffbffff]
[ 0.067728] PM: hibernation: Registered nosave memory: [mem 0xfffc0000-0xffffffff]
[ 0.067730] [mem 0xc0000000-0xfeffbfff] available for PCI devices
[ 0.067733] Booting paravirtualized kernel on KVM
[ 0.067735] clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1910969940391419 ns
[ 0.073667] setup_percpu: NR_CPUS:64 nr_cpumask_bits:20 nr_cpu_ids:20 nr_node_ids:1
[ 0.074775] percpu: Embedded 56 pages/cpu s191912 r8192 d29272 u262144
[ 0.074782] pcpu-alloc: s191912 r8192 d29272 u262144 alloc=1*2097152
[ 0.074784] pcpu-alloc: [0] 00 01 02 03 04 05 06 07 [0] 08 09 10 11 12 13 14 15
[ 0.074791] pcpu-alloc: [0] 16 17 18 19 -- -- -- --
[ 0.074812] Kernel command line: BOOT_IMAGE=/vmlinuz-6.9-cchauvet root=/dev/sda3 ro
[ 0.074840] Unknown kernel command line parameters "BOOT_IMAGE=/vmlinuz-6.9-cchauvet", will be passed to user space.
[ 0.074852] random: crng init done
[ 0.078594] Dentry cache hash table entries: 4194304 (order: 13, 33554432 bytes, linear)
[ 0.080482] Inode-cache hash table entries: 2097152 (order: 12, 16777216 bytes, linear)
[ 0.080864] Fallback order for Node 0: 0
[ 0.080869] Built 1 zonelists, mobility grouping on. Total pages: 8257246
[ 0.080871] Policy zone: Normal
[ 0.080873] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[ 0.080886] software IO TLB: area num 32.
[ 0.172214] Memory: 32869560K/33553904K available (18432K kernel code, 2817K rwdata, 6776K rodata, 2724K init, 1180K bss, 684084K reserved, 0K cma-reserved)
[ 0.172290] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=20, Nodes=1
[ 0.172326] Kernel/User page tables isolation: enabled
[ 0.174192] Dynamic Preempt: voluntary
[ 0.174272] rcu: Preemptible hierarchical RCU implementation.
[ 0.174273] rcu: RCU event tracing is enabled.
[ 0.174273] rcu: RCU restricting CPUs from NR_CPUS=64 to nr_cpu_ids=20.
[ 0.174274] Trampoline variant of Tasks RCU enabled.
[ 0.174275] rcu: RCU calculated value of scheduler-enlistment delay is 100 jiffies.
[ 0.174276] rcu: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=20
[ 0.174285] RCU Tasks: Setting shift to 5 and lim to 1 rcu_task_cb_adjust=1.
[ 0.175715] NR_IRQS: 4352, nr_irqs: 584, preallocated irqs: 16
[ 0.175935] rcu: srcu_init: Setting srcu_struct sizes based on contention.
[ 0.184887] Console: colour VGA+ 80x25
[ 0.184892] printk: legacy console [tty0] enabled
[ 0.224798] ACPI: Core revision 20230628
[ 0.225201] clocksource: hpet: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604467 ns
[ 0.225877] APIC: Switch to symmetric I/O mode setup
[ 0.226456] x2apic enabled
[ 0.227053] APIC: Switched APIC routing to: physical x2apic
[ 0.228587] ..TIMER: vector=0x30 apic1=0 pin1=2 apic2=-1 pin2=-1
[ 0.228909] clocksource: tsc-early: mask: 0xffffffffffffffff max_cycles: 0x2563fdaef8d, max_idle_ns: 440795313885 ns
[ 0.229500] Calibrating delay loop (skipped) preset value.. 5187.94 BogoMIPS (lpj=2593972)
[ 0.230608] Last level iTLB entries: 4KB 0, 2MB 0, 4MB 0
[ 0.230931] Last level dTLB entries: 4KB 0, 2MB 0, 4MB 0, 1GB 0
[ 0.231217] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
[ 0.231492] Spectre V2 : Mitigation: Retpolines
[ 0.231713] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch
[ 0.232078] Spectre V2 : Spectre v2 / SpectreRSB : Filling RSB on VMEXIT
[ 0.232491] Speculative Store Bypass: Vulnerable
[ 0.232736] MDS: Vulnerable: Clear CPU buffers attempted, no microcode
[ 0.233005] MMIO Stale Data: Unknown: No mitigations
[ 0.233246] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ 0.233490] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.233796] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.234133] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.234490] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'standard' format.
[ 0.255101] Freeing SMP alternatives memory: 48K
[ 0.255409] pid_max: default: 32768 minimum: 301
[ 0.255512] LSM: initializing lsm=capability,selinux
[ 0.255811] SELinux: Initializing.
[ 0.256144] Mount-cache hash table entries: 65536 (order: 7, 524288 bytes, linear)
[ 0.256557] Mountpoint-cache hash table entries: 65536 (order: 7, 524288 bytes, linear)
[ 0.359489] smpboot: CPU0: Intel AMD EPYC Processor (family: 0x17, model: 0x1, stepping: 0x2)
[ 0.359489] Performance Events: no PMU driver, software events only.
[ 0.359489] signal: max sigframe size: 1776
[ 0.359517] rcu: Hierarchical SRCU implementation.
[ 0.359803] rcu: Max phase no-delay instances is 400.
[ 0.360524] smp: Bringing up secondary CPUs ...
[ 0.360849] smpboot: x86: Booting SMP configuration:
[ 0.361165] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19
[ 0.593647] smp: Brought up 1 node, 20 CPUs
[ 0.594736] smpboot: Total of 20 processors activated (103758.88 BogoMIPS)
[ 0.598112] devtmpfs: initialized
[ 0.598886] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns
[ 0.599052] futex hash table entries: 8192 (order: 7, 524288 bytes, linear)
[ 0.599649] PM: RTC time: 14:51:16, date: 2024-05-30
[ 0.600497] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[ 0.600911] audit: initializing netlink subsys (disabled)
[ 0.601232] audit: type=2000 audit(1717080677.043:1): state=initialized audit_enabled=0 res=1
[ 0.601232] thermal_sys: Registered thermal governor 'step_wise'
[ 0.601491] thermal_sys: Registered thermal governor 'user_space'
[ 0.601815] cpuidle: using governor menu
[ 0.602760] PCI: Using configuration type 1 for base access
[ 0.603122] kprobes: kprobe jump-optimization is enabled. All kprobes are optimized if possible.
[ 0.603602] HugeTLB: registered 2.00 MiB page size, pre-allocated 0 pages
[ 0.604012] HugeTLB: 28 KiB vmemmap can be freed for a 2.00 MiB page
[ 0.604546] Demotion targets for Node 0: null
[ 0.605552] ACPI: Added _OSI(Module Device)
[ 0.605856] ACPI: Added _OSI(Processor Device)
[ 0.605856] ACPI: Added _OSI(3.0 _SCP Extensions)
[ 0.605856] ACPI: Added _OSI(Processor Aggregator Device)
[ 0.606983] ACPI: 1 ACPI AML tables successfully acquired and loaded
[ 0.611588] ACPI: _OSC evaluation for CPUs failed, trying _PDC
[ 0.612598] ACPI: Interpreter enabled
[ 0.612845] ACPI: PM: (supports S0 S3 S4 S5)
[ 0.613099] ACPI: Using IOAPIC for interrupt routing
[ 0.613502] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug
[ 0.613947] PCI: Using E820 reservations for host bridge windows
[ 0.614336] ACPI: Enabled 2 GPEs in block 00 to 0F
[ 0.617072] ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-ff])
[ 0.617395] acpi PNP0A03:00: _OSC: OS supports [ASPM ClockPM Segments MSI HPX-Type3]
[ 0.617491] acpi PNP0A03:00: _OSC: not requesting OS control; OS requires [ExtendedConfig ASPM ClockPM MSI]
[ 0.617966] acpi PNP0A03:00: fail to add MMCONFIG information, can't access extended configuration space under this bridge
[ 0.618594] PCI host bridge to bus 0000:00
[ 0.618878] pci_bus 0000:00: root bus resource [io 0x0000-0x0cf7 window]
[ 0.619491] pci_bus 0000:00: root bus resource [io 0x0d00-0xffff window]
[ 0.619832] pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff window]
[ 0.620256] pci_bus 0000:00: root bus resource [mem 0xc0000000-0xfebfffff window]
[ 0.620491] pci_bus 0000:00: root bus resource [mem 0x840000000-0x8bfffffff window]
[ 0.620926] pci_bus 0000:00: root bus resource [bus 00-ff]
[ 0.621538] pci 0000:00:00.0: [8086:1237] type 00 class 0x060000 conventional PCI endpoint
[ 0.622735] pci 0000:00:01.0: [8086:7000] type 00 class 0x060100 conventional PCI endpoint
[ 0.624098] pci 0000:00:01.1: [8086:7010] type 00 class 0x010180 conventional PCI endpoint
[ 0.626897] pci 0000:00:01.1: BAR 4 [io 0xc040-0xc04f]
[ 0.628924] pci 0000:00:01.1: BAR 0 [io 0x01f0-0x01f7]: legacy IDE quirk
[ 0.629298] pci 0000:00:01.1: BAR 1 [io 0x03f6]: legacy IDE quirk
[ 0.629491] pci 0000:00:01.1: BAR 2 [io 0x0170-0x0177]: legacy IDE quirk
[ 0.629844] pci 0000:00:01.1: BAR 3 [io 0x0376]: legacy IDE quirk
[ 0.630551] pci 0000:00:01.2: [8086:7020] type 00 class 0x0c0300 conventional PCI endpoint
[ 0.633145] pci 0000:00:01.2: BAR 4 [io 0xc000-0xc01f]
[ 0.634573] pci 0000:00:01.3: [8086:7113] type 00 class 0x068000 conventional PCI endpoint
[ 0.635958] pci 0000:00:01.3: quirk: [io 0x0600-0x063f] claimed by PIIX4 ACPI
[ 0.636384] pci 0000:00:01.3: quirk: [io 0x0700-0x070f] claimed by PIIX4 SMB
[ 0.636712] pci 0000:00:02.0: [1234:1111] type 00 class 0x030000 conventional PCI endpoint
[ 0.638873] pci 0000:00:02.0: BAR 0 [mem 0xfd000000-0xfdffffff pref]
[ 0.640862] pci 0000:00:02.0: BAR 2 [mem 0xfebd0000-0xfebd0fff]
[ 0.647507] pci 0000:00:02.0: ROM [mem 0xfebc0000-0xfebcffff pref]
[ 0.647971] pci 0000:00:02.0: Video device with shadowed ROM at [mem 0x000c0000-0x000dffff]
[ 0.649184] pci 0000:00:03.0: [1af4:1000] type 00 class 0x020000 conventional PCI endpoint
[ 0.650492] pci 0000:00:03.0: BAR 0 [io 0xc020-0xc03f]
[ 0.651491] pci 0000:00:03.0: BAR 1 [mem 0xfebd1000-0xfebd1fff]
[ 0.653918] pci 0000:00:03.0: BAR 4 [mem 0xfe000000-0xfe003fff 64bit pref]
[ 0.655492] pci 0000:00:03.0: ROM [mem 0xfeb80000-0xfebbffff pref]
[ 0.659614] ACPI: PCI: Interrupt link LNKA configured for IRQ 10
[ 0.660083] ACPI: PCI: Interrupt link LNKB configured for IRQ 10
[ 0.660496] ACPI: PCI: Interrupt link LNKC configured for IRQ 11
[ 0.660919] ACPI: PCI: Interrupt link LNKD configured for IRQ 11
[ 0.661297] ACPI: PCI: Interrupt link LNKS configured for IRQ 9
[ 0.663247] iommu: Default domain type: Translated
[ 0.663492] iommu: DMA domain TLB invalidation policy: lazy mode
[ 0.663944] SCSI subsystem initialized
[ 0.664516] libata version 3.00 loaded.
[ 0.664553] ACPI: bus type USB registered
[ 0.664837] usbcore: registered new interface driver usbfs
[ 0.665134] usbcore: registered new interface driver hub
[ 0.665500] usbcore: registered new device driver usb
[ 0.665824] pps_core: LinuxPPS API ver. 1 registered
[ 0.666093] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[ 0.666496] PTP clock support registered
[ 0.666762] Advanced Linux Sound Architecture Driver Initialized.
[ 0.667700] NetLabel: Initializing
[ 0.667961] NetLabel: domain hash size = 128
[ 0.668231] NetLabel: protocols = UNLABELED CIPSOv4 CALIPSO
[ 0.668519] NetLabel: unlabeled traffic allowed by default
[ 0.668897] PCI: Using ACPI for IRQ routing
[ 0.668897] PCI: pci_cache_line_size set to 64 bytes
[ 0.669503] e820: reserve RAM buffer [mem 0x0009fc00-0x0009ffff]
[ 0.669507] e820: reserve RAM buffer [mem 0xbffde000-0xbfffffff]
[ 0.669537] pci 0000:00:02.0: vgaarb: setting as boot VGA device
[ 0.669830] pci 0000:00:02.0: vgaarb: bridge control possible
[ 0.670125] pci 0000:00:02.0: vgaarb: VGA device added: decodes=io+mem,owns=io+mem,locks=none
[ 0.670491] vgaarb: loaded
[ 0.670763] hpet0: at MMIO 0xfed00000, IRQs 2, 8, 0
[ 0.671056] hpet0: 3 comparators, 64-bit 100.000000 MHz counter
[ 0.674740] clocksource: Switched to clocksource kvm-clock
[ 0.675027] VFS: Disk quotas dquot_6.6.0
[ 0.675338] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[ 0.675753] pnp: PnP ACPI init
[ 0.676033] pnp 00:02: [dma 2]
[ 0.676190] pnp: PnP ACPI: found 6 devices
[ 0.684290] clocksource: acpi_pm: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 2085701024 ns
[ 0.684874] NET: Registered PF_INET protocol family
[ 0.685465] IP idents hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[ 0.688750] tcp_listen_portaddr_hash hash table entries: 16384 (order: 6, 262144 bytes, linear)
[ 0.689302] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[ 0.689755] TCP established hash table entries: 262144 (order: 9, 2097152 bytes, linear)
[ 0.690925] TCP bind hash table entries: 65536 (order: 9, 2097152 bytes, linear)
[ 0.691658] TCP: Hash tables configured (established 262144 bind 65536)
[ 0.692046] UDP hash table entries: 16384 (order: 7, 524288 bytes, linear)
[ 0.692491] UDP-Lite hash table entries: 16384 (order: 7, 524288 bytes, linear)
[ 0.693037] NET: Registered PF_UNIX/PF_LOCAL protocol family
[ 0.693810] RPC: Registered named UNIX socket transport module.
[ 0.694157] RPC: Registered udp transport module.
[ 0.695203] RPC: Registered tcp transport module.
[ 0.695483] RPC: Registered tcp-with-tls transport module.
[ 0.695786] RPC: Registered tcp NFSv4.1 backchannel transport module.
[ 0.696577] pci_bus 0000:00: resource 4 [io 0x0000-0x0cf7 window]
[ 0.696923] pci_bus 0000:00: resource 5 [io 0x0d00-0xffff window]
[ 0.697274] pci_bus 0000:00: resource 6 [mem 0x000a0000-0x000bffff window]
[ 0.697620] pci_bus 0000:00: resource 7 [mem 0xc0000000-0xfebfffff window]
[ 0.697971] pci_bus 0000:00: resource 8 [mem 0x840000000-0x8bfffffff window]
[ 0.698348] pci 0000:00:01.0: PIIX3: Enabling Passive Release
[ 0.698652] pci 0000:00:00.0: Limiting direct PCI/PCI transfers
[ 0.709842] ACPI: \_SB_.LNKD: Enabled at IRQ 11
[ 0.721301] pci 0000:00:01.2: quirk_usb_early_handoff+0x0/0x7a0 took 21828 usecs
[ 0.721774] PCI: CLS 0 bytes, default 64
[ 0.722573] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[ 0.722912] software IO TLB: mapped [mem 0x00000000bbfde000-0x00000000bffde000] (64MB)
[ 0.723363] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x2563fdaef8d, max_idle_ns: 440795313885 ns
[ 0.739129] Initialise system trusted keyrings
[ 0.739674] workingset: timestamp_bits=40 max_order=23 bucket_order=0
[ 0.740417] NFS: Registering the id_resolver key type
[ 0.740716] Key type id_resolver registered
[ 0.740982] Key type id_legacy registered
[ 0.741358] 9p: Installing v9fs 9p2000 file system support
[ 0.754577] Key type asymmetric registered
[ 0.754883] Asymmetric key parser 'x509' registered
[ 0.755182] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[ 0.755659] io scheduler mq-deadline registered
[ 0.755948] io scheduler kyber registered
[ 0.758001] input: Power Button as /devices/LNXSYSTM:00/LNXPWRBN:00/input/input0
[ 0.758526] ACPI: button: Power Button [PWRF]
[ 0.770429] ACPI: \_SB_.LNKC: Enabled at IRQ 10
[ 0.771964] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[ 0.772449] 00:04: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[ 0.773514] Non-volatile memory driver v1.3
[ 0.773818] Linux agpgart interface v0.103
[ 0.774164] ACPI: bus type drm_connector registered
[ 0.779361] loop: module loaded
[ 0.780218] ata_piix 0000:00:01.1: version 2.13
[ 0.781248] scsi host0: ata_piix
[ 0.781907] scsi host1: ata_piix
[ 0.782194] ata1: PATA max MWDMA2 cmd 0x1f0 ctl 0x3f6 bmdma 0xc040 irq 14 lpm-pol 0
[ 0.786424] ata2: PATA max MWDMA2 cmd 0x170 ctl 0x376 bmdma 0xc048 irq 15 lpm-pol 0
[ 0.788761] e100: Intel(R) PRO/100 Network Driver
[ 0.789037] e100: Copyright(c) 1999-2006 Intel Corporation
[ 0.789330] e1000: Intel(R) PRO/1000 Network Driver
[ 0.789607] e1000: Copyright (c) 1999-2006 Intel Corporation.
[ 0.789947] e1000e: Intel(R) PRO/1000 Network Driver
[ 0.790247] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
[ 0.790584] sky2: driver version 1.30
[ 0.802587] uhci_hcd 0000:00:01.2: UHCI Host Controller
[ 0.803002] uhci_hcd 0000:00:01.2: new USB bus registered, assigned bus number 1
[ 0.803488] uhci_hcd 0000:00:01.2: irq 11, io port 0x0000c000
[ 0.803862] usb usb1: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.09
[ 0.804332] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 0.804698] usb usb1: Product: UHCI Host Controller
[ 0.804977] usb usb1: Manufacturer: Linux 6.9.0 uhci_hcd
[ 0.805258] usb usb1: SerialNumber: 0000:00:01.2
[ 0.805753] hub 1-0:1.0: USB hub found
[ 0.806042] hub 1-0:1.0: 2 ports detected
[ 0.806482] usbcore: registered new interface driver usblp
[ 0.806839] usbcore: registered new interface driver usb-storage
[ 0.807219] i8042: PNP: PS/2 Controller [PNP0303:KBD,PNP0f13:MOU] at 0x60,0x64 irq 1,12
[ 0.808447] serio: i8042 KBD port at 0x60,0x64 irq 1
[ 0.808777] serio: i8042 AUX port at 0x60,0x64 irq 12
[ 0.809333] rtc_cmos 00:05: RTC can wake from S4
[ 0.810278] input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input1
[ 0.811038] rtc_cmos 00:05: registered as rtc0
[ 0.812540] rtc_cmos 00:05: alarms up to one day, y3k, 242 bytes nvram, hpet irqs
[ 0.813307] device-mapper: ioctl: 4.48.0-ioctl (2023-03-01) initialised: dm-devel@lists.linux.dev
[ 0.813871] intel_pstate: CPU model not supported
[ 0.814168] hid: raw HID events driver (C) Jiri Kosina
[ 0.814506] usbcore: registered new interface driver usbhid
[ 0.814832] usbhid: USB HID core driver
[ 0.816887] Initializing XFRM netlink socket
[ 0.817872] NET: Registered PF_INET6 protocol family
[ 0.820217] Segment Routing with IPv6
[ 0.820915] In-situ OAM (IOAM) with IPv6
[ 0.821652] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
[ 0.822861] NET: Registered PF_PACKET protocol family
[ 0.823818] 9pnet: Installing 9P2000 support
[ 0.824508] Key type dns_resolver registered
[ 0.828674] IPI shorthand broadcast: enabled
[ 0.835479] sched_clock: Marking stable (784008872, 50546772)->(859623618, -25067974)
[ 0.837074] Timer migration: 2 hierarchy levels; 8 children per group; 2 crossnode level
[ 0.840156] registered taskstats version 1
[ 0.840833] Loading compiled-in X.509 certificates
[ 0.845416] PM: Magic number: 8:74:891
[ 0.846208] event_source msr: hash matches
[ 0.846909] printk: legacy console [netcon0] enabled
[ 0.847666] netconsole: network logging started
[ 0.848457] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[ 0.849991] kworker/u80:2 (150) used greatest stack depth: 14016 bytes left
[ 0.851046] Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[ 0.852406] Loaded X.509 cert 'wens: 61c038651aabdcf94bd0ac7ff06c7248db18c600'
[ 0.853600] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[ 0.854798] cfg80211: failed to load regulatory.db
[ 0.855517] ALSA device list:
[ 0.856127] No soundcards found.
[ 0.945902] ata2: found unknown device (class 0)
[ 0.946818] ata1: found unknown device (class 0)
[ 0.949108] ata2.00: ATAPI: QEMU DVD-ROM, 2.5+, max UDMA/100
[ 0.950265] ata1.00: ATA-7: QEMU HARDDISK, 2.5+, max UDMA/100
[ 0.951119] ata1.00: 41943040 sectors, multi 16: LBA48
[ 0.954203] scsi 0:0:0:0: Direct-Access ATA QEMU HARDDISK 2.5+ PQ: 0 ANSI: 5
[ 0.955917] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 0.956005] sd 0:0:0:0: [sda] 41943040 512-byte logical blocks: (21.5 GB/20.0 GiB)
[ 0.957882] scsi 1:0:0:0: CD-ROM QEMU QEMU DVD-ROM 2.5+ PQ: 0 ANSI: 5
[ 0.957932] sd 0:0:0:0: [sda] Write Protect is off
[ 0.959799] sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
[ 0.960021] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 0.963084] sd 0:0:0:0: [sda] Preferred minimum I/O size 512 bytes
[ 0.965530] sda: sda1 sda2 sda3
[ 0.966525] sd 0:0:0:0: [sda] Attached SCSI disk
[ 0.980441] sr 1:0:0:0: [sr0] scsi3-mmc drive: 4x/4x cd/rw xa/form2 tray
[ 0.981323] cdrom: Uniform CD-ROM driver Revision: 3.20
[ 1.000831] sr 1:0:0:0: Attached scsi CD-ROM sr0
[ 1.001129] sr 1:0:0:0: Attached scsi generic sg1 type 5
[ 1.027680] usb 1-1: new full-speed USB device number 2 using uhci_hcd
[ 1.197936] usb 1-1: New USB device found, idVendor=0627, idProduct=0001, bcdDevice= 0.00
[ 1.199181] usb 1-1: New USB device strings: Mfr=1, Product=4, SerialNumber=11
[ 1.200213] usb 1-1: Product: QEMU USB Keyboard
[ 1.200948] usb 1-1: Manufacturer: QEMU
[ 1.201606] usb 1-1: SerialNumber: 68284-0000:00:01.2-1
[ 1.212007] input: QEMU QEMU USB Keyboard as /devices/pci0000:00/0000:00:01.2/usb1/1-1/1-1:1.0/0003:0627:0001.0001/input/input4
[ 1.267149] hid-generic 0003:0627:0001.0001: input,hidraw0: USB HID v1.11 Keyboard [QEMU QEMU USB Keyboard] on usb-0000:00:01.2-1/input0
[ 1.444414] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input3
[ 1.445693] md: Waiting for all devices to be available before autodetect
[ 1.446697] md: If you don't use raid, use raid=noautodetect
[ 1.447487] md: Autodetecting RAID arrays.
[ 1.448152] md: autorun ...
[ 1.448701] md: ... autorun DONE.
[ 1.812639] EXT4-fs (sda3): orphan cleanup on readonly fs
[ 1.814472] EXT4-fs (sda3): mounted filesystem b0067cf0-3fd2-438d-96de-de58bfaec138 ro with ordered data mode. Quota mode: none.
[ 1.815926] VFS: Mounted root (ext4 filesystem) readonly on device 8:3.
[ 1.818233] devtmpfs: mounted
[ 1.821378] Freeing unused kernel image (initmem) memory: 2724K
[ 1.822487] Write protecting the kernel read-only data: 26624k
[ 1.824650] Freeing unused kernel image (rodata/data gap) memory: 1416K
[ 1.888524] x86/mm: Checked W+X mappings: passed, no W+X pages found.
[ 1.891102] x86/mm: Checking user space page tables
[ 1.938712] x86/mm: Checked W+X mappings: passed, no W+X pages found.
[ 1.939109] Run /sbin/init as init process
[ 1.939425] with arguments:
[ 1.939425] /sbin/init
[ 1.939426] with environment:
[ 1.939427] HOME=/
[ 1.939428] TERM=linux
[ 1.939429] BOOT_IMAGE=/vmlinuz-6.9-cchauvet
[ 2.016988] stty (179) used greatest stack depth: 12632 bytes left
[ 2.415319] udevd[311]: Starting systemd-udevd version 255
[ 2.431169] udevd[313]: Using default interface naming scheme 'v255'.
[ 2.666312] main: loading out-of-tree module taints kernel.
[ 2.668345] Hello world !
[ 3.106567] Adding 2097148k swap on /dev/sda2. Priority:1 extents:1 across:2097148k
[ 3.161714] EXT4-fs (sda3): re-mounted b0067cf0-3fd2-438d-96de-de58bfaec138 ro. Quota mode: none.
[ 3.262492] EXT4-fs (sda3): re-mounted b0067cf0-3fd2-438d-96de-de58bfaec138 r/w. Quota mode: none.
[ 3.297985] EXT4-fs (sda1): mounted filesystem 3140652f-dc11-4544-83f6-c779750d95a4 r/w without journal. Quota mode: none.

7
ass05/Makefile Normal file
View File

@ -0,0 +1,7 @@
obj-m += main.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

74
ass05/main.c Normal file
View File

@ -0,0 +1,74 @@
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#define STUDENT_LOGIN "cchauvet"
MODULE_LICENSE("GPL");
static ssize_t misc_write(struct file *file, const char __user *buf,
size_t len, loff_t *ppos)
{
char data[10];
size_t len_red = 10 > len ? len : 10;
if (copy_from_user(data, buf, len_red))
return -EFAULT;
if (strcmp(data, STUDENT_LOGIN))
return -EINVAL;
return len_red;
}
static ssize_t misc_read(struct file *file, char __user *buf,
size_t count, loff_t *f_pos)
{
char data[] = STUDENT_LOGIN;
size_t len = strlen(data);
if(*f_pos > 0)
return 0;
if (copy_to_user(buf, data, len))
return -EFAULT;
*f_pos += len;
return len;
}
const struct file_operations fops = {
.write = misc_write,
.read = misc_read,
};
static struct miscdevice misc_device = {
.name = "fortytwo",
.minor = MISC_DYNAMIC_MINOR,
.fops = &fops,
};
static int __init module_start(void)
{
int error = misc_register(&misc_device);
if (error) {
pr_err("misc_register failed!!!\n");
return error;
}
pr_info("misc_register init done!!!\n");
return 0;
}
static void __exit module_end(void)
{
misc_deregister(&misc_device);
pr_info("misc_register exit done!!!\n");
}
module_init(module_start)
module_exit(module_end)

20772
ass06/kern.log Normal file

File diff suppressed because it is too large Load Diff

18
ass07/Makefile Normal file
View File

@ -0,0 +1,18 @@
obj-m += main.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
test: all
rmmod -f main || true
insmod main.ko
cat /sys/kernel/debug/fortytwo/foo
echo "bozo" > /sys/kernel/debug/fortytwo/foo
cat /sys/kernel/debug/fortytwo/foo
cat /sys/kernel/debug/fortytwo/id
echo -n cchauvet > /sys/kernel/debug/fortytwo/id
echo bozo > /sys/kernel/debug/fortytwo/id || true
cat /sys/kernel/debug/fortytwo/jiffies

143
ass07/main.c Normal file
View File

@ -0,0 +1,143 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#include <linux/rwlock_types.h>
#define STUDENT_LOGIN "cchauvet"
MODULE_LICENSE("GPL");
struct dentry *subdir;
struct dentry *id_file;
struct dentry *jiffies_file;
struct dentry *foo_file;
static ssize_t id_read(struct file *, char *, size_t, loff_t *);
static ssize_t id_write(struct file *, const char *, size_t, loff_t *);
const struct file_operations id_file_fops = {
.owner = THIS_MODULE,
.write = id_write,
.read = id_read,
};
static ssize_t foo_read(struct file *, char *, size_t, loff_t *);
static ssize_t foo_write(struct file *, const char *, size_t, loff_t *);
const struct file_operations foo_file_fops = {
.owner = THIS_MODULE,
.write = foo_write,
.read = foo_read,
};
char foo_data[PAGE_SIZE];
size_t foo_data_len = 0;
DEFINE_MUTEX(foo_data_mutex);
static int __init module_start(void)
{
subdir = debugfs_create_dir("fortytwo", NULL);
if (!subdir)
goto create_fail;
id_file = debugfs_create_file("id", 0666, subdir, NULL, &id_file_fops);
if (!id_file)
goto create_fail;
debugfs_create_size_t("jiffies", 0444, subdir, (size_t *) &jiffies);
foo_file = debugfs_create_file("foo",0644, subdir, NULL, &foo_file_fops);
if (!foo_file)
goto create_fail;
printk(KERN_INFO "Hello world !\n");
return 0;
create_fail:
debugfs_remove_recursive(subdir);
return -ENOENT;
}
static void __exit module_end(void)
{
debugfs_remove_recursive(subdir);
printk(KERN_INFO "Cleaning up module.\n");
}
static ssize_t id_read(struct file *f, char *buf, size_t len, loff_t *f_pos)
{
char data[] = STUDENT_LOGIN;
size_t data_len = strlen(data);
if(*f_pos > 0)
return 0;
if (copy_to_user(buf, data, data_len))
return -EFAULT;
*f_pos += data_len;
return data_len;
}
static ssize_t id_write(struct file *f, const char *buf, size_t len, loff_t *offset)
{
char data[10];
size_t len_red = 10 > len ? len : 10;
if (copy_from_user(data, buf, len_red))
return -EFAULT;
if (strcmp(data, STUDENT_LOGIN))
return -EINVAL;
return len_red;
}
static ssize_t foo_read(struct file *f, char __user *buf, size_t len, loff_t *offset)
{
size_t len_red;
mutex_lock(&foo_data_mutex);
if (!buf)
return -EINVAL;
if (*offset > foo_data_len)
return 0;
if (len + *offset >= foo_data_len)
len_red = foo_data_len - *offset;
else
len_red = len;
if (copy_to_user(buf, foo_data + *offset, len_red))
return -EFAULT;
mutex_unlock(&foo_data_mutex);
*offset += len_red;
return len_red;
}
static ssize_t foo_write(struct file *, const char __user *buf, size_t len, loff_t *offset)
{
if (len > PAGE_SIZE)
return -EINVAL;
mutex_lock(&foo_data_mutex);
if (copy_from_user(foo_data, buf, len))
return -EFAULT;
foo_data_len = len;
mutex_unlock(&foo_data_mutex);
*offset = len;
return len;
}
module_init(module_start);
module_exit(module_end);

15
ass07/proof Normal file
View File

@ -0,0 +1,15 @@
make -C /lib/modules/6.10.0-rc1-00027-g4a4be1ad3a6e/build M=/root/lp/ass07 modules
make[1]: Entering directory '/usr/src/linux'
make[1]: Leaving directory '/usr/src/linux'
rmmod -f main || true
insmod main.ko
cat /sys/kernel/debug/fortytwo/foo
echo "bozo" > /sys/kernel/debug/fortytwo/foo
cat /sys/kernel/debug/fortytwo/foo
bozo
cat /sys/kernel/debug/fortytwo/id
cchauvetecho -n cchauvet > /sys/kernel/debug/fortytwo/id
echo bozo > /sys/kernel/debug/fortytwo/id || true
/bin/sh: line 1: echo: write error: Invalid argument
cat /sys/kernel/debug/fortytwo/jiffies
4294891809

7
ass08/Makefile Normal file
View File

@ -0,0 +1,7 @@
obj-m += main.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

63
ass08/main.c Normal file
View File

@ -0,0 +1,63 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <linux/slab.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Louis Solofrizzo <louis@ne02ptzero.me>");
MODULE_DESCRIPTION("Useless module");
static ssize_t myfd_read(struct file *fp, char __user *user, size_t size, loff_t *offs);
static ssize_t myfd_write(struct file *fp, const char __user *user,
size_t size, loff_t *offs);
static struct file_operations myfd_fops = {
.owner = THIS_MODULE,
.read = &myfd_read,
.write = &myfd_write
};
static struct miscdevice myfd_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "reverse",
.fops = &myfd_fops
};
char str[PAGE_SIZE];
static int __init myfd_init(void)
{
str[0] = 0;
misc_register(&myfd_device);
return 0;
}
static void __exit myfd_cleanup(void)
{
misc_deregister(&myfd_device);
}
ssize_t myfd_read(struct file *fp, char __user *buf, size_t size, loff_t *offs)
{
size_t str_len;
char tmp[PAGE_SIZE + 1];
str_len = strlen(str);
for (size_t i = 0; i != str_len; i++)
tmp[i] = str[str_len - 1 - i];
return simple_read_from_buffer(buf, size, offs, tmp, str_len);
}
ssize_t myfd_write(struct file *fp, const char __user *buf, size_t size, loff_t *offs)
{
ssize_t res;
res = simple_write_to_buffer(str, sizeof(str), offs, buf, PAGE_SIZE) + 1;
str[size] = 0x0;
return res;
}
module_init(myfd_init);
module_exit(myfd_cleanup)

7
ass09/Makefile Normal file
View File

@ -0,0 +1,7 @@
obj-m += main.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

80
ass09/main.c Normal file
View File

@ -0,0 +1,80 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/seq_file.h>
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/path.h>
#include <linux/proc_fs.h>
#include <linux/nsproxy.h>
#include <../fs/mount.h>
#define PROCFS_MAX_SIZE 1024
#define PROCFS_NAME "mymounts"
MODULE_LICENSE("GPL");
static int ft_proc_open(struct inode *inode, struct file *file);
static struct proc_dir_entry *proc_file;
static const struct proc_ops proc_file_ops = {
.proc_open = ft_proc_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};
static void show_mount(struct seq_file *m, struct mount *mnt)
{
struct path mnt_path = {
.dentry = mnt->mnt.mnt_root,
.mnt = &mnt->mnt
};
seq_printf(m, "%-15s", mnt->mnt_devname);
seq_path(m, &mnt_path, " \t\n\\");
seq_putc(m, '\n');
}
static void traverse_mount_tree(struct seq_file *m, struct rb_node *node)
{
struct mount *mnt;
if (!node)
return;
mnt = rb_entry(node, struct mount, mnt_node);
show_mount(m, mnt);
traverse_mount_tree(m, node->rb_left);
traverse_mount_tree(m, node->rb_right);
}
static int ft_proc_show(struct seq_file *m, void *v)
{
struct rb_root *root = &current->nsproxy->mnt_ns->mounts;
traverse_mount_tree(m, root->rb_node);
return 0;
}
static int ft_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, ft_proc_show, NULL);
}
static int __init mymounts_init(void)
{
proc_file = proc_create(PROCFS_NAME, 0644, NULL, &proc_file_ops);
if (proc_file == NULL) {
proc_remove(proc_file);
pr_err("could not initialize /proc/%s\n", PROCFS_NAME);
return -ENOMEM;
}
return 0;
}
static void __exit mymounts_exit(void)
{
proc_remove(proc_file);
}
module_init(mymounts_init);
module_exit(mymounts_exit);