linux stat 设备号,Linux stat(2)调用给出了不存在的设备ID

stat.c(建有cc stat.c -o stat)

#include

#include

#include

#include

#include

#include

#include

int main()

{

char *path = "/home/smoku/test.txt";

unsigned int maj, min;

struct stat sb;

if (stat(path, &sb) < 0) {

fprintf(stderr, "Error getting stat for '%s': %d %s\n", path, errno, strerror(errno));

return 1;

}

maj = major(sb.st_dev);

min = minor(sb.st_dev);

fprintf(stderr, "Found '%s' => %u:%u\n", path, maj, min);

return 0;

}

得到0:44

$ ls -l /home/smoku/test.txt

-rw-r--r-- 1 smoku smoku 306 08-30 09:33 /home/smoku/test.txt

$ ./stat

Found '/home/smoku/test.txt' => 0:44

$ /usr/bin/stat -c "%d" /home/smoku/test.txt

44

但是......有我的系统中没有这样的设备和/home是0:35

$ grep /home /proc/self/mountinfo

75 59 0:35 /home /home rw,relatime shared:30 - btrfs /dev/bcache0 rw,ssd,space_cache,subvolid=258,subvol=/home

为什么我能得到一个设备ID吗? es在我的系统中不存在?

2016-09-14

smoku

+2

你检查什么'stat'回报?它不会返回失败('-1')? –

+0

@JoachimPileborg ...它最有可能的... –

+0

是的,我做到了。这只是真实节目的摘录。 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值