Procfs in Linux (Virtual File System) EmbeTronicX 2
Procfs in Linux (Virtual File System) EmbeTronicX 2
Women's Shoes
On AG
Menu
Linux
Table of Contents
1. Introduction
2. Procfs in Linux
2.1. Introduction
3. Creating procfs directory
4. Creating Procfs Entry
5. Procfs File System
6. Open and Release Function
7. Write Function
8. Read Function
9. Remove Proc Entry
10. Procfs in Linux – Complete Driver Source
Code
11. MakeFile
12. Building and Testing Driver
Introduction
IOCTL
Procfs
Sysfs
Configfs
Debugfs
Sysctl
UDP Sockets
Netlink Sockets
Procfs in Linux
Introduction
so important.
system information.
cat /proc/meminfo
kernel.
cat /proc/modules
/proc/interrupts — registered
/proc/partitions — currently
partitions
filesystem drivers
kernel space.
→
Creating procfs directory
Table of Contents
struct proc_dir_entry
proc_dir_entry *parent)
where,
NULL.
in version 3.10.
Where,
defined as below,
1. proc_create("etx_proc",0666,NULL,&proc
init function.
entry.
create_proc_read_entry()
create_proc_entry()
file linux/proc_fs.h.
entries.
Write Function
an array “etx_array”.
Read Function
return length;;
}
Example:
1. remove_proc_entry("etx_proc",NULL);
proc_dir_entry *parent).
source code.
Note:
LINUX_KERNEL_VERSION.
Example:
Your Linux
LINUX_KERNEL_VERSION
Kernel version
v3.10 310
v5.6 506
v5.10 510
1. /*************************************
2. * \file driver.c
3. *
4. * \details Simple Linux device dri
5. *
6. * \author EmbeTronicX
7. *
8. * \Tested with Linux raspberrypi 5.10
9. *
10. * ************************************
11. #include <linux/kernel.h>
12. #include <linux/init.h>
13. #include <linux/module.h>
14. #include <linux/kdev_t.h>
15. #include <linux/fs.h>
16. #include <linux/cdev.h>
17. #include <linux/device.h>
18. #include<linux/slab.h>
19. #include<linux/uaccess.h>
20. #include <linux/ioctl.h>
21. #include<linux/proc_fs.h>
22. #include <linux/err.h>
23.
24. /*
25. ** I am using the kernel 5.10.27-v7l.
26. ** If you are using the kernel 3.10, t
27. ** and for kernel 5.1, set this as 501
28. ** changed in kernel above v5.5.
29. **
30. */
31. #define LINUX_KERNEL_VERSION 510
32.
33. #define WR_VALUE _IOW('a','a',int32_t*
34. #define RD_VALUE _IOR('a','b',int32_t*
35.
36. int32_t value = 0;
37. char etx_array[20]="try_proc_array\n"
38. static int len = 1;
39.
40.
41. dev_t dev = 0;
42. static struct class *dev_class;
43. static struct cdev etx_cdev;
44. static struct proc_dir_entry *parent;
45.
46. /*
47. ** Function Prototypes
48. */
49. static int __init etx_driver_init
50. static void __exit etx_driver_exit
51.
52. /*************** Driver Functions ****
53. static int etx_open(struct inode
54. static int etx_release(struct ino
55. static ssize_t etx_read(struct file *
56. static ssize_t etx_write(struct file
57. static long etx_ioctl(struct file
58.
59. /***************** Procfs Functions **
60. static int open_proc(struct inode
61. static int release_proc(struct in
62. static ssize_t read_proc(struct file
63. static ssize_t write_proc(struct file
64.
65. /*
66. ** File operation sturcture
67. */
68. static struct file_operations fops =
69. {
70. .owner = THIS_MODULE,
71. .read = etx_read,