libtar: support backing up and restoring new Android user.* xattr
Support for backing up and restoring user.default, user.inode_cache, and
user.inode_code_cache xattrs introduced in Android 7.x
Change-Id: I6e0aa7fc9cd30ed004ef28ebb58d60a82e518123
diff --git a/libtar/append.c b/libtar/append.c
index d8ba3ca..8896764 100644
--- a/libtar/append.c
+++ b/libtar/append.c
@@ -40,6 +40,7 @@
#ifdef HAVE_EXT4_CRYPT
# include "ext4crypt_tar.h"
#endif
+#include "android_utils.h"
struct tar_dev
{
@@ -172,6 +173,32 @@
}
}
+ /* get android user.default xattr */
+ if (TH_ISDIR(t) && t->options & TAR_STORE_ANDROID_USER_XATTR)
+ {
+ if (getxattr(realname, "user.default", NULL, 0) >= 0)
+ {
+ t->th_buf.has_user_default = 1;
+#if 1 //def DEBUG
+ printf("storing xattr user.default\n");
+#endif
+ }
+ if (getxattr(realname, "user.inode_cache", NULL, 0) >= 0)
+ {
+ t->th_buf.has_user_cache = 1;
+#if 1 //def DEBUG
+ printf("storing xattr user.inode_cache\n");
+#endif
+ }
+ if (getxattr(realname, "user.inode_code_cache", NULL, 0) >= 0)
+ {
+ t->th_buf.has_user_code_cache = 1;
+#if 1 //def DEBUG
+ printf("storing xattr user.inode_code_cache\n");
+#endif
+ }
+ }
+
/* check if it's a hardlink */
#ifdef DEBUG
puts("tar_append_file(): checking inode cache for hardlink...");