Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
3a33f489
Commit
3a33f489
authored
Jun 11, 2003
by
Alexander Viro
Committed by
Linus Torvalds
Jun 11, 2003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PATCH] tty_driver refcounting
drivers/char/pty.c converted to dynamic allocation
parent
956bf124
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
113 deletions
+103
-113
drivers/char/pty.c
drivers/char/pty.c
+99
-109
drivers/char/tty_io.c
drivers/char/tty_io.c
+4
-4
No files found.
drivers/char/pty.c
View file @
3a33f489
...
@@ -31,24 +31,12 @@
...
@@ -31,24 +31,12 @@
#include <asm/bitops.h>
#include <asm/bitops.h>
#include <linux/devpts_fs.h>
#include <linux/devpts_fs.h>
struct
pty_struct
{
static
struct
tty_driver
*
pty_driver
,
*
pty_slave_driver
;
int
magic
;
wait_queue_head_t
open_wait
;
};
#define PTY_MAGIC 0x5001
static
struct
tty_driver
pty_driver
,
pty_slave_driver
;
/* Note: one set of tables for BSD and one for Unix98 */
static
struct
pty_struct
pty_state
[
NR_PTYS
];
#ifdef CONFIG_UNIX98_PTYS
#ifdef CONFIG_UNIX98_PTYS
/* These are global because they are accessed in tty_io.c */
/* These are global because they are accessed in tty_io.c */
struct
tty_driver
ptm_driver
;
struct
tty_driver
*
ptm_driver
;
struct
tty_driver
pts_driver
;
struct
tty_driver
*
pts_driver
;
static
struct
pty_struct
ptm_state
[
UNIX98_NR_MAJORS
*
NR_PTYS
];
#endif
#endif
static
void
pty_close
(
struct
tty_struct
*
tty
,
struct
file
*
filp
)
static
void
pty_close
(
struct
tty_struct
*
tty
,
struct
file
*
filp
)
...
@@ -74,7 +62,7 @@ static void pty_close(struct tty_struct * tty, struct file * filp)
...
@@ -74,7 +62,7 @@ static void pty_close(struct tty_struct * tty, struct file * filp)
if
(
tty
->
driver
->
subtype
==
PTY_TYPE_MASTER
)
{
if
(
tty
->
driver
->
subtype
==
PTY_TYPE_MASTER
)
{
set_bit
(
TTY_OTHER_CLOSED
,
&
tty
->
flags
);
set_bit
(
TTY_OTHER_CLOSED
,
&
tty
->
flags
);
#ifdef CONFIG_UNIX98_PTYS
#ifdef CONFIG_UNIX98_PTYS
if
(
tty
->
driver
==
&
ptm_driver
)
if
(
tty
->
driver
==
ptm_driver
)
devpts_pty_kill
(
tty
->
index
);
devpts_pty_kill
(
tty
->
index
);
#endif
#endif
tty_vhangup
(
tty
->
link
);
tty_vhangup
(
tty
->
link
);
...
@@ -287,16 +275,10 @@ static void pty_flush_buffer(struct tty_struct *tty)
...
@@ -287,16 +275,10 @@ static void pty_flush_buffer(struct tty_struct *tty)
static
int
pty_open
(
struct
tty_struct
*
tty
,
struct
file
*
filp
)
static
int
pty_open
(
struct
tty_struct
*
tty
,
struct
file
*
filp
)
{
{
int
retval
;
int
retval
=
-
ENODEV
;
int
line
;
struct
pty_struct
*
pty
;
retval
=
-
ENODEV
;
if
(
!
tty
||
!
tty
->
link
)
if
(
!
tty
||
!
tty
->
link
)
goto
out
;
goto
out
;
line
=
tty
->
index
;
pty
=
(
struct
pty_struct
*
)(
tty
->
driver
->
driver_state
)
+
line
;
tty
->
driver_data
=
pty
;
retval
=
-
EIO
;
retval
=
-
EIO
;
if
(
test_bit
(
TTY_OTHER_CLOSED
,
&
tty
->
flags
))
if
(
test_bit
(
TTY_OTHER_CLOSED
,
&
tty
->
flags
))
...
@@ -307,7 +289,6 @@ static int pty_open(struct tty_struct *tty, struct file * filp)
...
@@ -307,7 +289,6 @@ static int pty_open(struct tty_struct *tty, struct file * filp)
goto
out
;
goto
out
;
clear_bit
(
TTY_OTHER_CLOSED
,
&
tty
->
link
->
flags
);
clear_bit
(
TTY_OTHER_CLOSED
,
&
tty
->
link
->
flags
);
wake_up_interruptible
(
&
pty
->
open_wait
);
set_bit
(
TTY_THROTTLED
,
&
tty
->
flags
);
set_bit
(
TTY_THROTTLED
,
&
tty
->
flags
);
set_bit
(
TTY_DO_WRITE_WAKEUP
,
&
tty
->
flags
);
set_bit
(
TTY_DO_WRITE_WAKEUP
,
&
tty
->
flags
);
retval
=
0
;
retval
=
0
;
...
@@ -321,105 +302,114 @@ static void pty_set_termios(struct tty_struct *tty, struct termios *old_termios)
...
@@ -321,105 +302,114 @@ static void pty_set_termios(struct tty_struct *tty, struct termios *old_termios)
tty
->
termios
->
c_cflag
|=
(
CS8
|
CREAD
);
tty
->
termios
->
c_cflag
|=
(
CS8
|
CREAD
);
}
}
static
struct
tty_operations
pty_ops
=
{
.
open
=
pty_open
,
.
close
=
pty_close
,
.
write
=
pty_write
,
.
write_room
=
pty_write_room
,
.
flush_buffer
=
pty_flush_buffer
,
.
chars_in_buffer
=
pty_chars_in_buffer
,
.
unthrottle
=
pty_unthrottle
,
.
set_termios
=
pty_set_termios
,
};
int
__init
pty_init
(
void
)
int
__init
pty_init
(
void
)
{
{
int
i
;
/* Traditional BSD devices */
/* Traditional BSD devices */
memset
(
&
pty_state
,
0
,
sizeof
(
pty_state
));
pty_driver
=
alloc_tty_driver
(
NR_PTYS
);
for
(
i
=
0
;
i
<
NR_PTYS
;
i
++
)
if
(
!
pty_driver
)
init_waitqueue_head
(
&
pty_state
[
i
].
open_wait
);
panic
(
"Couldn't allocate pty driver"
);
memset
(
&
pty_driver
,
0
,
sizeof
(
struct
tty_driver
));
pty_driver
.
magic
=
TTY_DRIVER_MAGIC
;
pty_slave_driver
=
alloc_tty_driver
(
NR_PTYS
);
pty_driver
.
owner
=
THIS_MODULE
;
if
(
!
pty_slave_driver
)
pty_driver
.
driver_name
=
"pty_master"
;
panic
(
"Couldn't allocate pty slave driver"
);
pty_driver
.
name
=
"pty"
;
pty_driver
.
devfs_name
=
"pty/m"
;
pty_driver
->
owner
=
THIS_MODULE
;
pty_driver
.
major
=
PTY_MASTER_MAJOR
;
pty_driver
->
driver_name
=
"pty_master"
;
pty_driver
.
minor_start
=
0
;
pty_driver
->
name
=
"pty"
;
pty_driver
.
num
=
NR_PTYS
;
pty_driver
->
devfs_name
=
"pty/m"
;
pty_driver
.
type
=
TTY_DRIVER_TYPE_PTY
;
pty_driver
->
major
=
PTY_MASTER_MAJOR
;
pty_driver
.
subtype
=
PTY_TYPE_MASTER
;
pty_driver
->
minor_start
=
0
;
pty_driver
.
init_termios
=
tty_std_termios
;
pty_driver
->
type
=
TTY_DRIVER_TYPE_PTY
;
pty_driver
.
init_termios
.
c_iflag
=
0
;
pty_driver
->
subtype
=
PTY_TYPE_MASTER
;
pty_driver
.
init_termios
.
c_oflag
=
0
;
pty_driver
->
init_termios
=
tty_std_termios
;
pty_driver
.
init_termios
.
c_cflag
=
B38400
|
CS8
|
CREAD
;
pty_driver
->
init_termios
.
c_iflag
=
0
;
pty_driver
.
init_termios
.
c_lflag
=
0
;
pty_driver
->
init_termios
.
c_oflag
=
0
;
pty_driver
.
flags
=
TTY_DRIVER_RESET_TERMIOS
|
TTY_DRIVER_REAL_RAW
;
pty_driver
->
init_termios
.
c_cflag
=
B38400
|
CS8
|
CREAD
;
pty_driver
.
driver_state
=
pty_state
;
pty_driver
->
init_termios
.
c_lflag
=
0
;
pty_driver
.
other
=
&
pty_slave_driver
;
pty_driver
->
flags
=
TTY_DRIVER_RESET_TERMIOS
|
TTY_DRIVER_REAL_RAW
;
pty_driver
->
other
=
pty_slave_driver
;
pty_driver
.
open
=
pty_open
;
tty_set_operations
(
pty_driver
,
&
pty_ops
);
pty_driver
.
close
=
pty_close
;
pty_driver
->
ioctl
=
pty_bsd_ioctl
;
pty_driver
.
write
=
pty_write
;
pty_driver
.
write_room
=
pty_write_room
;
pty_slave_driver
->
owner
=
THIS_MODULE
;
pty_driver
.
flush_buffer
=
pty_flush_buffer
;
pty_slave_driver
->
driver_name
=
"pty_slave"
;
pty_driver
.
chars_in_buffer
=
pty_chars_in_buffer
;
pty_slave_driver
->
name
=
"ttyp"
;
pty_driver
.
unthrottle
=
pty_unthrottle
;
pty_slave_driver
->
devfs_name
=
"pty/s"
;
pty_driver
.
set_termios
=
pty_set_termios
;
pty_slave_driver
->
major
=
PTY_SLAVE_MAJOR
;
pty_slave_driver
->
minor_start
=
0
;
pty_slave_driver
=
pty_driver
;
pty_slave_driver
->
type
=
TTY_DRIVER_TYPE_PTY
;
pty_slave_driver
.
driver_name
=
"pty_slave"
;
pty_slave_driver
->
subtype
=
PTY_TYPE_SLAVE
;
pty_slave_driver
.
proc_entry
=
0
;
pty_slave_driver
->
init_termios
=
tty_std_termios
;
pty_slave_driver
.
name
=
"ttyp"
;
pty_slave_driver
->
init_termios
.
c_cflag
=
B38400
|
CS8
|
CREAD
;
pty_slave_driver
.
devfs_name
=
"pty/s"
;
pty_slave_driver
->
flags
=
TTY_DRIVER_RESET_TERMIOS
|
pty_slave_driver
.
subtype
=
PTY_TYPE_SLAVE
;
TTY_DRIVER_REAL_RAW
|
TTY_DRIVER_NO_DEVFS
;
pty_slave_driver
.
major
=
PTY_SLAVE_MAJOR
;
pty_slave_driver
->
other
=
pty_driver
;
pty_slave_driver
.
minor_start
=
0
;
tty_set_operations
(
pty_slave_driver
,
&
pty_ops
);
pty_slave_driver
.
init_termios
=
tty_std_termios
;
pty_slave_driver
.
init_termios
.
c_cflag
=
B38400
|
CS8
|
CREAD
;
if
(
tty_register_driver
(
pty_driver
))
/* Slave ptys are registered when their corresponding master pty
* is opened, and unregistered when the pair is closed.
*/
pty_slave_driver
.
flags
|=
TTY_DRIVER_NO_DEVFS
;
pty_slave_driver
.
driver_state
=
pty_state
;
pty_slave_driver
.
other
=
&
pty_driver
;
if
(
tty_register_driver
(
&
pty_driver
))
panic
(
"Couldn't register pty driver"
);
panic
(
"Couldn't register pty driver"
);
if
(
tty_register_driver
(
&
pty_slave_driver
))
if
(
tty_register_driver
(
pty_slave_driver
))
panic
(
"Couldn't register pty slave driver"
);
panic
(
"Couldn't register pty slave driver"
);
/*
* only the master pty gets this ioctl (which is why we
* assign it here, instead of up with the rest of the
* pty_driver initialization. <cananian@alumni.princeton.edu>
*/
pty_driver
.
ioctl
=
pty_bsd_ioctl
;
/* Unix98 devices */
/* Unix98 devices */
#ifdef CONFIG_UNIX98_PTYS
#ifdef CONFIG_UNIX98_PTYS
devfs_mk_dir
(
"pts"
);
devfs_mk_dir
(
"pts"
);
printk
(
"pty: %d Unix98 ptys configured
\n
"
,
UNIX98_NR_MAJORS
*
NR_PTYS
);
printk
(
"pty: %d Unix98 ptys configured
\n
"
,
UNIX98_NR_MAJORS
*
NR_PTYS
);
ptm_driver
=
pty_driver
;
ptm_driver
=
alloc_tty_driver
(
UNIX98_NR_MAJORS
*
NR_PTYS
);
ptm_driver
.
name
=
"ptm"
;
if
(
!
ptm_driver
)
ptm_driver
.
proc_entry
=
0
;
panic
(
"Couldn't allocate Unix98 ptm driver"
);
ptm_driver
.
major
=
UNIX98_PTY_MASTER_MAJOR
;
pts_driver
=
alloc_tty_driver
(
UNIX98_NR_MAJORS
*
NR_PTYS
);
ptm_driver
.
minor_start
=
0
;
if
(
!
pts_driver
)
ptm_driver
.
num
=
UNIX98_NR_MAJORS
*
NR_PTYS
;
panic
(
"Couldn't allocate Unix98 pts driver"
);
ptm_driver
.
other
=
&
pts_driver
;
ptm_driver
.
flags
|=
TTY_DRIVER_NO_DEVFS
;
ptm_driver
->
owner
=
THIS_MODULE
;
ptm_driver
.
driver_state
=
ptm_state
;
ptm_driver
->
driver_name
=
"pty_master"
;
ptm_driver
->
name
=
"ptm"
;
for
(
i
=
0
;
i
<
UNIX98_NR_MAJORS
*
NR_PTYS
;
i
++
)
ptm_driver
->
major
=
UNIX98_PTY_MASTER_MAJOR
;
init_waitqueue_head
(
&
ptm_state
[
i
].
open_wait
);
ptm_driver
->
minor_start
=
0
;
ptm_driver
->
type
=
TTY_DRIVER_TYPE_PTY
;
pts_driver
=
pty_slave_driver
;
ptm_driver
->
subtype
=
PTY_TYPE_MASTER
;
pts_driver
.
name
=
"pts"
;
ptm_driver
->
init_termios
=
tty_std_termios
;
pts_driver
.
proc_entry
=
0
;
ptm_driver
->
init_termios
.
c_iflag
=
0
;
pts_driver
.
major
=
UNIX98_PTY_SLAVE_MAJOR
;
ptm_driver
->
init_termios
.
c_oflag
=
0
;
pts_driver
.
minor_start
=
0
;
ptm_driver
->
init_termios
.
c_cflag
=
B38400
|
CS8
|
CREAD
;
pts_driver
.
num
=
UNIX98_NR_MAJORS
*
NR_PTYS
;
ptm_driver
->
init_termios
.
c_lflag
=
0
;
pts_driver
.
other
=
&
ptm_driver
;
ptm_driver
->
flags
=
TTY_DRIVER_RESET_TERMIOS
|
TTY_DRIVER_REAL_RAW
|
pts_driver
.
flags
|=
TTY_DRIVER_NO_DEVFS
;
TTY_DRIVER_NO_DEVFS
;
pts_driver
.
driver_state
=
ptm_state
;
ptm_driver
->
other
=
pts_driver
;
tty_set_operations
(
ptm_driver
,
&
pty_ops
);
ptm_driver
.
ioctl
=
pty_unix98_ioctl
;
ptm_driver
->
ioctl
=
pty_unix98_ioctl
;
pts_driver
->
owner
=
THIS_MODULE
;
pts_driver
->
driver_name
=
"pty_slave"
;
pts_driver
->
name
=
"pts"
;
pts_driver
->
major
=
UNIX98_PTY_SLAVE_MAJOR
;
pts_driver
->
minor_start
=
0
;
pts_driver
->
type
=
TTY_DRIVER_TYPE_PTY
;
pts_driver
->
subtype
=
PTY_TYPE_SLAVE
;
pts_driver
->
init_termios
=
tty_std_termios
;
pts_driver
->
init_termios
.
c_cflag
=
B38400
|
CS8
|
CREAD
;
pts_driver
->
flags
=
TTY_DRIVER_RESET_TERMIOS
|
TTY_DRIVER_REAL_RAW
|
TTY_DRIVER_NO_DEVFS
;
pts_driver
->
other
=
ptm_driver
;
tty_set_operations
(
pts_driver
,
&
pty_ops
);
if
(
tty_register_driver
(
&
ptm_driver
))
if
(
tty_register_driver
(
ptm_driver
))
panic
(
"Couldn't register Unix98 ptm driver"
);
panic
(
"Couldn't register Unix98 ptm driver"
);
if
(
tty_register_driver
(
&
pts_driver
))
if
(
tty_register_driver
(
pts_driver
))
panic
(
"Couldn't register Unix98 pts driver"
);
panic
(
"Couldn't register Unix98 pts driver"
);
#endif
#endif
return
0
;
return
0
;
...
...
drivers/char/tty_io.c
View file @
3a33f489
...
@@ -126,8 +126,8 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
...
@@ -126,8 +126,8 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
struct
tty_ldisc
ldiscs
[
NR_LDISCS
];
/* line disc dispatch table */
struct
tty_ldisc
ldiscs
[
NR_LDISCS
];
/* line disc dispatch table */
#ifdef CONFIG_UNIX98_PTYS
#ifdef CONFIG_UNIX98_PTYS
extern
struct
tty_driver
ptm_driver
;
/* Unix98 pty masters; for /dev/ptmx */
extern
struct
tty_driver
*
ptm_driver
;
/* Unix98 pty masters; for /dev/ptmx */
extern
struct
tty_driver
pts_driver
;
/* Unix98 pty slaves; for /dev/ptmx */
extern
struct
tty_driver
*
pts_driver
;
/* Unix98 pty slaves; for /dev/ptmx */
#endif
#endif
extern
void
disable_early_printk
(
void
);
extern
void
disable_early_printk
(
void
);
...
@@ -1349,14 +1349,14 @@ static int tty_open(struct inode * inode, struct file * filp)
...
@@ -1349,14 +1349,14 @@ static int tty_open(struct inode * inode, struct file * filp)
#ifdef CONFIG_UNIX98_PTYS
#ifdef CONFIG_UNIX98_PTYS
/* find a device that is not in use. */
/* find a device that is not in use. */
retval
=
-
1
;
retval
=
-
1
;
driver
=
&
ptm_driver
;
driver
=
ptm_driver
;
for
(
index
=
0
;
index
<
driver
->
num
;
index
++
)
for
(
index
=
0
;
index
<
driver
->
num
;
index
++
)
if
(
!
init_dev
(
driver
,
index
,
&
tty
))
if
(
!
init_dev
(
driver
,
index
,
&
tty
))
goto
ptmx_found
;
/* ok! */
goto
ptmx_found
;
/* ok! */
return
-
EIO
;
/* no free ptys */
return
-
EIO
;
/* no free ptys */
ptmx_found:
ptmx_found:
set_bit
(
TTY_PTY_LOCK
,
&
tty
->
flags
);
/* LOCK THE SLAVE */
set_bit
(
TTY_PTY_LOCK
,
&
tty
->
flags
);
/* LOCK THE SLAVE */
devpts_pty_new
(
index
,
MKDEV
(
pts_driver
.
major
,
pts_driver
.
minor_start
)
+
index
);
devpts_pty_new
(
index
,
MKDEV
(
pts_driver
->
major
,
pts_driver
->
minor_start
)
+
index
);
noctty
=
1
;
noctty
=
1
;
#else
#else
return
-
ENODEV
;
return
-
ENODEV
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment