Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions 01_git/scissors/scissors-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

arr=( rock paper scissors )

RANGE=3
number=$RANDOM
let "number %= $RANGE"


echo "Please choose: rock (r) - paper (p) - scissors (s)"
read -p "your choice: " choice


if [ $choice == r ]; then
choice=0
elif [ $choice == p ]; then
choice=1
elif [ $choice == s ]; then
choice=2
fi



echo You choose ${arr[$choice]}, I choose ${arr[$number]}

if [ $choice -eq $number ]; then
echo draw!!!
elif [ $choice -eq 0 ]; then
if [ $number -eq 1 ]; then
echo You win: ${arr[$number]} beats ${arr[$choice]}
else
echo I win: ${arr[$choice]} beats ${arr[$number]}
fi
elif [ $choice -eq 1 ]; then #paper 1
if [ $number -eq 0 ]; then #rock 0
echo You win: ${arr[$choice]} beats ${arr[$number]}
else
echo I win: ${arr[$number]} beats ${arr[$choice]}
fi
elif [ $choice -eq 2 ]; then
if [ $number -eq 0 ]; then
echo I win: ${arr[$number]} beats ${arr[$choice]}
else
echo You win: ${arr[$choice]} beats ${arr[$number]}
fi
fi


# -lt less

22 changes: 22 additions & 0 deletions 02_bash/hwdetect/hwdetect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

arr1=( $(ls /dev) )
arr2=


while [ 0 ]
do

arr2=( $(ls /dev) )

for t in ${arr2[@]}; do
if [[ "${arr1[@]}" =~ "$t" ]]; then
continue
else
echo "New dev = $t"
fi
done
arr1=${arr2[@]}
sleep 1
done

18 changes: 18 additions & 0 deletions 03_module/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BUILD_KERNEL=/home/dtretiakov/Desktop/Linux-Kernel-ProCamp-2021/linux-stable


obj-m+=simplest-kernel-module.o
all: build rm-trash file-push-to-qemu

build:
make -C ${BUILD_KERNEL} M=$(PWD) modules

clean:
make -C ${BUILD_KERNEL} M=$(PWD) clean

rm-trash:
rm -f *.mod *.order *.o *. *.symvers *.mod.c .*.cmd

file-push-to-qemu:
sshpass -p 'pass' scp -P 8022 *.ko user@localhost:~

32 changes: 32 additions & 0 deletions 03_module/simplest-kernel-module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <linux/init.h> // Macros used to mark up functions __init __exit
#include <linux/module.h> // Core header for loading LKMs into the kernel
#include <linux/kernel.h> // Contains types, macros, functions for the kernel
#include <linux/moduleparam.h>

static int int_param1;
static int int_param2;
module_param(int_param1, int, 0);
module_param(int_param2, int, 0);

MODULE_LICENSE( "GPL" );
MODULE_DESCRIPTION("A simple Linux driver.");
MODULE_VERSION("0.1");

static int __init hello_init( void ) {
printk( KERN_NOTICE "Hello, world!" );

printk( KERN_NOTICE "int1 + int2 = %d", int_param1 + int_param2 );

return -1;
}

// static void __exit hello_exit( void ) {
// printk( KERN_DEBUG "Goodbye, world!" );
// }


module_init( hello_init );
//module_exit( hello_exit );



22 changes: 22 additions & 0 deletions 04_basic_struct/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BUILD_KERNEL=/home/dtretiakov/Desktop/Linux-Kernel-ProCamp-2021/linux-stable


obj-m+=kobject-module.o
all: build rm-trash file-push-to-qemu

build:
make -C $(BUILD_KERNEL) M=$(PWD) modules

clean:
make -C $(BUILD_KERNEL) M=$(PWD) clean

rm-trash:
rm -f *.mod *.order *.o *. *.symvers *.mod.c .*.cmd

file-push-to-qemu:
sshpass -p 'pass' scp -P 8022 *.ko user@localhost:~



# qemu
# !6770
94 changes: 94 additions & 0 deletions 04_basic_struct/kobject-module.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <linux/init.h> // Macros used to mark up functions __init __exit
#include <linux/module.h> // Core header for loading LKMs into the kernel
#include <linux/kernel.h> // Contains types, macros, functions for the kernel
#include <linux/moduleparam.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <linux/list.h>
#include <linux/slab.h>


MODULE_LICENSE( "GPL" );
MODULE_DESCRIPTION("A simple Linux...");
MODULE_VERSION("0.1");

static LIST_HEAD(linkedlist);

typedef struct my_arr_str_t {
char str [ 20 ];
struct list_head list;
} my_arr_str_s;

static my_arr_str_s my_arr [ 20 ];
static unsigned int counter = 0;
//static ssize_t value = 0;

