pwdコマンドはinodeを親ディレクトリに辿っていく。ルートディレクトリは. と..が同じinodeを指す。
macbookでls -ia。
$ ls -ia /
2 ./ 31452 Users/
2 ../ 22730 Volumes/
ので.と..のinodeをチェックしながら再帰的に辿るという実装。
void printpathto( ino_t this_inode )
{
ino_t my_inode;
char its_name[BUFSIZ];
if ( get_inode( ".." ) != this_inode )
{
chdir( ".." );
inum_to_name(this_inode, its_name, BUFSIZ);
my_inode = get_inode( "." );
printpathto( my_inode );
printf("/%s",its_name );
}
}