Skip to content

Instantly share code, notes, and snippets.

@Jongy
Last active December 14, 2019 22:24
Show Gist options
  • Save Jongy/381781dc8abf0e9b269a3130edb9294d to your computer and use it in GitHub Desktop.
Save Jongy/381781dc8abf0e9b269a3130edb9294d to your computer and use it in GitHub Desktop.
/dev/null tricks using my Linux kernel MicroPython
file_operations = partial_struct("file_operations")
null_fops = file_operations(null_fops)
from kernel_ffi import callback
def my_read_null(file, buf, count, ppos):
pos = p64(ppos)
b = "who said /dev/null must be empty?\n"[pos:]
l = min(len(b), count)
memcpy(buf, b, l)
p64(ppos, pos + l)
return l
c = callback(my_read_null)
null_fops.read = c.ptr()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment