aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohamad Ayyash <mkayyash@google.com>2015-03-02 16:00:56 -0800
committerMohamad Ayyash <mkayyash@google.com>2015-03-02 18:21:37 -0800
commit18fe5f67e87711ceb72ca0fb2282f32c4533f061 (patch)
tree10dc13fa944fd77fbf19960da6ca9e74f1c84dde
parentf0f00de050582fa10cd22c8bb93453d293aa65e3 (diff)
downloadsquashfs-tools-18fe5f67e87711ceb72ca0fb2282f32c4533f061.tar.gz
squashfs-tools: Add mount-point flag
This flag is necessary when android-fs-config or context-file are passed and the source directory is not mount point (e.g. absolute path, current dir '.', different dir name than mount point...etc). Change-Id: I3b4bdc401527765a571ff4e5fb5815c6d5e85adc Signed-off-by: Mohamad Ayyash <mkayyash@google.com>
-rw-r--r--squashfs-tools/android.c10
-rw-r--r--squashfs-tools/android.h1
-rw-r--r--squashfs-tools/mksquashfs.c39
-rw-r--r--squashfs-tools/xattr.c18
4 files changed, 63 insertions, 5 deletions
diff --git a/squashfs-tools/android.c b/squashfs-tools/android.c
index a59c210..aaf91b5 100644
--- a/squashfs-tools/android.c
+++ b/squashfs-tools/android.c
@@ -33,6 +33,16 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+void alloc_mounted_path(const char *mount_point, const char *subpath, char **mounted_path) {
+ *mounted_path = malloc(strlen(mount_point) + strlen(subpath) + 1);
+ if (*mounted_path == NULL) {
+ perror("Malloc Failure.");
+ exit(EXIT_FAILURE);
+ }
+ strcpy(*mounted_path, mount_point);
+ strcat(*mounted_path, subpath);
+}
+
void android_fs_config(const char *path, struct stat *stat) {
unsigned long capabilities = 0;
fs_config(path, S_ISDIR(stat->st_mode), &stat->st_uid, &stat->st_gid, &stat->st_mode,
diff --git a/squashfs-tools/android.h b/squashfs-tools/android.h
index 766cf0a..b290b8e 100644
--- a/squashfs-tools/android.h
+++ b/squashfs-tools/android.h
@@ -17,6 +17,7 @@
#ifndef _ANDROID_H_
#define _ANDROID_H_
+void alloc_mounted_path(const char *mount_point, const char *subpath, char **mounted_path);
void android_fs_config(const char *path, struct stat *stat);
struct selabel_handle *get_sehnd(const char *context_file);
char *set_selabel(const char *path, unsigned int mode, struct selabel_handle *sehnd);
diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
index 11401e2..9e80d0a 100644
--- a/squashfs-tools/mksquashfs.c
+++ b/squashfs-tools/mksquashfs.c
@@ -82,6 +82,7 @@
#include "android.h"
int android_config = FALSE;
char *context_file = NULL;
+char *mount_point = NULL;
#endif
/* ANDROID CHANGES END */
@@ -3049,8 +3050,16 @@ inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
/* ANDROID CHANGES START*/
#ifdef ANDROID
- if (android_config)
- android_fs_config(pathname(dir_ent), &inode_info->buf);
+ if (android_config) {
+ if (mount_point) {
+ char *mounted_path;
+ alloc_mounted_path(mount_point, subpathname(dir_ent), &mounted_path);
+ android_fs_config(mounted_path, &inode_info->buf);
+ free(mounted_path);
+ } else {
+ android_fs_config(pathname(dir_ent), &inode_info->buf);
+ }
+ }
#endif
/* ANDROID CHANGES END */
@@ -3062,6 +3071,16 @@ inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
dir->count++;
}
+/* ANDROID CHANGES START*/
+#ifdef ANDROID
+/* Weird linker bug that complains those inline functions are undefined. */
+extern inline void add_dir_entry(struct dir_ent *dir_ent, struct dir_info *sub_dir,
+ struct inode_info *inode_info);
+extern inline void add_dir_entry2(char *name, char *source_name,
+ char *nonstandard_pathname, struct dir_info *sub_dir,
+ struct inode_info *inode_info, struct dir_info *dir);
+#endif
+/* ANDROID CHANGES END */
inline void add_dir_entry2(char *name, char *source_name,
char *nonstandard_pathname, struct dir_info *sub_dir,
@@ -3138,7 +3157,10 @@ void dir_scan(squashfs_inode *inode, char *pathname,
/* ANDROID CHANGES START*/
#ifdef ANDROID
if (android_config)
- android_fs_config(pathname, &buf);
+ if (mount_point)
+ android_fs_config(mount_point, &buf);
+ else
+ android_fs_config(pathname, &buf);
#endif
/* ANDROID CHANGES END */
dir_ent->inode = lookup_inode(&buf);
@@ -5573,6 +5595,14 @@ print_compressor_options:
#ifdef ANDROID
else if(strcmp(argv[i], "-android-fs-config") == 0)
android_config = TRUE;
+ else if(strcmp(argv[i], "-mount-point") == 0) {
+ if(++i == argc) {
+ ERROR("%s: -mount-point: missing mount point name\n",
+ argv[0]);
+ exit(1);
+ }
+ mount_point = argv[i];
+ }
#endif
/* ANDROID CHANGES END */
@@ -5640,6 +5670,9 @@ printOptions:
#ifdef ANDROID
ERROR("-android-fs-config\tuse android fs config "
"for mode, uid, and gids of inodes\n");
+ ERROR("-mount-point <name>\tNeed to be provided when "
+ "android-fs-config or context-file\n\t\t\tare "
+ "enabled and source directory is not mount point\n");
#endif
/* ANDROID CHANGES END */
ERROR("\nFilesystem filter options:\n");
diff --git a/squashfs-tools/xattr.c b/squashfs-tools/xattr.c
index bef7115..a405234 100644
--- a/squashfs-tools/xattr.c
+++ b/squashfs-tools/xattr.c
@@ -85,6 +85,7 @@ extern int fd;
extern unsigned int xattr_bytes, total_xattr_bytes;
/* ANDROID CHANGES START*/
extern char *context_file;
+extern char *mount_point;
/* ANDROID CHANGES END */
/* helper functions from mksquashfs.c */
@@ -93,6 +94,11 @@ extern void write_destination(int, long long, int, void *);
extern long long generic_write_table(int, void *, int, void *, int);
extern int mangle(char *, char *, int, int, int, int);
extern char *pathname(struct dir_ent *);
+/* ANDROID CHANGES START*/
+#ifdef ANDROID
+extern char *subpathname(struct dir_ent *);
+#endif
+/* ANDROID CHANGES END */
/* helper functions and definitions from read_xattrs.c */
extern int read_xattrs_from_disk(int, struct squashfs_super_block *);
@@ -650,8 +656,16 @@ int read_xattrs(void *d)
if (context_file) {
if (sehnd == NULL)
sehnd = get_sehnd(context_file);
- xattrs = read_xattrs_from_context_file(filename, inode->buf.st_mode,
- sehnd, &xattr_list);
+ if (mount_point) {
+ char *mounted_path;
+ alloc_mounted_path(mount_point, subpathname(dir_ent), &mounted_path);
+ xattrs = read_xattrs_from_context_file(mounted_path, inode->buf.st_mode,
+ sehnd, &xattr_list);
+ free(mounted_path);
+ } else {
+ xattrs = read_xattrs_from_context_file(filename, inode->buf.st_mode,
+ sehnd, &xattr_list);
+ }
} else {
xattrs = read_xattrs_from_system(filename, &xattr_list);
}