#include #include #include //this version of pwd shows the number of subdirectory //in each level, and highlights the mounting points using std::cout; ino_t name2inode(const char * name) { struct stat info; lstat(name, &info); return info.st_ino; } dev_t name2device(const char * name) { struct stat info; stat(name, &info); return info.st_dev; } int inode2name(ino_t inode, dev_t device, char * name) { int dircount=0; DIR * dirp=opendir("."); dirent * direntp; struct stat info; stat(".", &info); if (info.st_dev!=device) while (direntp=readdir(dirp)) { stat(direntp->d_name, &info); if (info.st_mode & S_IFDIR) //count how many entries in directory dircount++; if (info.st_dev==device) { //highlight mounting point strcpy(name, "\033[7m"); strcpy(name+strlen(name), direntp->d_name); strcpy(name+strlen(name), "\033[m"); } } else while (direntp=readdir(dirp)) { stat(direntp->d_name, &info); if (info.st_mode & S_IFDIR) dircount++; if (direntp->d_ino==inode) { strcpy(name, direntp->d_name); } } return dircount; } void pwd(ino_t inode, dev_t device) { static int total_count=0; char name[256]; struct stat info; stat("..", &info); if (info.st_ino != inode) { chdir(".."); int count=inode2name(inode, device, name); pwd(info.st_ino, info.st_dev); cout<<"/"<<"{"<