diff options
author | Jin Qian <jinqian@google.com> | 2016-12-19 13:19:58 -0800 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2017-05-23 22:53:50 -0400 |
commit | 3946ee856015d8fb4ef7e20bc3d26a4168bf7d9e (patch) | |
tree | 258aece1e72ad667fd2d43f1a965b13abc53a24f /contrib | |
parent | 40a709517ef9add683d113beb6e34ba3d8dee263 (diff) |
AOSP: e2fsdroid: set timestamp based on source files
Timestamp was incorrectly set to -1 or left unset. Use lstat to read
timestamps from source files and set on target files.
Change-Id: I66b2c5281ae769a52bc4e1638895eb5285c18b7a
From AOSP commit: d882f1e23195d1fb16a6fe1887c842d04ab420b7
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/android/e2fsdroid.c | 8 | ||||
-rw-r--r-- | contrib/android/perms.c | 56 | ||||
-rw-r--r-- | contrib/android/perms.h | 4 |
3 files changed, 46 insertions, 22 deletions
diff --git a/contrib/android/e2fsdroid.c b/contrib/android/e2fsdroid.c index febeeda8..b310667f 100644 --- a/contrib/android/e2fsdroid.c +++ b/contrib/android/e2fsdroid.c @@ -17,7 +17,7 @@ static char *block_list; static char *basefs_out; static char *basefs_in; static char *mountpoint = ""; -static time_t fixed_time; +static time_t fixed_time = -1; static char *fs_config_file; static char *file_contexts; static char *product_out; @@ -52,12 +52,12 @@ static char *absolute_path(const char *file) int main(int argc, char *argv[]) { int c; - char *p; + char *p; int flags = EXT2_FLAG_RW; errcode_t retval; io_manager io_mgr; ext2_filsys fs = NULL; - struct fs_ops_callbacks fs_callbacks = { NULL, NULL }; + struct fs_ops_callbacks fs_callbacks = { NULL, NULL }; add_error_table(&et_ext2_error_table); @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) } if (android_configure) { - retval = android_configure_fs(fs, product_out, mountpoint, + retval = android_configure_fs(fs, src_dir, product_out, mountpoint, file_contexts, fs_config_file, fixed_time); if (retval) { com_err(prog_name, retval, "%s", diff --git a/contrib/android/perms.c b/contrib/android/perms.c index 64bae25e..02ce99f5 100644 --- a/contrib/android/perms.c +++ b/contrib/android/perms.c @@ -17,7 +17,9 @@ struct inode_params { ext2_filsys fs; char *path; char *filename; + char *src_dir; char *target_out; + char *mountpoint; fs_config_f fs_config_func; struct selabel_handle *sehnd; time_t fixed_time; @@ -141,25 +143,42 @@ static errcode_t set_timestamp(ext2_filsys fs, ext2_ino_t ino, { errcode_t retval; struct ext2_inode inode; + struct stat stat; + char *src_filename = NULL; - if (params->fixed_time != -1) { - retval = ext2fs_read_inode(fs, ino, &inode); - if (retval) { - com_err(__func__, retval, - _("while reading inode %u"), ino); - return retval; - } - inode.i_atime = 0; - inode.i_mtime = inode.i_ctime = params->fixed_time; - retval = ext2fs_write_inode(fs, ino, &inode); - if (retval) { + retval = ext2fs_read_inode(fs, ino, &inode); + if (retval) { + com_err(__func__, retval, + _("while reading inode %u"), ino); + return retval; + } + + if (params->fixed_time == -1) { + /* replace mountpoint from filename with src_dir */ + if (asprintf(&src_filename, "%s/%s", params->src_dir, + params->filename + strlen(params->mountpoint)) < 0) + return -ENOMEM; + retval = lstat(src_filename, &stat); + if (retval < 0) { com_err(__func__, retval, - _("while writting inode %u"), ino); - return retval; + _("while lstat file %s"), src_filename); + goto end; } + inode.i_atime = inode.i_ctime = inode.i_mtime = stat.st_mtime; + } else { + inode.i_atime = inode.i_ctime = inode.i_mtime = params->fixed_time; } - return 0; + retval = ext2fs_write_inode(fs, ino, &inode); + if (retval) { + com_err(__func__, retval, + _("while writting inode %u"), ino); + goto end; + } + +end: + free(src_filename); + return retval; } static int is_dir(ext2_filsys fs, ext2_ino_t ino) @@ -231,7 +250,8 @@ end: return retval; } -errcode_t __android_configure_fs(ext2_filsys fs, char *target_out, +errcode_t __android_configure_fs(ext2_filsys fs, char *src_dir, + char *target_out, char *mountpoint, fs_config_f fs_config_func, struct selabel_handle *sehnd, @@ -240,12 +260,14 @@ errcode_t __android_configure_fs(ext2_filsys fs, char *target_out, errcode_t retval; struct inode_params params = { .fs = fs, + .src_dir = src_dir, .target_out = target_out, .fs_config_func = fs_config_func, .sehnd = sehnd, .fixed_time = fixed_time, .path = mountpoint, .filename = mountpoint, + .mountpoint = mountpoint, }; /* walk_dir will add the "/". Don't add it twice. */ @@ -263,7 +285,7 @@ errcode_t __android_configure_fs(ext2_filsys fs, char *target_out, ¶ms); } -errcode_t android_configure_fs(ext2_filsys fs, char *target_out, +errcode_t android_configure_fs(ext2_filsys fs, char *src_dir, char *target_out, char *mountpoint, char *file_contexts, char *fs_config_file, time_t fixed_time) @@ -298,6 +320,6 @@ errcode_t android_configure_fs(ext2_filsys fs, char *target_out, } else if (mountpoint) fs_config_func = fs_config; - return __android_configure_fs(fs, target_out, mountpoint, + return __android_configure_fs(fs, src_dir, target_out, mountpoint, fs_config_func, sehnd, fixed_time); } diff --git a/contrib/android/perms.h b/contrib/android/perms.h index 6342faf4..f1ed3c5b 100644 --- a/contrib/android/perms.h +++ b/contrib/android/perms.h @@ -12,6 +12,7 @@ typedef void (*fs_config_f)(const char *path, int dir, # ifdef _WIN32 struct selabel_handle; static inline errcode_t android_configure_fs(ext2_filsys fs, + char *src_dir, char *target_out, char *mountpoint, char *file_contexts, @@ -29,7 +30,8 @@ static inline errcode_t android_configure_fs(ext2_filsys fs, # include <private/android_filesystem_config.h> # include <private/canned_fs_config.h> -errcode_t android_configure_fs(ext2_filsys fs, char *target_out, +errcode_t android_configure_fs(ext2_filsys fs, char *src_dir, + char *target_out, char *mountpoint, char *file_contexts, char *fs_config_file, time_t fixed_time); |