在Posix中如何使用dev_t类型? [英] In Posix how is type dev_t getting used?

查看:130
本文介绍了在Posix中如何使用dev_t类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所追求的是这种类型的含义以及可以使用它的接口.

在Posix规范中解释了dev_t用于设备ID.但是,对于路径描述的任何对象,什么设备ID意味着什么,该对象可以是文件,Direction,FIFO或物理设备?

例如,调用stat()将为您提供一个包含此类成员的结构;并且您可以在文件系统中统计任何种类的对象.然后,对于不同的文件类型,设备ID应该具有不同的含义.

解决方案

dev_t在绝大多数程序(可移植且未连接至单个OS的程序)中的唯一用途是确定两个文件名或文件描述符引用相同的基础文件.当且仅当两个文件的stat结构的st_inost_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