Skip to content

Commit

Permalink
proc: move /proc/modules boilerplate to kernel/module.c
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
  • Loading branch information
Alexey Dobriyan committed Oct 23, 2008
1 parent 31d85ab commit 3b5d5c6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
17 changes: 0 additions & 17 deletions fs/proc/proc_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@
#include <asm/div64.h>
#include "internal.h"

#ifdef CONFIG_MODULES
extern const struct seq_operations modules_op;
static int modules_open(struct inode *inode, struct file *file)
{
return seq_open(file, &modules_op);
}
static const struct file_operations proc_modules_operations = {
.open = modules_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
#endif

#ifdef CONFIG_PROC_PAGE_MONITOR
#define KPMSIZE sizeof(u64)
#define KPMMASK (KPMSIZE - 1)
Expand Down Expand Up @@ -209,9 +195,6 @@ void __init proc_misc_init(void)
proc_symlink("mounts", NULL, "self/mounts");

/* And now for trickier ones */
#ifdef CONFIG_MODULES
proc_create("modules", 0, NULL, &proc_modules_operations);
#endif
#ifdef CONFIG_SCHEDSTATS
proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
#endif
Expand Down
59 changes: 41 additions & 18 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#include <linux/moduleloader.h>
#include <linux/init.h>
#include <linux/kallsyms.h>
#include <linux/fs.h>
#include <linux/sysfs.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/elf.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
Expand Down Expand Up @@ -2599,23 +2601,6 @@ unsigned long module_kallsyms_lookup_name(const char *name)
}
#endif /* CONFIG_KALLSYMS */

/* Called by the /proc file system to return a list of modules. */
static void *m_start(struct seq_file *m, loff_t *pos)
{
mutex_lock(&module_mutex);
return seq_list_start(&modules, *pos);
}

static void *m_next(struct seq_file *m, void *p, loff_t *pos)
{
return seq_list_next(p, &modules, pos);
}

static void m_stop(struct seq_file *m, void *p)
{
mutex_unlock(&module_mutex);
}

static char *module_flags(struct module *mod, char *buf)
{
int bx = 0;
Expand Down Expand Up @@ -2649,6 +2634,24 @@ static char *module_flags(struct module *mod, char *buf)
return buf;
}

#ifdef CONFIG_PROC_FS
/* Called by the /proc file system to return a list of modules. */
static void *m_start(struct seq_file *m, loff_t *pos)
{
mutex_lock(&module_mutex);
return seq_list_start(&modules, *pos);
}

static void *m_next(struct seq_file *m, void *p, loff_t *pos)
{
return seq_list_next(p, &modules, pos);
}

static void m_stop(struct seq_file *m, void *p)
{
mutex_unlock(&module_mutex);
}

static int m_show(struct seq_file *m, void *p)
{
struct module *mod = list_entry(p, struct module, list);
Expand Down Expand Up @@ -2679,13 +2682,33 @@ static int m_show(struct seq_file *m, void *p)
Where refcount is a number or -, and deps is a comma-separated list
of depends or -.
*/
const struct seq_operations modules_op = {
static const struct seq_operations modules_op = {
.start = m_start,
.next = m_next,
.stop = m_stop,
.show = m_show
};

static int modules_open(struct inode *inode, struct file *file)
{
return seq_open(file, &modules_op);
}

static const struct file_operations proc_modules_operations = {
.open = modules_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};

static int __init proc_modules_init(void)
{
proc_create("modules", 0, NULL, &proc_modules_operations);
return 0;
}
module_init(proc_modules_init);
#endif

/* Given an address, look for it in the module exception tables. */
const struct exception_table_entry *search_module_extables(unsigned long addr)
{
Expand Down

0 comments on commit 3b5d5c6

Please sign in to comment.