私の仕事は、C で inode を使用して Unix コマンドを実装するpwd
ことです。「..」の inode が「.」の inode と同じになるまで、再帰的に戻る方法を見つけました。私が今抱えている問題は、「..」のディレクトリ名を取得する方法がわからないことです。stat 構造体を使用すると、サイズ、inode などのファイルに関するすべてを取得できますが、次のような出力を作成できるようにファイルを取得する必要があります。
/home/GONZAGA/tcosentino/documents/OS
これらのディレクトリ名を取得するにはどうすればよいですか?
私は stat 構造体を持っているので、これまでのところこれを出力できます:
[tcosentino@ada2 OS]$ ./a.out .
filename: .
device: 64768
inode: 55804237
protection: 40755
number of hard links: 5
user ID of owner: 81963576
group ID of owner: 501
device type (if inode device): 0
total size, in bytes: 4096
blocksize for filesystem I/O: 4096
number of blocks allocated: 8
time of last access: 1354817261 : Thu Dec 6 10:07:41 2012
time of last modification: 1354817249 : Thu Dec 6 10:07:29 2012
time of last change: 1354817249 : Thu Dec 6 10:07:29 2012