static ssize_t my_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
int res = 0;
int cursor = 0;
struct my_arr_str_t *cur_node = NULL;

list_for_each_entry(cur_node, &linkedlist, list){
res = sprintf(&buf[cursor], "%s\n", cur_node->str);

if (res > 0)
cursor += res;

}


//sprintf(buf, "%u\n", value);
return strlen(buf);
}

static ssize_t my_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t count)
{
sscanf(buf, "%s\n", my_arr[counter++].str);
//pr_info("add: |%s|\n", my_arr[counter - 1].str);
//list_add( &my_arr[counter - 1].list, &my_arr[0].list );
list_add_tail(&my_arr[counter - 1].list, &linkedlist);
return count;
}


static struct kobj_attribute list_attribute =
__ATTR(param, 0664, my_show, my_store);

static struct kobject *my_kobj;

static int my_init(void)
{
int res = 0;

INIT_LIST_HEAD(&my_arr[counter].list);

my_kobj = kobject_create_and_add("my-kobj", kernel_kobj);
if (!my_kobj)
return -ENOMEM;
res = sysfs_create_file(my_kobj, &list_attribute.attr);
if (res)
kobject_put(my_kobj);
return res;
}



static void my_exit(void)
{
struct my_arr_str_t *cur_node = NULL;
struct my_arr_str_t *tmp_node = NULL;

list_for_each_entry_safe(cur_node, tmp_node, &linkedlist, list) {
list_del(&cur_node->list);
}

kobject_put(my_kobj);
pr_info("module exited\n");
}

module_init(my_init);
module_exit(my_exit);

10 changes: 10 additions & 0 deletions 05_timers/part1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@




all:
gcc timers.c -o timers

clean:
rm -f timers

Binary file added 05_timers/part1/timers
Binary file not shown.
60 changes: 60 additions & 0 deletions 05_timers/part1/timers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <time.h>
#include <stdio.h>




int main()
{
struct timespec tp1, tp2;

clock_gettime( CLOCK_REALTIME, &tp1 );
clock_getres( CLOCK_REALTIME, &tp2 );
printf ( "%s| CLOCK_REALTIME = %ld| resolution =%ld (Nanoseconds)\n",ctime(&tp1.tv_sec), tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_MONOTONIC, &tp1 );
clock_getres( CLOCK_MONOTONIC, &tp2 );
printf( "CLOCK_MONOTONIC = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &tp1 );
clock_getres( CLOCK_PROCESS_CPUTIME_ID, &tp2 );
printf( "CLOCK_PROCESS_CPUTIME_ID = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_THREAD_CPUTIME_ID, &tp1 );
clock_getres( CLOCK_THREAD_CPUTIME_ID, &tp2 );
printf( "CLOCK_THREAD_CPUTIME_ID = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_MONOTONIC_RAW, &tp1 );
clock_getres( CLOCK_MONOTONIC_RAW, &tp2 );
printf( "CLOCK_MONOTONIC_RAW = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_REALTIME_COARSE, &tp1 );
clock_getres( CLOCK_REALTIME_COARSE, &tp2 );
printf( "CLOCK_REALTIME_COARSE = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_MONOTONIC_COARSE, &tp1 );
clock_getres( CLOCK_MONOTONIC_COARSE, &tp2 );
printf( "CLOCK_MONOTONIC_COARSE = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_BOOTTIME, &tp1 );
clock_getres( CLOCK_BOOTTIME, &tp2 );
printf( "CLOCK_BOOTTIME = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_REALTIME_ALARM, &tp1 );
clock_getres( CLOCK_REALTIME_ALARM, &tp2 );
printf( "CLOCK_BOOTTIME = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );

clock_gettime( CLOCK_TAI, &tp1 );
clock_getres( CLOCK_TAI, &tp2 );
printf( "CLOCK_TAI = %ld| resolution =%ld (Nanoseconds)\n", tp1.tv_sec, tp2.tv_nsec );



}







22 changes: 22 additions & 0 deletions 05_timers/part2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BUILD_KERNEL=/home/dtretiakov/Desktop/Linux-Kernel-ProCamp-2021/linux-stable


obj-m+=time-module.o
all: build rm-trash file-push-to-qemu

build:
make -C $(BUILD_KERNEL) M=$(PWD) modules

clean:
make -C $(BUILD_KERNEL) M=$(PWD) clean

rm-trash:
rm -f *.mod *.order *.o *. *.symvers *.mod.c .*.cmd

file-push-to-qemu:
sshpass -p 'pass' scp -P 8022 *.ko script-test user@localhost:~



# qemu
# !6770
5 changes: 5 additions & 0 deletions 05_timers/part2/script-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

dmesg -c
clear

Loading