`off_t` 之前的预期表达式

Expected expression before `off_t`

我正在尝试使用 c 发送 trim 命令,我根据这个答案找到了执行此操作的方法:how to TRIM a block on SSD disk?.

编译我正在使用的程序

gcc -D_GNU_SOURCE MyCode.c

但我收到以下错误:

TrimCommandsSenders.c:8:37: error: expected expression before ‘off_t’ #define IOCATADELETE _IOW('a', 104, off_t[2])

我做错了什么?

这是我使用的完整代码:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


//header - may already be defined
#define IOCATADELETE _IOW('a', 104, off_t[2])

int main(){
    //code
    int fd = open("/dev/nvme0n1", O_RDWR | O_DIRECT);
    off_t ioarg[2];
    ioarg[0] = 512; //block number
    ioarg[1] = 512; //size
    ioctl(fd, IOCATADELETE, ioarg);
    close(fd);
    return 0;
}

更新

考虑到评论,我已将我的代码更新为以下内容:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


off_t arr[2];
#define IOCATADELETE _IOW('a', 104, arr)

int main(){
    int fd = open("/dev/nvme0n1", O_RDWR | O_DIRECT);
    off_t my_ioarg[2];
    my_ioarg[0] = 512; //block number
    my_ioarg[1] = 512; //size
    ioctl(fd, IOCATADELETE, my_ioarg);
    close(fd);
    return 0;
}

我收到以下错误:

Undefined reference to "_IOW"

感谢任何帮助。

编译器产生的错误告诉你宏 _IOW 没有定义。

此宏及其用于生成 ioctl 命令编号的相关宏在 header“/usr/include/asm/ioctl.h”中定义。

包含此 header 以解决问题。

有关详细信息,请参阅 http://www.circlemud.org/jelson/software/fusd/docs/node31.html