C read():无效的参数

时间:2017-05-02 09:20:29

标签: c linux

我正在尝试从功能read()

的nbd设备中读取

以下是代码:

static uint64_t hash_log_free_list;
int fd = open(argv[2], O_RDWR|O_LARGEFILE);
assert(fd != -1);
int err = read(fd, &hash_log_free_list, sizeof(uint64_t));
if (err != sizeof(uint64_t))
{
    MSGDEBUG

    perror("read");
    printf("err: %d\n", err);
    abort();
}

argv [2]是一个nbd设备:/ dev / nbd0

MSGDEBUG 定义为打印__FILE __,_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 我收到错误消息:

  

错误!!! dedup.c:554:主读:无效参数错误:0   中止

我做错了吗?

1 个答案:

答案 0 :(得分:1)

read返回0,这不是错误,它只是告诉您没有什么可读的。

您可以在致电MSGDEBUG之前使用errno / perror,以确保其中包含实际数据。

另外,删除MSGDEBUG行,因为它打印的内容很可能同时更改read,因此您的setState({'i':i})可能会向您提供有关内容的信息。 {{1}},而不是之前的{{1}}。

相关问题