zoukankan      html  css  js  c++  java
  • C lstat major MAJOR 获得设备号

    #cat lstat.c
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>
    #include <stdio.h>
    #include <string.h>
    
    
    #define MINORBITS   20
    #define MINORMASK   ((1U << MINORBITS) - 1)
    #define MAJOR(dev)  ((unsigned int) ((dev) >> MINORBITS))
    #define MINOR(dev)  ((unsigned int) ((dev) & MINORMASK))
    
    int main(void)
    {
    
    	struct stat buf;
    
    	lstat("/dev/sdc", &buf);
    
    	int a = MAJOR(buf.st_dev);
    	int b = MINOR(buf.st_dev);
    
    	int c = MAJOR(buf.st_rdev);
    	int d = MINOR(buf.st_rdev);
    
    	int e = major(buf.st_rdev);
    	int f = minor(buf.st_rdev);
    
    	int g = major(buf.st_dev);
    	int h = minor(buf.st_dev);
    	printf("st_dev MAJOR:%d, MINOR:%d
    ", a, b);
    	printf("st_rdev MAJOR:%d, MINOR:%d
    ", c, d);
    	printf("st_dev major:%d, minor:%d
    ", g, h);
    	printf("st_rdev major:%d, minor:%d
    ", e, f);
    
    
    	return 0;
    
    }
    
    
    #./lstat
    st_dev MAJOR:0, MINOR:5
    st_rdev MAJOR:0, MINOR:2080
    st_dev major:0, minor:5
    st_rdev major:8, minor:32
    
    
    
  • 相关阅读:
    磁盘管理
    TCP/IP四层模型
    OSI七层模型详解
    kvm虚拟机
    mount 文件挂载
    ORA-01017: 用户名/口令无效; 登录被拒绝
    mybatis配置文件形式
    Spring+mybatis整合
    xmlBean学习二
    xmlBean学习一
  • 原文地址:https://www.cnblogs.com/muahao/p/8258026.html
Copyright © 2011-2022 走看看