Use nice file permission constants, fix readme paths

This commit is contained in:
Ciro Santilli
2017-06-13 09:50:48 +01:00
parent 1f1cf4b0bd
commit 89e6b0f97a
5 changed files with 11 additions and 7 deletions

View File

@@ -319,8 +319,9 @@ But TODO I don't think you can see where you are in the kernel source code and l
1. [panic](kernel_module/panic.c)
1. [params](kernel_module/params.c)
1. [fops](kernel_module/fops.c)
1. [ioctl](ioctl.c)
1. [poll](poll.c)
1. [ioctl](kernel_module/ioctl.c)
1. [poll](kernel_module/poll.c)
1. [anonymous_inode](kernel_module/anonymous_inode.c)
1. Asynchronous
1. [workqueue](kernel_module/workqueue.c)
1. [sleep](kernel_module/sleep.c)
@@ -329,7 +330,7 @@ But TODO I don't think you can see where you are in the kernel source code and l
1. [schedule](kernel_module/schedule.c)
1. [timer](kernel_module/timer.c)
1. [work_from_work](kernel_module/work_from_work.c)
1. [irq](irq.c)
1. [irq](kernel_module/irq.c)
1. Module dependencies
1. [dep.c](kernel_module/dep.c)
1. [dep2.c](kernel_module/dep2.c)

View File

@@ -4,7 +4,7 @@ https://stackoverflow.com/questions/4508998/what-is-anonymous-inode
anon_inode_getfd example:
- get an anonymous inode via ioctl from a debugfs entry
- read from that inode
- read jiffies from that inode
This method allows getting multiple file descriptors from a single filesystem,
which reduces namespace pollution.

View File

@@ -11,6 +11,7 @@ Requires `CONFIG_DEBUG_FS=y`.
#include <linux/debugfs.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <uapi/linux/stat.h> /* S_IRUSR */
MODULE_LICENSE("GPL");
@@ -25,7 +26,7 @@ static int myinit(void)
printk(KERN_ALERT "debugfs_create_dir failed");
return -1;
}
file = debugfs_create_u32("myfile", 0666, dir, &value);
file = debugfs_create_u32("myfile", S_IRUSR, dir, &value);
if (!file) {
printk(KERN_ALERT "debugfs_create_u32 failed");
return -1;

View File

@@ -24,6 +24,7 @@ Here we use debugfs.
#include <linux/kernel.h> /* min */
#include <linux/module.h>
#include <linux/printk.h> /* printk */
#include <uapi/linux/stat.h> /* S_IRUSR */
MODULE_LICENSE("GPL");
@@ -138,7 +139,7 @@ static const struct file_operations fops = {
static int myinit(void)
{
dir = debugfs_create_dir("lkmc_fops", 0);
debugfs_create_file("f", 0666, dir, NULL, &fops);
debugfs_create_file("f", S_IRUSR | S_IWUSR, dir, NULL, &fops);
return 0;
}

View File

@@ -16,6 +16,7 @@ Outcome: user echoes jiffies every second.
#include <linux/poll.h>
#include <linux/printk.h> /* printk */
#include <linux/wait.h> /* wait_queue_head_t, wait_event_interruptible, wake_up_interruptible */
#include <uapi/linux/stat.h> /* S_IRUSR */
MODULE_LICENSE("GPL");
@@ -71,7 +72,7 @@ static const struct file_operations fops = {
static int myinit(void)
{
dir = debugfs_create_dir("lkmc_poll", 0);
debugfs_create_file("f", 0666, dir, NULL, &fops);
debugfs_create_file("f", S_IRUSR | S_IWUSR, dir, NULL, &fops);
init_waitqueue_head(&waitqueue);
kthread = kthread_create(kthread_func, NULL, "mykthread");
wake_up_process(kthread);