19
19
#include <string.h>
20
20
#include <stdlib.h>
21
21
#include <errno.h>
22
+ #include <unistd.h>
22
23
23
24
#include "genimage.h"
24
25
@@ -68,6 +69,7 @@ static int rauc_generate(struct image *image)
68
69
struct image * child = image_get (part -> image );
69
70
const char * file = imageoutfile (child );
70
71
const char * target = part -> name ;
72
+ char * tmptarget ;
71
73
char * path , * tmp ;
72
74
73
75
if (part -> partition_type == RAUC_CERT )
@@ -105,10 +107,34 @@ static int rauc_generate(struct image *image)
105
107
goto out ;
106
108
}
107
109
108
- image_info (image , "adding file '%s' as '%s' ...\n" ,
109
- child -> file , target );
110
- ret = systemp (image , "cp --remove-destination '%s' '%s/%s'" ,
111
- file , tmpdir , target );
110
+ xasprintf (& tmptarget , "%s/%s" , tmpdir , target );
111
+
112
+ image_info (image , "adding file '%s' as '%s' (offset=%lld)...\n" ,
113
+ child -> file , target , (long long )part -> imageoffset );
114
+
115
+ if (part -> imageoffset ) {
116
+ unlink (tmptarget );
117
+
118
+ /*
119
+ * Starting with coreutils 9.1 you can use a 'B' suffix for
120
+ * skip=N instead of iflag=skip_bytes to have N count bytes, not
121
+ * (input) blocks.
122
+ *
123
+ * Note that dd doesn't behave as optimal as cp in the
124
+ * else branch below because it doesn't preserve holes.
125
+ * To improve here insert_image() should be extended to
126
+ * support part->imageoffset != 0 and then it can
127
+ * replace both commands.
128
+ */
129
+ ret = systemp (image , "dd if='%s' of='%s' iflag=skip_bytes skip=%lld" ,
130
+ file , tmptarget , (long long )part -> imageoffset );
131
+
132
+ } else {
133
+ ret = systemp (image , "cp --remove-destination '%s' '%s'" ,
134
+ file , tmptarget );
135
+ }
136
+
137
+ free (tmptarget );
112
138
if (ret )
113
139
goto out ;
114
140
}
@@ -193,6 +219,7 @@ static int rauc_parse(struct image *image, cfg_t *cfg)
193
219
part = xzalloc (sizeof * part );
194
220
part -> name = cfg_title (filesec );
195
221
part -> image = cfg_getstr (filesec , "image" );
222
+ part -> imageoffset = cfg_getint_suffix (filesec , "offset" );
196
223
part -> partition_type = RAUC_CONTENT ;
197
224
list_add_tail (& part -> list , & image -> partitions );
198
225
}
@@ -219,6 +246,7 @@ static int rauc_setup(struct image *image, cfg_t *cfg)
219
246
220
247
static cfg_opt_t file_opts [] = {
221
248
CFG_STR ("image" , NULL , CFGF_NONE ),
249
+ CFG_STR ("offset" , "0" , CFGF_NONE ),
222
250
CFG_END ()
223
251
};
224
252
0 commit comments