From e34bc9a91be456461ae51ac289d85e93b5359bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=EC=98=81?= <choi2054578@ajou.ac.kr> Date: Fri, 3 Jul 2020 20:33:21 +0900 Subject: [PATCH] Add new file --- gas_app.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 gas_app.c diff --git a/gas_app.c b/gas_app.c new file mode 100644 index 0000000..038cf35 --- /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; +} -- GitLab