diff --git a/jni/include/cpio.h b/jni/include/cpio.h index 394203c9a..18456bb74 100644 --- a/jni/include/cpio.h +++ b/jni/include/cpio.h @@ -47,6 +47,7 @@ void dump_cpio(struct vector *v, const char *filename); void cpio_vec_destroy(struct vector *v); void cpio_rm(struct vector *v, int recursive, const char *entry); void cpio_mkdir(struct vector *v, mode_t mode, const char *entry); +void cpio_ln(struct vector *v, const char *target, const char *entry); void cpio_add(struct vector *v, mode_t mode, const char *entry, const char *filename); int cpio_mv(struct vector *v, const char *from, const char *to); int cpio_extract(struct vector *v, const char *entry, const char *filename); diff --git a/jni/magiskboot/main.c b/jni/magiskboot/main.c index 265dd9a13..65904e080 100644 --- a/jni/magiskboot/main.c +++ b/jni/magiskboot/main.c @@ -35,9 +35,11 @@ static void usage(char *arg0) { " Do cpio related cmds to (modifications are done directly)\n" " Supported commands:\n" " -rm [-r] \n" - " Remove entry from , flag -r to remove recursively\n" + " Remove entry from , flag [-r] to remove recursively\n" " -mkdir \n" " Create directory as an \n" + " -ln \n" + " Create symlink to point to \n" " -add \n" " Add as an ; replaces if already exists\n" " -mv \n" diff --git a/jni/magiskboot/ramdisk.c b/jni/magiskboot/ramdisk.c index a2b060266..d01593586 100644 --- a/jni/magiskboot/ramdisk.c +++ b/jni/magiskboot/ramdisk.c @@ -105,6 +105,8 @@ int cpio_commands(const char *command, int argc, char *argv[]) { return cpio_extract(&v, argv[0], argv[1]); } else if (argc == 2 && strcmp(command, "mkdir") == 0) { cpio_mkdir(&v, strtoul(argv[0], NULL, 8), argv[1]); + } else if (argc == 2 && strcmp(command, "ln") == 0) { + cpio_ln(&v, argv[0], argv[1]); } else if (argc == 3 && strcmp(command, "add") == 0) { cpio_add(&v, strtoul(argv[0], NULL, 8), argv[1], argv[2]); } else { diff --git a/jni/utils/cpio.c b/jni/utils/cpio.c index 6d8efe5fb..045801f49 100644 --- a/jni/utils/cpio.c +++ b/jni/utils/cpio.c @@ -164,6 +164,15 @@ void cpio_mkdir(struct vector *v, mode_t mode, const char *entry) { fprintf(stderr, "Create directory [%s] (%04o)\n",entry, mode); } +void cpio_ln(struct vector *v, const char *target, const char *entry) { + cpio_entry *f = xcalloc(sizeof(*f), 1); + f->mode = S_IFLNK; + f->filename = strdup(entry); + f->data = strdup(target); + cpio_vec_insert(v, f); + fprintf(stderr, "Create symlink [%s] -> [%s]\n", entry, target); +} + void cpio_add(struct vector *v, mode_t mode, const char *entry, const char *filename) { int fd = xopen(filename, O_RDONLY); cpio_entry *f = xcalloc(sizeof(*f), 1);