procfs4: Shorten and indent

This commit is contained in:
Jim Huang 2021-08-07 10:54:19 +08:00
parent e1d31e9500
commit f8adcdb3c1

View File

@ -1,10 +1,9 @@
/* /*
* procfs4.c - create a "file" in /proc * procfs4.c - create a "file" in /proc
* This program uses the seq_file library to manage the /proc file. * This program uses the seq_file library to manage the /proc file.
*
*/ */
#include <linux/kernel.h> /* We're doing kernel work */ #include <linux/kernel.h> /* We are doing kernel work */
#include <linux/module.h> /* Specifically, a module */ #include <linux/module.h> /* Specifically, a module */
#include <linux/proc_fs.h> /* Necessary because we use proc fs */ #include <linux/proc_fs.h> /* Necessary because we use proc fs */
#include <linux/seq_file.h> /* for seq_file */ #include <linux/seq_file.h> /* for seq_file */
@ -18,12 +17,10 @@
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/** /* This function is called at the beginning of a sequence.
* This function is called at the beginning of a sequence.
* ie, when: * ie, when:
* - the /proc file is read (first time) * - the /proc file is read (first time)
* - after the function stop (end of sequence) * - after the function stop (end of sequence)
*
*/ */
static void *my_seq_start(struct seq_file *s, loff_t *pos) static void *my_seq_start(struct seq_file *s, loff_t *pos)
{ {
@ -33,17 +30,14 @@ static void *my_seq_start(struct seq_file *s, loff_t *pos)
if (*pos == 0) { if (*pos == 0) {
/* yes => return a non null value to begin the sequence */ /* yes => return a non null value to begin the sequence */
return &counter; return &counter;
} else { }
/* no => it's the end of the sequence, return end to stop reading */ /* no => it is the end of the sequence, return end to stop reading */
*pos = 0; *pos = 0;
return NULL; return NULL;
} }
}
/** /* This function is called after the beginning of a sequence.
* This function is called after the beginning of a sequence. * It is called untill the return is NULL (this ends the sequence).
* It's called untill the return is NULL (this ends the sequence).
*
*/ */
static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos) static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos)
{ {
@ -53,19 +47,13 @@ static void *my_seq_next(struct seq_file *s, void *v, loff_t *pos)
return NULL; return NULL;
} }
/** /* This function is called at the end of a sequence. */
* This function is called at the end of a sequence
*
*/
static void my_seq_stop(struct seq_file *s, void *v) static void my_seq_stop(struct seq_file *s, void *v)
{ {
/* nothing to do, we use a static value in start() */ /* nothing to do, we use a static value in start() */
} }
/** /* This function is called for each "step" of a sequence. */
* This function is called for each "step" of a sequence
*
*/
static int my_seq_show(struct seq_file *s, void *v) static int my_seq_show(struct seq_file *s, void *v)
{ {
loff_t *spos = (loff_t *) v; loff_t *spos = (loff_t *) v;
@ -74,28 +62,21 @@ static int my_seq_show(struct seq_file *s, void *v)
return 0; return 0;
} }
/** /* This structure gather "function" to manage the sequence */
* This structure gather "function" to manage the sequence static struct seq_operations my_seq_ops = {
* .start = my_seq_start,
*/
static struct seq_operations my_seq_ops = {.start = my_seq_start,
.next = my_seq_next, .next = my_seq_next,
.stop = my_seq_stop, .stop = my_seq_stop,
.show = my_seq_show}; .show = my_seq_show,
};
/** /* This function is called when the /proc file is open. */
* This function is called when the /proc file is open.
*
*/
static int my_open(struct inode *inode, struct file *file) static int my_open(struct inode *inode, struct file *file)
{ {
return seq_open(file, &my_seq_ops); return seq_open(file, &my_seq_ops);
}; };
/** /* This structure gather "function" that manage the /proc file */
* This structure gather "function" that manage the /proc file
*
*/
#ifdef HAVE_PROC_OPS #ifdef HAVE_PROC_OPS
static const struct proc_ops my_file_ops = { static const struct proc_ops my_file_ops = {
.proc_open = my_open, .proc_open = my_open,
@ -112,10 +93,7 @@ static const struct file_operations my_file_ops = {
}; };
#endif #endif
/** /* This function is called when the module is loaded. */
* This function is called when the module is loaded
*
*/
int init_module(void) int init_module(void)
{ {
struct proc_dir_entry *entry; struct proc_dir_entry *entry;
@ -130,10 +108,7 @@ int init_module(void)
return 0; return 0;
} }
/** /* This function is called when the module is unloaded. */
* This function is called when the module is unloaded.
*
*/
void cleanup_module(void) void cleanup_module(void)
{ {
remove_proc_entry(PROC_NAME, NULL); remove_proc_entry(PROC_NAME, NULL);