Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Kernel-GL-HRK/gl_kernel_BaseCamp_2022_II
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: US3RN2ME/gl_kernel_BaseCamp_2022_II
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
Loading
55 changes: 55 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

# Additional
scripts
13 changes: 13 additions & 0 deletions task1-simple-program/get_random_number.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdlib.h>
#include <time.h>
#include "get_random_number.h"

unsigned char get_random_number(unsigned char lower, unsigned char upper)
{
static unsigned char randomized;
if (!randomized) {
srand(time(NULL));
randomized = 1;
}
return rand() % (upper - lower + 1) + lower;
}
6 changes: 6 additions & 0 deletions task1-simple-program/get_random_number.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef FUNC_H
#define FUNC_H

unsigned char get_random_number(unsigned char, unsigned char);

#endif //FUNC_H
26 changes: 26 additions & 0 deletions task1-simple-program/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include "get_random_number.h"

static const unsigned char upper = 9;

int main(void)
{
unsigned char user_choice;

printf("Guess a number (0-%hhd) -> ", upper);

if (!scanf("%hhd", &user_choice) || user_choice > upper) {
printf("Wrong input\n");
return -1;
}

const unsigned char pc_choice = get_random_number(0, upper);

if (user_choice != pc_choice) {
printf("You lost %hhd != %hhd\n", user_choice, pc_choice);
return 1;
}

printf("You won %hhd = %hhd\n", user_choice, pc_choice);
return 0;
}
12 changes: 12 additions & 0 deletions task2-bash/script1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash

mkdir /tmp/guessanumber

cp ../task1-simple-program/*.{c, h} /tmp/guessanumber

tar -zcvf guessanumber.tar.gz /tmp/guessanumber

mkdir release

mv guessanumber.tar.gz release/

49 changes: 49 additions & 0 deletions task2-bash/script2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#! bin/bash

BLUE='\033[0;34m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'

PATH=../task1-simple-program

if ! [[ -f ${PATH}/main.out ]]; then
gcc ${PATH}/main.c ${PATH}/func.c -o ${PATH}/guess-number
fi

counter=1
wins=0
looses=0

while true; do
echo -e ${BLUE}"Tries: ${counter}\t Wins: ${wins}\t Looses: ${looses}"${NC}

((--counter))

${PATH}/main.out
ret=$?

if [ $ret -eq 0 ]; then
echo -e ${GREEN}"Good job"${NC}
((++wins))
elif [ $ret -eq 1 ]; then
echo -e ${RED}"Wish a goog luck next time"${NC}
((++looses))
fi

if [ $counter -eq 0 ]; then
echo -n -e ${YELLOW}"Want to continue (Y/N) | Number of tries ->"${NC}
read reply

case $reply in

No|NO|N|n) break ;;

("" | *[!0-9]*) ((++counter)) ;;

(*) counter=$reply ;;

esac
fi
done
77 changes: 77 additions & 0 deletions task3-make/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
CC =

CHECKER = ../scripts/checkpatch.pl
CHECKER_FLAGS = --no-tree -f

PROGRAM = main

DEBUG_FLAGS = -DDEBUG -g
WARN_FLAGS = -Wall -Wextra -Wpedantic

EXTRA_LDFLAGS =
EXTRA_CFLAGS = -fdata-sections -ffunction-sections
CPPFLAGS =
CFLAGS =

SRCDIR = ../task1-simple-program
SOURCES = $(SRCDIR)/main.c $(SRCDIR)/get_random_number.c
HEADERS = $(SRCDIR)/get_random_number.h
OBJS = $(addsuffix .o, $(basename $(SOURCES)))

LIBTYPE =

ifeq ($(LIBTYPE),static)
DEPS = libfunc.a
endif

ifeq ($(LIBTYPE),shared)
EXTRA_LDFLAGS = -lfunc -L ./
CFLAGS = -fPIC
DEPS = libfunc.so
endif

COMPILE.c = $(CC) $(EXTRA_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c
LINK.c = $(CC) $(EXTRA_CFLAGS) $(CPPFLAGS) $(LDFLAGS)

.PHONY: build debug warn check clean help

build:$(PROGRAM)

debug:CPPFLAGS += $(DEBUG_FLAGS)
debug:$(PROGRAM)

warn:CPPFLAGS += $(WARN_FLAGS)
warn:$(PROGRAM)

$(PROGRAM):$(OBJS) $(DEPS)
$(LINK.c) $(OBJS) $(EXTRA_LDFLAGS) -o $@
@echo Type ./$@ to execute the program.

objs:$(OBJS)

%.o:%.c
$(COMPILE.c) $< -o $@

lib%.so:%.o
$(CC) -shared -Wl,-soname,$@.1 -o $@.1.0 $^ -lc
ln -sf $@.1.0 $@.1
ln -sf $@.1 $@

lib%.a:%.o
ar rcs $@ $^

check:
$(foreach d,$(SOURCES),$(CHECKER) $(CHECKER_FLAGS) $(d))

clean:
rm -f $(OBJS) $(PROGRAM) *.a *.so $(PROGRAM).out

help:
@echo 'Usage: make [TARGET]'
@echo 'TARGETS:'
@echo ' build (=make) compile and link.'
@echo ' debug build with debug info.'
@echo ' warn build with all warnings.'
@echo ' objs compile only (no linking).'
@echo ' clean clean objects and the executable file.'
@echo ' help print this message.'
24 changes: 24 additions & 0 deletions task4-simple-module/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
TARGET_MODULE:=simple-module

ifneq ($(KERNELRELEASE),)
$(TARGET_MODULE)-objs := main.o
obj-m := $(TARGET_MODULE).o
else
BUILDSYSTEM_DIR:=/lib/modules/$(shell uname -r)/build
PWD:=$(shell pwd)

.PHONY: all clean load unload

all:
$(MAKE) -C $(BUILDSYSTEM_DIR) M=$(PWD) modules

clean:
$(MAKE) -C $(BUILDSYSTEM_DIR) M=$(PWD) clean

load:
insmod ./$(TARGET_MODULE).ko

unload:
rmmod ./$(TARGET_MODULE).ko

endif
48 changes: 48 additions & 0 deletions task4-simple-module/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
//
// Kernel module
// Prints "module_init" message on init
// Calculates and prints sum, subtraction and product of two parameters
// Prints "module_exit" message on exit

#include <linux/init.h>
#include <linux/module.h>

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Simple kernel module");
MODULE_AUTHOR("Tereshchenko Dmytro <buxdmo@gmail.com>");
MODULE_VERSION("1.0");

#ifdef pr_fmt
#undef pr_fmt
#endif

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

static int param1;
static int param2;

module_param(param1, int, 0660);
module_param(param2, int, 0660);

MODULE_PARM_DESC(param1, "First parameter");
MODULE_PARM_DESC(param2, "Second parameter");

/*===============================================================================================*/
static int driver_init(void)
{
pr_notice("module_init\n");
pr_info("The sum of %d and %d is %d\n", param1, param2, param1 + param2);
pr_info("The diff of %d and %d is %d\n", param1, param2, param1 - param2);
pr_info("The product of %d and %d is %d\n", param1, param2, param1 * param2);
return 0;
}
/*===============================================================================================*/
static void driver_exit(void)
{
pr_notice("module_exit\n");
}
/*===============================================================================================*/

module_init(driver_init);
module_exit(driver_exit);