mtdconcat.c (5def48982b778aaebe201f85af7170b7d0a6619f) mtdconcat.c (664addc248d2fed68d013d26ff2fc796d7134259)
1/*
2 * MTD device concatenation layer
3 *
4 * Copyright © 2002 Robert Kaiser <rkaiser@sysgo.de>
5 * Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
6 *
7 * NAND support by Christian Gan <cgan@iders.ca>
8 *

--- 112 unchanged lines hidden (view full) ---

121static int
122concat_write(struct mtd_info *mtd, loff_t to, size_t len,
123 size_t * retlen, const u_char * buf)
124{
125 struct mtd_concat *concat = CONCAT(mtd);
126 int err = -EINVAL;
127 int i;
128
1/*
2 * MTD device concatenation layer
3 *
4 * Copyright © 2002 Robert Kaiser <rkaiser@sysgo.de>
5 * Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
6 *
7 * NAND support by Christian Gan <cgan@iders.ca>
8 *

--- 112 unchanged lines hidden (view full) ---

121static int
122concat_write(struct mtd_info *mtd, loff_t to, size_t len,
123 size_t * retlen, const u_char * buf)
124{
125 struct mtd_concat *concat = CONCAT(mtd);
126 int err = -EINVAL;
127 int i;
128
129 if (!(mtd->flags & MTD_WRITEABLE))
130 return -EROFS;
131
132 *retlen = 0;
133
134 for (i = 0; i < concat->num_subdev; i++) {
135 struct mtd_info *subdev = concat->subdev[i];
136 size_t size, retsize;
137
138 if (to >= subdev->size) {
139 size = 0;
140 to -= subdev->size;
141 continue;
142 }
143 if (to + len > subdev->size)
144 size = subdev->size - to;
145 else
146 size = len;
147
129 *retlen = 0;
130
131 for (i = 0; i < concat->num_subdev; i++) {
132 struct mtd_info *subdev = concat->subdev[i];
133 size_t size, retsize;
134
135 if (to >= subdev->size) {
136 size = 0;
137 to -= subdev->size;
138 continue;
139 }
140 if (to + len > subdev->size)
141 size = subdev->size - to;
142 else
143 size = len;
144
148 if (!(subdev->flags & MTD_WRITEABLE))
149 err = -EROFS;
150 else
151 err = mtd_write(subdev, to, size, &retsize, buf);
152
145 err = mtd_write(subdev, to, size, &retsize, buf);
153 if (err)
154 break;
155
156 *retlen += retsize;
157 len -= size;
158 if (len == 0)
159 break;
160

--- 10 unchanged lines hidden (view full) ---

171{
172 struct mtd_concat *concat = CONCAT(mtd);
173 struct kvec *vecs_copy;
174 unsigned long entry_low, entry_high;
175 size_t total_len = 0;
176 int i;
177 int err = -EINVAL;
178
146 if (err)
147 break;
148
149 *retlen += retsize;
150 len -= size;
151 if (len == 0)
152 break;
153

--- 10 unchanged lines hidden (view full) ---

164{
165 struct mtd_concat *concat = CONCAT(mtd);
166 struct kvec *vecs_copy;
167 unsigned long entry_low, entry_high;
168 size_t total_len = 0;
169 int i;
170 int err = -EINVAL;
171
179 if (!(mtd->flags & MTD_WRITEABLE))
180 return -EROFS;
181
182 *retlen = 0;
183
184 /* Calculate total length of data */
185 for (i = 0; i < count; i++)
186 total_len += vecs[i].iov_len;
187
188 /* Check alignment */
189 if (mtd->writesize > 1) {

--- 25 unchanged lines hidden (view full) ---

215 if (size <= vecs_copy[entry_high].iov_len)
216 break;
217 size -= vecs_copy[entry_high++].iov_len;
218 }
219
220 old_iov_len = vecs_copy[entry_high].iov_len;
221 vecs_copy[entry_high].iov_len = size;
222
172 *retlen = 0;
173
174 /* Calculate total length of data */
175 for (i = 0; i < count; i++)
176 total_len += vecs[i].iov_len;
177
178 /* Check alignment */
179 if (mtd->writesize > 1) {

--- 25 unchanged lines hidden (view full) ---

205 if (size <= vecs_copy[entry_high].iov_len)
206 break;
207 size -= vecs_copy[entry_high++].iov_len;
208 }
209
210 old_iov_len = vecs_copy[entry_high].iov_len;
211 vecs_copy[entry_high].iov_len = size;
212
223 if (!(subdev->flags & MTD_WRITEABLE))
224 err = -EROFS;
225 else
226 err = mtd_writev(subdev, &vecs_copy[entry_low],
227 entry_high - entry_low + 1, to,
228 &retsize);
213 err = mtd_writev(subdev, &vecs_copy[entry_low],
214 entry_high - entry_low + 1, to, &retsize);
229
230 vecs_copy[entry_high].iov_len = old_iov_len - size;
231 vecs_copy[entry_high].iov_base += size;
232
233 entry_low = entry_high;
234
235 if (err)
236 break;

