aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-07 14:44:17 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-10-07 14:46:40 +0200
commit267d5318e1cbf69a071b5188dda50310af2f2f8b (patch)
tree9b17035763ab4c69458f28fe37258713c45920a5
parent3a7d758d1d5a9b6499bdc3f75077932ba66f89d7 (diff)
Cleanup: Move padd_file function to libtar
It's only ever used for padding tarballs. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/tar.h8
-rw-r--r--include/util.h7
-rw-r--r--lib/tar/Makemodule.am2
-rw-r--r--lib/tar/padd_file.c (renamed from lib/util/padd_file.c)12
-rw-r--r--lib/tar/write_header.c4
-rw-r--r--lib/util/Makemodule.am3
-rw-r--r--tar/sqfs2tar.c2
7 files changed, 18 insertions, 20 deletions
diff --git a/include/tar.h b/include/tar.h
index d0a483c..e86d775 100644
--- a/include/tar.h
+++ b/include/tar.h
@@ -109,6 +109,8 @@ typedef struct {
#define TAR_MAGIC_OLD "ustar "
#define TAR_VERSION_OLD " "
+#define TAR_RECORD_SIZE (512)
+
/*
Returns < 0 on failure, > 0 if cannot encode, 0 on success.
Prints error/warning messages to stderr.
@@ -130,4 +132,10 @@ int read_header(int fd, tar_header_decoded_t *out);
void clear_header(tar_header_decoded_t *hdr);
+/*
+ Write zero bytes to an output file to padd it to the tar record size.
+ Returns 0 on success. On failure, prints error message to stderr.
+*/
+int padd_file(int outfd, sqfs_u64 size);
+
#endif /* TAR_H */
diff --git a/include/util.h b/include/util.h
index b6102a3..3b1d16b 100644
--- a/include/util.h
+++ b/include/util.h
@@ -89,13 +89,6 @@ SQFS_INTERNAL
int popd(void);
/*
- Write zero bytes to an output file to padd it to specified block size.
- Returns 0 on success. On failure, prints error message to stderr.
-*/
-SQFS_INTERNAL
-int padd_file(int outfd, sqfs_u64 size, size_t blocksize);
-
-/*
Helper for allocating data structures with flexible array members.
'base_size' is the size of the struct itself, 'item_size' the size of a
diff --git a/lib/tar/Makemodule.am b/lib/tar/Makemodule.am
index 42f11ae..129d66f 100644
--- a/lib/tar/Makemodule.am
+++ b/lib/tar/Makemodule.am
@@ -2,7 +2,7 @@ libtar_a_SOURCES = lib/tar/read_header.c lib/tar/write_header.c lib/tar/skip.c
libtar_a_SOURCES += lib/tar/number.c lib/tar/checksum.c lib/tar/cleanup.c
libtar_a_SOURCES += lib/tar/read_sparse_map.c lib/tar/read_sparse_map_old.c
libtar_a_SOURCES += lib/tar/base64.c lib/tar/urldecode.c lib/tar/internal.h
-libtar_a_SOURCES += include/tar.h
+libtar_a_SOURCES += lib/tar/padd_file.c include/tar.h
libtar_a_CFLAGS = $(AM_CFLAGS)
libtar_a_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/lib/util/padd_file.c b/lib/tar/padd_file.c
index 1803139..471370d 100644
--- a/lib/util/padd_file.c
+++ b/lib/tar/padd_file.c
@@ -1,27 +1,25 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
+/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
* padd_file.c
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "config.h"
-
-#include "sqfs/io.h"
-#include "util.h"
+#include "tar.h"
#include <stdlib.h>
#include <stdio.h>
-int padd_file(int outfd, sqfs_u64 size, size_t blocksize)
+int padd_file(int outfd, sqfs_u64 size)
{
- size_t padd_sz = size % blocksize;
+ size_t padd_sz = size % TAR_RECORD_SIZE;
int status = -1;
sqfs_u8 *buffer;
if (padd_sz == 0)
return 0;
- padd_sz = blocksize - padd_sz;
+ padd_sz = TAR_RECORD_SIZE - padd_sz;
buffer = calloc(1, padd_sz);
if (buffer == NULL)
diff --git a/lib/tar/write_header.c b/lib/tar/write_header.c
index 4c8caa2..14802c0 100644
--- a/lib/tar/write_header.c
+++ b/lib/tar/write_header.c
@@ -109,7 +109,7 @@ static int write_gnu_header(int fd, const struct stat *orig,
return -1;
}
- return padd_file(fd, payload_len, 512);
+ return padd_file(fd, payload_len);
}
static size_t num_digits(size_t num)
@@ -152,7 +152,7 @@ static int write_schily_xattr(int fd, const struct stat *orig,
dprintf(fd, "%zu %s%s=%s\n", len, prefix, it->key, it->value);
}
- return padd_file(fd, total_size, 512);
+ return padd_file(fd, total_size);
}
int write_tar_header(int fd, const struct stat *sb, const char *name,
diff --git a/lib/util/Makemodule.am b/lib/util/Makemodule.am
index 58333ac..1ae931b 100644
--- a/lib/util/Makemodule.am
+++ b/lib/util/Makemodule.am
@@ -2,8 +2,7 @@ libutil_la_SOURCES = lib/util/write_data.c
libutil_la_SOURCES += lib/util/read_data.c include/util.h
libutil_la_SOURCES += lib/util/mkdir_p.c include/compat.h
libutil_la_SOURCES += lib/util/str_table.c include/str_table.h
-libutil_la_SOURCES += lib/util/dirstack.c lib/util/padd_file.c
-libutil_la_SOURCES += lib/util/alloc.c
+libutil_la_SOURCES += lib/util/dirstack.c lib/util/alloc.c
libutil_la_SOURCES += lib/util/canonicalize_name.c
libutil_la_CFLAGS = $(AM_CFLAGS)
libutil_la_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/tar/sqfs2tar.c b/tar/sqfs2tar.c
index 331a907..aaef0f7 100644
--- a/tar/sqfs2tar.c
+++ b/tar/sqfs2tar.c
@@ -310,7 +310,7 @@ static int write_tree_dfs(const sqfs_tree_node_t *n)
return -1;
}
- if (padd_file(STDOUT_FILENO, sb.st_size, 512)) {
+ if (padd_file(STDOUT_FILENO, sb.st_size)) {
free(name);
return -1;
}