LCOV - code coverage report
Current view: top level - drivers/tty/vt - vc_screen.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 259 1.2 %
Date: 2014-02-18 Functions: 1 14 7.1 %
Branches: 0 162 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Provide access to virtual console memory.
       3                 :            :  * /dev/vcs0: the screen as it is being viewed right now (possibly scrolled)
       4                 :            :  * /dev/vcsN: the screen of /dev/ttyN (1 <= N <= 63)
       5                 :            :  *            [minor: N]
       6                 :            :  *
       7                 :            :  * /dev/vcsaN: idem, but including attributes, and prefixed with
       8                 :            :  *      the 4 bytes lines,columns,x,y (as screendump used to give).
       9                 :            :  *      Attribute/character pair is in native endianity.
      10                 :            :  *            [minor: N+128]
      11                 :            :  *
      12                 :            :  * This replaces screendump and part of selection, so that the system
      13                 :            :  * administrator can control access using file system permissions.
      14                 :            :  *
      15                 :            :  * aeb@cwi.nl - efter Friedas begravelse - 950211
      16                 :            :  *
      17                 :            :  * machek@k332.feld.cvut.cz - modified not to send characters to wrong console
      18                 :            :  *       - fixed some fatal off-by-one bugs (0-- no longer == -1 -> looping and looping and looping...)
      19                 :            :  *       - making it shorter - scr_readw are macros which expand in PRETTY long code
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <linux/kernel.h>
      23                 :            : #include <linux/major.h>
      24                 :            : #include <linux/errno.h>
      25                 :            : #include <linux/export.h>
      26                 :            : #include <linux/tty.h>
      27                 :            : #include <linux/interrupt.h>
      28                 :            : #include <linux/mm.h>
      29                 :            : #include <linux/init.h>
      30                 :            : #include <linux/vt_kern.h>
      31                 :            : #include <linux/selection.h>
      32                 :            : #include <linux/kbd_kern.h>
      33                 :            : #include <linux/console.h>
      34                 :            : #include <linux/device.h>
      35                 :            : #include <linux/sched.h>
      36                 :            : #include <linux/fs.h>
      37                 :            : #include <linux/poll.h>
      38                 :            : #include <linux/signal.h>
      39                 :            : #include <linux/slab.h>
      40                 :            : #include <linux/notifier.h>
      41                 :            : 
      42                 :            : #include <asm/uaccess.h>
      43                 :            : #include <asm/byteorder.h>
      44                 :            : #include <asm/unaligned.h>
      45                 :            : 
      46                 :            : #undef attr
      47                 :            : #undef org
      48                 :            : #undef addr
      49                 :            : #define HEADER_SIZE     4
      50                 :            : 
      51                 :            : #define CON_BUF_SIZE (CONFIG_BASE_SMALL ? 256 : PAGE_SIZE)
      52                 :            : 
      53                 :            : struct vcs_poll_data {
      54                 :            :         struct notifier_block notifier;
      55                 :            :         unsigned int cons_num;
      56                 :            :         bool seen_last_update;
      57                 :            :         wait_queue_head_t waitq;
      58                 :            :         struct fasync_struct *fasync;
      59                 :            : };
      60                 :            : 
      61                 :            : static int
      62                 :          0 : vcs_notifier(struct notifier_block *nb, unsigned long code, void *_param)
      63                 :            : {
      64                 :            :         struct vt_notifier_param *param = _param;
      65                 :          0 :         struct vc_data *vc = param->vc;
      66                 :            :         struct vcs_poll_data *poll =
      67                 :            :                 container_of(nb, struct vcs_poll_data, notifier);
      68                 :          0 :         int currcons = poll->cons_num;
      69                 :            : 
      70         [ #  # ]:          0 :         if (code != VT_UPDATE)
      71                 :            :                 return NOTIFY_DONE;
      72                 :            : 
      73         [ #  # ]:          0 :         if (currcons == 0)
      74                 :          0 :                 currcons = fg_console;
      75                 :            :         else
      76                 :          0 :                 currcons--;
      77         [ #  # ]:          0 :         if (currcons != vc->vc_num)
      78                 :            :                 return NOTIFY_DONE;
      79                 :            : 
      80                 :          0 :         poll->seen_last_update = false;
      81                 :          0 :         wake_up_interruptible(&poll->waitq);
      82                 :          0 :         kill_fasync(&poll->fasync, SIGIO, POLL_IN);
      83                 :          0 :         return NOTIFY_OK;
      84                 :            : }
      85                 :            : 
      86                 :            : static void
      87                 :            : vcs_poll_data_free(struct vcs_poll_data *poll)
      88                 :            : {
      89                 :          0 :         unregister_vt_notifier(&poll->notifier);
      90                 :          0 :         kfree(poll);
      91                 :            : }
      92                 :            : 
      93                 :            : static struct vcs_poll_data *
      94                 :          0 : vcs_poll_data_get(struct file *file)
      95                 :            : {
      96                 :          0 :         struct vcs_poll_data *poll = file->private_data, *kill = NULL;
      97                 :            : 
      98         [ #  # ]:          0 :         if (poll)
      99                 :            :                 return poll;
     100                 :            : 
     101                 :            :         poll = kzalloc(sizeof(*poll), GFP_KERNEL);
     102         [ #  # ]:          0 :         if (!poll)
     103                 :            :                 return NULL;
     104                 :          0 :         poll->cons_num = iminor(file_inode(file)) & 127;
     105                 :          0 :         init_waitqueue_head(&poll->waitq);
     106                 :          0 :         poll->notifier.notifier_call = vcs_notifier;
     107         [ #  # ]:          0 :         if (register_vt_notifier(&poll->notifier) != 0) {
     108                 :          0 :                 kfree(poll);
     109                 :          0 :                 return NULL;
     110                 :            :         }
     111                 :            : 
     112                 :            :         /*
     113                 :            :          * This code may be called either through ->poll() or ->fasync().
     114                 :            :          * If we have two threads using the same file descriptor, they could
     115                 :            :          * both enter this function, both notice that the structure hasn't
     116                 :            :          * been allocated yet and go ahead allocating it in parallel, but
     117                 :            :          * only one of them must survive and be shared otherwise we'd leak
     118                 :            :          * memory with a dangling notifier callback.
     119                 :            :          */
     120                 :            :         spin_lock(&file->f_lock);
     121         [ #  # ]:          0 :         if (!file->private_data) {
     122                 :          0 :                 file->private_data = poll;
     123                 :            :         } else {
     124                 :            :                 /* someone else raced ahead of us */
     125                 :            :                 kill = poll;
     126                 :            :                 poll = file->private_data;
     127                 :            :         }
     128                 :            :         spin_unlock(&file->f_lock);
     129         [ #  # ]:          0 :         if (kill)
     130                 :            :                 vcs_poll_data_free(kill);
     131                 :            : 
     132                 :          0 :         return poll;
     133                 :            : }
     134                 :            : 
     135                 :            : /*
     136                 :            :  * Returns VC for inode.
     137                 :            :  * Must be called with console_lock.
     138                 :            :  */
     139                 :            : static struct vc_data*
     140                 :          0 : vcs_vc(struct inode *inode, int *viewed)
     141                 :            : {
     142                 :          0 :         unsigned int currcons = iminor(inode) & 127;
     143                 :            : 
     144 [ #  # ][ #  # ]:          0 :         WARN_CONSOLE_UNLOCKED();
                 [ #  # ]
     145                 :            : 
     146         [ #  # ]:          0 :         if (currcons == 0) {
     147                 :          0 :                 currcons = fg_console;
     148         [ #  # ]:          0 :                 if (viewed)
     149                 :          0 :                         *viewed = 1;
     150                 :            :         } else {
     151                 :          0 :                 currcons--;
     152         [ #  # ]:          0 :                 if (viewed)
     153                 :          0 :                         *viewed = 0;
     154                 :            :         }
     155                 :          0 :         return vc_cons[currcons].d;
     156                 :            : }
     157                 :            : 
     158                 :            : /*
     159                 :            :  * Returns size for VC carried by inode.
     160                 :            :  * Must be called with console_lock.
     161                 :            :  */
     162                 :            : static int
     163                 :          0 : vcs_size(struct inode *inode)
     164                 :            : {
     165                 :            :         int size;
     166                 :          0 :         int minor = iminor(inode);
     167                 :            :         struct vc_data *vc;
     168                 :            : 
     169 [ #  # ][ #  # ]:          0 :         WARN_CONSOLE_UNLOCKED();
                 [ #  # ]
     170                 :            : 
     171                 :          0 :         vc = vcs_vc(inode, NULL);
     172         [ #  # ]:          0 :         if (!vc)
     173                 :            :                 return -ENXIO;
     174                 :            : 
     175                 :          0 :         size = vc->vc_rows * vc->vc_cols;
     176                 :            : 
     177         [ #  # ]:          0 :         if (minor & 128)
     178                 :          0 :                 size = 2*size + HEADER_SIZE;
     179                 :          0 :         return size;
     180                 :            : }
     181                 :            : 
     182                 :          0 : static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
     183                 :            : {
     184                 :            :         int size;
     185                 :            : 
     186                 :          0 :         console_lock();
     187                 :          0 :         size = vcs_size(file_inode(file));
     188                 :          0 :         console_unlock();
     189         [ #  # ]:          0 :         if (size < 0)
     190                 :          0 :                 return size;
     191                 :          0 :         return fixed_size_llseek(file, offset, orig, size);
     192                 :            : }
     193                 :            : 
     194                 :            : 
     195                 :            : static ssize_t
     196                 :          0 : vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
     197                 :            : {
     198                 :          0 :         struct inode *inode = file_inode(file);
     199                 :            :         unsigned int currcons = iminor(inode);
     200                 :            :         struct vc_data *vc;
     201                 :            :         struct vcs_poll_data *poll;
     202                 :            :         long pos;
     203                 :            :         long attr, read;
     204                 :            :         int col, maxcol, viewed;
     205                 :            :         unsigned short *org = NULL;
     206                 :            :         ssize_t ret;
     207                 :            :         char *con_buf;
     208                 :            : 
     209                 :          0 :         con_buf = (char *) __get_free_page(GFP_KERNEL);
     210         [ #  # ]:          0 :         if (!con_buf)
     211                 :            :                 return -ENOMEM;
     212                 :            : 
     213                 :          0 :         pos = *ppos;
     214                 :            : 
     215                 :            :         /* Select the proper current console and verify
     216                 :            :          * sanity of the situation under the console lock.
     217                 :            :          */
     218                 :          0 :         console_lock();
     219                 :            : 
     220                 :          0 :         attr = (currcons & 128);
     221                 :            :         ret = -ENXIO;
     222                 :          0 :         vc = vcs_vc(inode, &viewed);
     223         [ #  # ]:          0 :         if (!vc)
     224                 :            :                 goto unlock_out;
     225                 :            : 
     226                 :            :         ret = -EINVAL;
     227         [ #  # ]:          0 :         if (pos < 0)
     228                 :            :                 goto unlock_out;
     229                 :          0 :         poll = file->private_data;
     230         [ #  # ]:          0 :         if (count && poll)
     231                 :          0 :                 poll->seen_last_update = true;
     232                 :            :         read = 0;
     233                 :            :         ret = 0;
     234         [ #  # ]:          0 :         while (count) {
     235                 :            :                 char *con_buf0, *con_buf_start;
     236                 :            :                 long this_round, size;
     237                 :            :                 ssize_t orig_count;
     238                 :            :                 long p = pos;
     239                 :            : 
     240                 :            :                 /* Check whether we are above size each round,
     241                 :            :                  * as copy_to_user at the end of this loop
     242                 :            :                  * could sleep.
     243                 :            :                  */
     244                 :          0 :                 size = vcs_size(inode);
     245         [ #  # ]:          0 :                 if (size < 0) {
     246         [ #  # ]:          0 :                         if (read)
     247                 :            :                                 break;
     248                 :            :                         ret = size;
     249                 :            :                         goto unlock_out;
     250                 :            :                 }
     251         [ #  # ]:          0 :                 if (pos >= size)
     252                 :            :                         break;
     253         [ #  # ]:          0 :                 if (count > size - pos)
     254                 :            :                         count = size - pos;
     255                 :            : 
     256                 :          0 :                 this_round = count;
     257         [ #  # ]:          0 :                 if (this_round > CON_BUF_SIZE)
     258                 :            :                         this_round = CON_BUF_SIZE;
     259                 :            : 
     260                 :            :                 /* Perform the whole read into the local con_buf.
     261                 :            :                  * Then we can drop the console spinlock and safely
     262                 :            :                  * attempt to move it to userspace.
     263                 :            :                  */
     264                 :            : 
     265                 :            :                 con_buf_start = con_buf0 = con_buf;
     266                 :            :                 orig_count = this_round;
     267                 :          0 :                 maxcol = vc->vc_cols;
     268         [ #  # ]:          0 :                 if (!attr) {
     269                 :          0 :                         org = screen_pos(vc, p, viewed);
     270                 :          0 :                         col = p % maxcol;
     271                 :          0 :                         p += maxcol - col;
     272         [ #  # ]:          0 :                         while (this_round-- > 0) {
     273                 :          0 :                                 *con_buf0++ = (vcs_scr_readw(vc, org++) & 0xff);
     274         [ #  # ]:          0 :                                 if (++col == maxcol) {
     275                 :          0 :                                         org = screen_pos(vc, p, viewed);
     276                 :            :                                         col = 0;
     277                 :          0 :                                         p += maxcol;
     278                 :            :                                 }
     279                 :            :                         }
     280                 :            :                 } else {
     281         [ #  # ]:          0 :                         if (p < HEADER_SIZE) {
     282                 :            :                                 size_t tmp_count;
     283                 :            : 
     284                 :          0 :                                 con_buf0[0] = (char)vc->vc_rows;
     285                 :          0 :                                 con_buf0[1] = (char)vc->vc_cols;
     286                 :          0 :                                 getconsxy(vc, con_buf0 + 2);
     287                 :            : 
     288                 :          0 :                                 con_buf_start += p;
     289                 :          0 :                                 this_round += p;
     290         [ #  # ]:          0 :                                 if (this_round > CON_BUF_SIZE) {
     291                 :            :                                         this_round = CON_BUF_SIZE;
     292                 :          0 :                                         orig_count = this_round - p;
     293                 :            :                                 }
     294                 :            : 
     295                 :            :                                 tmp_count = HEADER_SIZE;
     296         [ #  # ]:          0 :                                 if (tmp_count > this_round)
     297                 :            :                                         tmp_count = this_round;
     298                 :            : 
     299                 :            :                                 /* Advance state pointers and move on. */
     300                 :          0 :                                 this_round -= tmp_count;
     301                 :            :                                 p = HEADER_SIZE;
     302                 :          0 :                                 con_buf0 = con_buf + HEADER_SIZE;
     303                 :            :                                 /* If this_round >= 0, then p is even... */
     304         [ #  # ]:          0 :                         } else if (p & 1) {
     305                 :            :                                 /* Skip first byte for output if start address is odd
     306                 :            :                                  * Update region sizes up/down depending on free
     307                 :            :                                  * space in buffer.
     308                 :            :                                  */
     309                 :          0 :                                 con_buf_start++;
     310         [ #  # ]:          0 :                                 if (this_round < CON_BUF_SIZE)
     311                 :          0 :                                         this_round++;
     312                 :            :                                 else
     313                 :          0 :                                         orig_count--;
     314                 :            :                         }
     315         [ #  # ]:          0 :                         if (this_round > 0) {
     316                 :            :                                 unsigned short *tmp_buf = (unsigned short *)con_buf0;
     317                 :            : 
     318                 :          0 :                                 p -= HEADER_SIZE;
     319                 :          0 :                                 p /= 2;
     320                 :          0 :                                 col = p % maxcol;
     321                 :            : 
     322                 :          0 :                                 org = screen_pos(vc, p, viewed);
     323                 :          0 :                                 p += maxcol - col;
     324                 :            : 
     325                 :            :                                 /* Buffer has even length, so we can always copy
     326                 :            :                                  * character + attribute. We do not copy last byte
     327                 :            :                                  * to userspace if this_round is odd.
     328                 :            :                                  */
     329                 :          0 :                                 this_round = (this_round + 1) >> 1;
     330                 :            : 
     331         [ #  # ]:          0 :                                 while (this_round) {
     332                 :          0 :                                         *tmp_buf++ = vcs_scr_readw(vc, org++);
     333                 :          0 :                                         this_round --;
     334         [ #  # ]:          0 :                                         if (++col == maxcol) {
     335                 :          0 :                                                 org = screen_pos(vc, p, viewed);
     336                 :            :                                                 col = 0;
     337                 :          0 :                                                 p += maxcol;
     338                 :            :                                         }
     339                 :            :                                 }
     340                 :            :                         }
     341                 :            :                 }
     342                 :            : 
     343                 :            :                 /* Finally, release the console semaphore while we push
     344                 :            :                  * all the data to userspace from our temporary buffer.
     345                 :            :                  *
     346                 :            :                  * AKPM: Even though it's a semaphore, we should drop it because
     347                 :            :                  * the pagefault handling code may want to call printk().
     348                 :            :                  */
     349                 :            : 
     350                 :          0 :                 console_unlock();
     351                 :          0 :                 ret = copy_to_user(buf, con_buf_start, orig_count);
     352                 :          0 :                 console_lock();
     353                 :            : 
     354         [ #  # ]:          0 :                 if (ret) {
     355                 :          0 :                         read += (orig_count - ret);
     356                 :            :                         ret = -EFAULT;
     357                 :          0 :                         break;
     358                 :            :                 }
     359                 :          0 :                 buf += orig_count;
     360                 :          0 :                 pos += orig_count;
     361                 :          0 :                 read += orig_count;
     362                 :          0 :                 count -= orig_count;
     363                 :            :         }
     364                 :          0 :         *ppos += read;
     365         [ #  # ]:          0 :         if (read)
     366                 :            :                 ret = read;
     367                 :            : unlock_out:
     368                 :          0 :         console_unlock();
     369                 :          0 :         free_page((unsigned long) con_buf);
     370                 :          0 :         return ret;
     371                 :            : }
     372                 :            : 
     373                 :            : static ssize_t
     374                 :          0 : vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
     375                 :            : {
     376                 :          0 :         struct inode *inode = file_inode(file);
     377                 :            :         unsigned int currcons = iminor(inode);
     378                 :            :         struct vc_data *vc;
     379                 :            :         long pos;
     380                 :            :         long attr, size, written;
     381                 :            :         char *con_buf0;
     382                 :            :         int col, maxcol, viewed;
     383                 :            :         u16 *org0 = NULL, *org = NULL;
     384                 :            :         size_t ret;
     385                 :            :         char *con_buf;
     386                 :            : 
     387                 :          0 :         con_buf = (char *) __get_free_page(GFP_KERNEL);
     388         [ #  # ]:          0 :         if (!con_buf)
     389                 :            :                 return -ENOMEM;
     390                 :            : 
     391                 :          0 :         pos = *ppos;
     392                 :            : 
     393                 :            :         /* Select the proper current console and verify
     394                 :            :          * sanity of the situation under the console lock.
     395                 :            :          */
     396                 :          0 :         console_lock();
     397                 :            : 
     398                 :          0 :         attr = (currcons & 128);
     399                 :            :         ret = -ENXIO;
     400                 :          0 :         vc = vcs_vc(inode, &viewed);
     401         [ #  # ]:          0 :         if (!vc)
     402                 :            :                 goto unlock_out;
     403                 :            : 
     404                 :          0 :         size = vcs_size(inode);
     405                 :            :         ret = -EINVAL;
     406         [ #  # ]:          0 :         if (pos < 0 || pos > size)
     407                 :            :                 goto unlock_out;
     408         [ #  # ]:          0 :         if (count > size - pos)
     409                 :            :                 count = size - pos;
     410                 :            :         written = 0;
     411         [ #  # ]:          0 :         while (count) {
     412                 :          0 :                 long this_round = count;
     413                 :            :                 size_t orig_count;
     414                 :            :                 long p;
     415                 :            : 
     416         [ #  # ]:          0 :                 if (this_round > CON_BUF_SIZE)
     417                 :            :                         this_round = CON_BUF_SIZE;
     418                 :            : 
     419                 :            :                 /* Temporarily drop the console lock so that we can read
     420                 :            :                  * in the write data from userspace safely.
     421                 :            :                  */
     422                 :          0 :                 console_unlock();
     423                 :          0 :                 ret = copy_from_user(con_buf, buf, this_round);
     424                 :          0 :                 console_lock();
     425                 :            : 
     426         [ #  # ]:          0 :                 if (ret) {
     427                 :          0 :                         this_round -= ret;
     428         [ #  # ]:          0 :                         if (!this_round) {
     429                 :            :                                 /* Abort loop if no data were copied. Otherwise
     430                 :            :                                  * fail with -EFAULT.
     431                 :            :                                  */
     432         [ #  # ]:          0 :                                 if (written)
     433                 :            :                                         break;
     434                 :            :                                 ret = -EFAULT;
     435                 :            :                                 goto unlock_out;
     436                 :            :                         }
     437                 :            :                 }
     438                 :            : 
     439                 :            :                 /* The vcs_size might have changed while we slept to grab
     440                 :            :                  * the user buffer, so recheck.
     441                 :            :                  * Return data written up to now on failure.
     442                 :            :                  */
     443                 :          0 :                 size = vcs_size(inode);
     444         [ #  # ]:          0 :                 if (size < 0) {
     445         [ #  # ]:          0 :                         if (written)
     446                 :            :                                 break;
     447                 :          0 :                         ret = size;
     448                 :          0 :                         goto unlock_out;
     449                 :            :                 }
     450         [ #  # ]:          0 :                 if (pos >= size)
     451                 :            :                         break;
     452         [ #  # ]:          0 :                 if (this_round > size - pos)
     453                 :            :                         this_round = size - pos;
     454                 :            : 
     455                 :            :                 /* OK, now actually push the write to the console
     456                 :            :                  * under the lock using the local kernel buffer.
     457                 :            :                  */
     458                 :            : 
     459                 :            :                 con_buf0 = con_buf;
     460                 :          0 :                 orig_count = this_round;
     461                 :          0 :                 maxcol = vc->vc_cols;
     462                 :            :                 p = pos;
     463         [ #  # ]:          0 :                 if (!attr) {
     464                 :          0 :                         org0 = org = screen_pos(vc, p, viewed);
     465                 :          0 :                         col = p % maxcol;
     466                 :          0 :                         p += maxcol - col;
     467                 :            : 
     468         [ #  # ]:          0 :                         while (this_round > 0) {
     469                 :          0 :                                 unsigned char c = *con_buf0++;
     470                 :            : 
     471                 :          0 :                                 this_round--;
     472                 :          0 :                                 vcs_scr_writew(vc,
     473                 :          0 :                                                (vcs_scr_readw(vc, org) & 0xff00) | c, org);
     474                 :          0 :                                 org++;
     475         [ #  # ]:          0 :                                 if (++col == maxcol) {
     476                 :          0 :                                         org = screen_pos(vc, p, viewed);
     477                 :            :                                         col = 0;
     478                 :          0 :                                         p += maxcol;
     479                 :            :                                 }
     480                 :            :                         }
     481                 :            :                 } else {
     482         [ #  # ]:          0 :                         if (p < HEADER_SIZE) {
     483                 :            :                                 char header[HEADER_SIZE];
     484                 :            : 
     485                 :          0 :                                 getconsxy(vc, header + 2);
     486         [ #  # ]:          0 :                                 while (p < HEADER_SIZE && this_round > 0) {
     487                 :          0 :                                         this_round--;
     488                 :          0 :                                         header[p++] = *con_buf0++;
     489                 :            :                                 }
     490         [ #  # ]:          0 :                                 if (!viewed)
     491                 :          0 :                                         putconsxy(vc, header + 2);
     492                 :            :                         }
     493                 :          0 :                         p -= HEADER_SIZE;
     494                 :          0 :                         col = (p/2) % maxcol;
     495         [ #  # ]:          0 :                         if (this_round > 0) {
     496                 :          0 :                                 org0 = org = screen_pos(vc, p/2, viewed);
     497 [ #  # ][ #  # ]:          0 :                                 if ((p & 1) && this_round > 0) {
     498                 :            :                                         char c;
     499                 :            : 
     500                 :          0 :                                         this_round--;
     501                 :          0 :                                         c = *con_buf0++;
     502                 :            : #ifdef __BIG_ENDIAN
     503                 :            :                                         vcs_scr_writew(vc, c |
     504                 :            :                                              (vcs_scr_readw(vc, org) & 0xff00), org);
     505                 :            : #else
     506                 :          0 :                                         vcs_scr_writew(vc, (c << 8) |
     507                 :          0 :                                              (vcs_scr_readw(vc, org) & 0xff), org);
     508                 :            : #endif
     509                 :          0 :                                         org++;
     510                 :          0 :                                         p++;
     511         [ #  # ]:          0 :                                         if (++col == maxcol) {
     512                 :          0 :                                                 org = screen_pos(vc, p/2, viewed);
     513                 :            :                                                 col = 0;
     514                 :            :                                         }
     515                 :            :                                 }
     516                 :          0 :                                 p /= 2;
     517                 :          0 :                                 p += maxcol - col;
     518                 :            :                         }
     519         [ #  # ]:          0 :                         while (this_round > 1) {
     520                 :            :                                 unsigned short w;
     521                 :            : 
     522                 :            :                                 w = get_unaligned(((unsigned short *)con_buf0));
     523                 :          0 :                                 vcs_scr_writew(vc, w, org++);
     524                 :          0 :                                 con_buf0 += 2;
     525                 :          0 :                                 this_round -= 2;
     526         [ #  # ]:          0 :                                 if (++col == maxcol) {
     527                 :          0 :                                         org = screen_pos(vc, p, viewed);
     528                 :            :                                         col = 0;
     529                 :          0 :                                         p += maxcol;
     530                 :            :                                 }
     531                 :            :                         }
     532         [ #  # ]:          0 :                         if (this_round > 0) {
     533                 :            :                                 unsigned char c;
     534                 :            : 
     535                 :          0 :                                 c = *con_buf0++;
     536                 :            : #ifdef __BIG_ENDIAN
     537                 :            :                                 vcs_scr_writew(vc, (vcs_scr_readw(vc, org) & 0xff) | (c << 8), org);
     538                 :            : #else
     539                 :          0 :                                 vcs_scr_writew(vc, (vcs_scr_readw(vc, org) & 0xff00) | c, org);
     540                 :            : #endif
     541                 :            :                         }
     542                 :            :                 }
     543                 :          0 :                 count -= orig_count;
     544                 :          0 :                 written += orig_count;
     545                 :          0 :                 buf += orig_count;
     546                 :          0 :                 pos += orig_count;
     547         [ #  # ]:          0 :                 if (org0)
     548                 :          0 :                         update_region(vc, (unsigned long)(org0), org - org0);
     549                 :            :         }
     550                 :          0 :         *ppos += written;
     551                 :          0 :         ret = written;
     552         [ #  # ]:          0 :         if (written)
     553                 :          0 :                 vcs_scr_updated(vc);
     554                 :            : 
     555                 :            : unlock_out:
     556                 :          0 :         console_unlock();
     557                 :          0 :         free_page((unsigned long) con_buf);
     558                 :          0 :         return ret;
     559                 :            : }
     560                 :            : 
     561                 :            : static unsigned int
     562                 :          0 : vcs_poll(struct file *file, poll_table *wait)
     563                 :            : {
     564                 :          0 :         struct vcs_poll_data *poll = vcs_poll_data_get(file);
     565                 :            :         int ret = DEFAULT_POLLMASK|POLLERR|POLLPRI;
     566                 :            : 
     567         [ #  # ]:          0 :         if (poll) {
     568                 :          0 :                 poll_wait(file, &poll->waitq, wait);
     569         [ #  # ]:          0 :                 if (poll->seen_last_update)
     570                 :            :                         ret = DEFAULT_POLLMASK;
     571                 :            :         }
     572                 :          0 :         return ret;
     573                 :            : }
     574                 :            : 
     575                 :            : static int
     576                 :          0 : vcs_fasync(int fd, struct file *file, int on)
     577                 :            : {
     578                 :          0 :         struct vcs_poll_data *poll = file->private_data;
     579                 :            : 
     580         [ #  # ]:          0 :         if (!poll) {
     581                 :            :                 /* don't allocate anything if all we want is disable fasync */
     582         [ #  # ]:          0 :                 if (!on)
     583                 :            :                         return 0;
     584                 :          0 :                 poll = vcs_poll_data_get(file);
     585         [ #  # ]:          0 :                 if (!poll)
     586                 :            :                         return -ENOMEM;
     587                 :            :         }
     588                 :            : 
     589                 :          0 :         return fasync_helper(fd, file, on, &poll->fasync);
     590                 :            : }
     591                 :            : 
     592                 :            : static int
     593                 :          0 : vcs_open(struct inode *inode, struct file *filp)
     594                 :            : {
     595                 :          0 :         unsigned int currcons = iminor(inode) & 127;
     596                 :            :         int ret = 0;
     597                 :            :         
     598                 :          0 :         console_lock();
     599 [ #  # ][ #  # ]:          0 :         if(currcons && !vc_cons_allocated(currcons-1))
     600                 :            :                 ret = -ENXIO;
     601                 :          0 :         console_unlock();
     602                 :          0 :         return ret;
     603                 :            : }
     604                 :            : 
     605                 :          0 : static int vcs_release(struct inode *inode, struct file *file)
     606                 :            : {
     607                 :          0 :         struct vcs_poll_data *poll = file->private_data;
     608                 :            : 
     609         [ #  # ]:          0 :         if (poll)
     610                 :            :                 vcs_poll_data_free(poll);
     611                 :          0 :         return 0;
     612                 :            : }
     613                 :            : 
     614                 :            : static const struct file_operations vcs_fops = {
     615                 :            :         .llseek         = vcs_lseek,
     616                 :            :         .read           = vcs_read,
     617                 :            :         .write          = vcs_write,
     618                 :            :         .poll           = vcs_poll,
     619                 :            :         .fasync         = vcs_fasync,
     620                 :            :         .open           = vcs_open,
     621                 :            :         .release        = vcs_release,
     622                 :            : };
     623                 :            : 
     624                 :            : static struct class *vc_class;
     625                 :            : 
     626                 :          0 : void vcs_make_sysfs(int index)
     627                 :            : {
     628                 :         56 :         device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 1), NULL,
     629                 :            :                       "vcs%u", index + 1);
     630                 :         56 :         device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 129), NULL,
     631                 :            :                       "vcsa%u", index + 1);
     632                 :         56 : }
     633                 :            : 
     634                 :          0 : void vcs_remove_sysfs(int index)
     635                 :            : {
     636                 :          0 :         device_destroy(vc_class, MKDEV(VCS_MAJOR, index + 1));
     637                 :          0 :         device_destroy(vc_class, MKDEV(VCS_MAJOR, index + 129));
     638                 :          0 : }
     639                 :            : 
     640                 :          0 : int __init vcs_init(void)
     641                 :            : {
     642                 :            :         unsigned int i;
     643                 :            : 
     644         [ #  # ]:          0 :         if (register_chrdev(VCS_MAJOR, "vcs", &vcs_fops))
     645                 :          0 :                 panic("unable to get major %d for vcs device", VCS_MAJOR);
     646                 :          0 :         vc_class = class_create(THIS_MODULE, "vc");
     647                 :            : 
     648                 :          0 :         device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs");
     649                 :          0 :         device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa");
     650         [ #  # ]:          0 :         for (i = 0; i < MIN_NR_CONSOLES; i++)
     651                 :          0 :                 vcs_make_sysfs(i);
     652                 :          0 :         return 0;
     653                 :            : }

Generated by: LCOV version 1.9