@@ -143,9 +143,8 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
143
143
DEFINE_MUTEX (tty_mutex );
144
144
145
145
static ssize_t tty_read (struct file * , char __user * , size_t , loff_t * );
146
- static ssize_t tty_write (struct file * , const char __user * , size_t , loff_t * );
147
- ssize_t redirected_tty_write (struct file * , const char __user * ,
148
- size_t , loff_t * );
146
+ static ssize_t tty_write (struct kiocb * , struct iov_iter * );
147
+ ssize_t redirected_tty_write (struct kiocb * , struct iov_iter * );
149
148
static __poll_t tty_poll (struct file * , poll_table * );
150
149
static int tty_open (struct inode * , struct file * );
151
150
long tty_ioctl (struct file * file , unsigned int cmd , unsigned long arg );
@@ -478,7 +477,8 @@ static void tty_show_fdinfo(struct seq_file *m, struct file *file)
478
477
static const struct file_operations tty_fops = {
479
478
.llseek = no_llseek ,
480
479
.read = tty_read ,
481
- .write = tty_write ,
480
+ .write_iter = tty_write ,
481
+ .splice_write = iter_file_splice_write ,
482
482
.poll = tty_poll ,
483
483
.unlocked_ioctl = tty_ioctl ,
484
484
.compat_ioctl = tty_compat_ioctl ,
@@ -491,7 +491,8 @@ static const struct file_operations tty_fops = {
491
491
static const struct file_operations console_fops = {
492
492
.llseek = no_llseek ,
493
493
.read = tty_read ,
494
- .write = redirected_tty_write ,
494
+ .write_iter = redirected_tty_write ,
495
+ .splice_write = iter_file_splice_write ,
495
496
.poll = tty_poll ,
496
497
.unlocked_ioctl = tty_ioctl ,
497
498
.compat_ioctl = tty_compat_ioctl ,
@@ -607,9 +608,9 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
607
608
/* This breaks for file handles being sent over AF_UNIX sockets ? */
608
609
list_for_each_entry (priv , & tty -> tty_files , list ) {
609
610
filp = priv -> file ;
610
- if (filp -> f_op -> write == redirected_tty_write )
611
+ if (filp -> f_op -> write_iter == redirected_tty_write )
611
612
cons_filp = filp ;
612
- if (filp -> f_op -> write != tty_write )
613
+ if (filp -> f_op -> write_iter != tty_write )
613
614
continue ;
614
615
closecount ++ ;
615
616
__tty_fasync (-1 , filp , 0 ); /* can't block */
@@ -902,9 +903,9 @@ static inline ssize_t do_tty_write(
902
903
ssize_t (* write )(struct tty_struct * , struct file * , const unsigned char * , size_t ),
903
904
struct tty_struct * tty ,
904
905
struct file * file ,
905
- const char __user * buf ,
906
- size_t count )
906
+ struct iov_iter * from )
907
907
{
908
+ size_t count = iov_iter_count (from );
908
909
ssize_t ret , written = 0 ;
909
910
unsigned int chunk ;
910
911
@@ -956,14 +957,20 @@ static inline ssize_t do_tty_write(
956
957
size_t size = count ;
957
958
if (size > chunk )
958
959
size = chunk ;
960
+
959
961
ret = - EFAULT ;
960
- if (copy_from_user (tty -> write_buf , buf , size ) )
962
+ if (copy_from_iter (tty -> write_buf , size , from ) != size )
961
963
break ;
964
+
962
965
ret = write (tty , file , tty -> write_buf , size );
963
966
if (ret <= 0 )
964
967
break ;
968
+
969
+ /* FIXME! Have Al check this! */
970
+ if (ret != size )
971
+ iov_iter_revert (from , size - ret );
972
+
965
973
written += ret ;
966
- buf += ret ;
967
974
count -= ret ;
968
975
if (!count )
969
976
break ;
@@ -1023,9 +1030,9 @@ void tty_write_message(struct tty_struct *tty, char *msg)
1023
1030
* write method will not be invoked in parallel for each device.
1024
1031
*/
1025
1032
1026
- static ssize_t tty_write (struct file * file , const char __user * buf ,
1027
- size_t count , loff_t * ppos )
1033
+ static ssize_t tty_write (struct kiocb * iocb , struct iov_iter * from )
1028
1034
{
1035
+ struct file * file = iocb -> ki_filp ;
1029
1036
struct tty_struct * tty = file_tty (file );
1030
1037
struct tty_ldisc * ld ;
1031
1038
ssize_t ret ;
@@ -1038,18 +1045,15 @@ static ssize_t tty_write(struct file *file, const char __user *buf,
1038
1045
if (tty -> ops -> write_room == NULL )
1039
1046
tty_err (tty , "missing write_room method\n" );
1040
1047
ld = tty_ldisc_ref_wait (tty );
1041
- if (!ld )
1042
- return hung_up_tty_write (file , buf , count , ppos );
1043
- if (!ld -> ops -> write )
1048
+ if (!ld || !ld -> ops -> write )
1044
1049
ret = - EIO ;
1045
1050
else
1046
- ret = do_tty_write (ld -> ops -> write , tty , file , buf , count );
1051
+ ret = do_tty_write (ld -> ops -> write , tty , file , from );
1047
1052
tty_ldisc_deref (ld );
1048
1053
return ret ;
1049
1054
}
1050
1055
1051
- ssize_t redirected_tty_write (struct file * file , const char __user * buf ,
1052
- size_t count , loff_t * ppos )
1056
+ ssize_t redirected_tty_write (struct kiocb * iocb , struct iov_iter * iter )
1053
1057
{
1054
1058
struct file * p = NULL ;
1055
1059
@@ -1060,11 +1064,11 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
1060
1064
1061
1065
if (p ) {
1062
1066
ssize_t res ;
1063
- res = vfs_write (p , buf , count , & p -> f_pos );
1067
+ res = vfs_iocb_iter_write (p , iocb , iter );
1064
1068
fput (p );
1065
1069
return res ;
1066
1070
}
1067
- return tty_write (file , buf , count , ppos );
1071
+ return tty_write (iocb , iter );
1068
1072
}
1069
1073
1070
1074
/**
@@ -2293,7 +2297,7 @@ static int tioccons(struct file *file)
2293
2297
{
2294
2298
if (!capable (CAP_SYS_ADMIN ))
2295
2299
return - EPERM ;
2296
- if (file -> f_op -> write == redirected_tty_write ) {
2300
+ if (file -> f_op -> write_iter == redirected_tty_write ) {
2297
2301
struct file * f ;
2298
2302
spin_lock (& redirect_lock );
2299
2303
f = redirect ;
0 commit comments