drivers/tty/vt/selection.c
Source file repositories/reference/linux-study-clean/drivers/tty/vt/selection.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/vt/selection.c- Extension
.c- Size
- 11523 bytes
- Lines
- 460
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/tty.hlinux/sched.hlinux/mm.hlinux/mutex.hlinux/slab.hlinux/types.hlinux/uaccess.hlinux/kbd_kern.hlinux/vt_kern.hlinux/consolemap.hlinux/selection.hlinux/tiocl.hlinux/console.hlinux/tty_flip.hlinux/sched/signal.h
Detected Declarations
function interruptfunction highlight_pointerfunction sel_posfunction clear_selectionfunction vc_is_selfunction inwordfunction sel_loadlutfunction atedgefunction store_utf8function set_selection_userfunction vc_selection_store_charsfunction vc_do_selectionfunction is_space_on_vtfunction vc_selectionfunction set_selection_kernelfunction ioctlexport clear_selectionexport set_selection_kernelexport paste_selection
Annotated Snippet
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;
}
static int vc_do_selection(struct vc_data *vc, unsigned short mode, int ps,
int pe)
{
int new_sel_start, new_sel_end, spc;
bool unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
switch (mode) {
case TIOCL_SELCHAR: /* character-by-character selection */
new_sel_start = ps;
new_sel_end = pe;
break;
case TIOCL_SELWORD: /* word-by-word selection */
spc = is_space_on_vt(sel_pos(ps, unicode));
for (new_sel_start = ps; ; ps -= 2) {
if ((spc && !is_space_on_vt(sel_pos(ps, unicode))) ||
(!spc && !inword(sel_pos(ps, unicode))))
break;
new_sel_start = ps;
if (!(ps % vc->vc_size_row))
break;
}
spc = is_space_on_vt(sel_pos(pe, unicode));
for (new_sel_end = pe; ; pe += 2) {
if ((spc && !is_space_on_vt(sel_pos(pe, unicode))) ||
(!spc && !inword(sel_pos(pe, unicode))))
break;
new_sel_end = pe;
if (!((pe + 2) % vc->vc_size_row))
break;
}
break;
case TIOCL_SELLINE: /* line-by-line selection */
new_sel_start = rounddown(ps, vc->vc_size_row);
new_sel_end = rounddown(pe, vc->vc_size_row) +
vc->vc_size_row - 2;
break;
case TIOCL_SELPOINTER:
highlight_pointer(pe);
return 0;
default:
return -EINVAL;
}
/* 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) &&
is_space_on_vt(sel_pos(new_sel_end, unicode))) {
for (pe = new_sel_end + 2; ; pe += 2)
if (!is_space_on_vt(sel_pos(pe, unicode)) ||
atedge(pe, vc->vc_size_row))
break;
if (is_space_on_vt(sel_pos(pe, unicode)))
new_sel_end = pe;
}
if (vc_sel.start == -1) /* no current selection */
highlight(new_sel_start, new_sel_end);
else if (new_sel_start == vc_sel.start)
{
if (new_sel_end == vc_sel.end) /* no action required */
return 0;
else if (new_sel_end > vc_sel.end) /* extend to right */
highlight(vc_sel.end + 2, new_sel_end);
else /* contract from right */
highlight(new_sel_end + 2, vc_sel.end);
}
else if (new_sel_end == vc_sel.end)
{
if (new_sel_start < vc_sel.start) /* extend to left */
highlight(new_sel_start, vc_sel.start - 2);
else /* contract from left */
highlight(vc_sel.start, new_sel_start - 2);
Annotation
- Immediate include surface: `linux/module.h`, `linux/tty.h`, `linux/sched.h`, `linux/mm.h`, `linux/mutex.h`, `linux/slab.h`, `linux/types.h`, `linux/uaccess.h`.
- Detected declarations: `function interrupt`, `function highlight_pointer`, `function sel_pos`, `function clear_selection`, `function vc_is_sel`, `function inword`, `function sel_loadlut`, `function atedge`, `function store_utf8`, `function set_selection_user`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.