linux 如何得到设备文件的设备号(主设备号&次设备号)

本文介绍了如何在Linux系统中通过stat系统调用获取设备文件的设备号,包括主设备号和次设备号。利用<sys/stat.h>头文件中的stat结构体,结合<linux/kdev_t.h>中的MAJOR()和MINOR()宏,可以方便地提取所需信息。
摘要由CSDN通过智能技术生成

使用stat (/usr/include/sys/stat.h)系统调用,接口如下:

 stat (__const char *__path, struct stat *__statbuf)


得到的信息在stat结构体中:

struct stat
  {
    __dev_t st_dev;		/* Device.  */
#if __WORDSIZE == 32
    unsigned short int __pad1;
#endif
#if __WORDSIZE == 64 || !defined __USE_FILE_OFFSET64
    __ino_t st_ino;		/* File serial number.	*/
#else
    __ino_t __st_ino;			/* 32bit file serial number.	*/
#endif
#if __WORDSIZE == 32
    __mode_t st_mode;			/* File mode.  */
    __nlink_t st_nlink;			/* Link count.  */
#else
    __nlink_t st_nlink;		/* Link count.  */
    __mode_t st_mode;		/* File mode.  */
#endif
    __uid_t st_uid;		/* User ID of the file's owner.	*/
    __gid_t st_gid;		/* Group ID of the file's group.*/
#if __WORDSIZE == 64
    int pad0;
#endif
    __dev_t st_rdev;		/* Device number, if device.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值