blob: 3b50ffbf36adc8d5c52d367a947d7233da5140c4 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From b9254539811ce912bfd16dd1d185eba7a10cceff Mon Sep 17 00:00:00 2001
2From: Markus Mayer <mmayer@mmayer.net>
3Date: Wed, 7 Sep 2016 12:58:47 +0300
4Subject: [PATCH] ext4_utils: add -o argument to preserve ownership
5
6See also https://android-review.googlesource.com/#/c/100312/
7
8Upstream-Status: Inappropriate
9---
10 ext4_utils/make_ext4fs.c | 6 ++++++
11 ext4_utils/make_ext4fs_main.c | 10 ++++++++--
12 2 files changed, 14 insertions(+), 2 deletions(-)
13
14diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c
15index 732afbed7..2cbf04399 100644
16--- a/ext4_utils/make_ext4fs.c
17+++ b/ext4_utils/make_ext4fs.c
18@@ -67,6 +67,8 @@
19
20 #endif
21
22+int preserve_owner = 0;
23+
24 /* TODO: Not implemented:
25 Allocating blocks in the same block group as the file inode
26 Hash or binary tree directories
27@@ -185,6 +187,10 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path
28 } else {
29 dentries[i].mtime = fixed_time;
30 }
31+ if (preserve_owner) {
32+ dentries[i].uid = stat.st_uid;
33+ dentries[i].gid = stat.st_gid;
34+ }
35 uint64_t capabilities;
36 if (fs_config_func != NULL) {
37 #ifdef ANDROID
38diff --git a/ext4_utils/make_ext4fs_main.c b/ext4_utils/make_ext4fs_main.c
39index f8e7b9da9..e82d43277 100644
40--- a/ext4_utils/make_ext4fs_main.c
41+++ b/ext4_utils/make_ext4fs_main.c
42@@ -47,13 +47,15 @@ struct selabel_handle;
43 extern struct fs_info info;
44
45
46+extern int preserve_owner;
47+
48 static void usage(char *path)
49 {
50 fprintf(stderr, "%s [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]\n", basename(path));
51 fprintf(stderr, " [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]\n");
52 fprintf(stderr, " [ -L <label> ] [ -f ] [ -a <android mountpoint> ]\n");
53 fprintf(stderr, " [ -S file_contexts ] [ -C fs_config ] [ -T timestamp ]\n");
54- fprintf(stderr, " [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ] [ -B <block_list_file> ]\n");
55+ fprintf(stderr, " [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -o ] [ -v ] [ -B <block_list_file> ]\n");
56 fprintf(stderr, " <filename> [<directory>]\n");
57 }
58
59@@ -79,7 +81,7 @@ int main(int argc, char **argv)
60 struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "" } };
61 #endif
62
63- while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:S:T:C:B:fwzJsctv")) != -1) {
64+ while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:S:T:C:B:fwzJsctov")) != -1) {
65 switch (opt) {
66 case 'l':
67 info.len = parse_num(optarg);
68@@ -142,6 +144,10 @@ int main(int argc, char **argv)
69 }
70 #endif
71 break;
72+ case 'o':
73+ preserve_owner = 1;
74+ printf("Warning: Enabling 'preserve ownership', this is an unofficial feature!\n");
75+ break;
76 case 'v':
77 verbose = 1;
78 break;