aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/sqfs2tar/sqfs2tar.c22
-rw-r--r--bin/sqfs2tar/sqfs2tar.h3
-rw-r--r--bin/sqfs2tar/write_tree.c31
3 files changed, 32 insertions, 24 deletions
diff --git a/bin/sqfs2tar/sqfs2tar.c b/bin/sqfs2tar/sqfs2tar.c
index 305bd4b..aa2a5b7 100644
--- a/bin/sqfs2tar/sqfs2tar.c
+++ b/bin/sqfs2tar/sqfs2tar.c
@@ -9,7 +9,6 @@
sqfs_xattr_reader_t *xr;
sqfs_data_reader_t *data;
sqfs_super_t super;
-sqfs_hard_link_t *links = NULL;
FILE *out_file = NULL;
static sqfs_file_t *file;
@@ -115,7 +114,6 @@ int main(int argc, char **argv)
sqfs_compressor_t *cmp;
sqfs_id_table_t *idtbl;
sqfs_dir_reader_t *dr;
- sqfs_hard_link_t *lnk;
size_t i;
process_args(argc, argv);
@@ -240,18 +238,7 @@ int main(int argc, char **argv)
}
}
- if (!no_links) {
- if (sqfs_tree_find_hard_links(root, &links))
- goto out_tree;
-
- for (lnk = links; lnk != NULL; lnk = lnk->next) {
- lnk->target = assemble_tar_path(lnk->target, false);
- if (lnk->target == NULL)
- goto out;
- }
- }
-
- if (write_tree_dfs(root))
+ if (write_tree(root))
goto out;
if (terminate_archive())
@@ -260,13 +247,6 @@ int main(int argc, char **argv)
status = EXIT_SUCCESS;
fflush(out_file);
out:
- while (links != NULL) {
- lnk = links;
- links = links->next;
- free(lnk->target);
- free(lnk);
- }
-out_tree:
if (root != NULL)
sqfs_dir_tree_destroy(root);
out_xr:
diff --git a/bin/sqfs2tar/sqfs2tar.h b/bin/sqfs2tar/sqfs2tar.h
index 47d82ef..6eee2b1 100644
--- a/bin/sqfs2tar/sqfs2tar.h
+++ b/bin/sqfs2tar/sqfs2tar.h
@@ -37,7 +37,6 @@ void process_args(int argc, char **argv);
extern sqfs_xattr_reader_t *xr;
extern sqfs_data_reader_t *data;
extern sqfs_super_t super;
-extern sqfs_hard_link_t *links;
extern FILE *out_file;
char *assemble_tar_path(char *name, bool is_dir);
@@ -47,6 +46,6 @@ int get_xattrs(const char *name, const sqfs_inode_generic_t *inode,
tar_xattr_t **out);
/* write_tree.c */
-int write_tree_dfs(const sqfs_tree_node_t *n);
+int write_tree(const sqfs_tree_node_t *n);
#endif /* SQFS2TAR_H */
diff --git a/bin/sqfs2tar/write_tree.c b/bin/sqfs2tar/write_tree.c
index a84c20e..28e1cf0 100644
--- a/bin/sqfs2tar/write_tree.c
+++ b/bin/sqfs2tar/write_tree.c
@@ -6,6 +6,7 @@
*/
#include "sqfs2tar.h"
+static sqfs_hard_link_t *links = NULL;
static unsigned int record_counter;
static sqfs_hard_link_t *find_hard_link(const char *name, sqfs_u32 inum)
@@ -23,7 +24,7 @@ static sqfs_hard_link_t *find_hard_link(const char *name, sqfs_u32 inum)
return lnk;
}
-int write_tree_dfs(const sqfs_tree_node_t *n)
+static int write_tree_dfs(const sqfs_tree_node_t *n)
{
sqfs_hard_link_t *lnk = NULL;
tar_xattr_t *xattr = NULL;
@@ -133,3 +134,31 @@ out_skip:
free(name);
return ret;
}
+
+int write_tree(const sqfs_tree_node_t *n)
+{
+ sqfs_hard_link_t *lnk;
+ int status = -1;
+
+ if (!no_links) {
+ if (sqfs_tree_find_hard_links(n, &links))
+ return -1;
+
+ for (lnk = links; lnk != NULL; lnk = lnk->next) {
+ lnk->target = assemble_tar_path(lnk->target, false);
+
+ if (lnk->target == NULL)
+ goto out_links;
+ }
+ }
+
+ status = write_tree_dfs(n);
+out_links:
+ while (links != NULL) {
+ lnk = links;
+ links = links->next;
+ free(lnk->target);
+ free(lnk);
+ }
+ return status;
+}