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系統程式設計 第二版
298
|
第八章
裝置節點
裝置節點
device node
)是一種特殊檔案,應用程式可以透過它介接裝置驅動程式
device driver)。當應用程式在一個裝置節點上進行平常的 Unix I/O 時—像是開啟、
關閉、讀取、寫入…等等,核心並不會像一般檔案 I/O 那樣來處理這些要求。事實上,
核心會將此類要求傳遞給一個裝置驅動程式。裝置驅動程式會處理該 I/O 操作,以及把
結果傳回給用戶。裝置節點所提供的裝置抽象層,讓應用程式不需要熟悉裝置的具體情
況,甚至不必掌控特殊的介面。的確,在 Unix 系統上,裝置節點是存取硬體的標準機
制。網路裝置是罕見的例外,並且在 Unix 的歷史中,對此例外是否為錯誤有些爭論。
使用
read()
write()
mmap()
等呼叫來操作一個機器的所有硬體,的確具有一種優雅
的美感。
核心如何辨別應該由哪個裝置驅動程式來處理要求?每個裝置節點會被指定兩個數值,
稱為
主要編號
major numbe
r)及
次要編號
minor number
)。這些主要和次要編號會映
射至被載入核心的特定裝置驅動程式。如果一個裝置節點所具有的主要和次要編號並未
映射至核心裡的裝置驅動程式—會因為各種原因突然發生此情況—則裝置節點上的一個
open()
要求,會傳回
-1
並且把
errno
設定為
ENODEV
。於是我們會說,此裝置節點碰上了
不存在的裝置。
特殊裝置節點
特殊裝置節點存在於所有的 Linux 系統之上。這些裝置節點是 Linux 開發環境的一部
分,而且它們的存在被視為 Linux ABI ...
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

AGILE學習手冊 | SCRUM、XP、精實和看板方法

AGILE學習手冊 | SCRUM、XP、精實和看板方法

Andrew Stellman, Jennifer Greene
管理Kubernetes

管理Kubernetes

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

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

George T.Heineman, Gary Pollice, Stanley Selkow

Publisher Resources

ISBN: 9789862769812