Lines Matching full:ubi
8 /* This file mostly implements UBI kernel API functions */
16 #include "ubi.h"
19 * ubi_do_get_device_info - get information about UBI device.
20 * @ubi: UBI device description object
23 * This function is the same as 'ubi_get_device_info()', but it assumes the UBI
26 void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di) in ubi_do_get_device_info() argument
28 di->ubi_num = ubi->ubi_num; in ubi_do_get_device_info()
29 di->leb_size = ubi->leb_size; in ubi_do_get_device_info()
30 di->leb_start = ubi->leb_start; in ubi_do_get_device_info()
31 di->min_io_size = ubi->min_io_size; in ubi_do_get_device_info()
32 di->max_write_size = ubi->max_write_size; in ubi_do_get_device_info()
33 di->ro_mode = ubi->ro_mode; in ubi_do_get_device_info()
34 di->cdev = ubi->cdev.dev; in ubi_do_get_device_info()
39 * ubi_get_device_info - get information about UBI device.
40 * @ubi_num: UBI device number
43 * This function returns %0 in case of success, %-EINVAL if the UBI device
44 * number is invalid, and %-ENODEV if there is no such UBI device.
48 struct ubi_device *ubi; in ubi_get_device_info() local
52 ubi = ubi_get_device(ubi_num); in ubi_get_device_info()
53 if (!ubi) in ubi_get_device_info()
55 ubi_do_get_device_info(ubi, di); in ubi_get_device_info()
56 ubi_put_device(ubi); in ubi_get_device_info()
62 * ubi_do_get_volume_info - get information about UBI volume.
63 * @ubi: UBI device description object
67 void ubi_do_get_volume_info(struct ubi_device *ubi, struct ubi_volume *vol, in ubi_do_get_volume_info() argument
71 vi->ubi_num = ubi->ubi_num; in ubi_do_get_volume_info()
86 * ubi_get_volume_info - get information about UBI volume.
93 ubi_do_get_volume_info(desc->vol->ubi, desc->vol, vi); in ubi_get_volume_info()
98 * ubi_open_volume - open UBI volume.
99 * @ubi_num: UBI device number
105 * nobody else will be able to open this volume. UBI allows to have many volume
119 struct ubi_device *ubi; in ubi_open_volume() local
132 * First of all, we have to get the UBI device to prevent its removal. in ubi_open_volume()
134 ubi = ubi_get_device(ubi_num); in ubi_open_volume()
135 if (!ubi) in ubi_open_volume()
138 if (vol_id < 0 || vol_id >= ubi->vtbl_slots) { in ubi_open_volume()
153 spin_lock(&ubi->volumes_lock); in ubi_open_volume()
154 vol = ubi->volumes[vol_id]; in ubi_open_volume()
187 spin_unlock(&ubi->volumes_lock); in ubi_open_volume()
192 mutex_lock(&ubi->ckvol_mutex); in ubi_open_volume()
195 err = ubi_check_volume(ubi, vol_id); in ubi_open_volume()
197 mutex_unlock(&ubi->ckvol_mutex); in ubi_open_volume()
202 ubi_warn(ubi, "volume %d on UBI device %d is corrupted", in ubi_open_volume()
203 vol_id, ubi->ubi_num); in ubi_open_volume()
208 mutex_unlock(&ubi->ckvol_mutex); in ubi_open_volume()
213 spin_unlock(&ubi->volumes_lock); in ubi_open_volume()
218 ubi_err(ubi, "cannot open device %d, volume %d, error %d", in ubi_open_volume()
220 ubi_put_device(ubi); in ubi_open_volume()
226 * ubi_open_volume_nm - open UBI volume by name.
227 * @ubi_num: UBI device number
237 struct ubi_device *ubi; in ubi_open_volume_nm() local
252 ubi = ubi_get_device(ubi_num); in ubi_open_volume_nm()
253 if (!ubi) in ubi_open_volume_nm()
256 spin_lock(&ubi->volumes_lock); in ubi_open_volume_nm()
257 /* Walk all volumes of this UBI device */ in ubi_open_volume_nm()
258 for (i = 0; i < ubi->vtbl_slots; i++) { in ubi_open_volume_nm()
259 struct ubi_volume *vol = ubi->volumes[i]; in ubi_open_volume_nm()
266 spin_unlock(&ubi->volumes_lock); in ubi_open_volume_nm()
274 * We should put the UBI device even in case of success, because in ubi_open_volume_nm()
277 ubi_put_device(ubi); in ubi_open_volume_nm()
283 * ubi_get_num_by_path - get UBI device and volume number from device path
285 * @ubi_num: pointer to UBI device number to be set
286 * @vol_id: pointer to UBI volume ID to be set
318 * ubi_open_volume_path - open UBI volume by its character device node path.
343 * ubi_close_volume - close UBI volume.
349 struct ubi_device *ubi = vol->ubi; in ubi_close_volume() local
352 ubi->ubi_num, vol->vol_id, desc->mode); in ubi_close_volume()
354 spin_lock(&ubi->volumes_lock); in ubi_close_volume()
370 spin_unlock(&ubi->volumes_lock); in ubi_close_volume()
374 ubi_put_device(ubi); in ubi_close_volume()
393 struct ubi_device *ubi = vol->ubi; in leb_read_sanity_check() local
396 if (vol_id < 0 || vol_id >= ubi->vtbl_slots || lnum < 0 || in leb_read_sanity_check()
403 /* Empty static UBI volume */ in leb_read_sanity_check()
423 * @check: whether UBI has to check the read data's CRC or not.
447 struct ubi_device *ubi = vol->ubi; in ubi_leb_read() local
459 err = ubi_eba_read_leb(ubi, vol, lnum, buf, offset, len, check); in ubi_leb_read()
461 ubi_warn(ubi, "mark volume %d as corrupted", vol_id); in ubi_leb_read()
474 * @sgl: UBI scatter gather list to store the read data
477 * @check: whether UBI has to check the read data's CRC or not.
480 * storing the read data into a buffer it writes to an UBI scatter gather
487 struct ubi_device *ubi = vol->ubi; in ubi_leb_read_sg() local
499 err = ubi_eba_read_leb_sg(ubi, vol, sgl, lnum, offset, len, check); in ubi_leb_read_sg()
501 ubi_warn(ubi, "mark volume %d as corrupted", vol_id); in ubi_leb_read_sg()
523 * write finishes. UBI has a pool of reserved physical eraseblocks for this.
526 * occurred and UBI has not been able to recover from it, this function returns
538 struct ubi_device *ubi = vol->ubi; in ubi_leb_write() local
543 if (vol_id < 0 || vol_id >= ubi->vtbl_slots) in ubi_leb_write()
551 offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1)) in ubi_leb_write()
560 return ubi_eba_write_leb(ubi, vol, lnum, buf, offset, len); in ubi_leb_write()
583 struct ubi_device *ubi = vol->ubi; in ubi_leb_change() local
588 if (vol_id < 0 || vol_id >= ubi->vtbl_slots) in ubi_leb_change()
595 len > vol->usable_leb_size || len & (ubi->min_io_size - 1)) in ubi_leb_change()
604 return ubi_eba_atomic_leb_change(ubi, vol, lnum, buf, len); in ubi_leb_change()
623 struct ubi_device *ubi = vol->ubi; in ubi_leb_erase() local
637 err = ubi_eba_unmap_leb(ubi, vol, lnum); in ubi_leb_erase()
641 return ubi_wl_flush(ubi, vol->vol_id, lnum); in ubi_leb_erase()
656 * eraseblock will contain all 0xFF bytes when UBI is initialized again. For
663 * In other words, when un-mapping a logical eraseblock, UBI does not store
665 * eraseblock as "un-mapped" in RAM. If UBI is detached before the physical
673 * UBI guarantees that the old contents has gone forever. In other words, if an
684 struct ubi_device *ubi = vol->ubi; in ubi_leb_unmap() local
697 return ubi_eba_unmap_leb(ubi, vol, lnum); in ubi_leb_unmap()
720 struct ubi_device *ubi = vol->ubi; in ubi_leb_map() local
736 return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0); in ubi_leb_map()
747 * mean it will still be un-mapped after the UBI device is re-attached. The
773 * ubi_sync - synchronize UBI device buffers.
774 * @ubi_num: UBI device to synchronize
782 struct ubi_device *ubi; in ubi_sync() local
784 ubi = ubi_get_device(ubi_num); in ubi_sync()
785 if (!ubi) in ubi_sync()
788 mtd_sync(ubi->mtd); in ubi_sync()
789 ubi_put_device(ubi); in ubi_sync()
795 * ubi_flush - flush UBI work queue.
796 * @ubi_num: UBI device to flush work queue
808 struct ubi_device *ubi; in ubi_flush() local
811 ubi = ubi_get_device(ubi_num); in ubi_flush()
812 if (!ubi) in ubi_flush()
815 err = ubi_wl_flush(ubi, vol_id, lnum); in ubi_flush()
816 ubi_put_device(ubi); in ubi_flush()
830 * 'nb->notifier_call()' will be invoked when an UBI volume is created,
834 * Using UBI API from the volume notifier is prohibited.
851 * We are going to walk all UBI devices and all volumes, and in ubi_register_volume_notifier()
853 * event. We have to lock the @ubi_devices_mutex to make sure UBI in ubi_register_volume_notifier()