writing-char-drivers

writing-char-drivers is a skill for Claude Code, Codex from mohitmishra786/low-level-dev-skills. It costs 60 tokens per session (1,177 once invoked), scanned A, original, MIT.

A guide to Linux character drivers, which let programs communicate with devices through files such as those under /dev. It covers driver registration, reading and writing data, ioctl commands, polling, and mapping memory to user programs.

In plain words
What is it for?
Exposing hardware through a /dev device, implementing read/write/poll operations, designing ioctl commands, and mapping device memory to user space.
Why use it?
It explains how to create a controlled user-space interface for a kernel device while handling user-provided data safely.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Exposing hardware through a /dev device, implementing read/write/poll operations, designing ioctl commands, and mapping device memory to user space.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mohitmishra786/low-level-dev-skills/writing-char-drivers
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add mohitmishra786/low-level-dev-skills --skill writing-char-drivers
Clone the repo
git clone --depth 1 https://github.com/mohitmishra786/low-level-dev-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for writing-char-drivers

README.md
[![agentmods](https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/writing-char-drivers/github.svg)](https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/writing-char-drivers)
Your own site
<a href="https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/writing-char-drivers"><img src="https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/writing-char-drivers/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for writing-char-drivers

Your own site · 80×15
<a href="https://agentmods.dev/skills/mohitmishra786/low-level-dev-skills/writing-char-drivers"><img src="https://agentmods.dev/badge/skills/mohitmishra786/low-level-dev-skills/writing-char-drivers.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 60 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,177 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00060 $0.01177
Opus 5 $0.00030 $0.00589
Sonnet 5 $0.00012 $0.00235
Haiku 4.5 $0.00006 $0.00118

Measured 8d ago against content hash e37b289aa3f5, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

writing-char-drivers scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/kernel-dev/writing-char-drivers/SKILL.md · 160 lines

How it starts

The opening of the file, as written. The whole thing — 160 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Writing Character Drivers

Purpose

Guide agents through Linux character device implementation: struct file_operations, cdev registration, safe userspace copies, ioctl design, and basic mmap — focused depth beyond skills/kernel/device-drivers.

When to Use

  • Exposing hardware to /dev/mydev
  • Implementing read/write/poll from kernel
  • Defining ioctl commands with type-safe macros
  • Mapping device MMIO to userspace (carefully)

Workflow

1. Char device registration

#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/uaccess.h>

#define MY_MAJOR 0   /* 0 = dynamic alloc */
#define MY_MINOR 0

static dev_t devno;
static struct cdev my_cdev;
static struct class *class;

static const struct file_operations my_fops = {
    .owner          = THIS_MODULE,
    .open           = my_open,
    .release        = my_release,
    .read           = my_read,
    .write          = my_write,
    .unlocked_ioctl = my_ioctl,
    .llseek         = no_llseek,
};

static int __init my_init(void)
{
    int ret = alloc_chrdev_region(&devno, MY_MINOR, 1, "mydev");
    if (ret)
        return ret;

    cdev_init(&my_cdev, &my_fops);
    ret = cdev_add(&my_cdev, devno, 1);
    if (ret)
        goto err_cdev;

    class = class_create("mydev");
    device_create(class, NULL, devno, NULL, "mydev");
    return 0;

err_cdev:
    unregister_chrdev_region(devno, 1);
    return ret;
}

Modern drivers often use devm_* variants inside probe.

2. Safe userspace I/O

static ssize_t my_read(struct file *filp, char __user *buf,
                       size_t count, loff_t *ppos)
{
    char kbuf[128];
    ssize_t len;

    if (*ppos >= sizeof(kbuf))
        return 0;
    len = min(count, sizeof(kbuf) - *ppos);
    memcpy(kbuf, "data", 4);
    if (copy_to_user(buf, kbuf + *ppos, len))
        return -EFAULT;
    *ppos += len;
    return len;
}

Never dereference __user pointers directly.

3. ioctl pattern

#include <linux/ioctl.h>

#define MY_IOC_MAGIC 'k'
#define MY_IOC_RESET  _IO(MY_IOC_MAGIC, 0)
#define MY_IOC_SET    _IOW(MY_IOC_MAGIC, 1, int)

static long my_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
    switch (cmd) {
    case MY_IOC_RESET:
        return 0;
    case MY_IOC_SET: {
        int val;
        if (copy_from_user(&val, (void __user *)arg, sizeof(val)))
            return -EFAULT;
        return 0;
    }
    default:
        return -ENOTTY;
    }
}

Read the full file on GitHub · 160 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 160 lines · 60 tokens per session scan A e37b289aa3f5

Subscribe to this mod's changes

writing-char-drivers is a skill published in the GitHub repository mohitmishra786/low-level-dev-skills (203 stars, last pushed 2mo ago), licensed MIT. It adds 60 tokens to every session and 1,177 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.