16 /* Top-level details about a template file */
19 unsigned long long template_size; /* The size of the template file */
20 unsigned long long image_size; /* The size of the output image */
21 time_t template_mtime; /* The mtime of the template file */
22 unsigned char template_name[PATH_MAX]; /* The template file name */
23 unsigned char template_md5[33]; /* MD5 of the template file */
24 unsigned char image_md5[33]; /* MD5 of the image file */
25 } db_template_entry_t;
27 /* Details about the blocks in the template file; each points to a
28 * matched file, or a compressed lump of unmatched data in the
32 BT_FILE = 0, /* md5 pointer to a file */
33 BT_BLOCK /* pointer to a block of data from the template file */
38 unsigned long long image_offset; /* Start offset within the image */
39 unsigned long long size; /* Size of the lump */
40 unsigned long long uncomp_offset; /* Offset within the compressed template
41 data iff type is BT_BLOCK */
42 unsigned char template_id[33]; /* MD5 of the template */
44 unsigned char md5[33]; /* MD5 iff type is BT_FILE */
47 /* Details about files we know about: local mirror, files in a local
48 * ISO image, files listed in the jigdo, etc. */
51 FT_LOCAL = 0, /* We have the file directly-accessible in a local filesystem */
52 FT_ISO, /* We have the file in an ISO image locally */
53 FT_REMOTE, /* File is on a specified mirror */
54 FT_JIGDO /* We need to go to the upstream jigdo mirror site */
59 unsigned long long file_size; /* size of the file in bytes */
60 time_t mtime; /* mtime of the file when we saw it */
61 time_t time_added; /* time when this record was added */
63 unsigned char md5[33]; /* md5sum of the file */
64 char filename[PATH_MAX]; /* path to the file */
65 char extra[PATH_MAX]; /* empty for local files;
66 * path to ISO for local ISO loopbacks;
67 * base URL for remote files*/
70 /* Details about the compressed blocks of unmatched data within the
71 * template file. The data is stored within the template file as a
72 * series of compressed blocks, but we have no way to seek to the
73 * right compressed block; if we want to read from the middle of the
74 * image we have to decompress each in turn. Cache the details of each
75 * block so we can work from an uncompressed offset directly to the
76 * right compressed block. */
79 unsigned long long comp_offset; /* Start offset of this compressed block,
80 measured from the beginning of the
81 template file. NOTE: This is NOT the
82 start of the compressed data itself,
83 but the start of the header! */
84 unsigned long long uncomp_offset; /* Start offset when uncompressed */
85 unsigned long long comp_size; /* Size of the compressed block */
86 unsigned long long uncomp_size; /* Size of uncompressed block */
87 ctype_e comp_type; /* CT_GZIP or CT_BZIP2 */
88 unsigned char template_id[33]; /* MD5 of the template */
89 } db_compressed_entry_t;
97 /* Open/create the database */
98 JIGDB *db_open(char *db_name);
100 /* Close the database */
101 int db_close(JIGDB *dbp);
103 /* Delete ALL the template and compressed block entries for a
104 * specified template file */
105 int db_delete_template_cache(JIGDB *dbp, char *template_name);
107 /* Dump the contents of the DB for debug */
108 int db_dump(JIGDB *dbp);
110 /********************
116 /* Store a template entry */
117 int db_store_template(JIGDB *dbp, db_template_entry_t *entry);
119 /* Lookup a template entry. */
120 int db_lookup_template_by_path(JIGDB *dbp, char *template_name, db_template_entry_t **out);
122 /********************
128 /* Store a template match / non-match block entry */
129 int db_store_block(JIGDB *dbp, db_block_entry_t *entry);
131 /* Lookup a block by output offset. The specified offset will be
132 * within the range covered by the returned entry, or ENOENT. */
133 int db_lookup_block_by_offset(JIGDB *dbp, unsigned long long image_offset,
134 unsigned char *template_id, db_block_entry_t **out);
142 /* Store details of a file */
143 int db_store_file(JIGDB *dbp, db_file_entry_t *entry);
145 /* Lookup a file by md5 */
146 int db_lookup_file_by_md5(JIGDB *dbp, char *md5, db_file_entry_t **out);
148 /* Lookup a file by name */
149 int db_lookup_file_by_name(JIGDB *dbp, char *filename, db_file_entry_t **out);
151 /* Delete a file by name */
152 int db_delete_file_by_name(JIGDB *dbp, char *md5, enum filetype type, char *filename);
154 /* Delete files added previous to a specified date */
155 int db_delete_files_by_age(JIGDB *dbp, time_t date);
157 /* Delete a file entry */
158 int db_delete_file(JIGDB *dbp, char *md5, enum filetype type, char *filename);
160 /****************************
162 * Compressed block functions
164 ***************************/
166 /* Store details of a block */
167 int db_store_compressed(JIGDB *dbp, db_compressed_entry_t *entry);
169 /* Lookup a block by its UNCOMPRESSED offset */
170 int db_lookup_compressed_by_offset(JIGDB *dbp, unsigned long uncomp_offset,
171 unsigned char *template_id, db_compressed_entry_t **out);