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