}
}
-
-// hack
-vector<CInode*> MDCache::hack_add_file(string& fn, CInode *in) {
-
- // root?
- if (fn == "/") {
- if (!root) {
- root = in;
- add_inode( in );
- dout(7) << " added root " << root << endl;
- } else {
- root->inode.ino = in->inode.ino; // bleh
- }
- vector<CInode*> trace;
- trace.push_back(root);
- return trace;
- }
-
-
- // file.
- int lastslash = fn.rfind("/");
- string dirpart = fn.substr(0,lastslash);
- string file = fn.substr(lastslash+1);
-
- //dout(7) << "dirpart '" << dirpart << "' filepart '" << file << "' inode " << in << endl;
-
- CInode *diri = hack_get_file(dirpart);
- assert(diri);
-
- //dout(7) << " got dir " << diri << endl;
-
- if (diri->dir == NULL) {
- dout(4) << " making " << *diri << " into a dir" << endl;
- diri->inode.mode &= ~INODE_MODE_FILE;
- diri->inode.mode |= INODE_MODE_DIR;
- }
-
- assert(diri->is_dir());
- diri->get_or_open_dir(mds);
-
- add_inode( in );
- diri->dir->add_dentry( file, in );
-
- if (in->is_dir())
- in->get_or_open_dir(mds);
-
- vector<CInode*> trace;
- trace.push_back(diri);
- trace.push_back(in);
- while (diri->parent) {
- diri = diri->parent->dir->inode;
- trace.insert(trace.begin(),diri);
- }
- return trace;
-}
-
-CInode* MDCache::hack_get_file(string& fn) {
- unsigned off = 1;
- CInode *cur = root;
-
- // dirs
- while (off < fn.length()) {
- unsigned int slash = fn.find("/", off);
- if (slash == string::npos)
- slash = fn.length();
- string n = fn.substr(off, slash-off);
-
- //dout(7) << " looking up '" << n << "' in " << cur << endl;
-
- if (cur->dir == NULL) {
- //dout(7) << " not a directory!" << endl;
- return NULL; // this isn't a directory.
- }
-
- CDentry* den = cur->dir->lookup(n);
- if (den == NULL) return NULL; // file dne!
- cur = den->inode;
- off = slash+1;
- }
-
- //dump();
- lru.lru_status();
-
- return cur;
-}