@@ -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 );
@@ -438,8 +437,7 @@ static ssize_t hung_up_tty_read(struct file *file, char __user *buf,
438
437
return 0 ;
439
438
}
440
439
441
- static ssize_t hung_up_tty_write (struct file * file , const char __user * buf ,
442
- size_t count , loff_t * ppos )
440
+ static ssize_t hung_up_tty_write (struct kiocb * iocb , struct iov_iter * from )
443
441
{
444
442
return - EIO ;
445
443
}
@@ -478,7 +476,8 @@ static void tty_show_fdinfo(struct seq_file *m, struct file *file)
478
476
static const struct file_operations tty_fops = {
479
477
.llseek = no_llseek ,
480
478
.read = tty_read ,
481
- .write = tty_write ,
479
+ .write_iter = tty_write ,
480
+ .splice_write = iter_file_splice_write ,
482
481
.poll = tty_poll ,
483
482
.unlocked_ioctl = tty_ioctl ,
484
483
.compat_ioctl = tty_compat_ioctl ,
@@ -491,7 +490,8 @@ static const struct file_operations tty_fops = {
491
490
static const struct file_operations console_fops = {
492
491
.llseek = no_llseek ,
493
492
.read = tty_read ,
494
- .write = redirected_tty_write ,
493
+ .write_iter = redirected_tty_write ,
494
+ .splice_write = iter_file_splice_write ,
495
495
.poll = tty_poll ,
496
496
.unlocked_ioctl = tty_ioctl ,
497
497
.compat_ioctl = tty_compat_ioctl ,
@@ -503,7 +503,7 @@ static const struct file_operations console_fops = {
503
503
static const struct file_operations hung_up_tty_fops = {
504
504
.llseek = no_llseek ,
505
505
.read = hung_up_tty_read ,
506
- .write = hung_up_tty_write ,
506
+ .write_iter = hung_up_tty_write ,
507
507
.poll = hung_up_tty_poll ,
508
508
.unlocked_ioctl = hung_up_tty_ioctl ,
509
509
.compat_ioctl = hung_up_tty_compat_ioctl ,
@@ -606,9 +606,9 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
606
606
/* This breaks for file handles being sent over AF_UNIX sockets ? */
607
607
list_for_each_entry (priv , & tty -> tty_files , list ) {
608
608
filp = priv -> file ;
609
- if (filp -> f_op -> write == redirected_tty_write )
609
+ if (filp -> f_op -> write_iter == redirected_tty_write )
610
610
cons_filp = filp ;
611
- if (filp -> f_op -> write != tty_write )
611
+ if (filp -> f_op -> write_iter != tty_write )
612
612
continue ;
613
613
closecount ++ ;
614
614
__tty_fasync (-1 , filp , 0 ); /* can't block */
@@ -901,9 +901,9 @@ static inline ssize_t do_tty_write(
901
901
ssize_t (* write )(struct tty_struct * , struct file * , const unsigned char * , size_t ),
902
902
struct tty_struct * tty ,
903
903
struct file * file ,
904
- const char __user * buf ,
905
- size_t count )
904
+ struct iov_iter * from )
906
905
{
906
+ size_t count = iov_iter_count (from );
907
907
ssize_t ret , written = 0 ;
908
908
unsigned int chunk ;
909
909
@@ -955,14 +955,20 @@ static inline ssize_t do_tty_write(
955
955
size_t size = count ;
956
956
if (size > chunk )
957
957
size = chunk ;
958
+
958
959
ret = - EFAULT ;
959
- if (copy_from_user (tty -> write_buf , buf , size ) )
960
+ if (copy_from_iter (tty -> write_buf , size , from ) != size )
960
961
break ;
962
+
961
963
ret = write (tty , file , tty -> write_buf , size );
962
964
if (ret <= 0 )
963
965
break ;
966
+
967
+ /* FIXME! Have Al check this! */
968
+ if (ret != size )
969
+ iov_iter_revert (from , size - ret );
970
+
964
971
written += ret ;
965
- buf += ret ;
966
972
count -= ret ;
967
973
if (!count )
968
974
break ;
@@ -1022,9 +1028,9 @@ void tty_write_message(struct tty_struct *tty, char *msg)
1022
1028
* write method will not be invoked in parallel for each device.
1023
1029
*/
1024
1030
1025
- static ssize_t tty_write (struct file * file , const char __user * buf ,
1026
- size_t count , loff_t * ppos )
1031
+ static ssize_t tty_write (struct kiocb * iocb , struct iov_iter * from )
1027
1032
{
1033
+ struct file * file = iocb -> ki_filp ;
1028
1034
struct tty_struct * tty = file_tty (file );
1029
1035
struct tty_ldisc * ld ;
1030
1036
ssize_t ret ;
@@ -1038,17 +1044,16 @@ static ssize_t tty_write(struct file *file, const char __user *buf,
1038
1044
tty_err (tty , "missing write_room method\n" );
1039
1045
ld = tty_ldisc_ref_wait (tty );
1040
1046
if (!ld )
1041
- return hung_up_tty_write (file , buf , count , ppos );
1047
+ return hung_up_tty_write (iocb , from );
1042
1048
if (!ld -> ops -> write )
1043
1049
ret = - EIO ;
1044
1050
else
1045
- ret = do_tty_write (ld -> ops -> write , tty , file , buf , count );
1051
+ ret = do_tty_write (ld -> ops -> write , tty , file , from );
1046
1052
tty_ldisc_deref (ld );
1047
1053
return ret ;
1048
1054
}
1049
1055
1050
- ssize_t redirected_tty_write (struct file * file , const char __user * buf ,
1051
- size_t count , loff_t * ppos )
1056
+ ssize_t redirected_tty_write (struct kiocb * iocb , struct iov_iter * iter )
1052
1057
{
1053
1058
struct file * p = NULL ;
1054
1059
@@ -1059,11 +1064,11 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
1059
1064
1060
1065
if (p ) {
1061
1066
ssize_t res ;
1062
- res = vfs_write (p , buf , count , & p -> f_pos );
1067
+ res = vfs_iocb_iter_write (p , iocb , iter );
1063
1068
fput (p );
1064
1069
return res ;
1065
1070
}
1066
- return tty_write (file , buf , count , ppos );
1071
+ return tty_write (iocb , iter );
1067
1072
}
1068
1073
1069
1074
/*
@@ -2295,7 +2300,7 @@ static int tioccons(struct file *file)
2295
2300
{
2296
2301
if (!capable (CAP_SYS_ADMIN ))
2297
2302
return - EPERM ;
2298
- if (file -> f_op -> write == redirected_tty_write ) {
2303
+ if (file -> f_op -> write_iter == redirected_tty_write ) {
2299
2304
struct file * f ;
2300
2305
spin_lock (& redirect_lock );
2301
2306
f = redirect ;
0 commit comments