sys_indirect RFC - example usage from kernel POV
PATCH 6/6 sys_indirect RFC - example usage from kernel POV
This is an example of how to add a context set/unset wrapper inside the kernel, for something like open flags:
1) Alloc a new SYSIND_CTX_* sequential index inside linux/indirect.h
2) Define a new "struct sysind_ctx_*" to be used by userspace
3) Define proper set/unset functions inside kernel/sys_indirect.c
Signed-off-by Davide Libenzi <[email protected]>
- Davide
--- include/linux/indirect.h | 7 +++++++ kernel/sys_indirect.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-)
include/linux/indirect.h +7 -0
@@ -8,10 +8,17 @@#ifndef _LINUX_INDIRECT_H#define _LINUX_INDIRECT_H +#define SYSIND_CTX_OPENFLAGS 0 +struct indirect_ctx {__u32 ctx; }; +struct sysind_ctx_OPENFLAGS { +__u32 ctx; +__u32 flags; +}; +#ifdef __KERNEL__#include <linux/fsalloc.h>
kernel/sys_indirect.c +31 -1
@@ -24,9 +24,39 @@void (*unset)(struct indirect_op *); }; +struct indirect_op_OPENFLAGS { +struct indirect_op op; +unsigned long flags; +}; + +static int set_OPENFLAGS (struct fsa_context *ator, +const struct indirect_ctx __user *uctx, +struct indirect_op **pnew) +{ +struct indirect_op_OPENFLAGS *iop; +struct sysind_ctx_OPENFLAGS kctx; + +if (copy_from_user (&kctx, uctx,sizeof (*uctx))) +return -EFAULT ; + iop =fsa_alloc (ator,sizeof (struct indirect_op_OPENFLAGS )); +if (unlikely (!iop)) +return -ENOMEM ; + iop->op.ctx = kctx.ctx; +/* iop->flags = current->def_open_flags; */ +/* current->def_open_flags = kctx.flags; */ + *pnew = (struct indirect_op *) iop; + +return 0 ; +} + +static void unset_OPENFLAGS (struct indirect_op *iop) +{ +/* current->def_open_flags = ((struct indirect_op_OPENFLAGS *) iop)->flags; */ +} +static const struct indirect_procs inprocs[] = { - {NULL ,NULL }, + [SYSIND_CTX_OPENFLAGS ] = { set_OPENFLAGS, unset_OPENFLAGS }, };/**