License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* This module exports the functions:
|
|
|
|
*
|
2019-04-17 20:21:13 +08:00
|
|
|
* 'int set_selection_user(struct tiocl_selection __user *,
|
|
|
|
* struct tty_struct *)'
|
|
|
|
* 'int set_selection_kernel(struct tiocl_selection *, struct tty_struct *)'
|
2005-04-17 06:20:36 +08:00
|
|
|
* 'void clear_selection(void)'
|
|
|
|
* 'int paste_selection(struct tty_struct *)'
|
|
|
|
* 'int sel_loadlut(char __user *)'
|
|
|
|
*
|
|
|
|
* Now that /dev/vcs exists, most of this can disappear again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
2020-02-10 16:11:31 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-16 14:40:40 +08:00
|
|
|
#include <linux/kbd_kern.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/vt_kern.h>
|
|
|
|
#include <linux/consolemap.h>
|
|
|
|
#include <linux/selection.h>
|
|
|
|
#include <linux/tiocl.h>
|
|
|
|
#include <linux/console.h>
|
2013-06-15 21:36:15 +08:00
|
|
|
#include <linux/tty_flip.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-02-10 16:11:30 +08:00
|
|
|
#include <linux/sched/signal.h>
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Don't take this from <ctype.h>: 011-015 on the screen aren't spaces */
|
|
|
|
#define isspace(c) ((c) == ' ')
|
|
|
|
|
2012-02-28 22:49:23 +08:00
|
|
|
/* FIXME: all this needs locking */
|
2020-02-19 15:39:47 +08:00
|
|
|
static struct vc_selection {
|
|
|
|
struct mutex lock;
|
|
|
|
struct vc_data *cons; /* must not be deallocated */
|
|
|
|
char *buffer;
|
|
|
|
unsigned int buf_len;
|
|
|
|
volatile int start; /* cleared by clear_selection */
|
|
|
|
int end;
|
|
|
|
} vc_sel = {
|
|
|
|
.lock = __MUTEX_INITIALIZER(vc_sel.lock),
|
|
|
|
.start = -1,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* clear_selection, highlight and highlight_pointer can be called
|
|
|
|
from interrupt (via scrollback/front) */
|
|
|
|
|
|
|
|
/* set reverse video on characters s-e of console with selection. */
|
|
|
|
static inline void highlight(const int s, const int e)
|
|
|
|
{
|
2020-08-18 16:56:53 +08:00
|
|
|
invert_screen(vc_sel.cons, s, e-s+2, true);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* use complementary color to show the pointer */
|
|
|
|
static inline void highlight_pointer(const int where)
|
|
|
|
{
|
2020-02-19 15:39:47 +08:00
|
|
|
complement_pos(vc_sel.cons, where);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-07-18 10:10:44 +08:00
|
|
|
static u32
|
2020-02-19 15:39:46 +08:00
|
|
|
sel_pos(int n, bool unicode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2020-02-19 15:39:46 +08:00
|
|
|
if (unicode)
|
2020-02-19 15:39:47 +08:00
|
|
|
return screen_glyph_unicode(vc_sel.cons, n / 2);
|
|
|
|
return inverse_translate(vc_sel.cons, screen_glyph(vc_sel.cons, n), 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-02 23:00:02 +08:00
|
|
|
/**
|
|
|
|
* clear_selection - remove current selection
|
|
|
|
*
|
|
|
|
* Remove the current selection highlight, if any from the console
|
|
|
|
* holding the selection. The caller must hold the console lock.
|
|
|
|
*/
|
|
|
|
void clear_selection(void)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
highlight_pointer(-1); /* hide the pointer */
|
2020-02-19 15:39:47 +08:00
|
|
|
if (vc_sel.start != -1) {
|
|
|
|
highlight(vc_sel.start, vc_sel.end);
|
|
|
|
vc_sel.start = -1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 20:21:13 +08:00
|
|
|
EXPORT_SYMBOL_GPL(clear_selection);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-02-19 15:39:43 +08:00
|
|
|
bool vc_is_sel(struct vc_data *vc)
|
|
|
|
{
|
2020-02-19 15:39:47 +08:00
|
|
|
return vc == vc_sel.cons;
|
2020-02-19 15:39:43 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* User settable table: what characters are to be considered alphabetic?
|
2017-03-27 20:21:14 +08:00
|
|
|
* 128 bits. Locked by the console lock.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2017-03-27 20:21:14 +08:00
|
|
|
static u32 inwordLut[]={
|
2005-04-17 06:20:36 +08:00
|
|
|
0x00000000, /* control chars */
|
2017-03-27 20:21:13 +08:00
|
|
|
0x03FFE000, /* digits and "-./" */
|
2005-04-17 06:20:36 +08:00
|
|
|
0x87FFFFFE, /* uppercase and '_' */
|
|
|
|
0x07FFFFFE, /* lowercase */
|
|
|
|
};
|
|
|
|
|
2018-07-18 10:10:44 +08:00
|
|
|
static inline int inword(const u32 c)
|
|
|
|
{
|
2017-03-27 20:21:14 +08:00
|
|
|
return c > 0x7f || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-03-02 23:00:02 +08:00
|
|
|
/**
|
|
|
|
* set loadlut - load the LUT table
|
|
|
|
* @p: user table
|
|
|
|
*
|
|
|
|
* Load the LUT table from user space. The caller must hold the console
|
|
|
|
* lock. Make a temporary copy so a partial update doesn't make a mess.
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
int sel_loadlut(char __user *p)
|
|
|
|
{
|
2017-03-27 20:21:14 +08:00
|
|
|
u32 tmplut[ARRAY_SIZE(inwordLut)];
|
|
|
|
if (copy_from_user(tmplut, (u32 __user *)(p+4), sizeof(inwordLut)))
|
2012-03-02 23:00:02 +08:00
|
|
|
return -EFAULT;
|
2017-03-27 20:21:14 +08:00
|
|
|
memcpy(inwordLut, tmplut, sizeof(inwordLut));
|
2012-03-02 23:00:02 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* does screen address p correspond to character at LH/RH edge of screen? */
|
|
|
|
static inline int atedge(const int p, int size_row)
|
|
|
|
{
|
|
|
|
return (!(p % size_row) || !((p + 2) % size_row));
|
|
|
|
}
|
|
|
|
|
2018-07-18 10:10:43 +08:00
|
|
|
/* stores the char in UTF8 and returns the number of bytes used (1-4) */
|
|
|
|
static int store_utf8(u32 c, char *p)
|
2007-07-16 14:40:40 +08:00
|
|
|
{
|
|
|
|
if (c < 0x80) {
|
|
|
|
/* 0******* */
|
|
|
|
p[0] = c;
|
|
|
|
return 1;
|
|
|
|
} else if (c < 0x800) {
|
|
|
|
/* 110***** 10****** */
|
|
|
|
p[0] = 0xc0 | (c >> 6);
|
|
|
|
p[1] = 0x80 | (c & 0x3f);
|
|
|
|
return 2;
|
2018-07-18 10:10:43 +08:00
|
|
|
} else if (c < 0x10000) {
|
2007-07-16 14:40:40 +08:00
|
|
|
/* 1110**** 10****** 10****** */
|
|
|
|
p[0] = 0xe0 | (c >> 12);
|
|
|
|
p[1] = 0x80 | ((c >> 6) & 0x3f);
|
|
|
|
p[2] = 0x80 | (c & 0x3f);
|
|
|
|
return 3;
|
2018-07-18 10:10:43 +08:00
|
|
|
} else if (c < 0x110000) {
|
|
|
|
/* 11110*** 10****** 10****** 10****** */
|
|
|
|
p[0] = 0xf0 | (c >> 18);
|
|
|
|
p[1] = 0x80 | ((c >> 12) & 0x3f);
|
|
|
|
p[2] = 0x80 | ((c >> 6) & 0x3f);
|
|
|
|
p[3] = 0x80 | (c & 0x3f);
|
|
|
|
return 4;
|
|
|
|
} else {
|
|
|
|
/* outside Unicode, replace with U+FFFD */
|
|
|
|
p[0] = 0xef;
|
|
|
|
p[1] = 0xbf;
|
|
|
|
p[2] = 0xbd;
|
|
|
|
return 3;
|
|
|
|
}
|
2007-07-16 14:40:40 +08:00
|
|
|
}
|
|
|
|
|
2012-03-02 23:00:02 +08:00
|
|
|
/**
|
2019-04-17 20:21:13 +08:00
|
|
|
* set_selection_user - set the current selection.
|
2012-03-02 23:00:02 +08:00
|
|
|
* @sel: user selection info
|
|
|
|
* @tty: the console tty
|
|
|
|
*
|
|
|
|
* Invoked by the ioctl handle for the vt layer.
|
|
|
|
*
|
|
|
|
* The entire selection process is managed under the console_lock. It's
|
|
|
|
* a lot under the lock but its hardly a performance path
|
|
|
|
*/
|
2019-04-17 20:21:13 +08:00
|
|
|
int set_selection_user(const struct tiocl_selection __user *sel,
|
|
|
|
struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct tiocl_selection v;
|
|
|
|
|
|
|
|
if (copy_from_user(&v, sel, sizeof(*sel)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return set_selection_kernel(&v, tty);
|
|
|
|
}
|
|
|
|
|
2020-04-15 17:36:08 +08:00
|
|
|
static int vc_selection_store_chars(struct vc_data *vc, bool unicode)
|
|
|
|
{
|
|
|
|
char *bp, *obp;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Allocate a new buffer before freeing the old one ... */
|
|
|
|
/* chars can take up to 4 bytes with unicode */
|
|
|
|
bp = kmalloc_array((vc_sel.end - vc_sel.start) / 2 + 1, unicode ? 4 : 1,
|
2020-06-17 15:04:44 +08:00
|
|
|
GFP_KERNEL | __GFP_NOWARN);
|
2020-04-15 17:36:08 +08:00
|
|
|
if (!bp) {
|
|
|
|
printk(KERN_WARNING "selection: kmalloc() failed\n");
|
|
|
|
clear_selection();
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
kfree(vc_sel.buffer);
|
|
|
|
vc_sel.buffer = bp;
|
|
|
|
|
|
|
|
obp = bp;
|
|
|
|
for (i = vc_sel.start; i <= vc_sel.end; i += 2) {
|
|
|
|
u32 c = sel_pos(i, unicode);
|
|
|
|
if (unicode)
|
|
|
|
bp += store_utf8(c, bp);
|
|
|
|
else
|
|
|
|
*bp++ = c;
|
|
|
|
if (!isspace(c))
|
|
|
|
obp = bp;
|
|
|
|
if (!((i + 2) % vc->vc_size_row)) {
|
|
|
|
/* strip trailing blanks from line and add newline,
|
|
|
|
unless non-space at end of line. */
|
|
|
|
if (obp != bp) {
|
|
|
|
bp = obp;
|
|
|
|
*bp++ = '\r';
|
|
|
|
}
|
|
|
|
obp = bp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vc_sel.buf_len = bp - vc_sel.buffer;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-15 17:36:07 +08:00
|
|
|
static int vc_do_selection(struct vc_data *vc, unsigned short mode, int ps,
|
|
|
|
int pe)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2017-09-30 00:40:54 +08:00
|
|
|
int new_sel_start, new_sel_end, spc;
|
2020-04-15 17:36:07 +08:00
|
|
|
bool unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-04-15 17:36:07 +08:00
|
|
|
switch (mode) {
|
2020-02-19 15:39:51 +08:00
|
|
|
case TIOCL_SELCHAR: /* character-by-character selection */
|
|
|
|
new_sel_start = ps;
|
|
|
|
new_sel_end = pe;
|
|
|
|
break;
|
|
|
|
case TIOCL_SELWORD: /* word-by-word selection */
|
|
|
|
spc = isspace(sel_pos(ps, unicode));
|
|
|
|
for (new_sel_start = ps; ; ps -= 2) {
|
|
|
|
if ((spc && !isspace(sel_pos(ps, unicode))) ||
|
|
|
|
(!spc && !inword(sel_pos(ps, unicode))))
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
new_sel_start = ps;
|
2020-02-19 15:39:51 +08:00
|
|
|
if (!(ps % vc->vc_size_row))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
spc = isspace(sel_pos(pe, unicode));
|
|
|
|
for (new_sel_end = pe; ; pe += 2) {
|
|
|
|
if ((spc && !isspace(sel_pos(pe, unicode))) ||
|
|
|
|
(!spc && !inword(sel_pos(pe, unicode))))
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
new_sel_end = pe;
|
2020-02-19 15:39:51 +08:00
|
|
|
if (!((pe + 2) % vc->vc_size_row))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TIOCL_SELLINE: /* line-by-line selection */
|
2020-03-16 14:59:10 +08:00
|
|
|
new_sel_start = rounddown(ps, vc->vc_size_row);
|
|
|
|
new_sel_end = rounddown(pe, vc->vc_size_row) +
|
|
|
|
vc->vc_size_row - 2;
|
2020-02-19 15:39:51 +08:00
|
|
|
break;
|
|
|
|
case TIOCL_SELPOINTER:
|
|
|
|
highlight_pointer(pe);
|
2020-03-10 17:02:49 +08:00
|
|
|
return 0;
|
2020-02-19 15:39:51 +08:00
|
|
|
default:
|
2020-03-10 17:02:49 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* remove the pointer */
|
|
|
|
highlight_pointer(-1);
|
|
|
|
|
|
|
|
/* select to end of line if on trailing space */
|
|
|
|
if (new_sel_end > new_sel_start &&
|
|
|
|
!atedge(new_sel_end, vc->vc_size_row) &&
|
2020-02-19 15:39:46 +08:00
|
|
|
isspace(sel_pos(new_sel_end, unicode))) {
|
2005-04-17 06:20:36 +08:00
|
|
|
for (pe = new_sel_end + 2; ; pe += 2)
|
2020-02-19 15:39:46 +08:00
|
|
|
if (!isspace(sel_pos(pe, unicode)) ||
|
2005-04-17 06:20:36 +08:00
|
|
|
atedge(pe, vc->vc_size_row))
|
|
|
|
break;
|
2020-02-19 15:39:46 +08:00
|
|
|
if (isspace(sel_pos(pe, unicode)))
|
2005-04-17 06:20:36 +08:00
|
|
|
new_sel_end = pe;
|
|
|
|
}
|
2020-02-19 15:39:47 +08:00
|
|
|
if (vc_sel.start == -1) /* no current selection */
|
2005-04-17 06:20:36 +08:00
|
|
|
highlight(new_sel_start, new_sel_end);
|
2020-02-19 15:39:47 +08:00
|
|
|
else if (new_sel_start == vc_sel.start)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2020-02-19 15:39:47 +08:00
|
|
|
if (new_sel_end == vc_sel.end) /* no action required */
|
2020-02-28 19:54:06 +08:00
|
|
|
return 0;
|
2020-02-19 15:39:47 +08:00
|
|
|
else if (new_sel_end > vc_sel.end) /* extend to right */
|
|
|
|
highlight(vc_sel.end + 2, new_sel_end);
|
2005-04-17 06:20:36 +08:00
|
|
|
else /* contract from right */
|
2020-02-19 15:39:47 +08:00
|
|
|
highlight(new_sel_end + 2, vc_sel.end);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2020-02-19 15:39:47 +08:00
|
|
|
else if (new_sel_end == vc_sel.end)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2020-02-19 15:39:47 +08:00
|
|
|
if (new_sel_start < vc_sel.start) /* extend to left */
|
|
|
|
highlight(new_sel_start, vc_sel.start - 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
else /* contract from left */
|
2020-02-19 15:39:47 +08:00
|
|
|
highlight(vc_sel.start, new_sel_start - 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
else /* some other case; start selection from scratch */
|
|
|
|
{
|
|
|
|
clear_selection();
|
|
|
|
highlight(new_sel_start, new_sel_end);
|
|
|
|
}
|
2020-02-19 15:39:47 +08:00
|
|
|
vc_sel.start = new_sel_start;
|
|
|
|
vc_sel.end = new_sel_end;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-04-15 17:36:08 +08:00
|
|
|
return vc_selection_store_chars(vc, unicode);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2020-02-28 19:54:05 +08:00
|
|
|
|
2020-04-15 17:36:07 +08:00
|
|
|
static int vc_selection(struct vc_data *vc, struct tiocl_selection *v,
|
|
|
|
struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
int ps, pe;
|
|
|
|
|
|
|
|
poke_blanked_console();
|
|
|
|
|
|
|
|
if (v->sel_mode == TIOCL_SELCLEAR) {
|
|
|
|
/* useful for screendump without selection highlights */
|
|
|
|
clear_selection();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
v->xs = min_t(u16, v->xs - 1, vc->vc_cols - 1);
|
|
|
|
v->ys = min_t(u16, v->ys - 1, vc->vc_rows - 1);
|
|
|
|
v->xe = min_t(u16, v->xe - 1, vc->vc_cols - 1);
|
|
|
|
v->ye = min_t(u16, v->ye - 1, vc->vc_rows - 1);
|
|
|
|
|
|
|
|
if (mouse_reporting() && (v->sel_mode & TIOCL_SELMOUSEREPORT)) {
|
|
|
|
mouse_report(tty, v->sel_mode & TIOCL_SELBUTTONMASK, v->xs,
|
|
|
|
v->ys);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps = v->ys * vc->vc_size_row + (v->xs << 1);
|
|
|
|
pe = v->ye * vc->vc_size_row + (v->xe << 1);
|
|
|
|
if (ps > pe) /* make vc_sel.start <= vc_sel.end */
|
|
|
|
swap(ps, pe);
|
|
|
|
|
|
|
|
if (vc_sel.cons != vc) {
|
|
|
|
clear_selection();
|
|
|
|
vc_sel.cons = vc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vc_do_selection(vc, v->sel_mode, ps, pe);
|
|
|
|
}
|
|
|
|
|
2020-02-28 19:54:05 +08:00
|
|
|
int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2020-03-10 17:02:49 +08:00
|
|
|
mutex_lock(&vc_sel.lock);
|
2020-02-28 19:54:05 +08:00
|
|
|
console_lock();
|
2020-04-15 17:36:07 +08:00
|
|
|
ret = vc_selection(vc_cons[fg_console].d, v, tty);
|
2020-02-28 19:54:05 +08:00
|
|
|
console_unlock();
|
2020-02-19 15:39:47 +08:00
|
|
|
mutex_unlock(&vc_sel.lock);
|
2020-02-28 19:54:05 +08:00
|
|
|
|
2020-02-10 16:11:31 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-04-17 20:21:13 +08:00
|
|
|
EXPORT_SYMBOL_GPL(set_selection_kernel);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Insert the contents of the selection buffer into the
|
|
|
|
* queue of the tty associated with the current console.
|
|
|
|
* Invoked by ioctl().
|
2011-07-14 20:35:14 +08:00
|
|
|
*
|
2012-03-02 22:59:37 +08:00
|
|
|
* Locking: called without locks. Calls the ldisc wrongly with
|
|
|
|
* unsafe methods,
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int paste_selection(struct tty_struct *tty)
|
|
|
|
{
|
2009-01-02 21:47:26 +08:00
|
|
|
struct vc_data *vc = tty->driver_data;
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
int pasted = 0;
|
|
|
|
unsigned int count;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct tty_ldisc *ld;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
2020-02-10 16:11:30 +08:00
|
|
|
int ret = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-01-26 07:07:35 +08:00
|
|
|
console_lock();
|
2005-04-17 06:20:36 +08:00
|
|
|
poke_blanked_console();
|
2011-01-26 07:07:35 +08:00
|
|
|
console_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-10-19 04:26:32 +08:00
|
|
|
ld = tty_ldisc_ref_wait(tty);
|
2016-01-11 14:41:01 +08:00
|
|
|
if (!ld)
|
|
|
|
return -EIO; /* ldisc was hung up */
|
2013-06-15 21:36:15 +08:00
|
|
|
tty_buffer_lock_exclusive(&vc->port);
|
2010-06-02 04:53:06 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
add_wait_queue(&vc->paste_wait, &wait);
|
2020-02-19 15:39:47 +08:00
|
|
|
mutex_lock(&vc_sel.lock);
|
|
|
|
while (vc_sel.buffer && vc_sel.buf_len > pasted) {
|
2005-04-17 06:20:36 +08:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2020-02-10 16:11:30 +08:00
|
|
|
if (signal_pending(current)) {
|
|
|
|
ret = -EINTR;
|
|
|
|
break;
|
|
|
|
}
|
2016-04-10 08:11:36 +08:00
|
|
|
if (tty_throttled(tty)) {
|
2020-02-19 15:39:47 +08:00
|
|
|
mutex_unlock(&vc_sel.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
schedule();
|
2020-02-19 15:39:47 +08:00
|
|
|
mutex_lock(&vc_sel.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-13 08:47:35 +08:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2020-02-19 15:39:47 +08:00
|
|
|
count = vc_sel.buf_len - pasted;
|
|
|
|
count = tty_ldisc_receive_buf(ld, vc_sel.buffer + pasted, NULL,
|
2013-06-15 21:14:15 +08:00
|
|
|
count);
|
2005-04-17 06:20:36 +08:00
|
|
|
pasted += count;
|
|
|
|
}
|
2020-02-19 15:39:47 +08:00
|
|
|
mutex_unlock(&vc_sel.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
remove_wait_queue(&vc->paste_wait, &wait);
|
2007-05-08 15:30:52 +08:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-06-15 21:36:15 +08:00
|
|
|
tty_buffer_unlock_exclusive(&vc->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
tty_ldisc_deref(ld);
|
2020-02-10 16:11:30 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2019-04-17 20:21:13 +08:00
|
|
|
EXPORT_SYMBOL_GPL(paste_selection);
|