From aed96129bf18a3c17502b281d124caf61908ed80 Mon Sep 17 00:00:00 2001 From: jserv Date: Sat, 7 Aug 2021 03:02:04 +0000 Subject: [PATCH] deploy: 40e83aa14bc812c63d1f4d9ea21354c353a164c9 --- index.html | 3169 ++++++++++++++++++++++++++-------------------------- lkmpg.css | 3073 +++++++++++++++++++++++++------------------------- lkmpg.html | 3169 ++++++++++++++++++++++++++-------------------------- 3 files changed, 4667 insertions(+), 4744 deletions(-) diff --git a/index.html b/index.html index b4fff81..6951ce4 100644 --- a/index.html +++ b/index.html @@ -87,7 +87,7 @@
 0.16 Crypto
  0.16.1 Hash functions
  0.16.2 Symmetric key encryption -
 0.17 Standardising the interfaces: The Device Model +
 0.17 Standardizing the interfaces: The Device Model
 0.18 Optimizations
  0.18.1 Likely and Unlikely conditions
 0.19 Common Pitfalls @@ -2006,144 +2006,119 @@ still use the same way as in the previous example.
1/* 
 2 *  procfs4.c -  create a "file" in /proc 
 3 *  This program uses the seq_file library to manage the /proc file. 
-4 * 
-5 */ 
-6 
-7#include <linux/kernel.h>   /* We're doing kernel work */ 
-8#include <linux/module.h>   /* Specifically, a module */ 
-9#include <linux/proc_fs.h>  /* Necessary because we use proc fs */ 
-10#include <linux/seq_file.h> /* for seq_file */ 
-11#include <linux/version.h> 
-12 
-13#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) 
-14#define HAVE_PROC_OPS 
-15#endif 
-16 
-17#define PROC_NAME "iter" 
-18 
-19MODULE_LICENSE("GPL"); 
-20 
-21/** 
-22 * This function is called at the beginning of a sequence. 
-23 * ie, when: 
-24 *      - the /proc file is read (first time) 
-25 *      - after the function stop (end of sequence) 
-26 * 
-27 */ 
-28static void *my_seq_start(struct seq_file *s, loff_t *pos) 
-29{ 
-30    static unsigned long counter = 0; 
-31 
-32    /* beginning a new sequence ? */ 
-33    if (*pos == 0) { 
-34        /* yes => return a non null value to begin the sequence */ 
-35        return &counter; 
-36    } else { 
-37        /* no => it's the end of the sequence, return end to stop reading */ 
-38        *pos = 0; 
-39        return NULL; 
-40    } 
-41} 
-42 
-43/** 
-44 * This function is called after the beginning of a sequence. 
-45 * It's called untill the return is NULL (this ends the sequence). 
-46 * 
-47 */ 
-48static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos) 
-49{ 
-50    unsigned long *tmp_v = (unsigned long *) v; 
-51    (*tmp_v)++; 
-52    (*pos)++; 
-53    return NULL; 
+4 */ 
+5 
+6#include <linux/kernel.h>   /* We are doing kernel work */ 
+7#include <linux/module.h>   /* Specifically, a module */ 
+8#include <linux/proc_fs.h>  /* Necessary because we use proc fs */ 
+9#include <linux/seq_file.h> /* for seq_file */ 
+10#include <linux/version.h> 
+11 
+12#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) 
+13#define HAVE_PROC_OPS 
+14#endif 
+15 
+16#define PROC_NAME "iter" 
+17 
+18MODULE_LICENSE("GPL"); 
+19 
+20/* This function is called at the beginning of a sequence. 
+21 * ie, when: 
+22 *   - the /proc file is read (first time) 
+23 *   - after the function stop (end of sequence) 
+24 */ 
+25static void *my_seq_start(struct seq_file *s, loff_t *pos) 
+26{ 
+27    static unsigned long counter = 0; 
+28 
+29    /* beginning a new sequence? */ 
+30    if (*pos == 0) { 
+31        /* yes => return a non null value to begin the sequence */ 
+32        return &counter; 
+33    } 
+34    /* no => it is the end of the sequence, return end to stop reading */ 
+35    *pos = 0; 
+36    return NULL; 
+37} 
+38 
+39/* This function is called after the beginning of a sequence. 
+40 * It is called untill the return is NULL (this ends the sequence). 
+41 */ 
+42static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos) 
+43{ 
+44    unsigned long *tmp_v = (unsigned long *) v; 
+45    (*tmp_v)++; 
+46    (*pos)++; 
+47    return NULL; 
+48} 
+49 
+50/* This function is called at the end of a sequence. */ 
+51static void my_seq_stop(struct seq_file *s, void *v) 
+52{ 
+53    /* nothing to do, we use a static value in start() */ 
 54} 
 55 
