Skip to Content
LINUX系統程式設計 第二版
book

LINUX系統程式設計 第二版

by Robert Love
December 2013
Intermediate to advanced
496 pages
8h 57m
Chinese
GoTop Information, Inc.
Content preview from LINUX系統程式設計 第二版
46
|
第二章
EIO
同步期間發生了一個低階的 I/O 錯誤。這代表一個真正的 I/O 錯誤,而且往往出現在
會發生此類錯誤的地方。
在某些 Linux 版本中,叫用
fsync()
或許會失敗,因為背後的檔案系統可能並未實作
fsync()
,即使它有實作
fdatasync()
。如果
fsync()
傳回
EINVAL
,有此疑慮的應用程式可
能會想嘗試
fdatasync()
。例如:
if (fsync (fd) ==
1) {
/*
* 我們偏好 fsync(),但是如果 fsync() 失敗了,
* 讓我們試試 fdatasync()
*/
if (errno == EINVAL) {
if (fdatasync (fd) ==
1)
perror ("fdatasync");
} else
perror ("fsync");
}
因為 POSIX 需要
fsync()
,而
fdatasync()
只是一個選項,所以任何一般的 Linux 檔案系
統,總是應該為正規檔案實作
fsync()
系統呼叫。然而,老舊的檔案型態(或許沒有中
介資料需要同步)或奇怪的檔案系統可能只會實作
fdatasync()
sync()
雖然不是最理想的,但是應用範圍較廣的老式
sync()
系統呼叫,可讓
所有
緩衝區與磁碟
同步:
#include <unistd.h>
void sync (void);
此函式不需要參數,也沒有傳回值。它總是能成功並且返回,所有的緩衝區(包括資料
和中介資料)保證都會寫回磁碟。
4
標準並不要求
sync()
必須等到所有緩衝區全都出清到磁碟才返回;標準只要求該呼叫, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

優雅的SciPy|Python科學研究的美學

優雅的SciPy|Python科學研究的美學

Juan Nunez-Iglesias, Stéfan van der Walt, Harriet Dashnow
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9789862769812