udev works: /sys device tree, uevent netlink, datagram sockets with per-message credentials

Kernel devices (input, mem, tty, graphics, block) get /sys/devices/virtual
entries with dev/uevent/subsystem, /sys/class and /sys/dev links, input
capabilities, and writable uevent files that announce on the netlink socket.
eudev now runs, processes a full trigger and settles.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EVRhxi9zpdW2uDUN4FVcao
This commit is contained in:
Nexoniarz 2026-10-26 11:39:13 +01:00
commit 5d4d318ebf
10 changed files with 813 additions and 37 deletions

View file

@ -541,7 +541,13 @@ int sock_shutdown(struct socket*, int how);
int sockpair(struct socket **a, struct socket **b);
int sockpair_type(struct socket **a, struct socket **b, int type);
int sock_is_packet(struct socket *s);
int sock_netlink_bind(struct socket *s, uint groups);
uint sock_nl_groups(struct socket *s);
int sock_netlink_bind(struct socket *s, uint pid, uint groups);
int sock_uevent_send(struct socket *s, const char *msg, int len, uint dpid, uint dgroups);
uint sock_nl_from(struct socket *s);
uint sock_nl_pid(struct socket *s);
uint sock_nl_bound_groups(struct socket *s);
void dev_stat_numbers(int major, int minor, int *maj, int *min);
void uevent_send(uint groups, const char *msg, int len, struct socket *from);
const char* sockname(struct socket*);
// AF_INET addressing. Separate from sockbind/sockconnect because the families

44
include/dev/kdev.h Normal file
View file

@ -0,0 +1,44 @@
// SPDX-License-Identifier: GPL-2.0-or-later
//
// The devices the kernel implements itself, as /sys and udev see them.
//
// /dev holds them already (kernel/fs/devfs.c). This is the other half of what
// udev needs: for each node a place in /sys/devices, the class and dev/ links
// that lead back to it, the facts udev's rules read (MAJOR, MINOR, DEVNAME,
// input capabilities), and a way to announce it on the uevent netlink socket.
#pragma once
#include "core/types.h"
#define KDEV_NAME 24
#define KDEV_DEVNAME 32
#define KDEV_BLK0 256 // kdev indexes from here are block devices
enum { KD_NONE, KD_KEYBOARD, KD_MOUSE };
struct kdev {
char subsys[16]; // class: input, mem, tty, graphics, block
char name[KDEV_NAME]; // directory name under the parent
char devname[KDEV_DEVNAME]; // path below /dev, "" for a device with no node
short major, minor;
int block;
int parent; // kdev index of the device it hangs off, or -1
int cap; // KD_*: what an input device can do
};
int kdev_nsubsys(void);
const char *kdev_subsys(int s);
// Index of the Nth device that exists, 0.. until -1.
int kdev_nth(int n);
int kdev_get(int i, struct kdev *k);
// The numbers stat() shows for its node, which are what /sys must show too.
void kdev_numbers(const struct kdev *k, int *maj, int *min);
// "devices/virtual/input/input0/event0": where it lives below /sys.
int kdev_path(int i, char *buf, int cap);
// Announce a device on the uevent socket: action is "add", "remove", "change".
void kdev_uevent(int i, const char *action);
// What reading a device's `uevent` file says.
int kdev_uevent_text(int i, char *buf, int cap);

View file

@ -344,6 +344,11 @@ struct socket {
// AF_NETLINK only: which protocol, and the multicast groups bound.
int nlproto;
uint nlgroups;
uint nlpid; // port id, assigned at bind
uint nllast; // groups of the datagram read last
uint nlfrom; // port id (netlink) or pid (Unix) of its sender
uint pk_uid, pk_gid; // Unix packet: credentials of its sender
int pk_valid; // a packet has been read
// Connections waiting to be accepted, on a listener.
struct socket *queue[NBACKLOG];