return 0;
}
-void canned_fs_config(const char* path, int dir,
+void canned_fs_config(const char* path, int dir, const char* target_out_path,
unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) {
Path key;
key.path = path+1; // canned paths lack the leading '/'
unsigned c_uid, c_gid, c_mode;
uint64_t c_capabilities;
- fs_config(path, dir, &c_uid, &c_gid, &c_mode, &c_capabilities);
+ fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities);
if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid);
if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid);
#include <inttypes.h>
int load_canned_fs_config(const char* fn);
-void canned_fs_config(const char* path, int dir,
+void canned_fs_config(const char* path, int dir, const char* target_out_path,
unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities);
#endif
void ext4_parse_sb_info(struct ext4_super_block *sb);
u16 ext4_crc16(u16 crc_in, const void *buf, int size);
-typedef void (*fs_config_func_t)(const char *path, int dir, unsigned *uid, unsigned *gid,
- unsigned *mode, uint64_t *capabilities);
+typedef void (*fs_config_func_t)(const char *path, int dir, const char *target_out_path,
+ unsigned *uid, unsigned *gid, unsigned *mode, uint64_t *capabilities);
struct selabel_handle;
-int make_ext4fs_internal(int fd, const char *directory,
+int make_ext4fs_internal(int fd, const char *directory, const char *_target_out_directory,
const char *mountpoint, fs_config_func_t fs_config_func, int gzip,
int sparse, int crc, int wipe, int real_uuid,
struct selabel_handle *sehnd, int verbose, time_t fixed_time,
that does not exist on disk (e.g. lost+found).
dir_path is an absolute path, with trailing slash, to the same directory
if the image were mounted at the specified mount point */
-static u32 build_directory_structure(const char *full_path, const char *dir_path,
+static u32 build_directory_structure(const char *full_path, const char *dir_path, const char *target_out_path,
u32 dir_inode, fs_config_func_t fs_config_func,
struct selabel_handle *sehnd, int verbose, time_t fixed_time)
{
unsigned int uid = 0;
unsigned int gid = 0;
int dir = S_ISDIR(stat.st_mode);
- fs_config_func(dentries[i].path, dir, &uid, &gid, &mode, &capabilities);
+ fs_config_func(dentries[i].path, dir, target_out_path, &uid, &gid, &mode, &capabilities);
dentries[i].mode = mode;
dentries[i].uid = uid;
dentries[i].gid = gid;
ret = asprintf(&subdir_dir_path, "%s/", dentries[i].path);
if (ret < 0)
critical_error_errno("asprintf");
- entry_inode = build_directory_structure(subdir_full_path,
- subdir_dir_path, inode, fs_config_func, sehnd, verbose, fixed_time);
+ entry_inode = build_directory_structure(subdir_full_path, subdir_dir_path, target_out_path,
+ inode, fs_config_func, sehnd, verbose, fixed_time);
free(subdir_full_path);
free(subdir_dir_path);
} else if (dentries[i].file_type == EXT4_FT_SYMLINK) {
reset_ext4fs_info();
info.len = len;
- return make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 1, 0, 0, 0, sehnd, 0, -1, NULL);
+ return make_ext4fs_internal(fd, NULL, NULL, mountpoint, NULL, 0, 1, 0, 0, 0, sehnd, 0, -1, NULL);
}
int make_ext4fs(const char *filename, long long len,
return EXIT_FAILURE;
}
- status = make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 0, 0, 1, 0, sehnd, 0, -1, NULL);
+ status = make_ext4fs_internal(fd, NULL, NULL, mountpoint, NULL, 0, 0, 0, 1, 0, sehnd, 0, -1, NULL);
close(fd);
return status;
return canonicalize_slashes(str, false);
}
-int make_ext4fs_internal(int fd, const char *_directory,
+int make_ext4fs_internal(int fd, const char *_directory, const char *_target_out_directory,
const char *_mountpoint, fs_config_func_t fs_config_func, int gzip,
int sparse, int crc, int wipe, int real_uuid,
struct selabel_handle *sehnd, int verbose, time_t fixed_time,
u16 root_mode;
char *mountpoint;
char *directory = NULL;
+ char *target_out_directory = NULL;
if (setjmp(setjmp_env))
return EXIT_FAILURE; /* Handle a call to longjmp() */
directory = canonicalize_rel_slashes(_directory);
}
+ if (_target_out_directory) {
+ target_out_directory = canonicalize_rel_slashes(_target_out_directory);
+ }
+
if (info.len <= 0)
info.len = get_file_size(fd);
root_inode_num = build_default_directory_structure(mountpoint, sehnd);
#else
if (directory)
- root_inode_num = build_directory_structure(directory, mountpoint, 0,
+ root_inode_num = build_directory_structure(directory, mountpoint, target_out_directory, 0,
fs_config_func, sehnd, verbose, fixed_time);
else
root_inode_num = build_default_directory_structure(mountpoint, sehnd);
fprintf(stderr, " [ -L <label> ] [ -f ] [ -a <android mountpoint> ] [ -u ]\n");
fprintf(stderr, " [ -S file_contexts ] [ -C fs_config ] [ -T timestamp ]\n");
fprintf(stderr, " [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ] [ -B <block_list_file> ]\n");
- fprintf(stderr, " <filename> [<directory>]\n");
+ fprintf(stderr, " <filename> [[<directory>] <target_out_directory>]\n");
}
int main(int argc, char **argv)
int opt;
const char *filename = NULL;
const char *directory = NULL;
+ const char *target_out_directory = NULL;
char *mountpoint = NULL;
fs_config_func_t fs_config_func = NULL;
const char *fs_config_file = NULL;
if (optind < argc)
directory = argv[optind++];
+ if (optind < argc)
+ target_out_directory = argv[optind++];
+
if (optind < argc) {
fprintf(stderr, "Unexpected argument: %s\n", argv[optind]);
usage(argv[0]);
fd = STDOUT_FILENO;
}
- exitcode = make_ext4fs_internal(fd, directory, mountpoint, fs_config_func, gzip,
+ exitcode = make_ext4fs_internal(fd, directory, target_out_directory, mountpoint, fs_config_func, gzip,
sparse, crc, wipe, real_uuid, sehnd, verbose, fixed_time, block_list_file);
close(fd);
if (block_list_file)
cat<<EOT
Usage:
mkuserimg.sh [-s] SRC_DIR OUTPUT_FILE EXT_VARIANT MOUNT_POINT SIZE [-j <journal_size>]
- [-T TIMESTAMP] [-C FS_CONFIG] [-B BLOCK_LIST_FILE] [-L LABEL] [FILE_CONTEXTS]
+ [-T TIMESTAMP] [-C FS_CONFIG] [-D PRODUCT_OUT] [-B BLOCK_LIST_FILE] [-L LABEL] [FILE_CONTEXTS]
EOT
}
shift; shift
fi
+PRODUCT_OUT=
+if [[ "$1" == "-D" ]]; then
+ PRODUCT_OUT=$2
+ shift; shift
+fi
+
BLOCK_LIST=
if [[ "$1" == "-B" ]]; then
BLOCK_LIST=$2
OPT="$OPT -L $LABEL"
fi
-MAKE_EXT4FS_CMD="make_ext4fs $ENABLE_SPARSE_IMAGE -T $TIMESTAMP $OPT -l $SIZE $JOURNAL_FLAGS -a $MOUNT_POINT $OUTPUT_FILE $SRC_DIR"
+MAKE_EXT4FS_CMD="make_ext4fs $ENABLE_SPARSE_IMAGE -T $TIMESTAMP $OPT -l $SIZE $JOURNAL_FLAGS -a $MOUNT_POINT $OUTPUT_FILE $SRC_DIR $PRODUCT_OUT"
echo $MAKE_EXT4FS_CMD
$MAKE_EXT4FS_CMD
if [ $? -ne 0 ]; then
function usage() {
cat<<EOT
Usage:
-${0##*/} SRC_DIR OUTPUT_FILE [-s] [-m MOUNT_POINT] [-c FILE_CONTEXTS] [-b BLOCK_SIZE] [-z COMPRESSOR] [-zo COMPRESSOR_OPT]
+${0##*/} SRC_DIR OUTPUT_FILE [-s] [-m MOUNT_POINT] [-d PRODUCT_OUT] [-c FILE_CONTEXTS] [-b BLOCK_SIZE] [-z COMPRESSOR] [-zo COMPRESSOR_OPT]
EOT
}
shift; shift
fi
+PRODUCT_OUT=
+if [[ "$1" == "-d" ]]; then
+ PRODUCT_OUT=$2
+ shift; shift
+fi
+
FILE_CONTEXTS=
if [[ "$1" == "-c" ]]; then
FILE_CONTEXTS=$2
if [ -n "$MOUNT_POINT" ]; then
OPT="$OPT -mount-point $MOUNT_POINT"
fi
+if [ -n "$PRODUCT_OUT" ]; then
+ OPT="$OPT -product-out $PRODUCT_OUT"
+fi
if [ -n "$FILE_CONTEXTS" ]; then
OPT="$OPT -context-file $FILE_CONTEXTS"
fi