diff --git a/gas_app.c b/gas_app.c new file mode 100644 index 0000000000000000000000000000000000000000..038cf359ef761f807a249c0b7eee00ff9510fcef --- /dev/null +++ b/gas_app.c @@ -0,0 +1,51 @@ +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> + +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/sysmacros.h> + + +#define GAS_MAJOR_NUMBER 505 +#define GAS_MINOR_NUMBER 100 +#define GAS_DEV_PATH_NAME "/dev/gas_ioctl" + +#define IOCTL_MAGIC_NUMBER 'g' +#define IOCTL_CMD_GAS_ON _IO(IOCTL_MAGIC_NUMBER, 0) +#define IOCTL_CMD_GAS_OFF _IO(IOCTL_MAGIC_NUMBER, 1) + +int main(void) { + dev_t gas_dev; + int fd; + gas_dev = makedev(GAS_MAJOR_NUMBER, GAS_MINOR_NUMBER); + mknod(GAS_DEV_PATH_NAME, S_IFCHR | 0666, gas_dev); + + + fd = open(GAS_DEV_PATH_NAME, O_RDWR); + + if (fd < 0) { + printf("fail to open gas\n"); + return -1; + } + + int i = 0; + + while (i < 100) { + if (ioctl(fd, IOCTL_CMD_GAS_ON, 0) == 0) { + printf("gas on\n"); + sleep(1); + i++; + } + else + printf("no gas\n"); + sleep(1); + i++; + } + + close(fd); + return 0; +}