Correct the device major ID for pty slave

This commit is contained in:
jiangjianfeng 2025-11-06 09:41:13 +00:00 committed by Ruihan Li
parent a41db92b4e
commit 49485058ec
4 changed files with 10 additions and 1 deletions

View File

@ -80,6 +80,9 @@ impl PtyDriver {
}
impl TtyDriver for PtyDriver {
// Reference: <https://elixir.bootlin.com/linux/v6.17/source/include/uapi/linux/major.h#L147>.
const DEVICE_MAJOR_ID: u32 = 136;
fn push_output(&self, chs: &[u8]) -> Result<usize> {
if self.is_closed() {
return_errno_with_message!(Errno::EIO, "the pty master has been closed");

View File

@ -13,6 +13,9 @@ use crate::prelude::*;
///
/// [`Tty`]: super::Tty
pub trait TtyDriver: Send + Sync + 'static {
/// The device major ID.
const DEVICE_MAJOR_ID: u32;
/// Pushes characters into the output buffer.
///
/// This method returns the number of bytes pushed or fails with an error if no bytes can be

View File

@ -387,6 +387,6 @@ impl<D: TtyDriver> Device for Tty<D> {
}
fn id(&self) -> DeviceId {
DeviceId::new(4, self.index)
DeviceId::new(D::DEVICE_MAJOR_ID, self.index)
}
}

View File

@ -12,6 +12,9 @@ pub struct ConsoleDriver {
}
impl TtyDriver for ConsoleDriver {
// Reference: <https://elixir.bootlin.com/linux/v6.17/source/include/uapi/linux/major.h#L18>.
const DEVICE_MAJOR_ID: u32 = 4;
fn push_output(&self, chs: &[u8]) -> Result<usize> {
self.console.send(chs);
Ok(chs.len())