Ioctl
This commit is contained in:
parent
04b82dab30
commit
0657191cf0
5 changed files with 143 additions and 0 deletions
40
ioctl_chardev/test.c
Normal file
40
ioctl_chardev/test.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue