在Posix中如何使用dev_t类型? [英] In Posix how is type dev_t getting used?
问题描述
我所追求的是这种类型的含义以及可以使用它的接口.
在Posix规范中解释了dev_t
用于设备ID.但是,对于路径描述的任何对象,什么设备ID意味着什么,该对象可以是文件,Direction,FIFO或物理设备?
例如,调用stat()
将为您提供一个包含此类成员的结构;并且您可以在文件系统中统计任何种类的对象.然后,对于不同的文件类型,设备ID应该具有不同的含义.
dev_t
在绝大多数程序(可移植且未连接至单个OS的程序)中的唯一用途是确定两个文件名或文件描述符引用相同的基础文件.当且仅当两个文件的stat
结构的st_ino
和st_dev
条目彼此匹配时,才如此.
基本上,st_dev
告诉文件位于哪个设备"(例如,已安装的分区,网络共享等),并且st_ino
是单个设备上下文中文件的唯一标识符.
What I am after is the meaning of such type and what interface can use it.
It is explained in Posix spec that dev_t
is used for device IDs. However, what device id means for any object described by a path, which can be a file, a directy, a fifo or a physical device?
For example, calling stat()
shall give you a struct including a member of such type; and you can stat any kinds of object in your file system. The device id should have different meanings for different file types then.
The only use of dev_t
in the vast majority of programs (ones which are portable and not connected to a single OS) is to determine that two file names or file descriptors refer to the same underlying file. This is true if and only if the st_ino
and st_dev
entries for the two files' stat
structures match one another.
Basically, st_dev
tells which "device" (e.g. mounted partition, network share, etc.) the file resides on, and st_ino
is a unique identifier of the file within the context of a single device.
这篇关于在Posix中如何使用dev_t类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!