Rev 3403 | Rev 3561 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3403 | Rev 3535 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | * @brief Support for loading TMPFS file system dump. |
36 | * @brief Support for loading TMPFS file system dump. |
37 | */ |
37 | */ |
38 | 38 | ||
39 | #include "tmpfs.h" |
39 | #include "tmpfs.h" |
40 | #include "../../vfs/vfs.h" |
40 | #include "../../vfs/vfs.h" |
41 | #include <ipc/ipc.h> |
- | |
42 | #include <async.h> |
- | |
43 | #include <errno.h> |
41 | #include <errno.h> |
44 | #include <stdlib.h> |
42 | #include <stdlib.h> |
45 | #include <string.h> |
43 | #include <string.h> |
46 | #include <sys/types.h> |
44 | #include <sys/types.h> |
47 | #include <as.h> |
45 | #include <as.h> |
48 | #include <libfs.h> |
46 | #include <libblock.h> |
49 | #include <ipc/services.h> |
- | |
50 | #include <ipc/devmap.h> |
- | |
51 | #include <sys/mman.h> |
- | |
52 | #include <byteorder.h> |
47 | #include <byteorder.h> |
53 | 48 | ||
54 | #define TMPFS_BLOCK_SIZE 1024 |
49 | #define TMPFS_BLOCK_SIZE 1024 |
55 | 50 | ||
56 | struct rdentry { |
51 | struct rdentry { |
57 | uint8_t type; |
52 | uint8_t type; |
58 | uint32_t len; |
53 | uint32_t len; |
59 | } __attribute__((packed)); |
54 | } __attribute__((packed)); |
60 | 55 | ||
61 | static bool |
56 | static bool |
62 | tmpfs_restore_recursion(int phone, void *block, off_t *bufpos, size_t *buflen, |
57 | tmpfs_restore_recursion(int dev, off_t *bufpos, size_t *buflen, off_t *pos, |
63 | off_t *pos, tmpfs_dentry_t *parent) |
58 | tmpfs_dentry_t *parent) |
64 | { |
59 | { |
65 | struct rdentry entry; |
60 | struct rdentry entry; |
66 | libfs_ops_t *ops = &tmpfs_libfs_ops; |
61 | libfs_ops_t *ops = &tmpfs_libfs_ops; |
67 | 62 | ||
68 | do { |
63 | do { |
69 | char *fname; |
64 | char *fname; |
70 | tmpfs_dentry_t *node; |
65 | tmpfs_dentry_t *node; |
71 | uint32_t size; |
66 | uint32_t size; |
72 | 67 | ||
73 | if (!libfs_blockread(phone, block, bufpos, buflen, pos, &entry, |
68 | if (!block_read(dev, bufpos, buflen, pos, &entry, sizeof(entry), |
74 | sizeof(entry), TMPFS_BLOCK_SIZE)) |
69 | TMPFS_BLOCK_SIZE)) |
75 | return false; |
70 | return false; |
76 | 71 | ||
77 | entry.len = uint32_t_le2host(entry.len); |
72 | entry.len = uint32_t_le2host(entry.len); |
78 | 73 | ||
79 | switch (entry.type) { |
74 | switch (entry.type) { |
Line 88... | Line 83... | ||
88 | if (node == NULL) { |
83 | if (node == NULL) { |
89 | free(fname); |
84 | free(fname); |
90 | return false; |
85 | return false; |
91 | } |
86 | } |
92 | 87 | ||
93 | if (!libfs_blockread(phone, block, bufpos, buflen, pos, |
88 | if (!block_read(dev, bufpos, buflen, pos, fname, |
94 | fname, entry.len, TMPFS_BLOCK_SIZE)) { |
89 | entry.len, TMPFS_BLOCK_SIZE)) { |
95 | ops->destroy((void *) node); |
90 | ops->destroy((void *) node); |
96 | free(fname); |
91 | free(fname); |
97 | return false; |
92 | return false; |
98 | } |
93 | } |
99 | fname[entry.len] = 0; |
94 | fname[entry.len] = 0; |
Line 103... | Line 98... | ||
103 | free(fname); |
98 | free(fname); |
104 | return false; |
99 | return false; |
105 | } |
100 | } |
106 | free(fname); |
101 | free(fname); |
107 | 102 | ||
108 | if (!libfs_blockread(phone, block, bufpos, buflen, pos, |
103 | if (!block_read(dev, bufpos, buflen, pos, &size, |
109 | &size, sizeof(size), TMPFS_BLOCK_SIZE)) |
104 | sizeof(size), TMPFS_BLOCK_SIZE)) |
110 | return false; |
105 | return false; |
111 | 106 | ||
112 | size = uint32_t_le2host(size); |
107 | size = uint32_t_le2host(size); |
113 | 108 | ||
114 | node->data = malloc(size); |
109 | node->data = malloc(size); |
115 | if (node->data == NULL) |
110 | if (node->data == NULL) |
116 | return false; |
111 | return false; |
117 | 112 | ||
118 | node->size = size; |
113 | node->size = size; |
119 | if (!libfs_blockread(phone, block, bufpos, buflen, pos, |
114 | if (!block_read(dev, bufpos, buflen, pos, node->data, |
120 | node->data, size, TMPFS_BLOCK_SIZE)) |
115 | size, TMPFS_BLOCK_SIZE)) |
121 | return false; |
116 | return false; |
122 | 117 | ||
123 | break; |
118 | break; |
124 | case TMPFS_DIRECTORY: |
119 | case TMPFS_DIRECTORY: |
125 | fname = malloc(entry.len + 1); |
120 | fname = malloc(entry.len + 1); |
Line 130... | Line 125... | ||
130 | if (node == NULL) { |
125 | if (node == NULL) { |
131 | free(fname); |
126 | free(fname); |
132 | return false; |
127 | return false; |
133 | } |
128 | } |
134 | 129 | ||
135 | if (!libfs_blockread(phone, block, bufpos, buflen, pos, |
130 | if (!block_read(dev, bufpos, buflen, pos, |
136 | fname, entry.len, TMPFS_BLOCK_SIZE)) { |
131 | fname, entry.len, TMPFS_BLOCK_SIZE)) { |
137 | ops->destroy((void *) node); |
132 | ops->destroy((void *) node); |
138 | free(fname); |
133 | free(fname); |
139 | return false; |
134 | return false; |
140 | } |
135 | } |
Line 145... | Line 140... | ||
145 | free(fname); |
140 | free(fname); |
146 | return false; |
141 | return false; |
147 | } |
142 | } |
148 | free(fname); |
143 | free(fname); |
149 | 144 | ||
150 | if (!tmpfs_restore_recursion(phone, block, bufpos, |
145 | if (!tmpfs_restore_recursion(dev, bufpos, buflen, pos, |
151 | buflen, pos, node)) |
146 | node)) |
152 | return false; |
147 | return false; |
153 | 148 | ||
154 | break; |
149 | break; |
155 | default: |
150 | default: |
156 | return false; |
151 | return false; |
Line 161... | Line 156... | ||
161 | } |
156 | } |
162 | 157 | ||
163 | bool tmpfs_restore(dev_handle_t dev) |
158 | bool tmpfs_restore(dev_handle_t dev) |
164 | { |
159 | { |
165 | libfs_ops_t *ops = &tmpfs_libfs_ops; |
160 | libfs_ops_t *ops = &tmpfs_libfs_ops; |
- | 161 | int rc; |
|
166 | 162 | ||
167 | void *block = mmap(NULL, TMPFS_BLOCK_SIZE, |
163 | rc = block_init(dev, TMPFS_BLOCK_SIZE, 0, 0); |
168 | PROTO_READ | PROTO_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); |
- | |
169 | - | ||
170 | if (block == NULL) |
164 | if (rc != EOK) |
171 | return false; |
- | |
172 | - | ||
173 | int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, |
- | |
174 | DEVMAP_CONNECT_TO_DEVICE, dev); |
- | |
175 | - | ||
176 | if (phone < 0) { |
- | |
177 | munmap(block, TMPFS_BLOCK_SIZE); |
- | |
178 | return false; |
165 | return false; |
179 | } |
- | |
180 | - | ||
181 | if (ipc_share_out_start(phone, block, AS_AREA_READ | AS_AREA_WRITE) != |
- | |
182 | EOK) |
- | |
183 | goto error; |
- | |
184 | 166 | ||
185 | off_t bufpos = 0; |
167 | off_t bufpos = 0; |
186 | size_t buflen = 0; |
168 | size_t buflen = 0; |
187 | off_t pos = 0; |
169 | off_t pos = 0; |
188 | 170 | ||
189 | char tag[6]; |
171 | char tag[6]; |
190 | if (!libfs_blockread(phone, block, &bufpos, &buflen, &pos, tag, 5, |
172 | if (!block_read(dev, &bufpos, &buflen, &pos, tag, 5, |
191 | TMPFS_BLOCK_SIZE)) |
173 | TMPFS_BLOCK_SIZE)) |
192 | goto error; |
174 | goto error; |
193 | 175 | ||
194 | tag[5] = 0; |
176 | tag[5] = 0; |
195 | if (strcmp(tag, "TMPFS") != 0) |
177 | if (strcmp(tag, "TMPFS") != 0) |
196 | goto error; |
178 | goto error; |
197 | 179 | ||
198 | if (!tmpfs_restore_recursion(phone, block, &bufpos, &buflen, &pos, |
180 | if (!tmpfs_restore_recursion(dev, &bufpos, &buflen, &pos, |
199 | ops->root_get(dev))) |
181 | ops->root_get(dev))) |
200 | goto error; |
182 | goto error; |
201 | 183 | ||
202 | ipc_hangup(phone); |
184 | block_fini(dev); |
203 | munmap(block, TMPFS_BLOCK_SIZE); |
- | |
204 | return true; |
185 | return true; |
205 | 186 | ||
206 | error: |
187 | error: |
207 | ipc_hangup(phone); |
188 | block_fini(dev); |
208 | munmap(block, TMPFS_BLOCK_SIZE); |
- | |
209 | return false; |
189 | return false; |
210 | } |
190 | } |
211 | 191 | ||
212 | /** |
192 | /** |
213 | * @} |
193 | * @} |