]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
AOSP: e2fsdroid: set timestamp based on source files
authorJin Qian <jinqian@google.com>
Mon, 19 Dec 2016 21:19:58 +0000 (13:19 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 24 May 2017 02:53:50 +0000 (22:53 -0400)
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>
contrib/android/e2fsdroid.c
contrib/android/perms.c
contrib/android/perms.h

index febeeda8e4bb64bedd4ec5fd34167aaf02cd3f91..b310667fbd258cf91edca0cb61744029d54d4dd3 100644 (file)
@@ -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",
index 64bae25e2406f87227e9e464b3a21c7d4c6bf8c5..02ce99f596863caa85daa2d4ef9fcc768f9740fb 100644 (file)
@@ -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,
                                   &params);
 }
 
-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);
 }
index 6342faf46c551f1625afd70ecf409f08854ff754..f1ed3c5bdf4c2fe364cb0352b85ffb4c8238d86d 100644 (file)
@@ -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);