2013-12-21 90 views
0

鑑於在Linux中utimes(2)是一個系統調用,而futimes(3)是一個庫函數,我認爲futimes是根據utimes實現的。但是,utimes需要路徑名,而futimes需要文件描述符如何按照utimes來實現futimes?

因爲,它是「不可能的」,確定從文件描述符i節點號我不知道一個路徑這可怎麼辦呢? 「真實」系統調用是否始終在i-node號碼上工作?

回答

0

首先,您可能錯誤地提到了Posix,因爲後者沒有區別系統調用和庫函數。將futimes()放到庫調用中是Linux特有的。在glibc的(文件sysdeps/UNIX/SYSV/LINUX/futimes.c),存在評論:

/* Change the access time of the file associated with FD to TVP[0] and 
    the modification time of FILE to TVP[1]. 

    Starting with 2.6.22 the Linux kernel has the utimensat syscall which 
    can be used to implement futimes. Earlier kernels have no futimes() 
    syscall so we use the /proc filesystem. */ 

所以,這是使用utimensat()與指定的描述作爲參考之一作爲全部完成*在()調用。以前,這個工作使用utimes()作爲/ proc/$ {pid}/fd/$ {fd}路徑(太麻煩了,只有掛載/ proc時)。這是對第二個問題的回覆:儘管通常不可能從其描述符中檢測到文件名,但仍然可以單獨訪問該文件。 (順便說一下,有時會存儲用於打開文件的初始路徑;請參閱/ proc/$ pid/{cwd,exe})。 )系統調用(但我不知道爲什麼後者沒有命名爲「utimesat」)。