xref: /inferno-os/liblogfs/path.c (revision efbaac87ed5df1764747ea89043475db86c52e19)
1  #include "logfsos.h"
2  #include "logfs.h"
3  #include "local.h"
4  
5  enum {
6  	PATHMOD = 127
7  };
8  
9  static int
10  compare(void *a, void *b)
11  {
12  	Path *f = a;
13  	ulong path = (ulong)b;	/* sic */
14  	return f->path == path;
15  }
16  
17  static int
18  allocsize(void *key)
19  {
20  	USED(key);
21  	return sizeof(Path);
22  }
23  
24  char *
25  logfspathmapnew(PathMap **pathmapp)
26  {
27  	return logfsmapnew(PATHMOD, logfshashulong, compare, allocsize, nil, pathmapp);
28  }
29  
30  char *
31  logfspathmapnewentry(PathMap *m, ulong path, Entry *e, Path **pathmapp)
32  {
33  	char *errmsg;
34  	errmsg = logfsmapnewentry(m, (void*)path, pathmapp);
35  	if(errmsg)
36  		return errmsg;
37  	if(*pathmapp == nil)
38  		return nil;
39  	(*pathmapp)->path = path;
40  	(*pathmapp)->entry = e;
41  	return nil;
42  }
43  
44  Entry *
45  logfspathmapfinde(PathMap *m, ulong path)
46  {
47  	Path *p;
48  	p = logfspathmapfindentry(m, path);
49  	return p ? p->entry : nil;
50  }
51