drivers/char/lp.c
Source file repositories/reference/linux-study-clean/drivers/char/lp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/lp.c- Extension
.c- Size
- 28091 bytes
- Lines
- 1127
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/init.hlinux/errno.hlinux/kernel.hlinux/major.hlinux/sched/signal.hlinux/slab.hlinux/fcntl.hlinux/delay.hlinux/poll.hlinux/console.hlinux/device.hlinux/wait.hlinux/jiffies.hlinux/mutex.hlinux/compat.hlinux/parport.hlinux/lp.hasm/irq.hlinux/uaccess.h
Detected Declarations
function lp_claim_parport_or_blockfunction lp_release_parportfunction lp_preemptfunction lp_negotiatefunction lp_resetfunction lp_errorfunction lp_check_statusfunction lp_wait_readyfunction lp_writefunction lp_readfunction lp_openfunction ioctlfunction lp_releasefunction lp_do_ioctlfunction lp_set_timeoutfunction lp_set_timeout32function lp_set_timeout64function lp_ioctlfunction lp_compat_ioctlfunction lp_console_writefunction lp_setupfunction lp_registerfunction lp_attachfunction lp_detachfunction lp_initfunction lp_init_modulefunction lp_cleanup_modulemodule init lp_init_module
Annotated Snippet
static const struct file_operations lp_fops = {
.owner = THIS_MODULE,
.write = lp_write,
.unlocked_ioctl = lp_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = lp_compat_ioctl,
#endif
.open = lp_open,
.release = lp_release,
#ifdef CONFIG_PARPORT_1284
.read = lp_read,
#endif
.llseek = noop_llseek,
};
/* --- support for console on the line printer ----------------- */
#ifdef CONFIG_LP_CONSOLE
#define CONSOLE_LP 0
/* If the printer is out of paper, we can either lose the messages or
* stall until the printer is happy again. Define CONSOLE_LP_STRICT
* non-zero to get the latter behaviour. */
#define CONSOLE_LP_STRICT 1
/* The console must be locked when we get here. */
static void lp_console_write(struct console *co, const char *s,
unsigned count)
{
struct pardevice *dev = lp_table[CONSOLE_LP].dev;
struct parport *port = dev->port;
ssize_t written;
if (parport_claim(dev))
/* Nothing we can do. */
return;
parport_set_timeout(dev, 0);
/* Go to compatibility mode. */
parport_negotiate(port, IEEE1284_MODE_COMPAT);
do {
/* Write the data, converting LF->CRLF as we go. */
ssize_t canwrite = count;
char *lf = memchr(s, '\n', count);
if (lf)
canwrite = lf - s;
if (canwrite > 0) {
written = parport_write(port, s, canwrite);
if (written <= 0)
continue;
s += written;
count -= written;
canwrite -= written;
}
if (lf && canwrite <= 0) {
const char *crlf = "\r\n";
int i = 2;
/* Dodge the original '\n', and put '\r\n' instead. */
s++;
count--;
do {
written = parport_write(port, crlf, i);
if (written > 0) {
i -= written;
crlf += written;
}
} while (i > 0 && (CONSOLE_LP_STRICT || written > 0));
}
} while (count > 0 && (CONSOLE_LP_STRICT || written > 0));
parport_release(dev);
}
static struct console lpcons = {
.name = "lp",
.write = lp_console_write,
.flags = CON_PRINTBUFFER,
};
#endif /* console on line printer */
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/errno.h`, `linux/kernel.h`, `linux/major.h`, `linux/sched/signal.h`, `linux/slab.h`, `linux/fcntl.h`.
- Detected declarations: `function lp_claim_parport_or_block`, `function lp_release_parport`, `function lp_preempt`, `function lp_negotiate`, `function lp_reset`, `function lp_error`, `function lp_check_status`, `function lp_wait_ready`, `function lp_write`, `function lp_read`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern 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.