loader: remove shouting from ORB's variable name
[hvf.git] / cp / nucleus / direct.c
blob320e6d882319f0e4d39494377edb01c326b0e8f5
1 /*
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
5 * details.
6 */
8 #include <errno.h>
9 #include <ebcdic.h>
10 #include <directory.h>
11 #include <shell.h>
12 #include <slab.h>
13 #include <parser.h>
14 #include <lexer.h>
15 #include <edf.h>
16 #include <sclp.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)
26 struct user *u;
28 if (!userid)
29 return ERR_PTR(-ENOENT);
31 list_for_each_entry(u, &directory, list)
32 if (!strcasecmp(u->userid, userid))
33 return u;
35 return ERR_PTR(-ENOENT);
38 static void *_realloc(void *p, size_t s)
40 if (!p)
41 return malloc(s, ZONE_NORMAL);
43 if (s <= allocsize(p))
44 return p;
46 BUG();
47 return NULL;
50 static void _error(struct parser *p, char *msg)
52 sclp_msg("directory parse error: %s\n", msg);
53 BUG();
56 int load_directory(struct fs *fs)
58 struct parser p;
59 struct lexer l;
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));
66 p.lex = direct_lex;
67 p.lex_data = &l;
68 p.realloc = _realloc;
69 p.free = free;
70 p.error = _error;
72 /* set up the lexer */
73 memset(&l, 0, sizeof(l));
74 l.fs = fs;
75 l.init = 0;
77 /* parse! */
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)
84 struct user *user;
86 assert(name);
87 assert(prop->got_storage);
89 user = malloc(sizeof(struct user), ZONE_NORMAL);
90 assert(user);
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);
98 user->userid = name;
99 user->storage_size = prop->storage;
100 user->auth = auth;
102 FIXME("locking?");
103 list_add_tail(&user->list, &directory);