kernelmod_demo/ioctl_chardev/test.c
2026-02-24 13:49:54 +01:00

40 lines
581 B
C

#include <stdio.h>
// #include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/ioctl.h>
#include <sys/ioctl.h>
#include "my-ioctl.h"
int main(int argc, char **argv)
{
int fd;
if (argc < 2) {
printf("I need the file to open as an argument!\n");
return 0;
}
fd = open(argv[1], O_RDWR);
if (fd < 0) {
perror("open");
return 1;
}
if (ioctl(fd, MY_IOCTL_FILL)) {
perror("ioctl");
close(fd);
return 1;
}
if (ioctl(fd, MY_IOCTL_WIPE)) {
perror("ioctl");
close(fd);
return 1;
}
printf("ioctl successful\n");
close(fd);
return 0;
}