[patch] add class/tty/console/real_dev symlink

From: Hollis Blanchard
Date: Wed Oct 06 2004 - 18:57:16 EST


This patch adds a symlink from /sys/class/tty/console/real_dev to
e.g. /sys/class/tty/ttyS0 . This is needed because there is no way for
userspace to determine what device the kernel is using as its console, and in
the case of an installer that is important information. Otherwise, the
installer cannot know which serial port you're booting on, for example, and
so wouldn't know where to display itself.

This "works for me". I'm not overly attached to the name of the symlink
though. Comments?

--
Hollis Blanchard
IBM Linux Technology Center

===== drivers/char/tty_io.c 1.147 vs edited =====
--- 1.147/drivers/char/tty_io.c Sat Oct 2 17:45:19 2004
+++ edited/drivers/char/tty_io.c Wed Oct 6 17:08:27 2004
@@ -110,6 +110,8 @@
#define TTY_PARANOIA_CHECK 1
#define CHECK_TTY_COUNT 1

+static struct class_device *console_dev;
+
struct termios tty_std_termios = { /* for the benefit of tty drivers */
.c_iflag = ICRNL | IXON,
.c_oflag = OPOST | ONLCR,
@@ -2640,6 +2642,9 @@
{
char name[64];
dev_t dev = MKDEV(driver->major, driver->minor_start) + index;
+ struct class_device *tty_dev;
+ struct tty_driver *console_driver;
+ int console_index;

if (index >= driver->num) {
printk(KERN_ERR "Attempt to register invalid tty line number "
@@ -2654,7 +2659,12 @@
pty_line_name(driver, index, name);
else
tty_line_name(driver, index, name);
- class_simple_device_add(tty_class, dev, device, name);
+ tty_dev = class_simple_device_add(tty_class, dev, device, name);
+
+ console_driver = console_device(&console_index);
+ if ((console_driver == driver) && (console_index == index)) {
+ sysfs_create_link(&console_dev->kobj, &tty_dev->kobj, "real_dev");
+ }
}

/**
@@ -2921,7 +2931,8 @@
register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
panic("Couldn't register /dev/console driver\n");
devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console");
- class_simple_device_add(tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
+ console_dev = class_simple_device_add(tty_class, MKDEV(TTYAUX_MAJOR, 1),
+ NULL, "console");

#ifdef CONFIG_UNIX98_PTYS
cdev_init(&ptmx_cdev, &ptmx_fops);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/