Lines Matching +full:out +full:- +full:volume +full:- +full:limit
5 * SPDX-License-Identifier: GPL-2.0+
45 /* Maximum number of comma-separated items in the 'mtd=' parameter */
62 * struct mtd_dev_param - MTD device parameter description data structure.
82 /* UBI module parameter to enable fastmap automatically on non-fastmap images */
99 /* Slab cache for wear-leveling entries */
122 /* Protects @ubi_devices and @ubi->ref_count */
174 * ubi_volume_notify - send a volume change notification.
176 * @vol: volume description object of the changed volume
179 * This is a helper function which notifies all subscribers about a volume
180 * change event (creation, removal, re-sizing, re-naming, updating). Returns
205 * ubi_notify_all - send a notification to all volumes.
211 * notification for each volume. If @nb is %NULL, then all registered notifiers
225 mutex_lock(&ubi->device_mutex); in ubi_notify_all()
226 for (i = 0; i < ubi->vtbl_slots; i++) { in ubi_notify_all()
228 * Since the @ubi->device is locked, and we are not going to in ubi_notify_all()
229 * change @ubi->volumes, we do not have to lock in ubi_notify_all()
230 * @ubi->volumes_lock. in ubi_notify_all()
232 if (!ubi->volumes[i]) in ubi_notify_all()
235 ubi_do_get_volume_info(ubi, ubi->volumes[i], &nt.vi); in ubi_notify_all()
238 nb->notifier_call(nb, ntype, &nt); in ubi_notify_all()
245 mutex_unlock(&ubi->device_mutex); in ubi_notify_all()
251 * ubi_enumerate_volumes - send "add" notification for all existing volumes.
255 * %UBI_VOLUME_ADDED notification for each volume. If @nb is %NULL, then all
279 * ubi_get_device - get UBI device.
294 ubi_assert(ubi->ref_count >= 0); in ubi_get_device()
295 ubi->ref_count += 1; in ubi_get_device()
296 get_device(&ubi->dev); in ubi_get_device()
304 * ubi_put_device - drop an UBI device reference.
310 ubi->ref_count -= 1; in ubi_put_device()
311 put_device(&ubi->dev); in ubi_put_device()
316 * ubi_get_by_major - get UBI device by character device major number.
330 if (ubi && MAJOR(ubi->cdev.dev) == major) { in ubi_get_by_major()
331 ubi_assert(ubi->ref_count >= 0); in ubi_get_by_major()
332 ubi->ref_count += 1; in ubi_get_by_major()
333 get_device(&ubi->dev); in ubi_get_by_major()
344 * ubi_major2num - get UBI device number by character device major number.
348 * device was not found, this function returns -ENODEV, otherwise the UBI device
353 int i, ubi_num = -ENODEV; in ubi_major2num()
359 if (ubi && MAJOR(ubi->cdev.dev) == major) { in ubi_major2num()
360 ubi_num = ubi->ubi_num; in ubi_major2num()
382 * 'ubi_get_device()' will return -ENODEV and we fail. in dev_attribute_show()
385 * we still can use 'ubi->ubi_num'. in dev_attribute_show()
388 ubi = ubi_get_device(ubi->ubi_num); in dev_attribute_show()
390 return -ENODEV; in dev_attribute_show()
393 ret = sprintf(buf, "%d\n", ubi->leb_size); in dev_attribute_show()
395 ret = sprintf(buf, "%d\n", ubi->avail_pebs); in dev_attribute_show()
397 ret = sprintf(buf, "%d\n", ubi->good_peb_count); in dev_attribute_show()
399 ret = sprintf(buf, "%d\n", ubi->vol_count - UBI_INT_VOL_COUNT); in dev_attribute_show()
401 ret = sprintf(buf, "%d\n", ubi->max_ec); in dev_attribute_show()
403 ret = sprintf(buf, "%d\n", ubi->beb_rsvd_pebs); in dev_attribute_show()
405 ret = sprintf(buf, "%d\n", ubi->bad_peb_count); in dev_attribute_show()
407 ret = sprintf(buf, "%d\n", ubi->vtbl_slots); in dev_attribute_show()
409 ret = sprintf(buf, "%d\n", ubi->min_io_size); in dev_attribute_show()
411 ret = sprintf(buf, "%d\n", ubi->thread_enabled); in dev_attribute_show()
413 ret = sprintf(buf, "%d\n", ubi->mtd->index); in dev_attribute_show()
415 ret = -EINVAL; in dev_attribute_show()
445 * ubi_sysfs_init - initialize sysfs for an UBI device.
447 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
457 ubi->dev.release = dev_release; in ubi_sysfs_init()
458 ubi->dev.devt = ubi->cdev.dev; in ubi_sysfs_init()
459 ubi->dev.class = &ubi_class; in ubi_sysfs_init()
460 ubi->dev.groups = ubi_dev_groups; in ubi_sysfs_init()
461 dev_set_name(&ubi->dev, UBI_NAME_STR"%d", ubi->ubi_num); in ubi_sysfs_init()
462 err = device_register(&ubi->dev); in ubi_sysfs_init()
471 * ubi_sysfs_close - close sysfs for an UBI device.
476 device_unregister(&ubi->dev); in ubi_sysfs_close()
481 * kill_volumes - destroy all user volumes.
488 for (i = 0; i < ubi->vtbl_slots; i++) in kill_volumes()
489 if (ubi->volumes[i]) in kill_volumes()
490 ubi_free_volume(ubi, ubi->volumes[i]); in kill_volumes()
494 * uif_init - initialize user interfaces for an UBI device.
496 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
503 * driver core subsystem, this function takes a reference to @ubi->dev, because
519 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); in uif_init()
523 * dynamically. Major numbers of volume character devices are in uif_init()
526 * volume character devices start from 1. Thus, we allocate one major in uif_init()
527 * number and ubi->vtbl_slots + 1 minor numbers. in uif_init()
529 err = alloc_chrdev_region(&dev, 0, ubi->vtbl_slots + 1, ubi->ubi_name); in uif_init()
536 cdev_init(&ubi->cdev, &ubi_cdev_operations); in uif_init()
537 dbg_gen("%s major is %u", ubi->ubi_name, MAJOR(dev)); in uif_init()
538 ubi->cdev.owner = THIS_MODULE; in uif_init()
540 err = cdev_add(&ubi->cdev, dev, 1); in uif_init()
550 for (i = 0; i < ubi->vtbl_slots; i++) in uif_init()
551 if (ubi->volumes[i]) { in uif_init()
552 err = ubi_add_volume(ubi, ubi->volumes[i]); in uif_init()
554 ubi_err(ubi, "cannot add volume %d", i); in uif_init()
565 get_device(&ubi->dev); in uif_init()
567 cdev_del(&ubi->cdev); in uif_init()
569 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); in uif_init()
571 ubi->ubi_name, err); in uif_init()
576 * uif_close - close user interfaces for an UBI device.
579 * Note, since this function un-registers UBI volume device objects (@vol->dev),
587 cdev_del(&ubi->cdev); in uif_close()
588 unregister_chrdev_region(ubi->cdev.dev, ubi->vtbl_slots + 1); in uif_close()
592 * ubi_free_internal_volumes - free internal volumes.
599 for (i = ubi->vtbl_slots; in ubi_free_internal_volumes()
600 i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { in ubi_free_internal_volumes()
601 kfree(ubi->volumes[i]->eba_tbl); in ubi_free_internal_volumes()
602 kfree(ubi->volumes[i]); in ubi_free_internal_volumes()
608 int limit, device_pebs; in get_bad_peb_limit() local
621 * the MTD partition we are attaching (ubi->mtd). in get_bad_peb_limit()
623 device_size = mtd_get_device_size(ubi->mtd); in get_bad_peb_limit()
624 device_pebs = mtd_div_by_eb(device_size, ubi->mtd); in get_bad_peb_limit()
625 limit = mult_frac(device_pebs, max_beb_per1024, 1024); in get_bad_peb_limit()
628 if (mult_frac(limit, 1024, max_beb_per1024) < device_pebs) in get_bad_peb_limit()
629 limit += 1; in get_bad_peb_limit()
631 return limit; in get_bad_peb_limit()
635 * io_init - initialize I/O sub-system for a given UBI device.
639 * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are
641 * o EC header is always at offset zero - this cannot be changed;
643 * aligned to @io->hdrs_min_io_size;
645 * @io->min_io_size
655 if (ubi->mtd->numeraseregions != 0) { in io_init()
659 * characteristics. It looks like mostly multi-region flashes in io_init()
666 return -EINVAL; in io_init()
669 if (ubi->vid_hdr_offset < 0) in io_init()
670 return -EINVAL; in io_init()
677 ubi->peb_size = ubi->mtd->erasesize; in io_init()
678 ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd); in io_init()
679 ubi->flash_size = ubi->mtd->size; in io_init()
681 if (mtd_can_have_bb(ubi->mtd)) { in io_init()
682 ubi->bad_allowed = 1; in io_init()
683 ubi->bad_peb_limit = get_bad_peb_limit(ubi, max_beb_per1024); in io_init()
686 if (ubi->mtd->type == MTD_NORFLASH) { in io_init()
687 ubi_assert(ubi->mtd->writesize == 1); in io_init()
688 ubi->nor_flash = 1; in io_init()
691 ubi->min_io_size = ubi->mtd->writesize; in io_init()
692 ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft; in io_init()
699 if (!is_power_of_2(ubi->min_io_size)) { in io_init()
701 ubi->min_io_size); in io_init()
702 return -EINVAL; in io_init()
705 ubi_assert(ubi->hdrs_min_io_size > 0); in io_init()
706 ubi_assert(ubi->hdrs_min_io_size <= ubi->min_io_size); in io_init()
707 ubi_assert(ubi->min_io_size % ubi->hdrs_min_io_size == 0); in io_init()
709 ubi->max_write_size = ubi->mtd->writebufsize; in io_init()
714 if (ubi->max_write_size < ubi->min_io_size || in io_init()
715 ubi->max_write_size % ubi->min_io_size || in io_init()
716 !is_power_of_2(ubi->max_write_size)) { in io_init()
718 ubi->max_write_size, ubi->min_io_size); in io_init()
719 return -EINVAL; in io_init()
723 ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size); in io_init()
724 ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size); in io_init()
726 dbg_gen("min_io_size %d", ubi->min_io_size); in io_init()
727 dbg_gen("max_write_size %d", ubi->max_write_size); in io_init()
728 dbg_gen("hdrs_min_io_size %d", ubi->hdrs_min_io_size); in io_init()
729 dbg_gen("ec_hdr_alsize %d", ubi->ec_hdr_alsize); in io_init()
730 dbg_gen("vid_hdr_alsize %d", ubi->vid_hdr_alsize); in io_init()
732 if (ubi->vid_hdr_offset == 0) in io_init()
734 ubi->vid_hdr_offset = ubi->vid_hdr_aloffset = in io_init()
735 ubi->ec_hdr_alsize; in io_init()
737 ubi->vid_hdr_aloffset = ubi->vid_hdr_offset & in io_init()
738 ~(ubi->hdrs_min_io_size - 1); in io_init()
739 ubi->vid_hdr_shift = ubi->vid_hdr_offset - in io_init()
740 ubi->vid_hdr_aloffset; in io_init()
744 ubi->leb_start = ubi->vid_hdr_offset + UBI_VID_HDR_SIZE; in io_init()
745 ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size); in io_init()
747 dbg_gen("vid_hdr_offset %d", ubi->vid_hdr_offset); in io_init()
748 dbg_gen("vid_hdr_aloffset %d", ubi->vid_hdr_aloffset); in io_init()
749 dbg_gen("vid_hdr_shift %d", ubi->vid_hdr_shift); in io_init()
750 dbg_gen("leb_start %d", ubi->leb_start); in io_init()
752 /* The shift must be aligned to 32-bit boundary */ in io_init()
753 if (ubi->vid_hdr_shift % 4) { in io_init()
755 ubi->vid_hdr_shift); in io_init()
756 return -EINVAL; in io_init()
760 if (ubi->vid_hdr_offset < UBI_EC_HDR_SIZE || in io_init()
761 ubi->leb_start < ubi->vid_hdr_offset + UBI_VID_HDR_SIZE || in io_init()
762 ubi->leb_start > ubi->peb_size - UBI_VID_HDR_SIZE || in io_init()
763 ubi->leb_start & (ubi->min_io_size - 1)) { in io_init()
765 ubi->vid_hdr_offset, ubi->leb_start); in io_init()
766 return -EINVAL; in io_init()
773 ubi->max_erroneous = ubi->peb_count / 10; in io_init()
774 if (ubi->max_erroneous < 16) in io_init()
775 ubi->max_erroneous = 16; in io_init()
776 dbg_gen("max_erroneous %d", ubi->max_erroneous); in io_init()
781 * read-only mode. in io_init()
783 if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) { in io_init()
784 ubi_warn(ubi, "EC and VID headers are in the same minimal I/O unit, switch to read-only mode"); in io_init()
785 ubi->ro_mode = 1; in io_init()
788 ubi->leb_size = ubi->peb_size - ubi->leb_start; in io_init()
790 if (!(ubi->mtd->flags & MTD_WRITEABLE)) { in io_init()
791 ubi_msg(ubi, "MTD device %d is write-protected, attach in read-only mode", in io_init()
792 ubi->mtd->index); in io_init()
793 ubi->ro_mode = 1; in io_init()
797 * Note, ideally, we have to initialize @ubi->bad_peb_count here. But in io_init()
799 * over all physical eraseblocks and invoke mtd->block_is_bad() for in io_init()
800 * each physical eraseblock. So, we leave @ubi->bad_peb_count in io_init()
808 * autoresize - re-size the volume which has the "auto-resize" flag set.
810 * @vol_id: ID of the volume to re-size
812 * This function re-sizes the volume marked by the %UBI_VTBL_AUTORESIZE_FLG in
813 * the volume table to the largest possible size. See comments in ubi-header.h
820 struct ubi_volume *vol = ubi->volumes[vol_id]; in autoresize()
821 int err, old_reserved_pebs = vol->reserved_pebs; in autoresize()
823 if (ubi->ro_mode) { in autoresize()
824 ubi_warn(ubi, "skip auto-resize because of R/O mode"); in autoresize()
829 * Clear the auto-resize flag in the volume in-memory copy of the in autoresize()
830 * volume table, and 'ubi_resize_volume()' will propagate this change in autoresize()
833 ubi->vtbl[vol_id].flags &= ~UBI_VTBL_AUTORESIZE_FLG; in autoresize()
835 if (ubi->avail_pebs == 0) { in autoresize()
839 * No available PEBs to re-size the volume, clear the flag on in autoresize()
842 vtbl_rec = ubi->vtbl[vol_id]; in autoresize()
845 ubi_err(ubi, "cannot clean auto-resize flag for volume %d", in autoresize()
850 old_reserved_pebs + ubi->avail_pebs); in autoresize()
852 ubi_err(ubi, "cannot auto-resize volume %d", in autoresize()
859 ubi_msg(ubi, "volume %d (\"%s\") re-sized from %d to %d LEBs", in autoresize()
860 vol_id, vol->name, old_reserved_pebs, vol->reserved_pebs); in autoresize()
865 * ubi_attach_mtd_dev - attach an MTD device.
887 return -EINVAL; in ubi_attach_mtd_dev()
900 if (ubi && mtd->index == ubi->mtd->index) { in ubi_attach_mtd_dev()
902 mtd->index, i); in ubi_attach_mtd_dev()
903 return -EEXIST; in ubi_attach_mtd_dev()
908 * Make sure this MTD device is not emulated on top of an UBI volume in ubi_attach_mtd_dev()
915 if (mtd->type == MTD_UBIVOLUME) { in ubi_attach_mtd_dev()
916 ubi_err(ubi, "refuse attaching mtd%d - it is already emulated on top of UBI", in ubi_attach_mtd_dev()
917 mtd->index); in ubi_attach_mtd_dev()
918 return -EINVAL; in ubi_attach_mtd_dev()
929 return -ENFILE; in ubi_attach_mtd_dev()
933 return -EINVAL; in ubi_attach_mtd_dev()
938 return -EEXIST; in ubi_attach_mtd_dev()
944 return -ENOMEM; in ubi_attach_mtd_dev()
946 ubi->mtd = mtd; in ubi_attach_mtd_dev()
947 ubi->ubi_num = ubi_num; in ubi_attach_mtd_dev()
948 ubi->vid_hdr_offset = vid_hdr_offset; in ubi_attach_mtd_dev()
949 ubi->autoresize_vol_id = -1; in ubi_attach_mtd_dev()
952 ubi->fm_pool.used = ubi->fm_pool.size = 0; in ubi_attach_mtd_dev()
953 ubi->fm_wl_pool.used = ubi->fm_wl_pool.size = 0; in ubi_attach_mtd_dev()
959 ubi->fm_pool.max_size = min(((int)mtd_div_by_eb(ubi->mtd->size, in ubi_attach_mtd_dev()
960 ubi->mtd) / 100) * 5, UBI_FM_MAX_POOL_SIZE); in ubi_attach_mtd_dev()
961 ubi->fm_pool.max_size = max(ubi->fm_pool.max_size, in ubi_attach_mtd_dev()
964 ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2; in ubi_attach_mtd_dev()
965 ubi->fm_disabled = !fm_autoconvert; in ubi_attach_mtd_dev()
969 if (!ubi->fm_disabled && (int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) in ubi_attach_mtd_dev()
973 ubi->fm_disabled = 1; in ubi_attach_mtd_dev()
976 ubi_msg(ubi, "default fastmap pool size: %d", ubi->fm_pool.max_size); in ubi_attach_mtd_dev()
978 ubi->fm_wl_pool.max_size); in ubi_attach_mtd_dev()
980 ubi->fm_disabled = 1; in ubi_attach_mtd_dev()
982 mutex_init(&ubi->buf_mutex); in ubi_attach_mtd_dev()
983 mutex_init(&ubi->ckvol_mutex); in ubi_attach_mtd_dev()
984 mutex_init(&ubi->device_mutex); in ubi_attach_mtd_dev()
985 spin_lock_init(&ubi->volumes_lock); in ubi_attach_mtd_dev()
986 init_rwsem(&ubi->fm_protect); in ubi_attach_mtd_dev()
987 init_rwsem(&ubi->fm_eba_sem); in ubi_attach_mtd_dev()
989 ubi_msg(ubi, "attaching mtd%d", mtd->index); in ubi_attach_mtd_dev()
995 err = -ENOMEM; in ubi_attach_mtd_dev()
996 ubi->peb_buf = vmalloc(ubi->peb_size); in ubi_attach_mtd_dev()
997 if (!ubi->peb_buf) in ubi_attach_mtd_dev()
1001 ubi->fm_size = ubi_calc_fm_size(ubi); in ubi_attach_mtd_dev()
1002 ubi->fm_buf = vzalloc(ubi->fm_size); in ubi_attach_mtd_dev()
1003 if (!ubi->fm_buf) in ubi_attach_mtd_dev()
1009 mtd->index, err); in ubi_attach_mtd_dev()
1013 if (ubi->autoresize_vol_id != -1) { in ubi_attach_mtd_dev()
1014 err = autoresize(ubi, ubi->autoresize_vol_id); in ubi_attach_mtd_dev()
1027 ubi->bgt_thread = kthread_create(ubi_thread, ubi, "%s", ubi->bgt_name); in ubi_attach_mtd_dev()
1028 if (IS_ERR(ubi->bgt_thread)) { in ubi_attach_mtd_dev()
1029 err = PTR_ERR(ubi->bgt_thread); in ubi_attach_mtd_dev()
1031 ubi->bgt_name, err); in ubi_attach_mtd_dev()
1036 mtd->index, mtd->name, ubi->flash_size >> 20); in ubi_attach_mtd_dev()
1038 ubi->peb_size, ubi->peb_size >> 10, ubi->leb_size); in ubi_attach_mtd_dev()
1039 ubi_msg(ubi, "min./max. I/O unit sizes: %d/%d, sub-page size %d", in ubi_attach_mtd_dev()
1040 ubi->min_io_size, ubi->max_write_size, ubi->hdrs_min_io_size); in ubi_attach_mtd_dev()
1042 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset, ubi->leb_start); in ubi_attach_mtd_dev()
1044 ubi->good_peb_count, ubi->bad_peb_count, ubi->corr_peb_count); in ubi_attach_mtd_dev()
1045 ubi_msg(ubi, "user volume: %d, internal volumes: %d, max. volumes count: %d", in ubi_attach_mtd_dev()
1046 ubi->vol_count - UBI_INT_VOL_COUNT, UBI_INT_VOL_COUNT, in ubi_attach_mtd_dev()
1047 ubi->vtbl_slots); in ubi_attach_mtd_dev()
1049 ubi->max_ec, ubi->mean_ec, CONFIG_MTD_UBI_WL_THRESHOLD, in ubi_attach_mtd_dev()
1050 ubi->image_seq); in ubi_attach_mtd_dev()
1052 ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs); in ubi_attach_mtd_dev()
1056 * checks @ubi->thread_enabled. Otherwise we may fail to wake it up. in ubi_attach_mtd_dev()
1058 spin_lock(&ubi->wl_lock); in ubi_attach_mtd_dev()
1059 ubi->thread_enabled = 1; in ubi_attach_mtd_dev()
1061 wake_up_process(ubi->bgt_thread); in ubi_attach_mtd_dev()
1066 spin_unlock(&ubi->wl_lock); in ubi_attach_mtd_dev()
1075 get_device(&ubi->dev); in ubi_attach_mtd_dev()
1081 vfree(ubi->vtbl); in ubi_attach_mtd_dev()
1083 vfree(ubi->peb_buf); in ubi_attach_mtd_dev()
1084 vfree(ubi->fm_buf); in ubi_attach_mtd_dev()
1086 put_device(&ubi->dev); in ubi_attach_mtd_dev()
1093 * ubi_detach_mtd_dev - detach an MTD device.
1098 * underlying MTD device. Returns zero in case of success and %-EBUSY if the
1099 * UBI device is busy and cannot be destroyed, and %-EINVAL if it does not
1110 return -EINVAL; in ubi_detach_mtd_dev()
1114 return -EINVAL; in ubi_detach_mtd_dev()
1117 put_device(&ubi->dev); in ubi_detach_mtd_dev()
1118 ubi->ref_count -= 1; in ubi_detach_mtd_dev()
1119 if (ubi->ref_count) { in ubi_detach_mtd_dev()
1122 return -EBUSY; in ubi_detach_mtd_dev()
1126 ubi->ubi_name, ubi->ref_count); in ubi_detach_mtd_dev()
1131 ubi_assert(ubi_num == ubi->ubi_num); in ubi_detach_mtd_dev()
1133 ubi_msg(ubi, "detaching mtd%d", ubi->mtd->index); in ubi_detach_mtd_dev()
1146 if (ubi->bgt_thread) in ubi_detach_mtd_dev()
1147 kthread_stop(ubi->bgt_thread); in ubi_detach_mtd_dev()
1153 get_device(&ubi->dev); in ubi_detach_mtd_dev()
1160 vfree(ubi->vtbl); in ubi_detach_mtd_dev()
1161 put_mtd_device(ubi->mtd); in ubi_detach_mtd_dev()
1162 vfree(ubi->peb_buf); in ubi_detach_mtd_dev()
1163 vfree(ubi->fm_buf); in ubi_detach_mtd_dev()
1164 ubi_msg(ubi, "mtd%d is detached", ubi->mtd->index); in ubi_detach_mtd_dev()
1165 put_device(&ubi->dev); in ubi_detach_mtd_dev()
1171 * open_mtd_by_chdev - open an MTD device by its character device node path.
1191 mode = d_backing_inode(path.dentry)->i_mode; in open_mtd_by_chdev()
1194 return ERR_PTR(-EINVAL); in open_mtd_by_chdev()
1201 return ERR_PTR(-EINVAL); in open_mtd_by_chdev()
1208 * open_mtd_device - open MTD device by name, character device path, or number.
1231 if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV) in open_mtd_device()
1256 return -EINVAL; in ubi_init()
1267 goto out; in ubi_init()
1274 err = -ENOMEM; in ubi_init()
1290 mtd = open_mtd_device(p->name); in ubi_init()
1294 p->name, err); in ubi_init()
1295 /* See comment below re-ubi_is_module(). */ in ubi_init()
1302 err = ubi_attach_mtd_dev(mtd, p->ubi_num, in ubi_init()
1303 p->vid_hdr_offs, p->max_beb_per1024); in ubi_init()
1307 mtd->index); in ubi_init()
1312 * However, later on it was found out that this in ubi_init()
1319 * non-module case, but preserved the old behavior for in ubi_init()
1332 /* See comment above re-ubi_is_module(). */ in ubi_init()
1343 ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1); in ubi_init()
1351 out: in ubi_init()
1375 ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1); in ubi_exit()
1390 * bytes_str_to_int - convert a number of bytes string into an integer.
1404 return -EINVAL; in bytes_str_to_int()
1420 return -EINVAL; in bytes_str_to_int()
1432 return -ERANGE; in kstrtoint()
1438 * ubi_mtd_param_parse - parse the 'mtd=' UBI parameter.
1458 return -EINVAL; in ubi_mtd_param_parse()
1463 return -EINVAL; in ubi_mtd_param_parse()
1470 return -EINVAL; in ubi_mtd_param_parse()
1474 pr_warn("UBI warning: empty 'mtd=' parameter - ignored\n"); in ubi_mtd_param_parse()
1481 if (buf[len - 1] == '\n') in ubi_mtd_param_parse()
1482 buf[len - 1] = '\0'; in ubi_mtd_param_parse()
1489 return -EINVAL; in ubi_mtd_param_parse()
1493 strcpy(&p->name[0], tokens[0]); in ubi_mtd_param_parse()
1497 p->vid_hdr_offs = bytes_str_to_int(token); in ubi_mtd_param_parse()
1499 if (p->vid_hdr_offs < 0) in ubi_mtd_param_parse()
1500 return p->vid_hdr_offs; in ubi_mtd_param_parse()
1505 int err = kstrtoint(token, 10, &p->max_beb_per1024); in ubi_mtd_param_parse()
1510 return -EINVAL; in ubi_mtd_param_parse()
1516 int err = kstrtoint(token, 10, &p->ubi_num); in ubi_mtd_param_parse()
1521 return -EINVAL; in ubi_mtd_param_parse()
1524 p->ubi_num = UBI_DEV_NUM_AUTO; in ubi_mtd_param_parse()
1539 "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n"
1540 …"Example 2: mtd=content,1984 mtd=4 - attach MTD device with name \"content\" using VID header offs…
1541 …"Example 3: mtd=/dev/mtd1,0,25 - attach MTD device /dev/mtd1 using default VID header offset and r…
1542 …"Example 4: mtd=/dev/mtd1,0,0,5 - attach MTD device /dev/mtd1 to UBI 5 and using default values fo…
1551 MODULE_DESCRIPTION("UBI - Unsorted Block Images");