fastmap.c (1f81a5ccaba51c8884db8f060b9f606c29db931d) fastmap.c (3291b52f9ff0acc80a8ee3f92a960db937dccecb)
1/*
2 * Copyright (c) 2012 Linutronix GmbH
3 * Copyright (c) 2014 sigma star gmbh
4 * Author: Richard Weinberger <richard@nod.at>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2.

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

105/**
106 * new_fm_vhdr - allocate a new volume header for fastmap usage.
107 * @ubi: UBI device description object
108 * @vol_id: the VID of the new header
109 *
110 * Returns a new struct ubi_vid_hdr on success.
111 * NULL indicates out of memory.
112 */
1/*
2 * Copyright (c) 2012 Linutronix GmbH
3 * Copyright (c) 2014 sigma star gmbh
4 * Author: Richard Weinberger <richard@nod.at>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2.

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

105/**
106 * new_fm_vhdr - allocate a new volume header for fastmap usage.
107 * @ubi: UBI device description object
108 * @vol_id: the VID of the new header
109 *
110 * Returns a new struct ubi_vid_hdr on success.
111 * NULL indicates out of memory.
112 */
113static struct ubi_vid_hdr *new_fm_vhdr(struct ubi_device *ubi, int vol_id)
113static struct ubi_vid_io_buf *new_fm_vbuf(struct ubi_device *ubi, int vol_id)
114{
114{
115 struct ubi_vid_hdr *new;
115 struct ubi_vid_io_buf *new;
116 struct ubi_vid_hdr *vh;
116
117
117 new = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
118 new = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
118 if (!new)
119 goto out;
120
119 if (!new)
120 goto out;
121
121 new->vol_type = UBI_VID_DYNAMIC;
122 new->vol_id = cpu_to_be32(vol_id);
122 vh = ubi_get_vid_hdr(new);
123 vh->vol_type = UBI_VID_DYNAMIC;
124 vh->vol_id = cpu_to_be32(vol_id);
123
124 /* UBI implementations without fastmap support have to delete the
125 * fastmap.
126 */
125
126 /* UBI implementations without fastmap support have to delete the
127 * fastmap.
128 */
127 new->compat = UBI_COMPAT_DELETE;
129 vh->compat = UBI_COMPAT_DELETE;
128
129out:
130 return new;
131}
132
133/**
134 * add_aeb - create and add a attach erase block to a given list.
135 * @ai: UBI attach info object

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

403 *
404 * Returns 0 on success, if the pool is unusable UBI_BAD_FASTMAP is returned.
405 * < 0 indicates an internal error.
406 */
407static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
408 __be32 *pebs, int pool_size, unsigned long long *max_sqnum,
409 struct list_head *free)
410{
130
131out:
132 return new;
133}
134
135/**
136 * add_aeb - create and add a attach erase block to a given list.
137 * @ai: UBI attach info object

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

405 *
406 * Returns 0 on success, if the pool is unusable UBI_BAD_FASTMAP is returned.
407 * < 0 indicates an internal error.
408 */
409static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
410 __be32 *pebs, int pool_size, unsigned long long *max_sqnum,
411 struct list_head *free)
412{
413 struct ubi_vid_io_buf *vb;
411 struct ubi_vid_hdr *vh;
412 struct ubi_ec_hdr *ech;
413 struct ubi_ainf_peb *new_aeb;
414 int i, pnum, err, ret = 0;
415
416 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
417 if (!ech)
418 return -ENOMEM;
419
414 struct ubi_vid_hdr *vh;
415 struct ubi_ec_hdr *ech;
416 struct ubi_ainf_peb *new_aeb;
417 int i, pnum, err, ret = 0;
418
419 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
420 if (!ech)
421 return -ENOMEM;
422
420 vh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
421 if (!vh) {
423 vb = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
424 if (!vb) {
422 kfree(ech);
423 return -ENOMEM;
424 }
425
425 kfree(ech);
426 return -ENOMEM;
427 }
428
429 vh = ubi_get_vid_hdr(vb);
430
426 dbg_bld("scanning fastmap pool: size = %i", pool_size);
427
428 /*
429 * Now scan all PEBs in the pool to find changes which have been made
430 * after the creation of the fastmap
431 */
432 for (i = 0; i < pool_size; i++) {
433 int scrub = 0;

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

458
459 if (image_seq && (image_seq != ubi->image_seq)) {
460 ubi_err(ubi, "bad image seq: 0x%x, expected: 0x%x",
461 be32_to_cpu(ech->image_seq), ubi->image_seq);
462 ret = UBI_BAD_FASTMAP;
463 goto out;
464 }
465
431 dbg_bld("scanning fastmap pool: size = %i", pool_size);
432
433 /*
434 * Now scan all PEBs in the pool to find changes which have been made
435 * after the creation of the fastmap
436 */
437 for (i = 0; i < pool_size; i++) {
438 int scrub = 0;

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

463
464 if (image_seq && (image_seq != ubi->image_seq)) {
465 ubi_err(ubi, "bad image seq: 0x%x, expected: 0x%x",
466 be32_to_cpu(ech->image_seq), ubi->image_seq);
467 ret = UBI_BAD_FASTMAP;
468 goto out;
469 }
470
466 err = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
471 err = ubi_io_read_vid_hdr(ubi, pnum, vb, 0);
467 if (err == UBI_IO_FF || err == UBI_IO_FF_BITFLIPS) {
468 unsigned long long ec = be64_to_cpu(ech->ec);
469 unmap_peb(ai, pnum);
470 dbg_bld("Adding PEB to free: %i", pnum);
471
472 if (err == UBI_IO_FF_BITFLIPS)
473 scrub = 1;
474

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

504 ubi_err(ubi, "fastmap pool PEBs contains damaged PEBs!");
505 ret = err > 0 ? UBI_BAD_FASTMAP : err;
506 goto out;
507 }
508
509 }
510
511out:
472 if (err == UBI_IO_FF || err == UBI_IO_FF_BITFLIPS) {
473 unsigned long long ec = be64_to_cpu(ech->ec);
474 unmap_peb(ai, pnum);
475 dbg_bld("Adding PEB to free: %i", pnum);
476
477 if (err == UBI_IO_FF_BITFLIPS)
478 scrub = 1;
479

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

509 ubi_err(ubi, "fastmap pool PEBs contains damaged PEBs!");
510 ret = err > 0 ? UBI_BAD_FASTMAP : err;
511 goto out;
512 }
513
514 }
515
516out:
512 ubi_free_vid_hdr(ubi, vh);
517 ubi_free_vid_buf(vb);
513 kfree(ech);
514 return ret;
515}
516
517/**
518 * count_fastmap_pebs - Counts the PEBs found by fastmap.
519 * @ai: The UBI attach info object
520 */

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

