This source file includes following definitions.
- find_cpio_data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <linux/earlycpio.h>
21 #include <linux/kernel.h>
22 #include <linux/string.h>
23
24 enum cpio_fields {
25 C_MAGIC,
26 C_INO,
27 C_MODE,
28 C_UID,
29 C_GID,
30 C_NLINK,
31 C_MTIME,
32 C_FILESIZE,
33 C_MAJ,
34 C_MIN,
35 C_RMAJ,
36 C_RMIN,
37 C_NAMESIZE,
38 C_CHKSUM,
39 C_NFIELDS
40 };
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 struct cpio_data find_cpio_data(const char *path, void *data,
60 size_t len, long *nextoff)
61 {
62 const size_t cpio_header_len = 8*C_NFIELDS - 2;
63 struct cpio_data cd = { NULL, 0, "" };
64 const char *p, *dptr, *nptr;
65 unsigned int ch[C_NFIELDS], *chp, v;
66 unsigned char c, x;
67 size_t mypathsize = strlen(path);
68 int i, j;
69
70 p = data;
71
72 while (len > cpio_header_len) {
73 if (!*p) {
74
75 p += 4;
76 len -= 4;
77 continue;
78 }
79
80 j = 6;
81 chp = ch;
82 for (i = C_NFIELDS; i; i--) {
83 v = 0;
84 while (j--) {
85 v <<= 4;
86 c = *p++;
87
88 x = c - '0';
89 if (x < 10) {
90 v += x;
91 continue;
92 }
93
94 x = (c | 0x20) - 'a';
95 if (x < 6) {
96 v += x + 10;
97 continue;
98 }
99
100 goto quit;
101 }
102 *chp++ = v;
103 j = 8;
104 }
105
106 if ((ch[C_MAGIC] - 0x070701) > 1)
107 goto quit;
108
109 len -= cpio_header_len;
110
111 dptr = PTR_ALIGN(p + ch[C_NAMESIZE], 4);
112 nptr = PTR_ALIGN(dptr + ch[C_FILESIZE], 4);
113
114 if (nptr > p + len || dptr < p || nptr < dptr)
115 goto quit;
116
117 if ((ch[C_MODE] & 0170000) == 0100000 &&
118 ch[C_NAMESIZE] >= mypathsize &&
119 !memcmp(p, path, mypathsize)) {
120
121 if (nextoff)
122 *nextoff = (long)nptr - (long)data;
123
124 if (ch[C_NAMESIZE] - mypathsize >= MAX_CPIO_FILE_NAME) {
125 pr_warn(
126 "File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
127 p, MAX_CPIO_FILE_NAME);
128 }
129 strlcpy(cd.name, p + mypathsize, MAX_CPIO_FILE_NAME);
130
131 cd.data = (void *)dptr;
132 cd.size = ch[C_FILESIZE];
133 return cd;
134 }
135 len -= (nptr - p);
136 p = nptr;
137 }
138
139 quit:
140 return cd;
141 }