Wrap the xns holding a directory listing in a dirns class.

I'll be changing the dirns implementation soon.
上级 91424b90
#pragma once
u64 namehash(const strbuf<DIRSIZ>&);
class dirns : public rcu_freed
{
public:
dirns() : rcu_freed("dirns"), ns_(false) {}
bool remove(const strbuf<DIRSIZ>& name, const u32* vp = nullptr) {
return ns_.remove(name, vp);
}
int insert(const strbuf<DIRSIZ>& name, const u32& inum) {
return ns_.insert(name, inum);
}
u32 lookup(const strbuf<DIRSIZ>& name) {
return ns_.lookup(name);
}
template<class CB>
void enumerate(CB cb) {
return ns_.enumerate(cb);
}
virtual void do_gc(void) {
delete this;
}
NEW_DELETE_OPS(dirns);
private:
xns<strbuf<DIRSIZ>, u32, namehash> ns_;
};
......@@ -6,6 +6,8 @@
#include "atomic.hh"
#include "ref.hh"
class dirns;
u64 namehash(const strbuf<DIRSIZ>&);
struct file : public referenced, public rcu_freed {
......@@ -60,9 +62,9 @@ struct inode : public referenced, public rcu_freed
struct condvar cv;
struct spinlock lock;
char lockname[16];
std::atomic<xns<strbuf<DIRSIZ>, u32, namehash>*> dir;
std::atomic<dirns*> dir;
short type; // copy of disk inode
short type; // copy of disk inode
short major;
short minor;
u32 size;
......
......@@ -39,6 +39,7 @@
#include "file.hh"
#include "cpu.hh"
#include "kmtrace.hh"
#include "dirns.hh"
#define min(a, b) ((a) < (b) ? (a) : (b))
static void itrunc(struct inode*);
......@@ -708,7 +709,7 @@ dir_init(struct inode *dp)
if (dp->type != T_DIR)
panic("dir_init not DIR");
auto dir = new xns<strbuf<DIRSIZ>, u32, namehash>(false);
auto dir = new dirns();
for (u32 off = 0; off < dp->size; off += BSIZE) {
struct buf *bp = bread(dp->dev, bmap(dp, off / BSIZE), 0);
for (struct dirent *de = (struct dirent *) bp->data;
......
......@@ -13,6 +13,7 @@
#include "net.hh"
#include "kmtrace.hh"
#include "sperf.hh"
#include "dirns.hh"
static bool
getfile(int fd, sref<file> *f)
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论