832 * Returns 0 on success, UBI_NO_FASTMAP if no fastmap was found,
833 * UBI_BAD_FASTMAP if one was found but is not usable.
834 * < 0 indicates an internal error.
835 */
836int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
837 struct ubi_attach_info *scan_ai)
838{
839 struct ubi_fm_sb *fmsb, *fmsb2;
518 kfree(ech);
519 return ret;
520}
521
522/**
523 * count_fastmap_pebs - Counts the PEBs found by fastmap.
524 * @ai: The UBI attach info object
525 */

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

837 * Returns 0 on success, UBI_NO_FASTMAP if no fastmap was found,
838 * UBI_BAD_FASTMAP if one was found but is not usable.
839 * < 0 indicates an internal error.
840 */
841int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
842 struct ubi_attach_info *scan_ai)
843{
844 struct ubi_fm_sb *fmsb, *fmsb2;
845 struct ubi_vid_io_buf *vb;
840 struct ubi_vid_hdr *vh;
841 struct ubi_ec_hdr *ech;
842 struct ubi_fastmap_layout *fm;
843 struct ubi_ainf_peb *tmp_aeb, *aeb;
844 int i, used_blocks, pnum, fm_anchor, ret = 0;
845 size_t fm_size;
846 __be32 crc, tmp_crc;
847 unsigned long long sqnum = 0;

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

907 }
908
909 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
910 if (!ech) {
911 ret = -ENOMEM;
912 goto free_fm_sb;
913 }
914
846 struct ubi_vid_hdr *vh;
847 struct ubi_ec_hdr *ech;
848 struct ubi_fastmap_layout *fm;
849 struct ubi_ainf_peb *tmp_aeb, *aeb;
850 int i, used_blocks, pnum, fm_anchor, ret = 0;
851 size_t fm_size;
852 __be32 crc, tmp_crc;
853 unsigned long long sqnum = 0;

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

