@@ -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 ,
@@ -606,9 +607,9 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
606
607
/* This breaks for file handles being sent over AF_UNIX sockets ? */
607
608
list_for_each_entry (priv , & tty -> tty_files , list ) {
608
609
filp = priv -> file ;
609
- if (filp -> f_op -> write == redirected_tty_write )
610
+ if (filp -> f_op -> write_iter == redirected_tty_write )
610
611
cons_filp = filp ;
611
- if (filp -> f_op -> write != tty_write )
612
+ if (filp -> f_op -> write_iter != tty_write )
612
613
continue ;
613
614
closecount ++ ;
614
615
__tty_fasync (-1 , filp , 0 ); /* can't block */
@@ -901,9 +902,9 @@ static inline ssize_t do_tty_write(
901
902
ssize_t (* write )(struct tty_struct * , struct file * , const unsigned char * , size_t ),
902
903
struct tty_struct * tty ,
903
904
struct file * file ,
904
- const char __user * buf ,
905
- size_t count )
905
+ struct iov_iter * from )
906
906
{
907
+ size_t count = iov_iter_count (from );
907
908
ssize_t ret , written = 0 ;
908
909
unsigned int chunk ;
909
910
@@ -955,14 +956,20 @@ static inline ssize_t do_tty_write(
955
956
size_t size = count ;
956
957
if (size > chunk )
957
958
size = chunk ;
959
+
958
960
ret = - EFAULT ;
959
- if (copy_from_user (tty -> write_buf , buf , size ) )
961
+ if (copy_from_iter (tty -> write_buf , size , from ) != size )
960
962
break ;
963
+
961
964
ret = write (tty , file , tty -> write_buf , size );
962
965
if (ret <= 0 )
963
966
break ;
967
+
968
+ /* FIXME! Have Al check this! */
969
+ if (ret != size )
970
+ iov_iter_revert (from , size - ret );
971
+
964
972
written += ret ;
965
- buf += ret ;
966
973
count -= ret ;
967
974
if (!count )
968
975
break ;
@@ -1022,9 +1029,9 @@ void tty_write_message(struct tty_struct *tty, char *msg)
1022
1029
* write method will not be invoked in parallel for each device.
1023
1030
*/
1024
1031
1025
- static ssize_t tty_write (struct file * file , const char __user * buf ,
1026
- size_t count , loff_t * ppos )
1032
+ static ssize_t tty_write (struct kiocb * iocb , struct iov_iter * from )
1027
1033
{
1034
+ struct file * file = iocb -> ki_filp ;
1028
1035
struct tty_struct * tty = file_tty (file );
1029
1036
struct tty_ldisc * ld ;
1030
1037
ssize_t ret ;
@@ -1037,18 +1044,15 @@ static ssize_t tty_write(struct file *file, const char __user *buf,
1037
1044
if (tty -> ops -> write_room == NULL )
1038
1045
tty_err (tty , "missing write_room method\n" );
1039
1046
ld = tty_ldisc_ref_wait (tty );
1040
- if (!ld )
1041
- return hung_up_tty_write (file , buf , count , ppos );
1042
- if (!ld -> ops -> write )
1047
+ if (!ld || !ld -> ops -> write )
1043
1048
ret = - EIO ;
1044
1049
else
1045
- ret = do_tty_write (ld -> ops -> write , tty , file , buf , count );
1050
+ ret = do_tty_write (ld -> ops -> write , tty , file , from );
1046
1051
tty_ldisc_deref (ld );
1047
1052
return ret ;
1048
1053
}
1049
1054
1050
- ssize_t redirected_tty_write (struct file * file , const char __user * buf ,
1051
- size_t count , loff_t * ppos )
1055
+ ssize_t redirected_tty_write (struct kiocb * iocb , struct iov_iter * iter )
1052
1056
{
1053
1057
struct file * p = NULL ;
1054
1058
@@ -1059,11 +1063,11 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
1059
1063
1060
1064
if (p ) {
1061
1065
ssize_t res ;
1062
- res = vfs_write (p , buf , count , & p -> f_pos );
1066
+ res = vfs_iocb_iter_write (p , iocb , iter );
1063
1067
fput (p );
1064
1068
return res ;
1065
1069
}
1066
- return tty_write (file , buf , count , ppos );
1070
+ return tty_write (iocb , iter );
1067
1071
}
1068
1072
1069
1073
/*
@@ -2295,7 +2299,7 @@ static int tioccons(struct file *file)
2295
2299
{
2296
2300
if (!capable (CAP_SYS_ADMIN ))
2297
2301
return - EPERM ;
2298
- if (file -> f_op -> write == redirected_tty_write ) {
2302
+ if (file -> f_op -> write_iter == redirected_tty_write ) {
2299
2303
struct file * f ;
2300
2304
spin_lock (& redirect_lock );
2301
2305
f = redirect ;
0 commit comments