/* -------------------------------------------------------- do_pwd: * recursively follow a pathname back to a root * * base case: dir is a ROOT * if not base case: * (1) get_block and point DIR* dp to start of second block, which is .. * (2) use dp to get parent's ino * (3) load parent MINODE using iget * (4) Recusively call do_pwd(parent) * (5) print / and directory name -------------------------------------------------------------*/ void do_pwd(MINODE* dir) { MINODE* parent; int pino, ino; char* cp; DIR* dp; char buf[BLOCK_SIZE]; // (1) Base case: DIR is root if(dir == root) { printf("/"); return; } // Read in i_block[0], // which contains all of the directories contained in this DIR get_block(dir->dev, dir->INODE.i_block[0], buf); // Point to the beginning of the datablock cp = buf; dp = (DIR*) cp; // Get ino number of current directory ino = dp->inode; // go to second data block, get ino of .. cp += dp->rec_len; dp = (DIR* )cp; // dp now points to .., the parent's directory pino = dp->inode; // get parent's ino // Load the parent MINODE* parent = iget(dir->dev, pino); // Call pwd with parent's MINODE pointer do_pwd(parent); if(parent == NULL) { printf("Error: could not load MINODE %s", dp->name); return; } // (3) Print name followed by / // Search parent DIR for an entry with this ino // Get the name associated with this ino char* dirName = findmyname(parent, ino); printf("%s/", dirName); iput(parent); }
char* find_name(MINODE *mip) { int my_ino = 0; int parent_ino = 0; findino(mip, &my_ino, &parent_ino); MINODE* parent_mip = iget(running->cwd->device, parent_ino); char* my_name = NULL; findmyname(parent_mip, my_ino, &my_name); iput(parent_mip); return my_name; }