drivers/md/dm-vdo/errors.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/errors.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-vdo/errors.c- Extension
.c- Size
- 8616 bytes
- Lines
- 308
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: implementation source
- Status
- source 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 or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errors.hlinux/compiler.hlinux/errno.hlogger.hpermassert.hstring-utils.h
Detected Declarations
struct error_blockfunction uds_status_to_errnofunction uds_register_error_block
Annotated Snippet
struct error_block {
const char *name;
int base;
int last;
int max;
const struct error_info *infos;
};
#define MAX_ERROR_BLOCKS 6
static struct {
int allocated;
int count;
struct error_block blocks[MAX_ERROR_BLOCKS];
} registered_errors = {
.allocated = MAX_ERROR_BLOCKS,
.count = 1,
.blocks = { {
.name = "UDS Error",
.base = UDS_ERROR_CODE_BASE,
.last = UDS_ERROR_CODE_LAST,
.max = UDS_ERROR_CODE_BLOCK_END,
.infos = error_list,
} },
};
/* Get the error info for an error number. Also returns the name of the error block, if known. */
static const char *get_error_info(int errnum, const struct error_info **info_ptr)
{
struct error_block *block;
if (errnum == UDS_SUCCESS) {
*info_ptr = &successful;
return NULL;
}
for (block = registered_errors.blocks;
block < registered_errors.blocks + registered_errors.count;
block++) {
if ((errnum >= block->base) && (errnum < block->last)) {
*info_ptr = block->infos + (errnum - block->base);
return block->name;
} else if ((errnum >= block->last) && (errnum < block->max)) {
*info_ptr = NULL;
return block->name;
}
}
return NULL;
}
/* Return a string describing a system error message. */
static const char *system_string_error(int errnum, char *buf, size_t buflen)
{
size_t len;
const char *error_string = NULL;
if ((errnum > 0) && (errnum < ARRAY_SIZE(message_table)))
error_string = message_table[errnum];
len = ((error_string == NULL) ?
snprintf(buf, buflen, "Unknown error %d", errnum) :
snprintf(buf, buflen, "%s", error_string));
if (len < buflen)
return buf;
buf[0] = '\0';
return "System error";
}
/* Convert an error code to a descriptive string. */
const char *uds_string_error(int errnum, char *buf, size_t buflen)
{
char *buffer = buf;
char *buf_end = buf + buflen;
const struct error_info *info = NULL;
const char *block_name;
if (buf == NULL)
return NULL;
if (errnum < 0)
errnum = -errnum;
block_name = get_error_info(errnum, &info);
if (block_name != NULL) {
if (info != NULL) {
buffer = vdo_append_to_buffer(buffer, buf_end, "%s: %s",
block_name, info->message);
} else {
Annotation
- Immediate include surface: `errors.h`, `linux/compiler.h`, `linux/errno.h`, `logger.h`, `permassert.h`, `string-utils.h`.
- Detected declarations: `struct error_block`, `function uds_status_to_errno`, `function uds_register_error_block`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source implementation candidate.
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.