@@ -77,8 +77,8 @@ static int fill_buffer(int fd, unsigned char *buf, unsigned int nbytes, unsigned
}
/*
- * Export this to be used in other modules
- * It just copy a buffer to a file
+ * Export the copy_write{,_*} functions to be used in other modules
+ * for copying a buffer to a file.
*/
int copy_write(void *out, const void *buf, unsigned int len)
{
@@ -107,6 +107,31 @@ int copy_write(void *out, const void *buf, unsigned int len)
return 0;
}
+#if defined(__FreeBSD__)
+/*
+ * FreeBSD likes to have multiples of 512 bytes written
+ * to a device node, hence slice the buffer in palatable
+ * chunks assuming that only the last written buffer's
+ * length is smaller than cpio_utils.c's CPIO_BUFFER_SIZE and
+ * doesn't satisfy length % 512 == 0.
+ */
+int copy_write_padded(void *out, const void *buf, unsigned int len)
+{
+ if (len % 512 == 0) {
+ return copy_write(out, buf, len);
+ }
+
+ uint8_t buffer[512] = { 0 };
+ int chunklen = len - (len % 512);
+ int res = copy_write(out, buf, chunklen);
+ if (res != 0) {
+ return res;
+ }
+ memcpy(&buffer, buf+chunklen, len-chunklen);
+ return copy_write(out, buffer, 512);
+}
+#endif
+
/*
* Pipeline description
*
@@ -23,31 +23,6 @@
void raw_handler(void);
void raw_filecopy_handler(void);
-#if defined(__FreeBSD__)
-/*
- * FreeBSD likes to have multiples of 512 bytes written
- * to a device node, hence slice the buffer in palatable
- * chunks assuming that only the last written buffer's
- * length is smaller than cpio_utils.c's BUFF_SIZE and
- * doesn't satisfy length % 512 == 0.
- */
-static int copy_write_padded(void *out, const void *buf, unsigned int len)
-{
- if (len % 512 == 0) {
- return copy_write(out, buf, len);
- }
-
- uint8_t buffer[512] = { 0 };
- int chunklen = len - (len % 512);
- int res = copy_write(out, buf, chunklen);
- if (res != 0) {
- return res;
- }
- memcpy(&buffer, buf+chunklen, len-chunklen);
- return copy_write(out, buffer, 512);
-}
-#endif
-
static int install_raw_image(struct img_type *img,
void __attribute__ ((__unused__)) *data)
{
@@ -156,6 +156,9 @@ typedef int (*writeimage) (void *out, const void *buf, unsigned int len);
int openfile(const char *filename);
int copy_write(void *out, const void *buf, unsigned int len);
+#if defined(__FreeBSD__)
+int copy_write_padded(void *out, const void *buf, unsigned int len);
+#endif
int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs,
unsigned long long seek,
int skip_file, int compressed, uint32_t *checksum,
Shift copy_write_padded() from raw_handler.c to cpio_utils.c so that other handlers may use it as well, just like cpio_utils.c's copy_write(). Signed-off-by: Christian Storm <christian.storm@siemens.com> --- core/cpio_utils.c | 29 +++++++++++++++++++++++++++-- handlers/raw_handler.c | 25 ------------------------- include/util.h | 3 +++ 3 files changed, 30 insertions(+), 27 deletions(-)