-56/** 
-57 * This function is called at the end of a sequence 
-58 * 
-59 */ 
-60static void my_seq_stop(struct seq_file *s, void *v) 
-61{ 
-62    /* nothing to do, we use a static value in start() */ 
+56/* This function is called for each "step" of a sequence. */ 
+57static int my_seq_show(struct seq_file *s, void *v) 
+58{ 
+59    loff_t *spos = (loff_t *) v; 
+60 
+61    seq_printf(s, "%Ld\n", *spos); 
+62    return 0; 
 63} 
 64 
-65/** 
-66 * This function is called for each "step" of a sequence 
-67 * 
-68 */ 
-69static int my_seq_show(struct seq_file *s, void *v) 
-70{ 
-71    loff_t *spos = (loff_t *) v; 
+65/* This structure gather "function" to manage the sequence */ 
+66static struct seq_operations my_seq_ops = { 
+67    .start = my_seq_start, 
+68    .next = my_seq_next, 
+69    .stop = my_seq_stop, 
+70    .show = my_seq_show, 
+71}; 
 72 
-73    seq_printf(s, "%Ld\n", *spos); 
-74    return 0; 
-75} 
-76 
-77/** 
-78 * This structure gather "function" to manage the sequence 
-79 * 
-80 */ 
-81static struct seq_operations my_seq_ops = {.start = my_seq_start, 
-82                                           .next = my_seq_next, 
-83                                           .stop = my_seq_stop, 
-84                                           .show = my_seq_show}; 
-85 
-86/** 
-87 * This function is called when the /proc file is open. 
-88 * 
-89 */ 
-90static int my_open(struct inode *inode, struct file *file) 
-91{ 
-92    return seq_open(file, &my_seq_ops); 
+73/* This function is called when the /proc file is open. */ 
+74static int my_open(struct inode *inode, struct file *file) 
+75{ 
+76    return seq_open(file, &my_seq_ops); 
+77}; 
+78 
+79/* This structure gather "function" that manage the /proc file */ 
+80#ifdef HAVE_PROC_OPS 
+81static const struct proc_ops my_file_ops = { 
+82    .proc_open = my_open, 
+83    .proc_read = seq_read, 
+84    .proc_lseek = seq_lseek, 
+85    .proc_release = seq_release, 
+86}; 
+87#else 
+88static const struct file_operations my_file_ops = { 
+89    .open = my_open, 
+90    .read = seq_read, 
+91    .llseek = seq_lseek, 
+92    .release = seq_release, 
 93}; 
-94 
-95/** 
-96 * This structure gather "function" that manage the /proc file 
-97 * 
-98 */ 
-99#ifdef HAVE_PROC_OPS 
-100static const struct proc_ops my_file_ops = { 
-101    .proc_open = my_open, 
-102    .proc_read = seq_read, 
-103    .proc_lseek = seq_lseek, 
-104    .proc_release = seq_release, 
-105}; 
-106#else 
-107static const struct file_operations my_file_ops = { 
-108    .open = my_open, 
-109    .read = seq_read, 
-110    .llseek = seq_lseek, 
-111    .release = seq_release, 
-112}; 
-113#endif 
-114 
-115/** 
-116 * This function is called when the module is loaded 
-117 * 
-118 */ 
-119int init_module(void) 
-120{ 
-121    struct proc_dir_entry *entry; 
-122 
-123    entry = proc_create(PROC_NAME, 0, NULL, &my_file_ops); 
-124    if (entry == NULL) { 
-125        remove_proc_entry(PROC_NAME, NULL); 
-126        pr_debug("Error: Could not initialize /proc/%s\n", PROC_NAME); 
-127        return -ENOMEM; 
-128    } 
-129 
-130    return 0; 
-131} 
-132 
-133/** 
-134 * This function is called when the module is unloaded. 
-135 * 
-136 */ 
-137void cleanup_module(void) 
-138{ 
-139    remove_proc_entry(PROC_NAME, NULL); 
-140    pr_debug("/proc/%s removed\n", PROC_NAME); 
-141}
+94#endif +95 +96/* This function is called when the module is loaded. */ +97int init_module(void) +98{ +99    struct proc_dir_entry *entry; +100 +101    entry = proc_create(PROC_NAME, 0, NULL, &my_file_ops); +102    if (entry == NULL) { +103        remove_proc_entry(PROC_NAME, NULL); +104        pr_debug("Error: Could not initialize /proc/%s\n", PROC_NAME); +105        return -ENOMEM; +106    } +107 +108    return 0; +109} +110 +111/* This function is called when the module is unloaded. */ +112void cleanup_module(void) +113{ +114    remove_proc_entry(PROC_NAME, NULL); +115    pr_debug("/proc/%s removed\n", PROC_NAME); +116}

If you want more information, you can read this web page: