2 * (C) Copyright 2007-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
10 #include <directory.h>
18 #include "direct_grammar.h"
20 static LIST_HEAD(directory
);
22 int direct_parse(struct parser
*);
24 struct user
*find_user_by_id(char *userid
)
29 return ERR_PTR(-ENOENT
);
31 list_for_each_entry(u
, &directory
, list
)
32 if (!strcasecmp(u
->userid
, userid
))
35 return ERR_PTR(-ENOENT
);
38 static void *_realloc(void *p
, size_t s
)
41 return malloc(s
, ZONE_NORMAL
);
43 if (s
<= allocsize(p
))
50 static void _error(struct parser
*p
, char *msg
)
52 sclp_msg("directory parse error: %s\n", msg
);
56 int load_directory(struct fs
*fs
)
61 sclp_msg("LOADING DIRECTORY FROM '%*.*s' '%*.*s'\n",
62 8, 8, sysconf
.direct_fn
, 8, 8, sysconf
.direct_ft
);
64 /* set up the parser */
65 memset(&p
, 0, sizeof(p
));
72 /* set up the lexer */
73 memset(&l
, 0, sizeof(l
));
78 return direct_parse(&p
) ? -ECORRUPT
: 0;
81 void directory_alloc_user(char *name
, int auth
, struct directory_prop
*prop
,
82 struct list_head
*vdevs
)
87 assert(prop
->got_storage
);
89 user
= malloc(sizeof(struct user
), ZONE_NORMAL
);
92 memset(user
, 0, sizeof(struct user
));
94 INIT_LIST_HEAD(&user
->list
);
95 INIT_LIST_HEAD(&user
->devices
);
96 list_splice(vdevs
, &user
->devices
);
99 user
->storage_size
= prop
->storage
;
103 list_add_tail(&user
->list
, &directory
);