Search code examples
androidlinuxcygwin

How to use cpio to modify or creat ramdisk?


This question contain 2 parts.New is at line 29.

I use cygwin cpio command to creat ramdisk.But i find it cant used in android becouse file tree is E:\xx\xx. I need ramdisk content is \xx.How to do?

set "bin=E:\cygwin64\bin"
set "PATH=E:"
"%bin%"\find "%PATH%"\ramdisk -depth -print0 | "%bin%"\cpio --null -ov >e:\ramdisknew

when i use cpio -t the output like this.

E:\ramdisk/acct
E:\ramdisk/bugreports
E:\ramdisk/cache
E:\ramdisk/charger
E:\ramdisk/config
E:\ramdisk/d
E:\ramdisk/data

I need -t putput like this.

"E:\cygwin64\bin"\cpio -t "E:"\ramdisk0
acct
bugreports
cache
charger
config
d

data

I found in windows the file or dirctory Owner is 1000 not root maybe thats the problem.

So i changed Fedora 31.

The origin file ramdisk0 properties Kind=CPIO archive.

Use cpio -idv < /ramdisk0 then -ov to ramdisknew.Replace origin ramdisk0 to run android

It DONT work.

I find two problem

1.Output sequence become reverse not [acct bugreports cache d]

selinux_version
sepolicy
init.environ.rc
init.zygote32.rc
etc
config

2.ramdisknew hex content differ from ramdisk0 Origin ramdisk0 includ lot of '07070100049...' but ramdisknew have none The only string 'acct' is a dir still in format

[070701000493e0000041ed0000000000000000000000010000000000000000000000000000000000000000000000000000000500000000acct]

but in ramdisknew the format is[...Õ^Gð....acct]

origin ramdisk hex [part]

...
30 30 00 00  30 37 30 37  30 31 30 30  30 34 39 33 | 00..070701000493
65 31 30 30  30 30 61 31  61 34 30 30  30 30 30 30 | e10000a1a4000000
30 30 30 30  30 30 30 30  30 30 30 30  30 30 30 30 | 0000000000000000
30 31 30 30  30 30 30 30  30 30 30 30  30 30 30 30 | 0100000000000000
33 32 30 30  30 30 30 30  30 30 30 30  30 30 30 30 | 3200000000000000
30 30 30 30  30 30 30 30  30 30 30 30  30 30 30 30 | 0000000000000000
30 30 30 30  30 30 30 30  30 30 30 30  30 30 30 30 | 000000000b000000
30 30 62 75  67 72 65 70  6F 72 74 73  00 00 00 00 | 00bugreports.... 
2F 64 61 74  61 2F 75 73  65 72 5F 64  65 2F 30 2F | /data/user_de/0/com
...

new ramdisknew hex [part]

D5 5E 47 F0  0B 00 00 00  32 00 62 75  67 72 65 70 | Õ^Gð....2. bugrep
6F 72 74 73  00 00 2F 64  61 74 61 2F  75 73 65 72 | orts../data/user_de/0/com

How to fix it?


Solution

  • I believe something like this might work:

    pushd "%PATH%"\ramdisk
    "%bin%"\find . -depth -printf "%P\0" | "%bin%"\cpio --null -ov >e:\ramdisknew
    popd
    

    Cpio here apparently stores the full path as passed by Find. The pushd and popd commands temporarily change the working directory to where the files are stored. The find command is modified to look into the current directory (but that change isn't strictly necessary) and to print only the relative path (the %P); null character separators are retained (the \0 part).