diff options
| author | Manuel Traut <manut@linutronix.de> | 2017-07-11 19:13:28 +0200 |
|---|---|---|
| committer | Manuel Traut <manut@linutronix.de> | 2018-03-16 21:41:06 +0100 |
| commit | 9f53eae4a68c229ac114d61bf7b61873c95bb18d (patch) | |
| tree | 2646445a1432851afc3ab73d52c1504686082b40 | |
| parent | ebb074d963c85e394f445793eea76423e88af3f6 (diff) | |
added pruefung 2012..14
Signed-off-by: Manuel Traut <manut@linutronix.de>
| -rw-r--r-- | 2012-pruefung.tex | 169 | ||||
| -rw-r--r-- | 2013-pruefung.tex | 154 | ||||
| -rw-r--r-- | 2014-pruefung.tex | 442 |
3 files changed, 765 insertions, 0 deletions
diff --git a/2012-pruefung.tex b/2012-pruefung.tex new file mode 100644 index 0000000..4f5f8cc --- /dev/null +++ b/2012-pruefung.tex @@ -0,0 +1,169 @@ +\documentclass[addpoints,12pt]{exam} + +\usepackage{german} +\usepackage{listings,color} +\usepackage{graphicx} + +\firstpageheadrule +\runningheadrule +\lhead{Manuel Traut\\SoSe 2012} +\chead{Hochschule Ravensburg-Weingarten\\Linux-Kernelprogrammierung} +\rhead{MatrNr:\\Datum:} + +\firstpagefootrule +\runningfootrule +\firstpagefooter{Page \thepage\ of \numpages} +{} +{Punkte: \makebox[.5in]{\hrulefill}\\ +von \pointsonpage{\thepage} Punkten} + +\runningfooter{Page \thepage\ of \numpages} +{} +{} + +\pagestyle{headandfoot} + +\pointsinrightmargin +\pointpoints{Punkt}{Punkte} + +\begin{document} + + +\begin{coverpages} +\begin{titlepage} +\title{Pr\"ufung Linux-Kernelprogrammierung} +\author{Dozent: Manuel Traut} +\date{19. Juli 2012} +\maketitle +\begin{center} +Hochschule Ravensburg-Weingarten +\vspace{1cm} + +Dauer: 60 Minuten, erlaubte Hilfsmittel: keine +\end{center} + +\vspace{2cm} +Name:\enspace\hrulefill +\vspace{2cm} +MatrNr:\enspace\hrulefill +\begin{center} +\begin{lstlisting} + a8888b. + d888888b. + 8P"YP"Y88 (((((((()))))))))) + 8|o||o|88 ||VIEL ERFOLG !!|| + 8' .88 ((((((((((((())))) + 8`._.' Y8. + d/ `8b. + .dP . Y8b. + d8:' " `::88b. + d8" `Y88b + :8P ' :888 + 8a. : _a88P + ._/"Yaa_ : .| 88P| + \ YP" `| 8P `. + / \._____.d| .' + `--..__)888888P`._.' +\end{lstlisting} +\end{center} +\end{titlepage} +\end{coverpages} + + +\begin{questions} + +\section{Entwicklungsmodell} + +\question[1] Was versteht man unter dem Begriff 'Kernelpatch'? + +\question[3] F\"ur die Linuxkernelentwicklung wurde das + Versionskontrollsystem git entwickelt. Nennen Sie mind. 4 gravierende + Unterschiede zu Versionskontrollsystemen wie cvs oder svn. + +\question Im Linuxsourcetree gibt es einen Ordner 'staging'. +\begin{parts} +\part[1] Was findet man in diesem Ornder? +\part[2] Was ist zu beachten? +\end{parts} + +\question[4] Beschreiben Sie die Aufgaben und die Verantwortung eines Linux +Kernelmaintainers. + +\section{Tools} + +\question +\begin{parts} +\part[1] Was ist auf folgendem Bild zu sehen? +\part[3] Warum wird es ben\"otigt? +\part[4] Was kann mit diesem Tool gemacht werden? (beschreiben Sie Kategorien) +\end{parts} + +\includegraphics[height=0.3\textwidth]{./images/kconfig.png} + +\question [6] Ein von Ihnen entwickelter Kerneltreiber funktioniert nicht wie +erwartet. Welche Debugingm\"oglichkeiten haben Sie? + +Nennen Sie mindestens zwei und Beschreiben Sie Vor- und Nachteile + +\section{Plumbing Layer} + +\question [2] Sie starten ein Linuxsystem. Die letzten Ausgaben lauten: + 'freeing memory, loading init' + Nennen Sie 2 m\"ogliche Ursachen. + +\question [2] In 3.4-rc2 wurde die sogenannte x32 system call ABI Patche + gemerged. Was f\"ur Funktionalit\"at haben Sie eingef\"uhrt? + (grobe Beschreibung) + +\section{Programmierung} + +\question Zusammenspiel des Linuxtreibermodels: + +Denken Sie dabei an die Strukturen 'Bus', 'Device' und 'Driver'; +Beschreiben Sie: +\begin{parts} +\part [1] Wie kann die Zust\"andigkeit eines Treibers f\"ur ein Ger\"at + ausgedr\"uckt werden? +\part [2] Was wird typischerweise in einer register\_* Funktion gemacht? +\part [3] Wozu dient eine *probe Funktion? +\end{parts} + +\question Sie wollen einen SPI LED Baustein (erm\"oglicht das Steuern von 16 +LEDs - an, aus, helligkeit - mittels SPI Kommandos) an Ihr embedded Linux +Board anschliessen. Alle Treiber f\"ur Ihr Board sind bereits im Mainline Linux +enthalten. Allerdings gibt es noch keine Unterst\"utzung für Ihren LED Baustein. +Sie haben ein Datenblatt vom Hersteller des LED Bausteins, der die +unterst\"utzen SPI Befehle beschreibt. Was tun Sie nun? +\begin{parts} +\part [10] Beschreiben Sie 2 M\"oglichkeiten, wie Sie den LED Baustein per + Software integrieren k\"onnten. Nennen Sie jeweils Vor- und + Nachteile. Markieren Sie die M\"oglichkeit welche Sie f\"ur am + sinnvollsten erachten und f\"ur die Beantwortung der nachfolgenden + Fragen als Basis nutzen. + +\part [3] Welche Dateien im Linuxkernel werden Sie modifizieren / anlegen ? +\part [2] Wie k\"onnen die LEDs vom Kernel aus geschalten werden? (Pseudocode) +\part [5] Wie k\"onnen die LEDs vom Userspace aus geschalten werden? + Skizzieren Sie auch den Weg durch beteiligte Subsysteme. +\end{parts} + +\section{Rootfilesystem} + +\question Sie haben ein System mit 256 MB NAND Flash und sollen ein + GNU/Linux Userspace (ohne Xorg, etc) einrichten. Es sollen g\"angige Tools + f\"ur Netzwerk, Bluetooth und Audio vorhanden sein. + +\begin{parts} +\part [2] Wie erstellen Sie das Rootfilesystem ? (Tools, Steps, Pseudocode) +\part [6] Sie haben einen u-boot Bootloader und k\"onnen aus Flash und von SD + Card booten. Das Rootfilesystem soll zuk\"unftig auf einem ubifs + liegen. Wie gehen Sie vor? (Tools, Steps, Pseudocode) +\end{parts} +\end{questions} + +\vspace{1cm} +Punkte: \_\_\_\_ von \numpoints +\hspace{1cm} +Note: + +\end{document} diff --git a/2013-pruefung.tex b/2013-pruefung.tex new file mode 100644 index 0000000..cc0a827 --- /dev/null +++ b/2013-pruefung.tex @@ -0,0 +1,154 @@ +\documentclass[addpoints,12pt]{exam} + +\usepackage{ngerman} +\usepackage{listings,color} +\usepackage{graphicx} + +\firstpageheadrule +\runningheadrule +\lhead{Manuel Traut\\SoSe 2013} +\chead{Hochschule Ravensburg-Weingarten\\Linux-Kernelprogrammierung} +\rhead{MatrNr:\\Datum:} + +\firstpagefootrule +\runningfootrule +\firstpagefooter{Page \thepage\ of \numpages} +{} +{Punkte: \makebox[.5in]{\hrulefill}\\ +von \pointsonpage{\thepage} Punkten} + +\runningfooter{Page \thepage\ of \numpages} +{} +{} + +\pagestyle{headandfoot} + +\pointsinrightmargin +\pointpoints{Punkt}{Punkte} + +\begin{document} + + +\begin{coverpages} +\begin{titlepage} +\title{Pr\"ufung Linux-Kernelprogrammierung} +\author{Dozent: Manuel Traut} +\date{02. Juli 2013 16:30 Uhr\\Raum H143} +\maketitle +\begin{center} +Hochschule Ravensburg-Weingarten +\vspace{1cm} + +Dauer: 60 Minuten, erlaubte Hilfsmittel: keine +\end{center} + +\vspace{2cm} +Name:\enspace\hrulefill +\vspace{2cm} +MatrNr:\enspace\hrulefill +\begin{center} +\begin{lstlisting} + a8888b. + d888888b. + 8P"YP"Y88 (((((((()))))))))) + 8|o||o|88 ||VIEL ERFOLG !!|| + 8' .88 ((((((((((((())))) + 8`._.' Y8. + d/ `8b. + .dP . Y8b. + d8:' " `::88b. + d8" `Y88b + :8P ' :888 + 8a. : _a88P + ._/"Yaa_ : .| 88P| + \ YP" `| 8P `. + / \._____.d| .' + `--..__)888888P`._.' +\end{lstlisting} +\end{center} +\end{titlepage} +\end{coverpages} + + +\begin{questions} + +\section*{Entwicklungsmodell} + +\question[3] Was versteht man unter dem Begriff 'Kernelpatch'? Wie wird ein + Patch erstellt und angewendet? + +\question[4] F\"ur die Linuxkernelentwicklung wurde das + Versionskontrollsystem git entwickelt. Nennen Sie mind. 4 gravierende + Unterschiede zu Versionskontrollsystemen wie cvs oder svn. + +\question[6] Beschreiben Sie den Releasezyklus/Versionierung des Linuxkernels + (seit v3.0). Verwenden Sie in diesem Zusammenhang die Begriffe: + 'Release', 'stable Kernel', 'Release Candidate', 'merge window' + +\question Im Linuxsourcetree gibt es einen Ordner 'staging'. +\begin{parts} +\part[1] Was findet man in diesem Ordner? +\part[2] Wann wird der Code aus diesem Ordner gel\"oscht / verschoben? +\end{parts} + +\section*{Tools} + +\question +\begin{parts} +\part[1] Welches Tool ist auf folgendem Bild zu sehen? +\part[1] \"Uber welche Datei wird der Inhalt / Struktur des Tools gesteuert? +\part[8] Welche Einstellungen k\"onnen mit Hilfe dieses Tools konfiguriert + werden? (beschreiben Sie 4 Kategorien) +\end{parts} + +\includegraphics[height=0.3\textwidth]{./images/kconfig.png} + +\question[6] Ein von Ihnen entwickelter Kerneltreiber funktioniert nicht wie +erwartet. Welche Debugingm\"oglichkeiten haben Sie? + +Nennen Sie mindestens zwei und beschreiben Sie Vor- und Nachteile + +\question[5] Was mu\ss \space ein Bootloader tun um Linux zu booten? + +\section*{Programmierung} + +\question[6] Kernel- und Userspace arbeiten in unterschiedlichen + Addressr\"aumen. Nennen Sie 3 M\"oglichkeiten, wie Daten zwischen den + Bereichen ausgetauscht werden k\"onnen. Nennen Sie jeweils typische + Verwendung, gegebenenfalls Einschr\"ankungen. + +\question Das Kernelsubsystem 'Userspace-IO' (UIO) kann zur Entwicklung eigener + Treiber verwendet werden. +\begin{parts} +\part[3] Welche Einschr\"ankungen gelten? +\part[2] Mu\ss \space der komplette Quellcode des Treibers ver\"offentlicht + werden? +\end{parts} + +\question Sie wollen Ihren eigenen Treiber in Mainline Linux integriert + haben. +\begin{parts} +\part[4] Was \"ubermitteln Sie auf welchem Weg wohin? +\part[2] Wie wird die Qualit\"at Ihres Treibers gepr\"uft, wie reagieren Sie + gegebenenfalls auf Beanstandungen? +\end{parts} + +\section*{Rootfilesystem} + +\question Sie haben ein ARM embedded System mit 256 MB NAND Flash und sollen ein + GNU/Linux Userspace einrichten. Es soll Netzwerk, Bluetooth und Audio + Unterst\"utzung vorhanden sein. +\begin{parts} +\part [3] Aus welchen Komponenten besteht das Rootfilesystem? +\part [2] Wie erstellen Sie ein Rootfilesystem f\"ur dieses System? +\part [1] Was mu\ss \space beim \"Ubertragen der Daten auf das Zielmedium + beachtet werden? +\end{parts} +\end{questions} + +\vspace{1cm} +Punkte: \_\_\_\_ von \numpoints +\hspace{1cm} +Note: + +\end{document} diff --git a/2014-pruefung.tex b/2014-pruefung.tex new file mode 100644 index 0000000..ebb2232 --- /dev/null +++ b/2014-pruefung.tex @@ -0,0 +1,442 @@ +\documentclass[addpoints,12pt]{exam} + +\usepackage{ngerman} +\usepackage{listings,color} +\usepackage{graphicx} + +\firstpageheadrule +\runningheadrule +\lhead{Manuel Traut\\Sommersemester 2014} +\chead{Hochschule Ravensburg-Weingarten\\Linux-Kernelprogrammierung} +\rhead{MatrNr:\\Datum:} + +\firstpagefootrule +\runningfootrule +\firstpagefooter{Page \thepage\ of \numpages} +{} +{Punkte: \makebox[.5in]{\hrulefill}\\ +von \pointsonpage{\thepage} Punkten} + +\runningfooter{Page \thepage\ of \numpages} +{} +{} + +\pagestyle{headandfoot} + +\pointsinrightmargin +\pointpoints{Punkt}{Punkte} + +\begin{document} + + +\begin{coverpages} +\begin{titlepage} +\title{Pr\"ufung Linux-Kernelprogrammierung} +\author{Dozent: Manuel Traut} +\date{21. Juli 2014 08:00 Uhr} +\maketitle +\begin{center} +Hochschule Ravensburg-Weingarten +\vspace{1cm} + +Dauer: 60 Minuten, erlaubte Hilfsmittel: handschriftliche Mitschriebe/Notizen +\end{center} + +\vspace{2cm} +Name:\enspace\hrulefill +\vspace{2cm} +MatrNr:\enspace\hrulefill +\begin{center} +\begin{lstlisting} + a8888b. + d888888b. + 8P"YP"Y88 (((((((()))))))))) + 8|o||o|88 ||VIEL ERFOLG !!|| + 8' .88 ((((((((((((())))) + 8`._.' Y8. + d/ `8b. + .dP . Y8b. + d8:' " `::88b. + d8" `Y88b + :8P ' :888 + 8a. : _a88P + ._/"Yaa_ : .| 88P| + \ YP" `| 8P `. + / \._____.d| .' + `--..__)888888P`._.' +\end{lstlisting} +\end{center} +\end{titlepage} +\end{coverpages} + +\lstset{ % + basicstyle=\scriptsize, % the size of the fonts that are used for the code + breaklines=true, % sets automatic line breaking + frame=single, % adds a frame around the code + language=C, % the language of the code + numbers=left, % where to put the line-numbers; + numbersep=5pt, % how far the line-numbers are from the code + numberstyle=\tiny, % the style that is used for the line-numbers + tabsize=8, % sets default tabsize to 2 spaces +} + + +\begin{questions} + +\section*{Entwicklungsmodell - Development process} + +\question[7] Beschreiben Sie den Releasezyklus und die Versionierung des + Linuxkernel (seit v3.0). Verwenden Sie in diesem Zusammenhang die Begriffe: + 'stable Kernel', 'Release Candidate', 'merge window' +\begin{verbatim} +Describe the release cycle and version numbering of the Linux kernel +(since linux v3.0). Use the terms 'release candidate', 'merge window', +'stable kernel'. +\end{verbatim} + +\question Im Linux Quellcode gibt es einen Ordner 'staging'. +\begin{verbatim} +There is a folder named 'staging' inside the linux source tree. +\end{verbatim} +\begin{parts} +\part[1] Was findet man in diesem Ordner? +\begin{verbatim} +What is stored in this folder? +\end{verbatim} +\part[2] Wann werden Dateien aus diesem Ordner gel\"oscht / verschoben? +\begin{verbatim} +What conditions needs to be met that a file from this folder will be +moved or deleted? +\end{verbatim} +\end{parts} + +\question Der Linux Kernel wird im Versionskontrollsystem git verwaltet. +\begin{verbatim} +The Linux kernel is maintained in the version control system git. +\end{verbatim} +\begin{parts} +\part[1] Welches Subkommando verwenden Sie um den Quellcode z.B. des Linux +Kernels auf Ihren PC zu \"ubertragen? +\begin{verbatim} +Which subcommand to you use to transfer e.g. the source code of the linux +kernel to your pc? +\end{verbatim} +\part[3] Was k\"onnen Sie mit dem Subkommando 'branch' alles machen? +\begin{verbatim} +What can be done with the subcommand 'branch'? +\end{verbatim} +\end{parts} + +\newpage + +\section*{Tools} + +\question +\begin{parts} +\part[1] Welches Kommando f\"uhrt zu den Ausgaben auf folgendem Bild? +\begin{verbatim} +Which command was used to produce the following output? +\end{verbatim} +\part[1] \"Uber welche Dateien wird der Inhalt / Struktur des Tools gesteuert? +\begin{verbatim} +What files are used to alter the content and layout of the tool? +\end{verbatim} +\end{parts} + +\includegraphics[height=0.3\textwidth]{./images/kconfig.png} + +\question[6] Ein von Ihnen entwickelter Kerneltreiber funktioniert nicht wie +erwartet. Welche Debugging M\"oglichkeiten haben Sie? + +Nennen Sie mindestens zwei und beschreiben Sie Vor- und Nachteile + +\begin{verbatim} +You developed a linux driver that doesn't work as expected. +What kind of debugging is available? + +Describe the advantages and disadvantages of two different methods. +\end{verbatim} + + +\section*{Rootfilesysteme - Rootfilesystems} + +\question[2] Sie haben ein statisch gelinktes C Programm und wollen, dass der +Kernel dieses direkt anstartet. Wie erreichen Sie dies? +\begin{verbatim} +You have a staticly linked C application that should be started directly by +the kernel. What needs to be done? +\end{verbatim} + +\question[2] In welchen F\"allen macht es Sinn keine Linux Distribution +einzusetzen? +\begin{verbatim} +In which cases is it useful to avoid using a linux distribution? +\end{verbatim} + +\newpage + +\section*{Programmierung - Programming} + +\question Das Kernelsubsystem 'Userspace-IO' (UIO) kann zur Entwicklung eigener + Treiber verwendet werden. +\begin{verbatim} +The Userspace-IO (UIO) subsystem of the kernel can be used +to develop an own driver. +\end{verbatim} +\begin{parts} +\part[3] Welche Einschr\"ankungen gelten? +\begin{verbatim} +What limitations are given? +\end{verbatim} +\part[2] Mu\ss \space der Quellcode des Treibers ver\"offentlicht + werden? +\begin{verbatim} +Do you need to publish the source code of the driver? +\end{verbatim} +\part[1] F\"ur welche Hardware macht ein UIO Treiber keinen Sinn? +\begin{verbatim} +For what kind of hardware is an UIO driver non-sense? +\end{verbatim} +\end{parts} + +\question Sie wollen Ihren eigenen Treiber in Mainline Linux integriert + haben. +\begin{verbatim} +You have developed an own driver and you want to get it +integrated into mainline linux. +\end{verbatim} +\begin{parts} +\part[4] Was \"ubermitteln Sie auf welchem Weg wohin? +\begin{verbatim} +What do you transfer? How do you transfer it? And who is the recipient? +\end{verbatim} +\part[2] Wie wird die Qualit\"at Ihres Treibers gepr\"uft, wie reagieren Sie + gegebenenfalls auf Beanstandungen? +\begin{verbatim} +What will be done to check the quality of your driver? How do you react on +change requests? +\end{verbatim} +\end{parts} + +\newpage + +\question + +Die folgenden Fragen beziehen sich auf den Quellcode des Kernelmoduls im Anhang. +\begin{verbatim} +The following questions are related to the source code of the kernel module +in the appendix. +\end{verbatim} + +\begin{parts} +\part[2] Welche Zeile Quellcode m\"u\ss en Sie l\"oschen damit der Code keine + Funktion hat? +\begin{verbatim} +Which source-line needs to be deleted to disable the +functionality of the code? +\end{verbatim} + +\part[4] Welche 'virtuellen Dateien' werden von dem Code angelegt? +\begin{verbatim} +Which 'virtual files' are created by this code? +\end{verbatim} + +\part[2] In der probe Funktion wird eine major id ausgegeben. Was k\"onnen + Sie mit dieser Information anfangen? +\begin{verbatim} +The probe function reports a major id. +What can you do with this information? +\end{verbatim} + +\part[4] Sie wollen vom Userspace aus mittels des Kernelmoduls + folgende Datei erstellen. Welche Kommandos oder Pseudo-C Code verwenden Sie? +\begin{verbatim} +You want to use the kernel module to generate the following file from the +userspace. Which commands or Pseudo-C code do you use? +\end{verbatim} + +[/tmp/huhu.txt] +\begin{lstlisting} +8888 +\end{lstlisting} + +\part[6] Suchen Sie sich drei Funktionen aus, erkl\"aren Sie jeweils wann die +Funktion aufgerufen wird und was Sie tut. +\begin{verbatim} +Choose 3 functions. Explain for each function what triggers the call +and describe its job. +\end{verbatim} + +\part[4] Sie wollen dass der Code keine sysfs device Attribute mehr exportiert. +Nennen Sie alle Bereiche, die gel\"oscht werden k\"onnen. +\begin{verbatim} +You want the code to avoid exporting sysfs device attributes. +Which lines/areas of the source-code can be removed? +\end{verbatim} +\end{parts} + +\end{questions} + +\vspace{1cm} +Punkte: \_\_\_\_ von \numpoints +\hspace{1cm} +Note: + +\newpage + +\begin{appendix} +\begin{lstlisting} +/* + * Example driver for Linux + * Copyright (C) 2014, Manuel Traut <manut@mecka.net> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#include <linux/init.h> +#include <linux/device.h> +#include <linux/fs.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/types.h> + +#define DEVICE_NAME "hswgt" +static int major; + +static struct class *dummy; + +static struct device hswgt_dev = { + .init_name = DEVICE_NAME, +}; + +static ssize_t hswgt_show_ro(struct device *hswgt_dev, + struct device_attribute *hswgt_attr, char *buf) +{ + return scnprintf(buf, PAGE_SIZE, "%s\n", "show some cool value"); +} + +static ssize_t hswgt_show_rw(struct device *hswgt_dev, + struct device_attribute *hswgt_attr, char *buf) +{ + return scnprintf(buf, PAGE_SIZE, "%s\n", "write value, look at dmesg"); +} + +static ssize_t hswgt_store_rw(struct device *hswgt_dev, + struct device_attribute *hswgt_attr, const char *buf, size_t count) +{ + pr_notice("hswgt_store_rw: %s", buf); + return count; +} + + +static DEVICE_ATTR(hswgt_ro, S_IRUGO, hswgt_show_ro, NULL); +static DEVICE_ATTR(hswgt_rw, S_IWUSR|S_IRUGO, hswgt_show_rw, hswgt_store_rw); + +static struct attribute *hswgt_dev_attrs[] = { + &dev_attr_hswgt_ro.attr, + &dev_attr_hswgt_rw.attr, + NULL, +}; + +static struct attribute_group hswgt_dev_attr_group1 = { + .attrs = hswgt_dev_attrs, +}; + +static const struct attribute_group *hswgt_dev_attr_groups[] = { + &hswgt_dev_attr_group1, + NULL, +}; + +static int hswgt_char_open(struct inode *node, struct file *f) +{ + pr_notice("%s\n", __func__); + return 0; +} + +static ssize_t hswgt_char_read(struct file *f, char __user *buf, + size_t count, loff_t *pos) +{ + pr_notice("%s\n", __func__); + memset(buf, 8, count); + return count; +} + +static ssize_t hswgt_char_write(struct file *f, const char __user *buf, + size_t count, loff_t *pos) +{ + size_t i; + for (i = 0; i < count; i++) + pr_notice("%s[%d]: %x\n", __func__, (int)i, buf[i]); + return count; +} + +static const struct file_operations hswgt_fops = { + .open = hswgt_char_open, + .read = hswgt_char_read, + .write = hswgt_char_write, +}; + +static int __init hswgt_init(void) +{ + int ret = 0; + + pr_notice("%s\n", __func__); + + dummy = class_create(THIS_MODULE, "dummy"); + device_initialize(&hswgt_dev); + hswgt_dev.parent = NULL; + hswgt_dev.bus = NULL; + hswgt_dev.class = dummy; + hswgt_dev.groups = hswgt_dev_attr_groups; + + ret = device_add(&hswgt_dev); + if (ret) { + pr_err("%s device_add failed: %x\n", __func__, ret); + goto failed_dev; + } + + major = register_chrdev(0, "hswgt", &hswgt_fops); + if (major < 0) { + ret = major; + pr_err("%s register chrdev failed; %d\n", __func__, ret); + goto failed_char; + } + pr_notice("%s major device node %d\n", + __func__, major); + + return 0; + +failed_char: + unregister_chrdev(major, "hswgt"); +failed_dev: + device_del(&hswgt_dev); + class_destroy(dummy); + + return ret; +} + +static void __exit hswgt_exit(void) +{ + pr_notice("%s\n", __func__); + + device_del(&hswgt_dev); + class_destroy(dummy); + unregister_chrdev(major, "hswgt"); +} + +module_init(hswgt_init); +module_exit(hswgt_exit); + +MODULE_AUTHOR("Manuel Traut"); +MODULE_DESCRIPTION("dummy test driver"); +MODULE_VERSION("3"); +MODULE_LICENSE("GPL"); +\end{lstlisting} +\end{appendix} + + +\end{document} |
