/*
* 檔名:mypwd.c
* 描述:實現簡單的pwd命令
*/#include
#include
#include
#include
#include
#include
#include
/*根據檔名獲取檔案inode-number*/
ino_t get_ino_byname(char *filename)
return file_stat.st_ino;
}/*根據inode-number ,在當前目錄中查詢對應的檔名*/
char* find_name_byino(ino_t ino)
else
}closedir(dp);
}return filename;
}/*限制最大的目錄深度*/
#define max_dir_depth (256)
int main(int argc, char *argv)
}/*輸出完整路徑名*/
int i = current_depth-1;
for (i = current_depth-1; i>=0; i--)
fprintf(stdout, "%s\n", current_depth==0?"/":"");
return
0;}
自己寫Linux下的pwd命令
pwd命令用來顯示到達當前目錄的路徑。以下 在opensuse11下編譯通過 結構體dirent儲存目錄的詳細資訊 struct dirent include include include include define bufsize 512 ino t get inode char 從目錄名得到...
pwd 命令實現
最近linux課要考試了,在複習檔案系統。順便就嘗試實現一下pwd命令 這個命令的功能很簡單,就是顯示當前目錄的絕對路徑 key point 由於在linux unix檔案系統中,每個檔案對應的inode值都是唯一的。這個就是我們要尋找的突破點。演算法核心 1.拿到當前目錄中 這個目錄的st ino...
pwd命令的簡單實現
1.linux檔案系統的結構 1 檔案系統的三個區域 不會插入,囧 超級塊,i 節點表,資料區 2 各個區域的作用 a 超級塊 存放檔案系統本身的結構資訊,例如每個區域的大小 b i 節點表 用於存放檔案的的屬性,如大小,檔案所有者和最近修改 時間檔案系統中的每個檔案在該表中都有乙個i節點。c 資料...