[gcab] Add header reserve space for signing
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcab] Add header reserve space for signing
- Date: Tue, 12 Feb 2013 16:52:25 +0000 (UTC)
commit 20d27126f03f63acf376005c35ad907e5883f08f
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Tue Feb 12 17:50:50 2013 +0100
Add header reserve space for signing
gcab.1.in | 3 +++
gcab.c | 9 +++++++++
libgcab/cabinet.c | 11 +++++++++++
libgcab/gcab-cabinet.c | 13 +++++++++++--
4 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/gcab.1.in b/gcab.1.in
index 3f0e7f0..f4f0261 100644
--- a/gcab.1.in
+++ b/gcab.1.in
@@ -24,6 +24,9 @@ create files without pathnames
\fB\-C, --directory DIR\fR
change or extract to directory DIR
.TP
+\fB\-s, --space\fR
+Reserve space in cabinet for signing (e.g. -s 6144 reserves 6K bytes)
+.TP
\fB\-v, --verbose\fR
verbosely list files processed
.TP
diff --git a/gcab.c b/gcab.c
index b99cce6..9fa86bf 100644
--- a/gcab.c
+++ b/gcab.c
@@ -77,6 +77,7 @@ main (int argc, char *argv[])
gchar *change = NULL;
int version = 0;
int nopath = 0;
+ int space = 0;
int compress = 0;
int list = 0;
int create = 0;
@@ -90,6 +91,7 @@ main (int argc, char *argv[])
{ "directory", 'C', 0, G_OPTION_ARG_FILENAME, &change, N_("Change to directory DIR"), N_("DIR") },
{ "zip", 'z', 0, G_OPTION_ARG_NONE, &compress, N_("Use zip compression"), NULL },
{ "nopath", 'n', 0, G_OPTION_ARG_NONE, &nopath, N_("Do not include path"), NULL },
+ { "space", 's', 0, G_OPTION_ARG_INT, &space, N_("Reserve space in cabinet for signing (e.g. -s 6144 reserves 6K bytes)"), NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, N_("FILE INPUT_FILES...") },
{ NULL }
};
@@ -171,6 +173,13 @@ individual files from the archive.\
if (args[1] == NULL)
gcab_error (_("please specify input files."));
+ if (space) {
+ GByteArray *reserved = g_byte_array_sized_new (space);
+ g_byte_array_set_size (reserved, space);
+ g_object_set (cabinet, "reserved", reserved, NULL);
+ g_byte_array_unref (reserved);
+ }
+
folder = gcab_folder_new (compress ? GCAB_COMPRESSION_MSZIP : 0);
for (i = 1; args[i]; i++) {
diff --git a/libgcab/cabinet.c b/libgcab/cabinet.c
index 518026c..cdcd4dd 100644
--- a/libgcab/cabinet.c
+++ b/libgcab/cabinet.c
@@ -157,6 +157,8 @@ G_GNUC_INTERNAL gboolean
cheader_write (cheader_t *ch, GDataOutputStream *out,
GCancellable *cancellable, GError **error)
{
+ GOutputStream *stream = g_filter_output_stream_get_base_stream (G_FILTER_OUTPUT_STREAM (out));
+
if (!W1 ('M') || !W1 ('S') || !W1 ('C') || !W1 ('F') ||
!W4 (ch->res1) ||
!W4 (ch->size) ||
@@ -172,6 +174,15 @@ cheader_write (cheader_t *ch, GDataOutputStream *out,
!W2 (ch->cabID))
return FALSE;
+ if (ch->flags & CABINET_HEADER_RESERVE) {
+ W2 (ch->res_header);
+ W1 (ch->res_folder);
+ W1 (ch->res_data);
+ if (g_output_stream_write (stream, ch->reserved, ch->res_header,
+ cancellable, error) == -1)
+ return FALSE;
+ }
+
return TRUE;
}
diff --git a/libgcab/gcab-cabinet.c b/libgcab/gcab-cabinet.c
index e5f10ce..ec50a93 100644
--- a/libgcab/gcab-cabinet.c
+++ b/libgcab/gcab-cabinet.c
@@ -209,12 +209,21 @@ gcab_cabinet_write (GCabCabinet *self,
dstream = g_data_output_stream_new (out);
g_data_output_stream_set_byte_order (dstream, G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN);
+ if (self->reserved) {
+ header.offsetfiles += self->reserved->len + 4;
+ header.flags = CABINET_HEADER_RESERVE;
+ header.res_header = self->reserved->len;
+ header.res_folder = 0;
+ header.res_data = 0;
+ header.reserved = self->reserved->data;
+ }
+
files = gcab_folder_get_files (cabfolder);
for (l = files; l != NULL; l = l->next)
sumstr += strlen (GCAB_FILE (l->data)->name) + 1;
folder.typecomp = cabfolder->comptype;
- folder.offsetdata = CFI_START + nfiles * 16 + sumstr;
+ folder.offsetdata = header.offsetfiles + nfiles * 16 + sumstr;
folder.ndatab = gcab_folder_get_ndatablocks (cabfolder);
/* avoid seeking to allow growing output streams */
@@ -257,7 +266,7 @@ gcab_cabinet_write (GCabCabinet *self,
goto end;
header.nfiles = nfiles;
- header.size += CFI_START + nfiles * 16; /* 1st part cfile struct = 16 bytes */
+ header.size += header.offsetfiles + nfiles * 16; /* 1st part cfile struct = 16 bytes */
header.size += sumstr;
if (!cheader_write (&header, dstream, cancellable, error))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]