Commit | Line | Data |
---|---|---|
03d1089e MS |
1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
2 | /* | |
3 | * Copyright 2023 Red Hat | |
4 | */ | |
5 | ||
6 | #ifndef UDS_ERRORS_H | |
7 | #define UDS_ERRORS_H | |
8 | ||
9 | #include <linux/compiler.h> | |
10 | #include <linux/types.h> | |
11 | ||
12 | /* Custom error codes and error-related utilities for UDS */ | |
13 | ||
14 | /* Valid status codes for internal UDS functions. */ | |
15 | enum uds_status_codes { | |
16 | /* Successful return */ | |
17 | UDS_SUCCESS = 0, | |
18 | ||
19 | /* Used as a base value for reporting internal errors */ | |
20 | UDS_ERROR_CODE_BASE = 1024, | |
21 | /* Index overflow */ | |
22 | UDS_OVERFLOW = UDS_ERROR_CODE_BASE + 0, | |
23 | /* Invalid argument passed to internal routine */ | |
24 | UDS_INVALID_ARGUMENT = UDS_ERROR_CODE_BASE + 1, | |
25 | /* UDS data structures are in an invalid state */ | |
26 | UDS_BAD_STATE = UDS_ERROR_CODE_BASE + 2, | |
27 | /* Attempt to enter the same name into an internal structure twice */ | |
28 | UDS_DUPLICATE_NAME = UDS_ERROR_CODE_BASE + 3, | |
29 | /* An assertion failed */ | |
30 | UDS_ASSERTION_FAILED = UDS_ERROR_CODE_BASE + 4, | |
31 | /* A request has been queued for later processing (not an error) */ | |
32 | UDS_QUEUED = UDS_ERROR_CODE_BASE + 5, | |
33 | /* A problem has occurred with a buffer */ | |
34 | UDS_BUFFER_ERROR = UDS_ERROR_CODE_BASE + 6, | |
35 | /* No directory was found where one was expected */ | |
36 | UDS_NO_DIRECTORY = UDS_ERROR_CODE_BASE + 7, | |
37 | /* This error range has already been registered */ | |
38 | UDS_ALREADY_REGISTERED = UDS_ERROR_CODE_BASE + 8, | |
39 | /* Attempt to read or write data outside the valid range */ | |
40 | UDS_OUT_OF_RANGE = UDS_ERROR_CODE_BASE + 9, | |
41 | /* Could not load modules */ | |
42 | UDS_EMODULE_LOAD = UDS_ERROR_CODE_BASE + 10, | |
43 | /* The index session is disabled */ | |
44 | UDS_DISABLED = UDS_ERROR_CODE_BASE + 11, | |
45 | /* Unknown error */ | |
46 | UDS_UNKNOWN_ERROR = UDS_ERROR_CODE_BASE + 12, | |
47 | /* The index configuration or volume format is no longer supported */ | |
48 | UDS_UNSUPPORTED_VERSION = UDS_ERROR_CODE_BASE + 13, | |
49 | /* Some index structure is corrupt */ | |
50 | UDS_CORRUPT_DATA = UDS_ERROR_CODE_BASE + 14, | |
51 | /* No index state found */ | |
52 | UDS_NO_INDEX = UDS_ERROR_CODE_BASE + 15, | |
53 | /* Attempt to access incomplete index save data */ | |
54 | UDS_INDEX_NOT_SAVED_CLEANLY = UDS_ERROR_CODE_BASE + 16, | |
55 | /* One more than the last UDS_INTERNAL error code */ | |
56 | UDS_ERROR_CODE_LAST, | |
57 | /* One more than the last error this block will ever use */ | |
58 | UDS_ERROR_CODE_BLOCK_END = UDS_ERROR_CODE_BASE + 440, | |
59 | }; | |
60 | ||
61 | enum { | |
62 | UDS_MAX_ERROR_NAME_SIZE = 80, | |
63 | UDS_MAX_ERROR_MESSAGE_SIZE = 128, | |
64 | }; | |
65 | ||
66 | struct error_info { | |
67 | const char *name; | |
68 | const char *message; | |
69 | }; | |
70 | ||
71 | const char * __must_check uds_string_error(int errnum, char *buf, size_t buflen); | |
72 | ||
73 | const char *uds_string_error_name(int errnum, char *buf, size_t buflen); | |
74 | ||
75 | int uds_map_to_system_error(int error); | |
76 | ||
77 | int uds_register_error_block(const char *block_name, int first_error, | |
78 | int last_reserved_error, const struct error_info *infos, | |
79 | size_t info_size); | |
80 | ||
81 | #endif /* UDS_ERRORS_H */ |