I'm trying to write a kernel module which disables input between certain times of day. I found out how to get the time (How to get current hour (time of day) in linux kernel space) and how to schedule a function. I can't seem to work out how to disable the inputs though. I'm thinking there has to be some place the kernel to do this but having read the API I'm still no further forward. I suppose I should just access the drivers directly and shut them off or something, but that seems a little non-generic. I开发者_高级运维s this even possible?
Thanks for your time.
I'm not sure, but if you're in userspace, it should be sufficient to switch to an unused virtual console, then put the keyboard into raw mode. This will block the key combinations which would normally switch back into another virtual console. That won't disable the mouse, but X should ignore the mouse if it is not the current VT (just make sure gpm isn't running).
You also have to disable the magic-sysrq key combination if that is enabled, as there is a sysrq key to take the keyboard out of raw mode, which would otherwise get around this.
EDIT: it should be possible to do all of this from kernel space, provided you're in a normal task context. A kernel thread would do, I expect.
You can open files and devices from the kernel, it's just not recommended. A task which has a namespace containing /dev (I'm not sure whether kernel tasks do). You can call filp_open (I think) and get a file *, which you can then call the appropriate methods on its file_operations (f_op). This should include the ioctls required to do the above.
There might be a way of opening a device directly, not via the filp_open.
In short, it should be possible. It's a very dodgy thing to do from kernel space.
One way I can think of is disabling the IRQs for keyword and mouse. disable_irq and enable_irq can be used to do that.
Here is IRQ numbers for x86. May be you have to consult other table to get IRQ for other platforms like SPARC, IA-64 if you need.
精彩评论