--- 157 unchanged lines hidden (view full) ---

394static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
395{
396 struct mtd_concat *concat = CONCAT(mtd);
397 struct mtd_info *subdev;
398 int i, err;
399 uint64_t length, offset = 0;
400 struct erase_info *erase;
401
215
216 vecs_copy[entry_high].iov_len = old_iov_len - size;
217 vecs_copy[entry_high].iov_base += size;
218
219 entry_low = entry_high;
220
221 if (err)
222 break;

--- 157 unchanged lines hidden (view full) ---

380static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
381{
382 struct mtd_concat *concat = CONCAT(mtd);
383 struct mtd_info *subdev;
384 int i, err;
385 uint64_t length, offset = 0;
386 struct erase_info *erase;
387
402 if (!(mtd->flags & MTD_WRITEABLE))
403 return -EROFS;
404
405 /*
406 * Check for proper erase block alignment of the to-be-erased area.
407 * It is easier to do this based on the super device's erase
408 * region info rather than looking at each particular sub-device
409 * in turn.
410 */
411 if (!concat->mtd.numeraseregions) {
412 /* the easy case: device has uniform erase block size */

--- 71 unchanged lines hidden (view full) ---

484 subdev = concat->subdev[i]; /* get current subdevice */
485
486 /* limit length to subdevice's size: */
487 if (erase->addr + length > subdev->size)
488 erase->len = subdev->size - erase->addr;
489 else
490 erase->len = length;
491
388 /*
389 * Check for proper erase block alignment of the to-be-erased area.
390 * It is easier to do this based on the super device's erase
391 * region info rather than looking at each particular sub-device
392 * in turn.
393 */
394 if (!concat->mtd.numeraseregions) {
395 /* the easy case: device has uniform erase block size */

--- 71 unchanged lines hidden (view full) ---

467 subdev = concat->subdev[i]; /* get current subdevice */
468
469 /* limit length to subdevice's size: */
470 if (erase->addr + length > subdev->size)
471 erase->len = subdev->size - erase->addr;
472 else
473 erase->len = length;
474
492 if (!(subdev->flags & MTD_WRITEABLE)) {
493 err = -EROFS;
494 break;
495 }
496 length -= erase->len;
497 if ((err = concat_dev_erase(subdev, erase))) {
498 /* sanity check: should never happen since
499 * block alignment has been checked above */
500 BUG_ON(err == -EINVAL);
501 if (erase->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
502 instr->fail_addr = erase->fail_addr + offset;
503 break;

--- 477 unchanged lines hidden ---
475 length -= erase->len;
476 if ((err = concat_dev_erase(subdev, erase))) {
477 /* sanity check: should never happen since
478 * block alignment has been checked above */
479 BUG_ON(err == -EINVAL);
480 if (erase->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
481 instr->fail_addr = erase->fail_addr + offset;
482 break;

--- 477 unchanged lines hidden ---