summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérôme Glisse <jglisse@redhat.com>2017-08-03 18:31:02 -0400
committerJérôme Glisse <jglisse@redhat.com>2017-08-04 17:38:07 -0400
commita471504e4bb164d72d2bb02119cac40b8306a8ce (patch)
tree2b8ded10e1b3e26ba2037e9d4a73d54cc1f63a3b
parentf3fcb56f6007d94b72246918562950f57ae34f87 (diff)
compote: basic infrastructure to test compote module
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
-rw-r--r--Makefile18
-rw-r--r--compote.c76
-rw-r--r--compote.h26
-rwxr-xr-xmkdev.sh9
4 files changed, 129 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8573309
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,18 @@
+# Copyright 2017 Jérôme Glisse <jglisse@redhat.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+CFLAGS = -std=c99 -Wall -O0 -g -D_GNU_SOURCE
+LFLAGS = -lm
+CC = gcc
+
+all: compote
+
+compote: compote.o
+ $(CC) $(CFLAGS) $< -o $@
diff --git a/compote.c b/compote.c
new file mode 100644
index 0000000..1267118
--- /dev/null
+++ b/compote.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2017 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Authors: Jérôme Glisse <jglisse@redhat.com>
+ */
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <strings.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "compote.h"
+
+
+int compote_context_new(compote_context_t **ctxp)
+{
+ compote_context_t *ctx;
+ int fd;
+
+ fd = open("/dev/compote", O_RDWR, 0);
+ if (fd < 0) {
+ fprintf(stderr, "could not open compote device\n");
+ return -ENODEV;
+ }
+
+ ctx = calloc(1, sizeof(*ctx));
+ if (ctx == NULL) {
+ close(fd);
+ return -ENOMEM;
+ }
+
+ ctx->fd = fd;
+
+ *ctxp = ctx;
+ return 0;
+}
+
+void compote_context_del(compote_context_t **ctxp)
+{
+ compote_context_t *ctx = *ctxp;
+
+ *ctxp = NULL;
+ close(ctx->fd);
+ free(ctx);
+}
+
+int main(int argc, char *argv[])
+{
+ compote_context_t *ctx;
+ int ret;
+
+ ret = compote_context_new(&ctx);
+ if (ret) {
+ return ret;
+ }
+
+ printf("La compote c'est bon !\n");
+
+ compote_context_del(&ctx);
+ return 0;
+}
diff --git a/compote.h b/compote.h
new file mode 100644
index 0000000..f2ea929
--- /dev/null
+++ b/compote.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Authors: Jérôme Glisse <jglisse@redhat.com>
+ */
+#ifndef COMPOTE_H
+#define COMPOTE_H
+
+typedef struct {
+ int fd;
+} compote_context_t;
+
+int compote_context_new(compote_context_t **ctxp);
+void compote_context_del(compote_context_t **ctxp);
+
+#endif // COMPOTE_H
diff --git a/mkdev.sh b/mkdev.sh
new file mode 100755
index 0000000..fe52d0e
--- /dev/null
+++ b/mkdev.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+sync
+# device0
+rm -f /dev/compote
+major=$(awk "\$2==\"compote\" {print \$1}" /proc/devices)
+echo compote major is $major
+mknod /dev/compote c $major 0
+chgrp wheel /dev/compote
+chmod 664 /dev/compote