Started work on JD interface
authorSteve McIntyre <steve@einval.com>
Thu, 26 May 2005 23:24:31 +0000 (23:24 +0000)
committerSteve McIntyre <steve@einval.com>
Thu, 26 May 2005 23:24:31 +0000 (23:24 +0000)
Makefile
jd_interface.c [new file with mode: 0644]

index f98fd62..29ed48c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ all: $(BINS)
 DB_OBJ=jigdb-sql.o
 DBLIB=-lsqlite3
 
-mkimage: mkimage.o endian.o md5.o parse_jigdo.o parse_template.o decompress.o $(DB_OBJ)
+mkimage: mkimage.o endian.o md5.o parse_jigdo.o parse_template.o decompress.o jd_interface.o $(DB_OBJ)
        $(CC) -o $@ $+ -lz -lbz2 $(DBLIB)
 
 jigsum: jigsum.o md5.o $(DB_OBJ)
diff --git a/jd_interface.c b/jd_interface.c
new file mode 100644 (file)
index 0000000..c22c08a
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * jd_interface.c
+ *
+ * Interfaces for building an ISO image, using the data stored in the DB
+ *
+ * Copyright (c) 2005 Steve McIntyre <steve@einval.com>
+ *
+ * GPL v2 - see COPYING
+ */
+
+#include <errno.h>
+#include <math.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include "endian.h"
+#include "jigdb.h"
+#include "jte.h"
+
+typedef struct _jd_state
+{
+    char *template_filename;
+    FILE *template;
+} jd_state_t;
+
+JD *jd_open(char *template_file)
+{
+    jd_state_t *jd = NULL;
+    
+    jd = calloc(1, sizeof(jd_state_t));
+    if (!jd)
+    {
+        errno = ENOMEM;
+        return NULL;
+    }
+    
+    jd->template_filename = template_file;
+    jd->template = fopen(template_file, "rb");
+    if (!jd->template)
+    {
+        free(jd);
+        return NULL;
+    }
+
+    return jd;
+}
+
+int jd_close(JD *state)
+{
+    jd_state_t *jd = state;
+    
+    if (jd)
+    {
+        if (jd->template)
+            fclose(jd->template);
+        free(jd);
+    }
+    return 0;
+}
+
+int jd_md5(JD *state, unsigned char md5[16]);
+
+int jd_read(JD *state, INT64 start_offset, INT64 length, unsigned char *buffer, INT64 *bytes_read);
+int jd_size(JD *state, INT64 *size);
+int jd_last_filename(JD *state, char **name);