summaryrefslogtreecommitdiff
path: root/include/fstree.h
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-19 16:10:39 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-22 22:07:44 +0100
commit1466f1f8571aca423156ee7ef4094a0c082f88d7 (patch)
tree76863754fe3a0546ec8279da97cbeae7700b0abc /include/fstree.h
parent0a6c5d7fa2f276b8e155d69bea17650bad46f089 (diff)
Add basic support for handling and serializing hard links
In libfstree, add a function to add a hard link to the fstree. The hard links stores the target in the data.target field, canonicalizes the target and sets a sentinel mode. A second function is used to resolve link, i.e. replacing it with a direct pointer, setting another sentinel mode and increasing the targets link count. The post process function tries to resolve unresolved hard links and only allocates inode numbers for nodes that aren't hard links. If the target node of a hard link does not have an inode number yet, the two need to be swapped, since this is also the order in which they are serialized. The serialization function in libcommon simply has to skip hard link nodes and when writing directory entries, use the inode num/ref of the target node. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/fstree.h')
-rw-r--r--include/fstree.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/include/fstree.h b/include/fstree.h
index aff3952..7f81cf5 100644
--- a/include/fstree.h
+++ b/include/fstree.h
@@ -17,6 +17,9 @@
#include "sqfs/predef.h"
#include "compat.h"
+#define FSTREE_MODE_HARD_LINK (0)
+#define FSTREE_MODE_HARD_LINK_RESOLVED (1)
+
typedef struct tree_node_t tree_node_t;
typedef struct file_info_t file_info_t;
typedef struct dir_info_t dir_info_t;
@@ -40,6 +43,9 @@ struct dir_info_t {
/* Set to true for implicitly generated directories. */
bool created_implicitly;
+
+ /* Used by recursive tree walking code to avoid hard link loops */
+ bool visited;
};
/* A node in a file system tree */
@@ -68,12 +74,13 @@ struct tree_node_t {
Generated on the fly when writing inodes. */
sqfs_u64 inode_ref;
- /* Type specific data. Pointers are into payload area blow. */
+ /* Type specific data. "target" pointer is into payload area below. */
union {
dir_info_t dir;
file_info_t file;
char *target;
sqfs_u64 devno;
+ tree_node_t *target_node;
} data;
sqfs_u8 payload[];
@@ -156,13 +163,15 @@ int fstree_from_file(fstree_t *fs, const char *filename, FILE *fp);
/*
This function performs all the necessary post processing steps on the file
system tree, i.e. recursively sorting all directory entries by name,
- allocating inode numbers and stringing all files nodes together into a
- linked list.
+ allocating inode numbers, resolving hard links and stringing all files nodes
+ together into a linked list.
The total inode count is stored in unique_inode_count. The head of the file
list is pointed to by fs->files.
+
+ Returns 0 on success, prints to stderr on failure.
*/
-void fstree_post_process(fstree_t *fs);
+int fstree_post_process(fstree_t *fs);
/*
Generate a string holding the full path of a node. Returned
@@ -205,4 +214,17 @@ int canonicalize_name(char *filename);
*/
bool is_filename_sane(const char *name, bool check_os_specific);
+/*
+ Add a hard link node. Returns NULL on failure and sets errno.
+ */
+tree_node_t *fstree_add_hard_link(fstree_t *fs, const char *path,
+ const char *target);
+
+/*
+ Resolve a hard link node and replace it with a direct pointer to the target.
+
+ Returns 0 on success. On failure, errno is set.
+ */
+int fstree_resolve_hard_link(fstree_t *fs, tree_node_t *node);
+
#endif /* FSTREE_H */