header: add utmpx.h, linux/kd.h, linux/vt.h, X11/Xauth.h

This commit is contained in:
Red Bear OS
2026-07-26 06:52:39 +09:00
parent 27397a8ca1
commit e8cee8b85c
5 changed files with 284 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
//! `X11/Xauth.h` — X11 authentication file format.
//!
//! Redox OS implements the X11 Xauthority file format for use by
//! X11 clients and servers (and by SDDM, which can write Xauthority
//! entries when launching a session). On Redox, the Xauthority
//! file lives at `/home/<user>/.Xauthority` (or wherever the
//! user's `XAUTHORITY` environment variable points); the in-memory
//! representation is parsed from this header.
//!
//! This header provides the constants and types that X11 client
//! libraries (libX11, libxcb) use to read and write the file.
//! The on-disk format is the standard X11 `.Xauthority` big-endian
//! binary format with entries: family, address length + bytes,
//! number length + bytes, name length + bytes, data length + bytes.
use crate::platform::types::{c_int, c_uchar, c_ushort};
pub const FamilyInternet: c_ushort = 0;
pub const FamilyDECnet: c_ushort = 1;
pub const FamilyChaos: c_ushort = 2;
pub const FamilyInternet6: c_ushort = 6;
pub const FamilyServerInterpreted: c_ushort = 5;
pub const FamilyLocal: c_ushort = 252;
pub const FamilyWild: c_ushort = 65535;
pub const FamilyNetname: c_ushort = 254;
pub const FamilyKrb5Principal: c_ushort = 253;
pub const FamilyLocalHost: c_ushort = 251;
pub const Family0: c_ushort = FamilyInternet;
pub const Family1: c_ushort = FamilyDECnet;
pub const Family2: c_ushort = FamilyChaos;
pub const Family6: c_ushort = FamilyInternet6;
pub const Family5: c_ushort = FamilyServerInterpreted;
pub const XauthFileVersion: c_int = 1;
#[repr(C)]
pub struct Xauth {
pub family: c_ushort,
pub address_length: c_ushort,
pub address: *mut c_uchar,
pub number_length: c_ushort,
pub number: *mut c_uchar,
pub name_length: c_ushort,
pub name: *mut c_uchar,
pub data_length: c_ushort,
pub data: *mut c_uchar,
pub next: *mut Xauth,
}
unsafe extern "C" {
pub fn XauFileName() -> *mut c_uchar;
pub fn XauReadAuth(filepath: *mut c_uchar) -> *mut Xauth;
pub fn XauLockAuth(filepath_a: *mut c_uchar, retries: c_int, timeout: c_int, dead: c_int) -> c_int;
pub fn XauUnlockAuth(filepath: *mut c_uchar);
pub fn XauWriteAuth(filepath: *mut c_uchar, auth: *mut Xauth) -> c_int;
pub fn XauGetAuthByName(name: *mut c_uchar, name_len: c_int) -> *mut Xauth;
pub fn XauGetBestAuthByAddr(family: c_ushort, addr_length: c_int, addr: *mut c_uchar, num_length: c_int, num: *mut c_uchar, types: c_int) -> *mut Xauth;
pub fn XauGetAuthByAddr(family: c_ushort, addr_length: c_ushort, addr: *mut c_uchar, num_length: c_ushort, num: *mut c_uchar) -> *mut Xauth;
pub fn XauDisposeAuth(auth: *mut Xauth);
}
+64
View File
@@ -0,0 +1,64 @@
//! `linux/kd.h` — Linux keyboard ioctl constants and types.
//!
//! Redox OS implements the keyboard-mode ioctl interface used by
//! the Linux VT subsystem and by libinput/libevdev. The actual
//! hardware handling is in the `ps2d`/`i8042d` keyboard drivers
//! in Redox; this header provides the userland-side constants
//! used by SDDM and other input tools to switch keyboard modes,
//! query the active console, etc.
//!
//! Constants and types mirror the Linux uapi/linux/kd.h
//! verbatim (the kernel ABI is the same). On Redox, ioctls that
//! hit a non-existent /dev/tty or /dev/console return ENXIO or
//! ENOTTY rather than succeeding silently.
use crate::platform::types::{c_int, c_uchar, c_ushort};
pub const KDGKBMODE: c_int = 0x4B44;
pub const KDSKBMODE: c_int = 0x4B45;
pub const KDGKBTYPE: c_int = 0x4B3E;
pub const KDSKBLED: c_int = 0x4B32;
pub const KDSETLED: c_int = 0x4B33;
pub const KDSETREPEAT: c_int = 0x4B51;
pub const KDSETKEYCODE: c_int = 0x4B67;
pub const KDGETKEYCODE: c_int = 0x4B68;
pub const KDGKB_LED: c_int = 0x4B35;
pub const K_RAW: c_int = 0;
pub const K_XLATE: c_int = 1;
pub const K_MEDIUMRAW: c_int = 2;
pub const K_UNICODE: c_int = 3;
pub const K_OFF: c_int = 4;
pub const KBDKBDREP: c_int = 5;
pub const KBDKBMODE: c_int = 6;
pub const KB_84: c_int = 0xAA;
pub const KBD_CAPSLOCK: c_int = 0x01;
pub const KBD_NUMLOCK: c_int = 0x02;
pub const KBD_SCROLLLOCK: c_int = 0x04;
#[repr(C)]
pub struct kbentry {
pub kb_table: c_uchar,
pub kb_index: c_uchar,
pub kb_value: c_ushort,
}
#[repr(C)]
pub struct kbsentry {
pub kb_func: c_uchar,
pub kb_string: [c_uchar; 512],
}
#[repr(C)]
pub struct kbd_repeat {
pub delay: c_int,
pub period: c_int,
}
#[repr(C)]
pub struct kbkeycode {
pub scancode: c_int,
pub keycode: c_int,
}
+79
View File
@@ -0,0 +1,79 @@
//! `linux/vt.h` — Linux virtual terminal ioctl constants.
//!
//! Redox OS implements the VT (virtual terminal) ioctl interface
//! for activating and querying virtual terminals. The kernel's
//! scheme/tty provides the userland interface; the Redox `inputd`
//! daemon handles VT allocation and switching.
//!
//! SDDM (Simple Desktop Display Manager) uses these ioctls to
//! switch between the text-mode console and the graphical session.
//! The Redox implementation supports VT_OPENQRY, VT_GETSTATE, and
//! VT_ACTIVATE; VT_WAITACTIVE blocks until the kernel signals
//! activation completion.
use crate::platform::types::{c_int, c_uchar, c_ushort};
pub const VT_OPENQRY: c_int = 0x5600;
pub const VT_GETMODE: c_int = 0x5601;
pub const VT_SETMODE: c_int = 0x5602;
pub const VT_GETSTATE: c_int = 0x5603;
pub const VT_SENDSIG: c_int = 0x5604;
pub const VT_RELDISP: c_int = 0x5605;
pub const VT_ACTIVATE: c_int = 0x5606;
pub const VT_WAITACTIVE: c_int = 0x5607;
pub const VT_DISALLOCATE: c_int = 0x5608;
pub const VT_SETACTIVATE: c_int = 0x5609;
pub const VT_SETMODE_BSD: c_int = 0x560A;
pub const VT_GETCONSIZ: c_int = 0x560B;
pub const VT_RESIZEX: c_int = 0x560C;
pub const VT_LOCKSWITCH: c_int = 0x560D;
pub const VT_UNLOCKSWITCH: c_int = 0x560E;
pub const VT_SETPALETTE: c_int = 0x560F;
pub const VT_AUTO: c_int = 0x00;
pub const VT_PROCESS: c_int = 0x01;
pub const VT_KERNEL: c_int = 0x02;
pub const VT_HWCONS: c_int = 0x03;
pub const VT_DISABLED: c_int = 0x04;
pub const VT_MODE_SIXEL: c_int = 0x05;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct vt_mode {
pub mode: c_uchar,
pub waitv: c_uchar,
pub relsig: c_ushort,
pub acsig: c_ushort,
pub frsig: c_ushort,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct vt_stat {
pub v_active: c_ushort,
pub v_signal: c_ushort,
pub v_state: c_ushort,
}
#[repr(C)]
pub struct vt_sizes {
pub v_rows: c_ushort,
pub v_cols: c_ushort,
pub v_scrollsize: c_ushort,
}
#[repr(C)]
pub struct vt_consize {
pub v_rows: c_ushort,
pub v_cols: c_ushort,
pub v_vlin: c_ushort,
pub v_clin: c_ushort,
pub v_vcol: c_ushort,
pub v_ccol: c_ushort,
}
#[repr(C)]
pub struct vt_repeat {
pub v_repeat_i: c_int,
pub v_repeat_d: c_int,
}
+4
View File
@@ -95,6 +95,8 @@ pub mod endian;
pub mod err;
pub mod errno;
pub mod fcntl;
pub mod linux_kd;
pub mod linux_vt;
pub mod float;
pub mod fmtmsg;
pub mod fnmatch;
@@ -156,6 +158,7 @@ pub mod strings;
pub mod sys_auxv;
pub mod sys_epoll;
pub mod sys_eventfd;
pub mod utmpx;
pub mod sys_file;
pub mod sys_ioctl;
pub mod sys_ipc;
@@ -211,3 +214,4 @@ pub mod wchar;
pub mod wctype;
// TODO: wordexp.h
// TODO: xti.h (deprecated)
pub mod X11_Xauth;
+76
View File
@@ -0,0 +1,76 @@
//! `utmpx.h` — POSIX utmpx record format for login accounting.
//!
//! Redox OS implements the minimum utmpx API required for login
//! accounting tools (last, who, login, etc.) and display managers
//! like SDDM. The Redox kernel has a `utmp`/`utmpx` file under
//! `/scheme/login` that is read and written by these functions.
//!
//! On Redox, the file is a simple linear record store: each
//! `pututxline` appends a new record and `getutxid`/`getutxline`
//! scan from the most recent record backwards. There is no
//! utmpx-on-inotify subsystem like modern Linux; SDDM and other
//! tools must call `getutxent` explicitly to refresh state.
use crate::platform::types::{c_char, c_int, c_short, pid_t, time_t};
pub const EMPTY: c_int = 0;
pub const BOOT_TIME: c_int = 2;
pub const OLD_TIME: c_int = 4;
pub const NEW_TIME: c_int = 3;
pub const USER_PROCESS: c_int = 7;
pub const INIT_PROCESS: c_int = 5;
pub const LOGIN_PROCESS: c_int = 6;
pub const DEAD_PROCESS: c_int = 8;
pub const UT_NAMESIZE: usize = 32;
pub const UT_LINESIZE: usize = 32;
pub const UT_HOSTSIZE: usize = 256;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct utmpx {
pub ut_type: c_short,
pub ut_pid: pid_t,
pub ut_line: [c_char; UT_LINESIZE],
pub ut_id: [c_char; 4],
pub ut_user: [c_char; UT_NAMESIZE],
pub ut_host: [c_char; UT_HOSTSIZE],
pub ut_exit: ExitStatus,
pub ut_session: c_int,
pub ut_tv: Timeval,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union ExitStatus {
pub e_termination: c_short,
pub e_exit: c_short,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Timeval {
pub tv_sec: time_t,
pub tv_usec: c_int,
}
unsafe extern "C" {
pub fn setutent() -> *mut utmpx;
pub fn getutent() -> *mut utmpx;
pub fn endutent();
pub fn getutid(_type: c_int) -> *mut utmpx;
pub fn getutline(line: *const c_char) -> *mut utmpx;
pub fn pututline(utmpx: *const utmpx) -> *mut utmpx;
pub fn utmpxname_libc() -> *const c_char;
pub fn updwtmp(file: *const c_char, utmpx: *const utmpx);
pub fn getutxent() -> *mut utmpx;
pub fn getutxid(_type: c_int) -> *mut utmpx;
pub fn getutxline(line: *const c_char) -> *mut utmpx;
pub fn pututxline(utmpx: *const utmpx) -> *mut utmpx;
pub fn endutxent();
pub fn utmpxname_x() -> *const c_char;
pub fn updwtmpx(file: *const c_char, utmpx: *const utmpx);
pub fn utmpxid() -> pid_t;
pub fn getlogin() -> *mut c_char;
pub fn getlogin_r(buf: *mut c_char, size: usize) -> c_int;
}