1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include "macro.h"
5 #include "missing_ioprio.h"
6 
7 int ioprio_class_to_string_alloc(int i, char **s);
8 int ioprio_class_from_string(const char *s);
9 
ioprio_class_is_valid(int i)10 static inline bool ioprio_class_is_valid(int i) {
11         return IN_SET(i, IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE);
12 }
13 
ioprio_priority_is_valid(int i)14 static inline bool ioprio_priority_is_valid(int i) {
15         return i >= 0 && i < IOPRIO_BE_NR;
16 }
17 
18 int ioprio_parse_priority(const char *s, int *ret);
19 
20 /* IOPRIO_CLASS_NONE with any prio value is another way to say IOPRIO_CLASS_BE with level 4. Encode that in a
21  * proper macro. */
22 #define IOPRIO_DEFAULT_CLASS_AND_PRIO ioprio_prio_value(IOPRIO_CLASS_BE, 4)
23 
ioprio_normalize(int v)24 static inline int ioprio_normalize(int v) {
25         /* Converts IOPRIO_CLASS_NONE to what it actually means */
26         return ioprio_prio_class(v) == IOPRIO_CLASS_NONE ? IOPRIO_DEFAULT_CLASS_AND_PRIO : v;
27 }
28