vtbl.c (91f4285fe389a2729efcd5db642d7652d8f27a40) vtbl.c (3291b52f9ff0acc80a8ee3f92a960db937dccecb)
1/*
2 * Copyright (c) International Business Machines Corp., 2006
3 * Copyright (c) Nokia Corporation, 2006, 2007
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

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

294 *
295 * This function returns zero in case of success and a negative error code in
296 * case of failure.
297 */
298static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai,
299 int copy, void *vtbl)
300{
301 int err, tries = 0;
1/*
2 * Copyright (c) International Business Machines Corp., 2006
3 * Copyright (c) Nokia Corporation, 2006, 2007
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

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

294 *
295 * This function returns zero in case of success and a negative error code in
296 * case of failure.
297 */
298static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai,
299 int copy, void *vtbl)
300{
301 int err, tries = 0;
302 struct ubi_vid_io_buf *vidb;
302 struct ubi_vid_hdr *vid_hdr;
303 struct ubi_ainf_peb *new_aeb;
304
305 dbg_gen("create volume table (copy #%d)", copy + 1);
306
303 struct ubi_vid_hdr *vid_hdr;
304 struct ubi_ainf_peb *new_aeb;
305
306 dbg_gen("create volume table (copy #%d)", copy + 1);
307
307 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
308 if (!vid_hdr)
308 vidb = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
309 if (!vidb)
309 return -ENOMEM;
310
310 return -ENOMEM;
311
312 vid_hdr = ubi_get_vid_hdr(vidb);
313
311retry:
312 new_aeb = ubi_early_get_peb(ubi, ai);
313 if (IS_ERR(new_aeb)) {
314 err = PTR_ERR(new_aeb);
315 goto out_free;
316 }
317
318 vid_hdr->vol_type = UBI_LAYOUT_VOLUME_TYPE;
319 vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOLUME_ID);
320 vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT;
321 vid_hdr->data_size = vid_hdr->used_ebs =
322 vid_hdr->data_pad = cpu_to_be32(0);
323 vid_hdr->lnum = cpu_to_be32(copy);
324 vid_hdr->sqnum = cpu_to_be64(++ai->max_sqnum);
325
326 /* The EC header is already there, write the VID header */
314retry:
315 new_aeb = ubi_early_get_peb(ubi, ai);
316 if (IS_ERR(new_aeb)) {
317 err = PTR_ERR(new_aeb);
318 goto out_free;
319 }
320
321 vid_hdr->vol_type = UBI_LAYOUT_VOLUME_TYPE;
322 vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOLUME_ID);
323 vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT;
324 vid_hdr->data_size = vid_hdr->used_ebs =
325 vid_hdr->data_pad = cpu_to_be32(0);
326 vid_hdr->lnum = cpu_to_be32(copy);
327 vid_hdr->sqnum = cpu_to_be64(++ai->max_sqnum);
328
329 /* The EC header is already there, write the VID header */
327 err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vid_hdr);
330 err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vidb);
328 if (err)
329 goto write_error;
330
331 /* Write the layout volume contents */
332 err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size);
333 if (err)
334 goto write_error;
335
336 /*
337 * And add it to the attaching information. Don't delete the old version
338 * of this LEB as it will be deleted and freed in 'ubi_add_to_av()'.
339 */
340 err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0);
341 ubi_free_aeb(ai, new_aeb);
331 if (err)
332 goto write_error;
333
334 /* Write the layout volume contents */
335 err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size);
336 if (err)
337 goto write_error;
338
339 /*
340 * And add it to the attaching information. Don't delete the old version
341 * of this LEB as it will be deleted and freed in 'ubi_add_to_av()'.
342 */
343 err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0);
344 ubi_free_aeb(ai, new_aeb);
342 ubi_free_vid_hdr(ubi, vid_hdr);
345 ubi_free_vid_buf(vidb);
343 return err;
344
345write_error:
346 if (err == -EIO && ++tries <= 5) {
347 /*
348 * Probably this physical eraseblock went bad, try to pick
349 * another one.
350 */
351 list_add(&new_aeb->u.list, &ai->erase);
352 goto retry;
353 }
354 ubi_free_aeb(ai, new_aeb);
355out_free:
346 return err;
347
348write_error:
349 if (err == -EIO && ++tries <= 5) {
350 /*
351 * Probably this physical eraseblock went bad, try to pick
352 * another one.
353 */
354 list_add(&new_aeb->u.list, &ai->erase);
355 goto retry;
356 }
357 ubi_free_aeb(ai, new_aeb);
358out_free:
356 ubi_free_vid_hdr(ubi, vid_hdr);
359 ubi_free_vid_buf(vidb);
357 return err;
358
359}
360
361/**
362 * process_lvol - process the layout volume.
363 * @ubi: UBI device description object
364 * @ai: attaching information

--- 504 unchanged lines hidden ---
360 return err;
361
362}
363
364/**
365 * process_lvol - process the layout volume.
366 * @ubi: UBI device description object
367 * @ai: attaching information

--- 504 unchanged lines hidden ---