913 }
914
915 ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
916 if (!ech) {
917 ret = -ENOMEM;
918 goto free_fm_sb;
919 }
920
915 vh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
916 if (!vh) {
921 vb = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
922 if (!vb) {
917 ret = -ENOMEM;
918 goto free_hdr;
919 }
920
923 ret = -ENOMEM;
924 goto free_hdr;
925 }
926
927 vh = ubi_get_vid_hdr(vb);
928
921 for (i = 0; i < used_blocks; i++) {
922 int image_seq;
923
924 pnum = be32_to_cpu(fmsb->block_loc[i]);
925
926 if (ubi_io_is_bad(ubi, pnum)) {
927 ret = UBI_BAD_FASTMAP;
928 goto free_hdr;

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

955 */
956 if (image_seq && (image_seq != ubi->image_seq)) {
957 ubi_err(ubi, "wrong image seq:%d instead of %d",
958 be32_to_cpu(ech->image_seq), ubi->image_seq);
959 ret = UBI_BAD_FASTMAP;
960 goto free_hdr;
961 }
962
929 for (i = 0; i < used_blocks; i++) {
930 int image_seq;
931
932 pnum = be32_to_cpu(fmsb->block_loc[i]);
933
934 if (ubi_io_is_bad(ubi, pnum)) {
935 ret = UBI_BAD_FASTMAP;
936 goto free_hdr;

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

963 */
964 if (image_seq && (image_seq != ubi->image_seq)) {
965 ubi_err(ubi, "wrong image seq:%d instead of %d",
966 be32_to_cpu(ech->image_seq), ubi->image_seq);
967 ret = UBI_BAD_FASTMAP;
968 goto free_hdr;
969 }
970
963 ret = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
971 ret = ubi_io_read_vid_hdr(ubi, pnum, vb, 0);
964 if (ret && ret != UBI_IO_BITFLIPS) {
965 ubi_err(ubi, "unable to read fastmap block# %i (PEB: %i)",
966 i, pnum);
967 goto free_hdr;
968 }
969
970 if (i == 0) {
971 if (be32_to_cpu(vh->vol_id) != UBI_FM_SB_VOLUME_ID) {

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

1045 ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size;
1046 ubi_msg(ubi, "attached by fastmap");
1047 ubi_msg(ubi, "fastmap pool size: %d", ubi->fm_pool.max_size);
1048 ubi_msg(ubi, "fastmap WL pool size: %d",
1049 ubi->fm_wl_pool.max_size);
1050 ubi->fm_disabled = 0;
1051 ubi->fast_attach = 1;
1052
972 if (ret && ret != UBI_IO_BITFLIPS) {
973 ubi_err(ubi, "unable to read fastmap block# %i (PEB: %i)",
974 i, pnum);
975 goto free_hdr;
976 }
977
978 if (i == 0) {
979 if (be32_to_cpu(vh->vol_id) != UBI_FM_SB_VOLUME_ID) {

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

1053 ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size;
1054 ubi_msg(ubi, "attached by fastmap");
1055 ubi_msg(ubi, "fastmap pool size: %d", ubi->fm_pool.max_size);
1056 ubi_msg(ubi, "fastmap WL pool size: %d",
1057 ubi->fm_wl_pool.max_size);
1058 ubi->fm_disabled = 0;
1059 ubi->fast_attach = 1;
1060
1053 ubi_free_vid_hdr(ubi, vh);
1061 ubi_free_vid_buf(vb);
1054 kfree(ech);
1055out:
1056 up_write(&ubi->fm_protect);
1057 if (ret == UBI_BAD_FASTMAP)
1058 ubi_err(ubi, "Attach by fastmap failed, doing a full scan!");
1059 return ret;
1060
1061free_hdr:
1062 kfree(ech);
1063out:
1064 up_write(&ubi->fm_protect);
1065 if (ret == UBI_BAD_FASTMAP)
1066 ubi_err(ubi, "Attach by fastmap failed, doing a full scan!");
1067 return ret;
1068
1069free_hdr:
1062 ubi_free_vid_hdr(ubi, vh);
1070 ubi_free_vid_buf(vb);
1063 kfree(ech);
1064free_fm_sb:
1065 kfree(fmsb);
1066 kfree(fm);
1067 goto out;
1068}
1069
1070/**

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

1082 struct ubi_fm_sb *fmsb;
1083 struct ubi_fm_hdr *fmh;
1084 struct ubi_fm_scan_pool *fmpl, *fmpl_wl;
1085 struct ubi_fm_ec *fec;
1086 struct ubi_fm_volhdr *fvh;
1087 struct ubi_fm_eba *feba;
1088 struct ubi_wl_entry *wl_e;
1089 struct ubi_volume *vol;
1071 kfree(ech);
1072free_fm_sb:
1073 kfree(fmsb);
1074 kfree(fm);
1075 goto out;
1076}
1077
1078/**

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

1090 struct ubi_fm_sb *fmsb;
1091 struct ubi_fm_hdr *fmh;
1092 struct ubi_fm_scan_pool *fmpl, *fmpl_wl;
1093 struct ubi_fm_ec *fec;
1094 struct ubi_fm_volhdr *fvh;
1095 struct ubi_fm_eba *feba;
1096 struct ubi_wl_entry *wl_e;
1097 struct ubi_volume *vol;
1098 struct ubi_vid_io_buf *avbuf, *dvbuf;
1090 struct ubi_vid_hdr *avhdr, *dvhdr;
1091 struct ubi_work *ubi_wrk;
1092 struct rb_node *tmp_rb;
1093 int ret, i, j, free_peb_count, used_peb_count, vol_count;
1094 int scrub_peb_count, erase_peb_count;
1095 unsigned long *seen_pebs = NULL;
1096
1097 fm_raw = ubi->fm_buf;
1098 memset(ubi->fm_buf, 0, ubi->fm_size);
1099
1099 struct ubi_vid_hdr *avhdr, *dvhdr;
1100 struct ubi_work *ubi_wrk;
1101 struct rb_node *tmp_rb;
1102 int ret, i, j, free_peb_count, used_peb_count, vol_count;
1103 int scrub_peb_count, erase_peb_count;
1104 unsigned long *seen_pebs = NULL;
1105
1106 fm_raw = ubi->fm_buf;
1107 memset(ubi->fm_buf, 0, ubi->fm_size);
1108
1100 avhdr = new_fm_vhdr(ubi, UBI_FM_SB_VOLUME_ID);
1101 if (!avhdr) {
1109 avbuf = new_fm_vbuf(ubi, UBI_FM_SB_VOLUME_ID);
1110 if (!avbuf) {
1102 ret = -ENOMEM;
1103 goto out;
1104 }
1105
1111 ret = -ENOMEM;
1112 goto out;
1113 }
1114
1106 dvhdr = new_fm_vhdr(ubi, UBI_FM_DATA_VOLUME_ID);
1107 if (!dvhdr) {
1115 dvbuf = new_fm_vbuf(ubi, UBI_FM_DATA_VOLUME_ID);
1116 if (!dvbuf) {
1108 ret = -ENOMEM;
1109 goto out_kfree;
1110 }
1111
1117 ret = -ENOMEM;
1118 goto out_kfree;
1119 }
1120
1121 avhdr = ubi_get_vid_hdr(avbuf);
1122 dvhdr = ubi_get_vid_hdr(dvbuf);
1123
1112 seen_pebs = init_seen(ubi);
1113 if (IS_ERR(seen_pebs)) {
1114 ret = PTR_ERR(seen_pebs);
1115 goto out_kfree;
1116 }
1117
1118 spin_lock(&ubi->volumes_lock);
1119 spin_lock(&ubi->wl_lock);

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

1272
1273 avhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
1274 avhdr->lnum = 0;
1275
1276 spin_unlock(&ubi->wl_lock);
1277 spin_unlock(&ubi->volumes_lock);
1278
1279 dbg_bld("writing fastmap SB to PEB %i", new_fm->e[0]->pnum);
1124 seen_pebs = init_seen(ubi);
1125 if (IS_ERR(seen_pebs)) {
1126 ret = PTR_ERR(seen_pebs);
1127 goto out_kfree;
1128 }
1129
1130 spin_lock(&ubi->volumes_lock);
1131 spin_lock(&ubi->wl_lock);

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

1284
1285 avhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
1286 avhdr->lnum = 0;
1287
1288 spin_unlock(&ubi->wl_lock);
1289 spin_unlock(&ubi->volumes_lock);
1290
1291 dbg_bld("writing fastmap SB to PEB %i", new_fm->e[0]->pnum);
1280 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[0]->pnum, avhdr);
1292 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[0]->pnum, avbuf);
1281 if (ret) {
1282 ubi_err(ubi, "unable to write vid_hdr to fastmap SB!");
1283 goto out_kfree;
1284 }
1285
1286 for (i = 0; i < new_fm->used_blocks; i++) {
1287 fmsb->block_loc[i] = cpu_to_be32(new_fm->e[i]->pnum);
1288 set_seen(ubi, new_fm->e[i]->pnum, seen_pebs);

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

1293 fmsb->data_crc = cpu_to_be32(crc32(UBI_CRC32_INIT, fm_raw,
1294 ubi->fm_size));
1295
1296 for (i = 1; i < new_fm->used_blocks; i++) {
1297 dvhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
1298 dvhdr->lnum = cpu_to_be32(i);
1299 dbg_bld("writing fastmap data to PEB %i sqnum %llu",
1300 new_fm->e[i]->pnum, be64_to_cpu(dvhdr->sqnum));
1293 if (ret) {
1294 ubi_err(ubi, "unable to write vid_hdr to fastmap SB!");
1295 goto out_kfree;
1296 }
1297
1298 for (i = 0; i < new_fm->used_blocks; i++) {
1299 fmsb->block_loc[i] = cpu_to_be32(new_fm->e[i]->pnum);
1300 set_seen(ubi, new_fm->e[i]->pnum, seen_pebs);

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

1305 fmsb->data_crc = cpu_to_be32(crc32(UBI_CRC32_INIT, fm_raw,
1306 ubi->fm_size));
1307
1308 for (i = 1; i < new_fm->used_blocks; i++) {
1309 dvhdr->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
1310 dvhdr->lnum = cpu_to_be32(i);
1311 dbg_bld("writing fastmap data to PEB %i sqnum %llu",
1312 new_fm->e[i]->pnum, be64_to_cpu(dvhdr->sqnum));
1301 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[i]->pnum, dvhdr);
1313 ret = ubi_io_write_vid_hdr(ubi, new_fm->e[i]->pnum, dvbuf);
1302 if (ret) {
1303 ubi_err(ubi, "unable to write vid_hdr to PEB %i!",
1304 new_fm->e[i]->pnum);
1305 goto out_kfree;
1306 }
1307 }
1308
1309 for (i = 0; i < new_fm->used_blocks; i++) {

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

1318
1319 ubi_assert(new_fm);
1320 ubi->fm = new_fm;
1321
1322 ret = self_check_seen(ubi, seen_pebs);
1323 dbg_bld("fastmap written!");
1324
1325out_kfree:
1314 if (ret) {
1315 ubi_err(ubi, "unable to write vid_hdr to PEB %i!",
1316 new_fm->e[i]->pnum);
1317 goto out_kfree;
1318 }
1319 }
1320
1321 for (i = 0; i < new_fm->used_blocks; i++) {

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

1330
1331 ubi_assert(new_fm);
1332 ubi->fm = new_fm;
1333
1334 ret = self_check_seen(ubi, seen_pebs);
1335 dbg_bld("fastmap written!");
1336
1337out_kfree:
1326 ubi_free_vid_hdr(ubi, avhdr);
1327 ubi_free_vid_hdr(ubi, dvhdr);
1338 ubi_free_vid_buf(avbuf);
1339 ubi_free_vid_buf(dvbuf);
1328 free_seen(seen_pebs);
1329out:
1330 return ret;
1331}
1332
1333/**
1334 * erase_block - Manually erase a PEB.
1335 * @ubi: UBI device object

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

1389 * current fastmap in a valid state.
1390 * Returns 0 on success, < 0 indicates an internal error.
1391 */
1392static int invalidate_fastmap(struct ubi_device *ubi)
1393{
1394 int ret;
1395 struct ubi_fastmap_layout *fm;
1396 struct ubi_wl_entry *e;
1340 free_seen(seen_pebs);
1341out:
1342 return ret;
1343}
1344
1345/**
1346 * erase_block - Manually erase a PEB.
1347 * @ubi: UBI device object

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

1401 * current fastmap in a valid state.
1402 * Returns 0 on success, < 0 indicates an internal error.
1403 */
1404static int invalidate_fastmap(struct ubi_device *ubi)
1405{
1406 int ret;
1407 struct ubi_fastmap_layout *fm;
1408 struct ubi_wl_entry *e;
1397 struct ubi_vid_hdr *vh = NULL;
1409 struct ubi_vid_io_buf *vb = NULL;
1410 struct ubi_vid_hdr *vh;
1398
1399 if (!ubi->fm)
1400 return 0;
1401
1402 ubi->fm = NULL;
1403
1404 ret = -ENOMEM;
1405 fm = kzalloc(sizeof(*fm), GFP_KERNEL);
1406 if (!fm)
1407 goto out;
1408
1411
1412 if (!ubi->fm)
1413 return 0;
1414
1415 ubi->fm = NULL;
1416
1417 ret = -ENOMEM;
1418 fm = kzalloc(sizeof(*fm), GFP_KERNEL);
1419 if (!fm)
1420 goto out;
1421
1409 vh = new_fm_vhdr(ubi, UBI_FM_SB_VOLUME_ID);
1410 if (!vh)
1422 vb = new_fm_vbuf(ubi, UBI_FM_SB_VOLUME_ID);
1423 if (!vb)
1411 goto out_free_fm;
1412
1424 goto out_free_fm;
1425
1426 vh = ubi_get_vid_hdr(vb);
1427
1413 ret = -ENOSPC;
1414 e = ubi_wl_get_fm_peb(ubi, 1);
1415 if (!e)
1416 goto out_free_fm;
1417
1418 /*
1419 * Create fake fastmap such that UBI will fall back
1420 * to scanning mode.
1421 */
1422 vh->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
1428 ret = -ENOSPC;
1429 e = ubi_wl_get_fm_peb(ubi, 1);
1430 if (!e)
1431 goto out_free_fm;
1432
1433 /*
1434 * Create fake fastmap such that UBI will fall back
1435 * to scanning mode.
1436 */
1437 vh->sqnum = cpu_to_be64(ubi_next_sqnum(ubi));
1423 ret = ubi_io_write_vid_hdr(ubi, e->pnum, vh);
1438 ret = ubi_io_write_vid_hdr(ubi, e->pnum, vb);
1424 if (ret < 0) {
1425 ubi_wl_put_fm_peb(ubi, e, 0, 0);
1426 goto out_free_fm;
1427 }
1428
1429 fm->used_blocks = 1;
1430 fm->e[0] = e;
1431
1432 ubi->fm = fm;
1433
1434out:
1439 if (ret < 0) {
1440 ubi_wl_put_fm_peb(ubi, e, 0, 0);
1441 goto out_free_fm;
1442 }
1443
1444 fm->used_blocks = 1;
1445 fm->e[0] = e;
1446
1447 ubi->fm = fm;
1448
1449out:
1435 ubi_free_vid_hdr(ubi, vh);
1450 ubi_free_vid_buf(vb);
1436 return ret;
1437
1438out_free_fm:
1439 kfree(fm);
1440 goto out;
1441}
1442
1443/**

--- 190 unchanged lines hidden ---
1451 return ret;
1452
1453out_free_fm:
1454 kfree(fm);
1455 goto out;
1456}
1457
1458/**

--- 190 unchanged lines hidden ---