6#include <linux/limits.h>
7#include <linux/module.h>
8#include <linux/namei.h>
10#include <linux/string.h>
28 list_for_each_entry(it, &ul->
head,
list) {
42 list_for_each_entry_safe(it, tmp, &ul->
head,
list) {
48 spin_unlock(&ul->
lock);
65 ERR_MSG(
"ulist_load: invalid arguments ul=%p filename=%p\n", ul,
74 DBG_MSG(
"ulist_load: no config file '%s'\n", cfgpath);
77 ERR_MSG(
"ulist_load: error reading '%s': %d\n", cfgpath, ret);
82 DBG_MSG(
"ulist_load: empty config '%s'\n", cfgpath);
91 char *fields[3] = { NULL, NULL, NULL };
98 newline = strpbrk(p,
"\r\n");
99 len = newline ? (newline - p) : strlen(p);
111 ERR_MSG(
"ulist_load: skipping too-long line\n");
118 memcpy(line, p, len);
123 fields[0] = strsep(&cursor,
"|");
124 fields[1] = strsep(&cursor,
"|");
128 if (!fields[0] || !*fields[0]) {
129 ERR_MSG(
"ulist_load: missing value, skipping line\n");
136 if (fields[1] && *fields[1]) {
137 int err = kstrtou32(fields[1], 10, &
flags);
139 ERR_MSG(
"ulist_load: bad flags '%s', using 0\n", fields[1]);
145 if (fields[2] && *fields[2])
151 ERR_MSG(
"ulist_load: ulist_add(%s) failed: %d\n", fields[0], rc);
181 spin_lock(&ul->
lock);
182 list_for_each_entry(it, &ul->
head,
list) {
183 int n = scnprintf(q, left,
"%s|%u|%s\n", it->
value, it->
flags,
190 spin_unlock(&ul->
lock);
195 return ret > 0 ? 1 : ret;
214 struct ulist_item *it = kzalloc(
sizeof(*it), GFP_KERNEL);
221 INIT_LIST_HEAD(&it->
list);
223 spin_lock(&ul->
lock);
224 list_add_tail(&it->
list, &ul->
head);
225 spin_unlock(&ul->
lock);
238 spin_lock(&ul->
lock);
239 list_for_each_entry_safe(it, tmp, &ul->
head,
list) {
247 spin_unlock(&ul->
lock);
262 spin_lock(&ul->
lock);
263 list_for_each_entry(it, &ul->
head,
list) {
269 spin_unlock(&ul->
lock);
284 size_t left = buf_size;
288 if (!ul || !buf || buf_size == 0)
291 spin_lock(&ul->
lock);
292 list_for_each_entry(it, &ul->
head,
list) {
293 n = scnprintf(p, left,
"%s|%u|%s\n", it->
value, it->
flags,
300 spin_unlock(&ul->
lock);
305 buf[buf_size - 1] =
'\0';
#define ERR_MSG(fmt, args...)
#define DBG_MSG(fmt, args...)
void build_cfg_path(const char *fname, char *out, size_t sz)
int _write_file(const char *path, const char *buf, size_t len)
int _read_file(const char *path, char **out_buf)
int ulist_add(struct ulist *ul, const char *value, u32 flags, const char *payload)
void ulist_clear(struct ulist *ul)
int ulist_load(struct ulist *ul)
int ulist_list(struct ulist *ul, char *buf, size_t buf_size)
static bool ulist_has_item(struct ulist *ul, const char *value)
int ulist_save(struct ulist *ul)
int ulist_remove(struct ulist *ul, const char *value)
int ulist_contains(struct ulist *ul, const char *value)