From: Eric Biggers Date: Thu, 23 Mar 2023 00:44:21 +0000 (+0000) Subject: AOSP: ext2simg: fix same_file() to check st_dev X-Git-Tag: v1.47.1-wc1~116 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=eb6c137c51dcda142637981413e9a45da81b34e9;p=tools%2Fe2fsprogs.git AOSP: ext2simg: fix same_file() to check st_dev File identity is determined by the combination of st_dev and st_ino, not by st_ino alone. This fixes a bug where ext2simg would needlessly make a copy of all the data when the input and output files happened to have the same st_ino. Fixes: db6f320912cf ("AOSP: android: add the ext2simg tool") Change-Id: I94e4bf57d9f91b31e5438768805e9f10bec3411d Signed-off-by: Eric Biggers From AOSP commit: 0749f83a2cf4c134a2403701ab78388500e53f76 --- diff --git a/contrib/android/ext2simg.c b/contrib/android/ext2simg.c index 9ef54cf..1bc2308 100644 --- a/contrib/android/ext2simg.c +++ b/contrib/android/ext2simg.c @@ -189,7 +189,7 @@ static bool same_file(const char *in, const char *out) ext2fs_fatal(errno, "stat %s\n", in); if (lstat(out, &st2) == -1) ext2fs_fatal(errno, "stat %s\n", out); - return st1.st_ino == st2.st_ino; + return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino; } int main(int argc, char *argv[])