HEAD: better documentation for wvx509 constructors.
[wvapps.git] / funfs / cachefsicache.cc
bloba80e861126f9e92815a0e9820dfaa73de7eccc32
1 #include "cachefsicache.h"
3 #include <dirent.h>
4 #include <sys/stat.h>
5 #include <errno.h>
7 bool ICache::maybe_get_attr(WvString path, struct fuse_attr *attr)
9 INode *inode = maybe_get_inode(path);
10 if (!inode)
11 return false;
12 return inode->maybe_get_attr(attr);
15 bool ICache::maybe_get_link(WvString path, char *buf, size_t size)
17 INode *inode = maybe_get_inode(path);
18 if (!inode)
19 return false;
20 return inode->maybe_get_link(buf, size);
23 bool ICache::maybe_get_children(WvString path, WvFuseDirCb &cb)
25 INode *inode = maybe_get_inode(path);
26 if (!inode)
27 return false;
29 if (!inode->can_get_children())
30 return false;
32 struct dirent *de;
33 struct fuse_dirent fde;
34 WvString fullpath("%s/%s", cfg["Meta Root"].get(), path);
35 DIR *dp = opendir(fullpath);
37 if (!dp)
38 return false;
40 while (dp && (de = readdir(dp)) != NULL)
41 if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")
42 && strcmp(de->d_name, ".cachefsdirdata"))
44 strncpy(fde.name, de->d_name, NAME_MAX);
45 fde.namelen = strlen(de->d_name);
46 fde.type = maybe_get_mode(WvString("%s/%s", path, fde.name));
47 cb(&fde);
50 closedir(dp);
52 return true;
55 unsigned char ICache::maybe_get_mode(WvString path)
57 if (INode *inode = maybe_get_inode(path))
59 return inode->get_mode();
61 else
62 return DT_UNKNOWN;
65 void ICache::set_attr(WvStringParm path, struct fuse_attr *attr)
67 INode *inode = maybe_get_inode(path, IFTODT(attr->mode));
68 if (inode)
69 inode->set_attr(attr);
70 else
71 fprintf(stderr, "Cache error updating attributes "
72 "on node '%s'\n", path.cstr());
75 void ICache::set_link(WvStringParm path, char *buf)
77 INode *inode = maybe_get_inode(path, 0);
78 if (inode)
79 inode->set_link(buf);
80 else
81 fprintf(stderr, "Cache error updating link "
82 "on node '%s'\n", path.cstr());
85 void ICache::set_children(WvStringParm path)
87 INode *inode = maybe_get_inode(path, 0);
88 if (inode)
89 inode->set_children();
90 else
91 fprintf(stderr, "Cache error in set_children "
92 "on node '%s'\n", path.cstr());
95 INode *ICache::maybe_get_inode(WvStringParm path, unsigned char mode)
97 INode *inode = MyMRU::maybe_get(path);
99 if (inode)
100 return inode;
102 inode = new INode(this);
103 if (inode->init(path, mode))
105 MyMRU::add(path, inode);
106 return inode;
108 else
110 delete inode;
111 return NULL;