Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge git://git.infradead.org/~dedekind/ubi-2.6

+441 -188
+68 -35
drivers/mtd/ubi/build.c
··· 66 66 /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ 67 67 struct class *ubi_class; 68 68 69 - /* Slab cache for lock-tree entries */ 70 - struct kmem_cache *ubi_ltree_slab; 71 - 72 69 /* Slab cache for wear-leveling entries */ 73 70 struct kmem_cache *ubi_wl_entry_slab; 74 71 ··· 366 369 int i, err; 367 370 dev_t dev; 368 371 369 - mutex_init(&ubi->volumes_mutex); 370 - spin_lock_init(&ubi->volumes_lock); 371 - 372 372 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); 373 373 374 374 /* ··· 562 568 } 563 569 564 570 /* Similar for the data offset */ 565 - ubi->leb_start = ubi->vid_hdr_offset + ubi->vid_hdr_alsize; 571 + ubi->leb_start = ubi->vid_hdr_offset + UBI_EC_HDR_SIZE; 566 572 ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size); 567 573 568 574 dbg_msg("vid_hdr_offset %d", ubi->vid_hdr_offset); ··· 617 623 * uninitialized and initialize it after scanning. 618 624 */ 619 625 626 + return 0; 627 + } 628 + 629 + /** 630 + * autoresize - re-size the volume which has the "auto-resize" flag set. 631 + * @ubi: UBI device description object 632 + * @vol_id: ID of the volume to re-size 633 + * 634 + * This function re-sizes the volume marked by the @UBI_VTBL_AUTORESIZE_FLG in 635 + * the volume table to the largest possible size. See comments in ubi-header.h 636 + * for more description of the flag. Returns zero in case of success and a 637 + * negative error code in case of failure. 638 + */ 639 + static int autoresize(struct ubi_device *ubi, int vol_id) 640 + { 641 + struct ubi_volume_desc desc; 642 + struct ubi_volume *vol = ubi->volumes[vol_id]; 643 + int err, old_reserved_pebs = vol->reserved_pebs; 644 + 645 + /* 646 + * Clear the auto-resize flag in the volume in-memory copy of the 647 + * volume table, and 'ubi_resize_volume()' will propogate this change 648 + * to the flash. 649 + */ 650 + ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG; 651 + 652 + if (ubi->avail_pebs == 0) { 653 + struct ubi_vtbl_record vtbl_rec; 654 + 655 + /* 656 + * No avalilable PEBs to re-size the volume, clear the flag on 657 + * flash and exit. 658 + */ 659 + memcpy(&vtbl_rec, &ubi->vtbl[vol_id], 660 + sizeof(struct ubi_vtbl_record)); 661 + err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 662 + if (err) 663 + ubi_err("cannot clean auto-resize flag for volume %d", 664 + vol_id); 665 + } else { 666 + desc.vol = vol; 667 + err = ubi_resize_volume(&desc, 668 + old_reserved_pebs + ubi->avail_pebs); 669 + if (err) 670 + ubi_err("cannot auto-resize volume %d", vol_id); 671 + } 672 + 673 + if (err) 674 + return err; 675 + 676 + ubi_msg("volume %d (\"%s\") re-sized from %d to %d LEBs", vol_id, 677 + vol->name, old_reserved_pebs, vol->reserved_pebs); 620 678 return 0; 621 679 } 622 680 ··· 748 702 ubi->mtd = mtd; 749 703 ubi->ubi_num = ubi_num; 750 704 ubi->vid_hdr_offset = vid_hdr_offset; 705 + ubi->autoresize_vol_id = -1; 706 + 707 + mutex_init(&ubi->buf_mutex); 708 + mutex_init(&ubi->ckvol_mutex); 709 + mutex_init(&ubi->volumes_mutex); 710 + spin_lock_init(&ubi->volumes_lock); 751 711 752 712 dbg_msg("attaching mtd%d to ubi%d: VID header offset %d", 753 713 mtd->index, ubi_num, vid_hdr_offset); ··· 762 710 if (err) 763 711 goto out_free; 764 712 765 - mutex_init(&ubi->buf_mutex); 766 - mutex_init(&ubi->ckvol_mutex); 767 713 ubi->peb_buf1 = vmalloc(ubi->peb_size); 768 714 if (!ubi->peb_buf1) 769 715 goto out_free; ··· 781 731 if (err) { 782 732 dbg_err("failed to attach by scanning, error %d", err); 783 733 goto out_free; 734 + } 735 + 736 + if (ubi->autoresize_vol_id != -1) { 737 + err = autoresize(ubi, ubi->autoresize_vol_id); 738 + if (err) 739 + goto out_detach; 784 740 } 785 741 786 742 err = uif_init(ubi); ··· 914 858 } 915 859 916 860 /** 917 - * ltree_entry_ctor - lock tree entries slab cache constructor. 918 - * @obj: the lock-tree entry to construct 919 - * @cache: the lock tree entry slab cache 920 - * @flags: constructor flags 921 - */ 922 - static void ltree_entry_ctor(struct kmem_cache *cache, void *obj) 923 - { 924 - struct ubi_ltree_entry *le = obj; 925 - 926 - le->users = 0; 927 - init_rwsem(&le->mutex); 928 - } 929 - 930 - /** 931 861 * find_mtd_device - open an MTD device by its name or number. 932 862 * @mtd_dev: name or number of the device 933 863 * ··· 975 933 goto out_version; 976 934 } 977 935 978 - ubi_ltree_slab = kmem_cache_create("ubi_ltree_slab", 979 - sizeof(struct ubi_ltree_entry), 0, 980 - 0, &ltree_entry_ctor); 981 - if (!ubi_ltree_slab) 982 - goto out_dev_unreg; 983 - 984 936 ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab", 985 937 sizeof(struct ubi_wl_entry), 986 938 0, 0, NULL); 987 939 if (!ubi_wl_entry_slab) 988 - goto out_ltree; 940 + goto out_dev_unreg; 989 941 990 942 /* Attach MTD devices */ 991 943 for (i = 0; i < mtd_devs; i++) { ··· 1016 980 mutex_unlock(&ubi_devices_mutex); 1017 981 } 1018 982 kmem_cache_destroy(ubi_wl_entry_slab); 1019 - out_ltree: 1020 - kmem_cache_destroy(ubi_ltree_slab); 1021 983 out_dev_unreg: 1022 984 misc_deregister(&ubi_ctrl_cdev); 1023 985 out_version: ··· 1039 1005 mutex_unlock(&ubi_devices_mutex); 1040 1006 } 1041 1007 kmem_cache_destroy(ubi_wl_entry_slab); 1042 - kmem_cache_destroy(ubi_ltree_slab); 1043 1008 misc_deregister(&ubi_ctrl_cdev); 1044 1009 class_remove_file(ubi_class, &ubi_version); 1045 1010 class_destroy(ubi_class); ··· 1099 1066 struct mtd_dev_param *p; 1100 1067 char buf[MTD_PARAM_LEN_MAX]; 1101 1068 char *pbuf = &buf[0]; 1102 - char *tokens[3] = {NULL, NULL, NULL}; 1069 + char *tokens[2] = {NULL, NULL}; 1103 1070 1104 1071 if (!val) 1105 1072 return -EINVAL; ··· 1129 1096 if (buf[len - 1] == '\n') 1130 1097 buf[len - 1] = '\0'; 1131 1098 1132 - for (i = 0; i < 3; i++) 1099 + for (i = 0; i < 2; i++) 1133 1100 tokens[i] = strsep(&pbuf, ","); 1134 1101 1135 1102 if (pbuf) {
+64 -18
drivers/mtd/ubi/cdev.c
··· 132 132 if (vol->updating) { 133 133 ubi_warn("update of volume %d not finished, volume is damaged", 134 134 vol->vol_id); 135 + ubi_assert(!vol->changing_leb); 135 136 vol->updating = 0; 137 + vfree(vol->upd_buf); 138 + } else if (vol->changing_leb) { 139 + dbg_msg("only %lld of %lld bytes received for atomic LEB change" 140 + " for volume %d:%d, cancel", vol->upd_received, 141 + vol->upd_bytes, vol->ubi->ubi_num, vol->vol_id); 142 + vol->changing_leb = 0; 136 143 vfree(vol->upd_buf); 137 144 } 138 145 ··· 191 184 struct ubi_volume_desc *desc = file->private_data; 192 185 struct ubi_volume *vol = desc->vol; 193 186 struct ubi_device *ubi = vol->ubi; 194 - int err, lnum, off, len, vol_id = desc->vol->vol_id, tbuf_size; 187 + int err, lnum, off, len, tbuf_size; 195 188 size_t count_save = count; 196 189 void *tbuf; 197 190 uint64_t tmp; 198 191 199 192 dbg_msg("read %zd bytes from offset %lld of volume %d", 200 - count, *offp, vol_id); 193 + count, *offp, vol->vol_id); 201 194 202 195 if (vol->updating) { 203 196 dbg_err("updating"); ··· 211 204 return 0; 212 205 213 206 if (vol->corrupted) 214 - dbg_msg("read from corrupted volume %d", vol_id); 207 + dbg_msg("read from corrupted volume %d", vol->vol_id); 215 208 216 209 if (*offp + count > vol->used_bytes) 217 210 count_save = count = vol->used_bytes - *offp; ··· 281 274 uint64_t tmp; 282 275 283 276 dbg_msg("requested: write %zd bytes to offset %lld of volume %u", 284 - count, *offp, desc->vol->vol_id); 277 + count, *offp, vol->vol_id); 285 278 286 279 if (vol->vol_type == UBI_STATIC_VOLUME) 287 280 return -EROFS; ··· 358 351 struct ubi_volume *vol = desc->vol; 359 352 struct ubi_device *ubi = vol->ubi; 360 353 361 - if (!vol->updating) 354 + if (!vol->updating && !vol->changing_leb) 362 355 return vol_cdev_direct_write(file, buf, count, offp); 363 356 364 - err = ubi_more_update_data(ubi, vol->vol_id, buf, count); 357 + if (vol->updating) 358 + err = ubi_more_update_data(ubi, vol, buf, count); 359 + else 360 + err = ubi_more_leb_change_data(ubi, vol, buf, count); 361 + 365 362 if (err < 0) { 366 - ubi_err("cannot write %zd bytes of update data, error %d", 363 + ubi_err("cannot accept more %zd bytes of data, error %d", 367 364 count, err); 368 365 return err; 369 366 } 370 367 371 368 if (err) { 372 369 /* 373 - * Update is finished, @err contains number of actually written 374 - * bytes now. 370 + * The operation is finished, @err contains number of actually 371 + * written bytes. 375 372 */ 376 373 count = err; 374 + 375 + if (vol->changing_leb) { 376 + revoke_exclusive(desc, UBI_READWRITE); 377 + return count; 378 + } 377 379 378 380 err = ubi_check_volume(ubi, vol->vol_id); 379 381 if (err < 0) ··· 398 382 revoke_exclusive(desc, UBI_READWRITE); 399 383 } 400 384 401 - *offp += count; 402 385 return count; 403 386 } 404 387 ··· 442 427 if (err < 0) 443 428 break; 444 429 445 - err = ubi_start_update(ubi, vol->vol_id, bytes); 430 + err = ubi_start_update(ubi, vol, bytes); 446 431 if (bytes == 0) 447 432 revoke_exclusive(desc, UBI_READWRITE); 433 + break; 434 + } 448 435 449 - file->f_pos = 0; 436 + /* Atomic logical eraseblock change command */ 437 + case UBI_IOCEBCH: 438 + { 439 + struct ubi_leb_change_req req; 440 + 441 + err = copy_from_user(&req, argp, 442 + sizeof(struct ubi_leb_change_req)); 443 + if (err) { 444 + err = -EFAULT; 445 + break; 446 + } 447 + 448 + if (desc->mode == UBI_READONLY || 449 + vol->vol_type == UBI_STATIC_VOLUME) { 450 + err = -EROFS; 451 + break; 452 + } 453 + 454 + /* Validate the request */ 455 + err = -EINVAL; 456 + if (req.lnum < 0 || req.lnum >= vol->reserved_pebs || 457 + req.bytes < 0 || req.lnum >= vol->usable_leb_size) 458 + break; 459 + if (req.dtype != UBI_LONGTERM && req.dtype != UBI_SHORTTERM && 460 + req.dtype != UBI_UNKNOWN) 461 + break; 462 + 463 + err = get_exclusive(desc); 464 + if (err < 0) 465 + break; 466 + 467 + err = ubi_start_leb_change(ubi, vol, &req); 468 + if (req.bytes == 0) 469 + revoke_exclusive(desc, UBI_READWRITE); 450 470 break; 451 471 } 452 472 ··· 497 447 break; 498 448 } 499 449 500 - if (desc->mode == UBI_READONLY) { 450 + if (desc->mode == UBI_READONLY || 451 + vol->vol_type == UBI_STATIC_VOLUME) { 501 452 err = -EROFS; 502 453 break; 503 454 } 504 455 505 456 if (lnum < 0 || lnum >= vol->reserved_pebs) { 506 457 err = -EINVAL; 507 - break; 508 - } 509 - 510 - if (vol->vol_type != UBI_DYNAMIC_VOLUME) { 511 - err = -EROFS; 512 458 break; 513 459 } 514 460
+19 -21
drivers/mtd/ubi/eba.c
··· 78 78 */ 79 79 static int ubi_get_compat(const struct ubi_device *ubi, int vol_id) 80 80 { 81 - if (vol_id == UBI_LAYOUT_VOL_ID) 81 + if (vol_id == UBI_LAYOUT_VOLUME_ID) 82 82 return UBI_LAYOUT_VOLUME_COMPAT; 83 83 return 0; 84 84 } ··· 137 137 { 138 138 struct ubi_ltree_entry *le, *le1, *le_free; 139 139 140 - le = kmem_cache_alloc(ubi_ltree_slab, GFP_NOFS); 140 + le = kmalloc(sizeof(struct ubi_ltree_entry), GFP_NOFS); 141 141 if (!le) 142 142 return ERR_PTR(-ENOMEM); 143 143 144 + le->users = 0; 145 + init_rwsem(&le->mutex); 144 146 le->vol_id = vol_id; 145 147 le->lnum = lnum; 146 148 ··· 190 188 spin_unlock(&ubi->ltree_lock); 191 189 192 190 if (le_free) 193 - kmem_cache_free(ubi_ltree_slab, le_free); 191 + kfree(le_free); 194 192 195 193 return le; 196 194 } ··· 238 236 239 237 up_read(&le->mutex); 240 238 if (free) 241 - kmem_cache_free(ubi_ltree_slab, le); 239 + kfree(le); 242 240 } 243 241 244 242 /** ··· 294 292 free = 0; 295 293 spin_unlock(&ubi->ltree_lock); 296 294 if (free) 297 - kmem_cache_free(ubi_ltree_slab, le); 295 + kfree(le); 298 296 299 297 return 1; 300 298 } ··· 323 321 324 322 up_write(&le->mutex); 325 323 if (free) 326 - kmem_cache_free(ubi_ltree_slab, le); 324 + kfree(le); 327 325 } 328 326 329 327 /** ··· 340 338 int lnum) 341 339 { 342 340 int err, pnum, vol_id = vol->vol_id; 343 - 344 - ubi_assert(ubi->ref_count > 0); 345 - ubi_assert(vol->ref_count > 0); 346 341 347 342 if (ubi->ro_mode) 348 343 return -EROFS; ··· 388 389 int err, pnum, scrub = 0, vol_id = vol->vol_id; 389 390 struct ubi_vid_hdr *vid_hdr; 390 391 uint32_t uninitialized_var(crc); 391 - 392 - ubi_assert(ubi->ref_count > 0); 393 - ubi_assert(vol->ref_count > 0); 394 392 395 393 err = leb_read_lock(ubi, vol_id, lnum); 396 394 if (err) ··· 612 616 int err, pnum, tries = 0, vol_id = vol->vol_id; 613 617 struct ubi_vid_hdr *vid_hdr; 614 618 615 - ubi_assert(ubi->ref_count > 0); 616 - ubi_assert(vol->ref_count > 0); 617 - 618 619 if (ubi->ro_mode) 619 620 return -EROFS; 620 621 ··· 745 752 struct ubi_vid_hdr *vid_hdr; 746 753 uint32_t crc; 747 754 748 - ubi_assert(ubi->ref_count > 0); 749 - ubi_assert(vol->ref_count > 0); 750 - 751 755 if (ubi->ro_mode) 752 756 return -EROFS; 753 757 ··· 859 869 struct ubi_vid_hdr *vid_hdr; 860 870 uint32_t crc; 861 871 862 - ubi_assert(ubi->ref_count > 0); 863 - ubi_assert(vol->ref_count > 0); 864 - 865 872 if (ubi->ro_mode) 866 873 return -EROFS; 874 + 875 + if (len == 0) { 876 + /* 877 + * Special case when data length is zero. In this case the LEB 878 + * has to be unmapped and mapped somewhere else. 879 + */ 880 + err = ubi_eba_unmap_leb(ubi, vol, lnum); 881 + if (err) 882 + return err; 883 + return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype); 884 + } 867 885 868 886 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 869 887 if (!vid_hdr)
+4 -6
drivers/mtd/ubi/kapi.c
··· 480 480 { 481 481 struct ubi_volume *vol = desc->vol; 482 482 struct ubi_device *ubi = vol->ubi; 483 - int err, vol_id = vol->vol_id; 483 + int err; 484 484 485 - dbg_msg("erase LEB %d:%d", vol_id, lnum); 485 + dbg_msg("erase LEB %d:%d", vol->vol_id, lnum); 486 486 487 487 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 488 488 return -EROFS; ··· 541 541 { 542 542 struct ubi_volume *vol = desc->vol; 543 543 struct ubi_device *ubi = vol->ubi; 544 - int vol_id = vol->vol_id; 545 544 546 - dbg_msg("unmap LEB %d:%d", vol_id, lnum); 545 + dbg_msg("unmap LEB %d:%d", vol->vol_id, lnum); 547 546 548 547 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 549 548 return -EROFS; ··· 578 579 { 579 580 struct ubi_volume *vol = desc->vol; 580 581 struct ubi_device *ubi = vol->ubi; 581 - int vol_id = vol->vol_id; 582 582 583 - dbg_msg("unmap LEB %d:%d", vol_id, lnum); 583 + dbg_msg("unmap LEB %d:%d", vol->vol_id, lnum); 584 584 585 585 if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) 586 586 return -EROFS;
+7 -3
drivers/mtd/ubi/scan.c
··· 286 286 * FIXME: but this is anyway obsolete and will be removed at 287 287 * some point. 288 288 */ 289 - 290 289 dbg_bld("using old crappy leb_ver stuff"); 290 + 291 + if (v1 == v2) { 292 + ubi_err("PEB %d and PEB %d have the same version %lld", 293 + seb->pnum, pnum, v1); 294 + return -EINVAL; 295 + } 291 296 292 297 abs = v1 - v2; 293 298 if (abs < 0) ··· 395 390 vfree(buf); 396 391 out_free_vidh: 397 392 ubi_free_vid_hdr(ubi, vh); 398 - ubi_assert(err < 0); 399 393 return err; 400 394 } 401 395 ··· 858 854 } 859 855 860 856 vol_id = be32_to_cpu(vidh->vol_id); 861 - if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOL_ID) { 857 + if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOLUME_ID) { 862 858 int lnum = be32_to_cpu(vidh->lnum); 863 859 864 860 /* Unsupported internal volume */
+39 -16
drivers/mtd/ubi/ubi.h
··· 144 144 * @readers: number of users holding this volume in read-only mode 145 145 * @writers: number of users holding this volume in read-write mode 146 146 * @exclusive: whether somebody holds this volume in exclusive mode 147 - * @checked: if this static volume was checked 148 147 * 149 148 * @reserved_pebs: how many physical eraseblocks are reserved for this volume 150 149 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME) ··· 151 152 * @used_ebs: how many logical eraseblocks in this volume contain data 152 153 * @last_eb_bytes: how many bytes are stored in the last logical eraseblock 153 154 * @used_bytes: how many bytes of data this volume contains 154 - * @upd_marker: non-zero if the update marker is set for this volume 155 - * @corrupted: non-zero if the volume is corrupted (static volumes only) 156 155 * @alignment: volume alignment 157 156 * @data_pad: how many bytes are not used at the end of physical eraseblocks to 158 157 * satisfy the requested alignment 159 158 * @name_len: volume name length 160 159 * @name: volume name 161 160 * 162 - * @updating: whether the volume is being updated 163 161 * @upd_ebs: how many eraseblocks are expected to be updated 164 - * @upd_bytes: how many bytes are expected to be received 165 - * @upd_received: how many update bytes were already received 166 - * @upd_buf: update buffer which is used to collect update data 162 + * @ch_lnum: LEB number which is being changing by the atomic LEB change 163 + * operation 164 + * @ch_dtype: data persistency type which is being changing by the atomic LEB 165 + * change operation 166 + * @upd_bytes: how many bytes are expected to be received for volume update or 167 + * atomic LEB change 168 + * @upd_received: how many bytes were already received for volume update or 169 + * atomic LEB change 170 + * @upd_buf: update buffer which is used to collect update data or data for 171 + * atomic LEB change 167 172 * 168 173 * @eba_tbl: EBA table of this volume (LEB->PEB mapping) 174 + * @checked: %1 if this static volume was checked 175 + * @corrupted: %1 if the volume is corrupted (static volumes only) 176 + * @upd_marker: %1 if the update marker is set for this volume 177 + * @updating: %1 if the volume is being updated 178 + * @changing_leb: %1 if the atomic LEB change ioctl command is in progress 169 179 * 170 180 * @gluebi_desc: gluebi UBI volume descriptor 171 181 * @gluebi_refcount: reference count of the gluebi MTD device ··· 197 189 int readers; 198 190 int writers; 199 191 int exclusive; 200 - int checked; 201 192 202 193 int reserved_pebs; 203 194 int vol_type; ··· 204 197 int used_ebs; 205 198 int last_eb_bytes; 206 199 long long used_bytes; 207 - int upd_marker; 208 - int corrupted; 209 200 int alignment; 210 201 int data_pad; 211 202 int name_len; 212 203 char name[UBI_VOL_NAME_MAX+1]; 213 204 214 - int updating; 215 205 int upd_ebs; 206 + int ch_lnum; 207 + int ch_dtype; 216 208 long long upd_bytes; 217 209 long long upd_received; 218 210 void *upd_buf; 219 211 220 212 int *eba_tbl; 213 + int checked:1; 214 + int corrupted:1; 215 + int upd_marker:1; 216 + int updating:1; 217 + int changing_leb:1; 221 218 222 219 #ifdef CONFIG_MTD_UBI_GLUEBI 223 - /* Gluebi-related stuff may be compiled out */ 220 + /* 221 + * Gluebi-related stuff may be compiled out. 222 + * TODO: this should not be built into UBI but should be a separate 223 + * ubimtd driver which works on top of UBI and emulates MTD devices. 224 + */ 224 225 struct ubi_volume_desc *gluebi_desc; 225 226 int gluebi_refcount; 226 227 struct mtd_info gluebi_mtd; ··· 265 250 * @rsvd_pebs: count of reserved physical eraseblocks 266 251 * @avail_pebs: count of available physical eraseblocks 267 252 * @beb_rsvd_pebs: how many physical eraseblocks are reserved for bad PEB 268 - * handling 253 + * handling 269 254 * @beb_rsvd_level: normal level of PEBs reserved for bad PEB handling 270 255 * 256 + * @autoresize_vol_id: ID of the volume which has to be auto-resized at the end 257 + * of UBI ititializetion 271 258 * @vtbl_slots: how many slots are available in the volume table 272 259 * @vtbl_size: size of the volume table in bytes 273 260 * @vtbl: in-RAM volume table copy ··· 350 333 int beb_rsvd_pebs; 351 334 int beb_rsvd_level; 352 335 336 + int autoresize_vol_id; 353 337 int vtbl_slots; 354 338 int vtbl_size; 355 339 struct ubi_vtbl_record *vtbl; 356 340 struct mutex volumes_mutex; 357 341 358 342 int max_ec; 343 + /* TODO: mean_ec is not updated run-time, fix */ 359 344 int mean_ec; 360 345 361 346 /* EBA unit's stuff */ ··· 418 399 #endif 419 400 }; 420 401 421 - extern struct kmem_cache *ubi_ltree_slab; 422 402 extern struct kmem_cache *ubi_wl_entry_slab; 423 403 extern struct file_operations ubi_ctrl_cdev_operations; 424 404 extern struct file_operations ubi_cdev_operations; ··· 438 420 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol); 439 421 440 422 /* upd.c */ 441 - int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes); 442 - int ubi_more_update_data(struct ubi_device *ubi, int vol_id, 423 + int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol, 424 + long long bytes); 425 + int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, 443 426 const void __user *buf, int count); 427 + int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, 428 + const struct ubi_leb_change_req *req); 429 + int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol, 430 + const void __user *buf, int count); 444 431 445 432 /* misc.c */ 446 433 int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, int length);
+131 -45
drivers/mtd/ubi/upd.c
··· 22 22 */ 23 23 24 24 /* 25 - * This file contains implementation of the volume update functionality. 25 + * This file contains implementation of the volume update and atomic LEB change 26 + * functionality. 26 27 * 27 28 * The update operation is based on the per-volume update marker which is 28 29 * stored in the volume table. The update marker is set before the update ··· 46 45 /** 47 46 * set_update_marker - set update marker. 48 47 * @ubi: UBI device description object 49 - * @vol_id: volume ID 48 + * @vol: volume description object 50 49 * 51 - * This function sets the update marker flag for volume @vol_id. Returns zero 50 + * This function sets the update marker flag for volume @vol. Returns zero 52 51 * in case of success and a negative error code in case of failure. 53 52 */ 54 - static int set_update_marker(struct ubi_device *ubi, int vol_id) 53 + static int set_update_marker(struct ubi_device *ubi, struct ubi_volume *vol) 55 54 { 56 55 int err; 57 56 struct ubi_vtbl_record vtbl_rec; 58 - struct ubi_volume *vol = ubi->volumes[vol_id]; 59 57 60 - dbg_msg("set update marker for volume %d", vol_id); 58 + dbg_msg("set update marker for volume %d", vol->vol_id); 61 59 62 60 if (vol->upd_marker) { 63 - ubi_assert(ubi->vtbl[vol_id].upd_marker); 61 + ubi_assert(ubi->vtbl[vol->vol_id].upd_marker); 64 62 dbg_msg("already set"); 65 63 return 0; 66 64 } 67 65 68 - memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record)); 66 + memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], 67 + sizeof(struct ubi_vtbl_record)); 69 68 vtbl_rec.upd_marker = 1; 70 69 71 70 mutex_lock(&ubi->volumes_mutex); 72 - err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 71 + err = ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec); 73 72 mutex_unlock(&ubi->volumes_mutex); 74 73 vol->upd_marker = 1; 75 74 return err; ··· 78 77 /** 79 78 * clear_update_marker - clear update marker. 80 79 * @ubi: UBI device description object 81 - * @vol_id: volume ID 80 + * @vol: volume description object 82 81 * @bytes: new data size in bytes 83 82 * 84 - * This function clears the update marker for volume @vol_id, sets new volume 83 + * This function clears the update marker for volume @vol, sets new volume 85 84 * data size and clears the "corrupted" flag (static volumes only). Returns 86 85 * zero in case of success and a negative error code in case of failure. 87 86 */ 88 - static int clear_update_marker(struct ubi_device *ubi, int vol_id, long long bytes) 87 + static int clear_update_marker(struct ubi_device *ubi, struct ubi_volume *vol, 88 + long long bytes) 89 89 { 90 90 int err; 91 91 uint64_t tmp; 92 92 struct ubi_vtbl_record vtbl_rec; 93 - struct ubi_volume *vol = ubi->volumes[vol_id]; 94 93 95 - dbg_msg("clear update marker for volume %d", vol_id); 94 + dbg_msg("clear update marker for volume %d", vol->vol_id); 96 95 97 - memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record)); 96 + memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], 97 + sizeof(struct ubi_vtbl_record)); 98 98 ubi_assert(vol->upd_marker && vtbl_rec.upd_marker); 99 99 vtbl_rec.upd_marker = 0; 100 100 ··· 111 109 } 112 110 113 111 mutex_lock(&ubi->volumes_mutex); 114 - err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); 112 + err = ubi_change_vtbl_record(ubi, vol->vol_id, &vtbl_rec); 115 113 mutex_unlock(&ubi->volumes_mutex); 116 114 vol->upd_marker = 0; 117 115 return err; ··· 120 118 /** 121 119 * ubi_start_update - start volume update. 122 120 * @ubi: UBI device description object 123 - * @vol_id: volume ID 121 + * @vol: volume description object 124 122 * @bytes: update bytes 125 123 * 126 124 * This function starts volume update operation. If @bytes is zero, the volume 127 125 * is just wiped out. Returns zero in case of success and a negative error code 128 126 * in case of failure. 129 127 */ 130 - int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes) 128 + int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol, 129 + long long bytes) 131 130 { 132 131 int i, err; 133 132 uint64_t tmp; 134 - struct ubi_volume *vol = ubi->volumes[vol_id]; 135 133 136 - dbg_msg("start update of volume %d, %llu bytes", vol_id, bytes); 134 + dbg_msg("start update of volume %d, %llu bytes", vol->vol_id, bytes); 135 + ubi_assert(!vol->updating && !vol->changing_leb); 137 136 vol->updating = 1; 138 137 139 - err = set_update_marker(ubi, vol_id); 138 + err = set_update_marker(ubi, vol); 140 139 if (err) 141 140 return err; 142 141 ··· 149 146 } 150 147 151 148 if (bytes == 0) { 152 - err = clear_update_marker(ubi, vol_id, 0); 149 + err = clear_update_marker(ubi, vol, 0); 153 150 if (err) 154 151 return err; 155 152 err = ubi_wl_flush(ubi); ··· 170 167 } 171 168 172 169 /** 170 + * ubi_start_leb_change - start atomic LEB change. 171 + * @ubi: UBI device description object 172 + * @vol: volume description object 173 + * @req: operation request 174 + * 175 + * This function starts atomic LEB change operation. Returns zero in case of 176 + * success and a negative error code in case of failure. 177 + */ 178 + int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, 179 + const struct ubi_leb_change_req *req) 180 + { 181 + ubi_assert(!vol->updating && !vol->changing_leb); 182 + 183 + dbg_msg("start changing LEB %d:%d, %u bytes", 184 + vol->vol_id, req->lnum, req->bytes); 185 + if (req->bytes == 0) 186 + return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0, 187 + req->dtype); 188 + 189 + vol->upd_bytes = req->bytes; 190 + vol->upd_received = 0; 191 + vol->changing_leb = 1; 192 + vol->ch_lnum = req->lnum; 193 + vol->ch_dtype = req->dtype; 194 + 195 + vol->upd_buf = vmalloc(req->bytes); 196 + if (!vol->upd_buf) 197 + return -ENOMEM; 198 + 199 + return 0; 200 + } 201 + 202 + /** 173 203 * write_leb - write update data. 174 204 * @ubi: UBI device description object 175 - * @vol_id: volume ID 205 + * @vol: volume description object 176 206 * @lnum: logical eraseblock number 177 207 * @buf: data to write 178 208 * @len: data size ··· 231 195 * This function returns zero in case of success and a negative error code in 232 196 * case of failure. 233 197 */ 234 - static int write_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf, 235 - int len, int used_ebs) 198 + static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, 199 + void *buf, int len, int used_ebs) 236 200 { 237 - int err, l; 238 - struct ubi_volume *vol = ubi->volumes[vol_id]; 201 + int err; 239 202 240 203 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { 241 - l = ALIGN(len, ubi->min_io_size); 242 - memset(buf + len, 0xFF, l - len); 204 + len = ALIGN(len, ubi->min_io_size); 205 + memset(buf + len, 0xFF, len - len); 243 206 244 - l = ubi_calc_data_len(ubi, buf, l); 245 - if (l == 0) { 207 + len = ubi_calc_data_len(ubi, buf, len); 208 + if (len == 0) { 246 209 dbg_msg("all %d bytes contain 0xFF - skip", len); 247 210 return 0; 248 211 } 249 - if (len != l) 250 - dbg_msg("skip last %d bytes (0xFF)", len - l); 251 212 252 - err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, l, UBI_UNKNOWN); 213 + err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len, UBI_UNKNOWN); 253 214 } else { 254 215 /* 255 216 * When writing static volume, and this is the last logical ··· 272 239 * @count: how much bytes to write 273 240 * 274 241 * This function writes more data to the volume which is being updated. It may 275 - * be called arbitrary number of times until all of the update data arrive. 276 - * This function returns %0 in case of success, number of bytes written during 277 - * the last call if the whole volume update was successfully finished, and a 242 + * be called arbitrary number of times until all the update data arriveis. This 243 + * function returns %0 in case of success, number of bytes written during the 244 + * last call if the whole volume update has been successfully finished, and a 278 245 * negative error code in case of failure. 279 246 */ 280 - int ubi_more_update_data(struct ubi_device *ubi, int vol_id, 247 + int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, 281 248 const void __user *buf, int count) 282 249 { 283 250 uint64_t tmp; 284 - struct ubi_volume *vol = ubi->volumes[vol_id]; 285 251 int lnum, offs, err = 0, len, to_write = count; 286 252 287 253 dbg_msg("write %d of %lld bytes, %lld already passed", ··· 325 293 * is the last chunk, it's time to flush the buffer. 326 294 */ 327 295 ubi_assert(flush_len <= vol->usable_leb_size); 328 - err = write_leb(ubi, vol_id, lnum, vol->upd_buf, 329 - flush_len, vol->upd_ebs); 296 + err = write_leb(ubi, vol, lnum, vol->upd_buf, flush_len, 297 + vol->upd_ebs); 330 298 if (err) 331 299 return err; 332 300 } ··· 353 321 354 322 if (len == vol->usable_leb_size || 355 323 vol->upd_received + len == vol->upd_bytes) { 356 - err = write_leb(ubi, vol_id, lnum, vol->upd_buf, len, 357 - vol->upd_ebs); 324 + err = write_leb(ubi, vol, lnum, vol->upd_buf, 325 + len, vol->upd_ebs); 358 326 if (err) 359 327 break; 360 328 } ··· 368 336 ubi_assert(vol->upd_received <= vol->upd_bytes); 369 337 if (vol->upd_received == vol->upd_bytes) { 370 338 /* The update is finished, clear the update marker */ 371 - err = clear_update_marker(ubi, vol_id, vol->upd_bytes); 339 + err = clear_update_marker(ubi, vol, vol->upd_bytes); 372 340 if (err) 373 341 return err; 374 342 err = ubi_wl_flush(ubi); 375 343 if (err == 0) { 344 + vol->updating = 0; 376 345 err = to_write; 377 346 vfree(vol->upd_buf); 378 - vol->updating = 0; 379 347 } 348 + } 349 + 350 + return err; 351 + } 352 + 353 + /** 354 + * ubi_more_leb_change_data - accept more data for atomic LEB change. 355 + * @vol: volume description object 356 + * @buf: write data (user-space memory buffer) 357 + * @count: how much bytes to write 358 + * 359 + * This function accepts more data to the volume which is being under the 360 + * "atomic LEB change" operation. It may be called arbitrary number of times 361 + * until all data arrives. This function returns %0 in case of success, number 362 + * of bytes written during the last call if the whole "atomic LEB change" 363 + * operation has been successfully finished, and a negative error code in case 364 + * of failure. 365 + */ 366 + int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol, 367 + const void __user *buf, int count) 368 + { 369 + int err; 370 + 371 + dbg_msg("write %d of %lld bytes, %lld already passed", 372 + count, vol->upd_bytes, vol->upd_received); 373 + 374 + if (ubi->ro_mode) 375 + return -EROFS; 376 + 377 + if (vol->upd_received + count > vol->upd_bytes) 378 + count = vol->upd_bytes - vol->upd_received; 379 + 380 + err = copy_from_user(vol->upd_buf + vol->upd_received, buf, count); 381 + if (err) 382 + return -EFAULT; 383 + 384 + vol->upd_received += count; 385 + 386 + if (vol->upd_received == vol->upd_bytes) { 387 + int len = ALIGN((int)vol->upd_bytes, ubi->min_io_size); 388 + 389 + memset(vol->upd_buf + vol->upd_bytes, 0xFF, len - vol->upd_bytes); 390 + len = ubi_calc_data_len(ubi, vol->upd_buf, len); 391 + err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum, 392 + vol->upd_buf, len, UBI_UNKNOWN); 393 + if (err) 394 + return err; 395 + } 396 + 397 + ubi_assert(vol->upd_received <= vol->upd_bytes); 398 + if (vol->upd_received == vol->upd_bytes) { 399 + vol->changing_leb = 0; 400 + err = count; 401 + vfree(vol->upd_buf); 380 402 } 381 403 382 404 return err;
+1 -13
drivers/mtd/ubi/vmt.c
··· 497 497 498 498 dbg_msg("re-size volume %d to from %d to %d PEBs", 499 499 vol_id, vol->reserved_pebs, reserved_pebs); 500 - ubi_assert(desc->mode == UBI_EXCLUSIVE); 501 - ubi_assert(vol == ubi->volumes[vol_id]); 502 500 503 501 if (vol->vol_type == UBI_STATIC_VOLUME && 504 502 reserved_pebs < vol->used_ebs) { ··· 523 525 goto out_free; 524 526 } 525 527 spin_unlock(&ubi->volumes_lock); 526 - 527 528 528 529 /* Reserve physical eraseblocks */ 529 530 pebs = reserved_pebs - vol->reserved_pebs; ··· 743 746 goto fail; 744 747 } 745 748 746 - if (vol->upd_marker != 0 && vol->upd_marker != 1) { 747 - ubi_err("bad upd_marker"); 748 - goto fail; 749 - } 750 - 751 749 if (vol->upd_marker && vol->corrupted) { 752 750 dbg_err("update marker and corrupted simultaneously"); 753 751 goto fail; ··· 777 785 778 786 n = (long long)vol->used_ebs * vol->usable_leb_size; 779 787 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { 780 - if (vol->corrupted != 0) { 788 + if (vol->corrupted) { 781 789 ubi_err("corrupted dynamic volume"); 782 790 goto fail; 783 791 } ··· 794 802 goto fail; 795 803 } 796 804 } else { 797 - if (vol->corrupted != 0 && vol->corrupted != 1) { 798 - ubi_err("bad corrupted"); 799 - goto fail; 800 - } 801 805 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) { 802 806 ubi_err("bad used_ebs"); 803 807 goto fail;
+17 -6
drivers/mtd/ubi/vtbl.c
··· 89 89 struct ubi_volume *layout_vol; 90 90 91 91 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots); 92 - layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOL_ID)]; 92 + layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; 93 93 94 94 if (!vtbl_rec) 95 95 vtbl_rec = &empty_vtbl_record; ··· 111 111 } 112 112 113 113 paranoid_vtbl_check(ubi); 114 - return ubi_wl_flush(ubi); 114 + return 0; 115 115 } 116 116 117 117 /** ··· 269 269 * this volume table copy was found during scanning. It has to be wiped 270 270 * out. 271 271 */ 272 - sv = ubi_scan_find_sv(si, UBI_LAYOUT_VOL_ID); 272 + sv = ubi_scan_find_sv(si, UBI_LAYOUT_VOLUME_ID); 273 273 if (sv) 274 274 old_seb = ubi_scan_find_seb(sv, copy); 275 275 ··· 281 281 } 282 282 283 283 vid_hdr->vol_type = UBI_VID_DYNAMIC; 284 - vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOL_ID); 284 + vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOLUME_ID); 285 285 vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT; 286 286 vid_hdr->data_size = vid_hdr->used_ebs = 287 287 vid_hdr->data_pad = cpu_to_be32(0); ··· 514 514 vol->name[vol->name_len] = '\0'; 515 515 vol->vol_id = i; 516 516 517 + if (vtbl[i].flags & UBI_VTBL_AUTORESIZE_FLG) { 518 + /* Auto re-size flag may be set only for one volume */ 519 + if (ubi->autoresize_vol_id != -1) { 520 + ubi_err("more then one auto-resize volume (%d " 521 + "and %d)", ubi->autoresize_vol_id, i); 522 + return -EINVAL; 523 + } 524 + 525 + ubi->autoresize_vol_id = i; 526 + } 527 + 517 528 ubi_assert(!ubi->volumes[i]); 518 529 ubi->volumes[i] = vol; 519 530 ubi->vol_count += 1; ··· 590 579 vol->last_eb_bytes = vol->reserved_pebs; 591 580 vol->used_bytes = 592 581 (long long)vol->used_ebs * (ubi->leb_size - vol->data_pad); 593 - vol->vol_id = UBI_LAYOUT_VOL_ID; 582 + vol->vol_id = UBI_LAYOUT_VOLUME_ID; 594 583 vol->ref_count = 1; 595 584 596 585 ubi_assert(!ubi->volumes[i]); ··· 743 732 ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE; 744 733 ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size); 745 734 746 - sv = ubi_scan_find_sv(si, UBI_LAYOUT_VOL_ID); 735 + sv = ubi_scan_find_sv(si, UBI_LAYOUT_VOLUME_ID); 747 736 if (!sv) { 748 737 /* 749 738 * No logical eraseblocks belonging to the layout volume were
-1
drivers/mtd/ubi/wl.c
··· 1303 1303 * Make sure all the works which have been done in parallel are 1304 1304 * finished. 1305 1305 */ 1306 - ubi_assert(ubi->ref_count > 0); 1307 1306 down_write(&ubi->work_sem); 1308 1307 up_write(&ubi->work_sem); 1309 1308
-17
include/linux/mtd/ubi.h
··· 26 26 #include <mtd/ubi-user.h> 27 27 28 28 /* 29 - * UBI data type hint constants. 30 - * 31 - * UBI_LONGTERM: long-term data 32 - * UBI_SHORTTERM: short-term data 33 - * UBI_UNKNOWN: data persistence is unknown 34 - * 35 - * These constants are used when data is written to UBI volumes in order to 36 - * help the UBI wear-leveling unit to find more appropriate physical 37 - * eraseblocks. 38 - */ 39 - enum { 40 - UBI_LONGTERM = 1, 41 - UBI_SHORTTERM, 42 - UBI_UNKNOWN 43 - }; 44 - 45 - /* 46 29 * enum ubi_open_mode - UBI volume open mode constants. 47 30 * 48 31 * UBI_READONLY: read-only mode
+44 -3
include/mtd/ubi-header.h
··· 58 58 }; 59 59 60 60 /* 61 + * Volume flags used in the volume table record. 62 + * 63 + * @UBI_VTBL_AUTORESIZE_FLG: auto-resize this volume 64 + * 65 + * %UBI_VTBL_AUTORESIZE_FLG flag can be set only for one volume in the volume 66 + * table. UBI automatically re-sizes the volume which has this flag and makes 67 + * the volume to be of largest possible size. This means that if after the 68 + * initialization UBI finds out that there are available physical eraseblocks 69 + * present on the device, it automatically appends all of them to the volume 70 + * (the physical eraseblocks reserved for bad eraseblocks handling and other 71 + * reserved physical eraseblocks are not taken). So, if there is a volume with 72 + * the %UBI_VTBL_AUTORESIZE_FLG flag set, the amount of available logical 73 + * eraseblocks will be zero after UBI is loaded, because all of them will be 74 + * reserved for this volume. Note, the %UBI_VTBL_AUTORESIZE_FLG bit is cleared 75 + * after the volume had been initialized. 76 + * 77 + * The auto-resize feature is useful for device production purposes. For 78 + * example, different NAND flash chips may have different amount of initial bad 79 + * eraseblocks, depending of particular chip instance. Manufacturers of NAND 80 + * chips usually guarantee that the amount of initial bad eraseblocks does not 81 + * exceed certain percent, e.g. 2%. When one creates an UBI image which will be 82 + * flashed to the end devices in production, he does not know the exact amount 83 + * of good physical eraseblocks the NAND chip on the device will have, but this 84 + * number is required to calculate the volume sized and put them to the volume 85 + * table of the UBI image. In this case, one of the volumes (e.g., the one 86 + * which will store the root file system) is marked as "auto-resizable", and 87 + * UBI will adjust its size on the first boot if needed. 88 + * 89 + * Note, first UBI reserves some amount of physical eraseblocks for bad 90 + * eraseblock handling, and then re-sizes the volume, not vice-versa. This 91 + * means that the pool of reserved physical eraseblocks will always be present. 92 + */ 93 + enum { 94 + UBI_VTBL_AUTORESIZE_FLG = 0x01, 95 + }; 96 + 97 + /* 61 98 * Compatibility constants used by internal volumes. 62 99 * 63 100 * @UBI_COMPAT_DELETE: delete this internal volume before anything is written ··· 299 262 300 263 /* The layout volume contains the volume table */ 301 264 302 - #define UBI_LAYOUT_VOL_ID UBI_INTERNAL_VOL_START 265 + #define UBI_LAYOUT_VOLUME_ID UBI_INTERNAL_VOL_START 266 + #define UBI_LAYOUT_VOLUME_TYPE UBI_VID_DYNAMIC 267 + #define UBI_LAYOUT_VOLUME_ALIGN 1 303 268 #define UBI_LAYOUT_VOLUME_EBS 2 304 269 #define UBI_LAYOUT_VOLUME_NAME "layout volume" 305 270 #define UBI_LAYOUT_VOLUME_COMPAT UBI_COMPAT_REJECT ··· 328 289 * @upd_marker: if volume update was started but not finished 329 290 * @name_len: volume name length 330 291 * @name: the volume name 331 - * @padding2: reserved, zeroes 292 + * @flags: volume flags (%UBI_VTBL_AUTORESIZE_FLG) 293 + * @padding: reserved, zeroes 332 294 * @crc: a CRC32 checksum of the record 333 295 * 334 296 * The volume table records are stored in the volume table, which is stored in ··· 364 324 __u8 upd_marker; 365 325 __be16 name_len; 366 326 __u8 name[UBI_VOL_NAME_MAX+1]; 367 - __u8 padding2[24]; 327 + __u8 flags; 328 + __u8 padding[23]; 368 329 __be32 crc; 369 330 } __attribute__ ((packed)); 370 331
+47 -4
include/mtd/ubi-user.h
··· 63 63 * 64 64 * Volume update should be done via the %UBI_IOCVOLUP IOCTL command of the 65 65 * corresponding UBI volume character device. A pointer to a 64-bit update 66 - * size should be passed to the IOCTL. After then, UBI expects user to write 66 + * size should be passed to the IOCTL. After this, UBI expects user to write 67 67 * this number of bytes to the volume character device. The update is finished 68 68 * when the claimed number of bytes is passed. So, the volume update sequence 69 69 * is something like: ··· 72 72 * ioctl(fd, UBI_IOCVOLUP, &image_size); 73 73 * write(fd, buf, image_size); 74 74 * close(fd); 75 + * 76 + * Atomic eraseblock change 77 + * ~~~~~~~~~~~~~~~~~~~~~~~~ 78 + * 79 + * Atomic eraseblock change operation is done via the %UBI_IOCEBCH IOCTL 80 + * command of the corresponding UBI volume character device. A pointer to 81 + * &struct ubi_leb_change_req has to be passed to the IOCTL. Then the user is 82 + * expected to write the requested amount of bytes. This is similar to the 83 + * "volume update" IOCTL. 75 84 */ 76 85 77 86 /* ··· 122 113 #define UBI_IOCVOLUP _IOW(UBI_VOL_IOC_MAGIC, 0, int64_t) 123 114 /* An eraseblock erasure command, used for debugging, disabled by default */ 124 115 #define UBI_IOCEBER _IOW(UBI_VOL_IOC_MAGIC, 1, int32_t) 116 + /* An atomic eraseblock change command */ 117 + #define UBI_IOCEBCH _IOW(UBI_VOL_IOC_MAGIC, 2, int32_t) 125 118 126 119 /* Maximum MTD device name length supported by UBI */ 127 120 #define MAX_UBI_MTD_NAME_LEN 127 121 + 122 + /* 123 + * UBI data type hint constants. 124 + * 125 + * UBI_LONGTERM: long-term data 126 + * UBI_SHORTTERM: short-term data 127 + * UBI_UNKNOWN: data persistence is unknown 128 + * 129 + * These constants are used when data is written to UBI volumes in order to 130 + * help the UBI wear-leveling unit to find more appropriate physical 131 + * eraseblocks. 132 + */ 133 + enum { 134 + UBI_LONGTERM = 1, 135 + UBI_SHORTTERM = 2, 136 + UBI_UNKNOWN = 3, 137 + }; 128 138 129 139 /* 130 140 * UBI volume type constants. ··· 153 125 */ 154 126 enum { 155 127 UBI_DYNAMIC_VOLUME = 3, 156 - UBI_STATIC_VOLUME = 4, 128 + UBI_STATIC_VOLUME = 4, 157 129 }; 158 130 159 131 /** ··· 165 137 * 166 138 * This data structure is used to specify MTD device UBI has to attach and the 167 139 * parameters it has to use. The number which should be assigned to the new UBI 168 - * device is passed in @ubi_num. UBI may automatically assing the number if 140 + * device is passed in @ubi_num. UBI may automatically assign the number if 169 141 * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in 170 142 * @ubi_num. 171 143 * ··· 204 176 * @padding2: reserved for future, not used, has to be zeroed 205 177 * @name: volume name 206 178 * 207 - * This structure is used by userspace programs when creating new volumes. The 179 + * This structure is used by user-space programs when creating new volumes. The 208 180 * @used_bytes field is only necessary when creating static volumes. 209 181 * 210 182 * The @alignment field specifies the required alignment of the volume logical ··· 248 220 struct ubi_rsvol_req { 249 221 int64_t bytes; 250 222 int32_t vol_id; 223 + } __attribute__ ((packed)); 224 + 225 + /** 226 + * struct ubi_leb_change_req - a data structure used in atomic logical 227 + * eraseblock change requests. 228 + * @lnum: logical eraseblock number to change 229 + * @bytes: how many bytes will be written to the logical eraseblock 230 + * @dtype: data type (%UBI_LONGTERM, %UBI_SHORTTERM, %UBI_UNKNOWN) 231 + * @padding: reserved for future, not used, has to be zeroed 232 + */ 233 + struct ubi_leb_change_req { 234 + int32_t lnum; 235 + int32_t bytes; 236 + uint8_t dtype; 237 + uint8_t padding[7]; 251 238 } __attribute__ ((packed)); 252 239 253 240 #endif /* __UBI_USER_H__ */