Atlas - proc.c

Home / systems / linux / kernel / modules Lines: 2 | Size: 976 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 * Proc 3 * 4 * I try writing to proc 5 * 6 * 0x4248 7 */ 8 9#include <linux/init.h> 10#include <linux/module.h> 11#include <linux/proc_fs.h> 12#include <linux/seq_file.h> 13#include <linux/mm.h> 14#include <linux/sysinfo.h> 15 16 17static int demo_show(struct seq_file *m, void *v) 18{ 19 struct sysinfo si; 20 si_meminfo(&si); 21 seq_printf(m, "totalram = %lu\n", si.totalram); 22 23 return 0; 24} 25 26static int demo_open(struct inode *inode, struct file *file) 27{ 28 return single_open(file, demo_show, NULL); 29} 30 31static const struct proc_ops demo_fops = { 32 .proc_open = demo_open, 33 .proc_read = seq_read, 34 .proc_lseek = seq_lseek, 35 .proc_release = single_release, 36}; 37 38static int __init demo_init(void) 39{ 40 if (!proc_create("demo_proc", 0444, NULL, &demo_fops)) 41 return -ENOMEM; 42 43 return 0; 44} 45 46static void __exit demo_exit(void) 47{ 48 remove_proc_entry("demo_proc", NULL); 49} 50 51module_init(demo_init); 52module_exit(demo_exit); 53MODULE_LICENSE("GPL"); 54MODULE_AUTHOR("0x4248"); 55MODULE_DESCRIPTION("A hello world driver"); 56
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.