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系統程式設計 第二版
146
|
第四章
return 1;
}
fd = open (argv[1], O_RDONLY);
if (fd < 0) {
perror ("open");
return 1;
}
print_blocks (fd);
return 0;
}
因為檔案往往是連續的,所以很難按照邏輯區塊來排序我們的 I/O 要求,比較有意義
的做法是按照所指定檔案之第一個邏輯區塊的位置來排序。於是,不需要用到
get_nr_
blocks()
,而且我們的應用程式可以根據:
get_block (fd, 0);
的傳回值來進行排序。
FIBMAP
的缺點是需要
CAP_SYS_RAWIO
的能力—也就是,需要 root
的特權。因此,不具 root 特權的應用程式無法採用這個方法。此外,儘管
FIBMAP
命令已
經標準化,但是它的實作則留給檔案系統自己來完成。儘管一些常見的檔案系統(例如
ext2
ext3
)都會支援它,不過一些比較少見的檔案系統可能不會支援它。如果
FIBMAP
未受支援,
ioctl()
呼叫將傳回
EINVAL
然而,這個方法的一個優點是,它會傳回特定檔案所在之
實體
磁碟區塊,也就是你實際
想排序的東西。即使你只是根據一個區塊的位置來排序針對單一檔案的所有 I/O(核心
I/O 排班器是以逐區塊的方式來排序每個要求),此方法仍舊非常接近理想的順序。
然而,因為這個方法需要用到 root 的特權,所以對許多人來說似乎有點不切實際。
結語
在接連這三章的課程中,我們觸及了 Linux 中檔案 I/O 的所有面向。第 ...
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

深入理解運算原理|從簡單的機器到無所不能的程式

深入理解運算原理|從簡單的機器到無所不能的程式

Tom Stuart
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
算法技术手册(原书第2 版)

算法技术手册(原书第2 版)

George T.Heineman, Gary Pollice, Stanley Selkow

Publisher Resources

ISBN: 9789862769812