2 * Copyright (c) International Business Machines Corp., 2006
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: Artem Bityutskiy (Битюцкий Артём)
21 /* This file mostly implements UBI kernel API functions */
23 #include <linux/module.h>
24 #include <linux/err.h>
25 #include <linux/slab.h>
26 #include <linux/namei.h>
28 #include <asm/div64.h>
32 * ubi_do_get_device_info - get information about UBI device.
33 * @ubi: UBI device description object
34 * @di: the information is stored here
36 * This function is the same as 'ubi_get_device_info()', but it assumes the UBI
37 * device is locked and cannot disappear.
39 void ubi_do_get_device_info(struct ubi_device
*ubi
, struct ubi_device_info
*di
)
41 di
->ubi_num
= ubi
->ubi_num
;
42 di
->leb_size
= ubi
->leb_size
;
43 di
->leb_start
= ubi
->leb_start
;
44 di
->min_io_size
= ubi
->min_io_size
;
45 di
->max_write_size
= ubi
->max_write_size
;
46 di
->ro_mode
= ubi
->ro_mode
;
47 di
->cdev
= ubi
->cdev
.dev
;
49 EXPORT_SYMBOL_GPL(ubi_do_get_device_info
);
52 * ubi_get_device_info - get information about UBI device.
53 * @ubi_num: UBI device number
54 * @di: the information is stored here
56 * This function returns %0 in case of success, %-EINVAL if the UBI device
57 * number is invalid, and %-ENODEV if there is no such UBI device.
59 int ubi_get_device_info(int ubi_num
, struct ubi_device_info
*di
)
61 struct ubi_device
*ubi
;
63 if (ubi_num
< 0 || ubi_num
>= UBI_MAX_DEVICES
)
65 ubi
= ubi_get_device(ubi_num
);
68 ubi_do_get_device_info(ubi
, di
);
72 EXPORT_SYMBOL_GPL(ubi_get_device_info
);
75 * ubi_do_get_volume_info - get information about UBI volume.
76 * @ubi: UBI device description object
77 * @vol: volume description object
78 * @vi: the information is stored here
80 void ubi_do_get_volume_info(struct ubi_device
*ubi
, struct ubi_volume
*vol
,
81 struct ubi_volume_info
*vi
)
83 vi
->vol_id
= vol
->vol_id
;
84 vi
->ubi_num
= ubi
->ubi_num
;
85 vi
->size
= vol
->reserved_pebs
;
86 vi
->used_bytes
= vol
->used_bytes
;
87 vi
->vol_type
= vol
->vol_type
;
88 vi
->corrupted
= vol
->corrupted
;
89 vi
->upd_marker
= vol
->upd_marker
;
90 vi
->alignment
= vol
->alignment
;
91 vi
->usable_leb_size
= vol
->usable_leb_size
;
92 vi
->name_len
= vol
->name_len
;
94 vi
->cdev
= vol
->cdev
.dev
;
98 * ubi_get_volume_info - get information about UBI volume.
99 * @desc: volume descriptor
100 * @vi: the information is stored here
102 void ubi_get_volume_info(struct ubi_volume_desc
*desc
,
103 struct ubi_volume_info
*vi
)
105 ubi_do_get_volume_info(desc
->vol
->ubi
, desc
->vol
, vi
);
107 EXPORT_SYMBOL_GPL(ubi_get_volume_info
);
110 * ubi_open_volume - open UBI volume.
111 * @ubi_num: UBI device number
115 * The @mode parameter specifies if the volume should be opened in read-only
116 * mode, read-write mode, or exclusive mode. The exclusive mode guarantees that
117 * nobody else will be able to open this volume. UBI allows to have many volume
118 * readers and one writer at a time.
120 * If a static volume is being opened for the first time since boot, it will be
121 * checked by this function, which means it will be fully read and the CRC
122 * checksum of each logical eraseblock will be checked.
124 * This function returns volume descriptor in case of success and a negative
125 * error code in case of failure.
127 struct ubi_volume_desc
*ubi_open_volume(int ubi_num
, int vol_id
, int mode
)
130 struct ubi_volume_desc
*desc
;
131 struct ubi_device
*ubi
;
132 struct ubi_volume
*vol
;
134 dbg_gen("open device %d, volume %d, mode %d", ubi_num
, vol_id
, mode
);
136 if (ubi_num
< 0 || ubi_num
>= UBI_MAX_DEVICES
)
137 return ERR_PTR(-EINVAL
);
139 if (mode
!= UBI_READONLY
&& mode
!= UBI_READWRITE
&&
140 mode
!= UBI_EXCLUSIVE
&& mode
!= UBI_METAONLY
)
141 return ERR_PTR(-EINVAL
);
144 * First of all, we have to get the UBI device to prevent its removal.
146 ubi
= ubi_get_device(ubi_num
);
148 return ERR_PTR(-ENODEV
);
150 if (vol_id
< 0 || vol_id
>= ubi
->vtbl_slots
) {
155 desc
= kmalloc(sizeof(struct ubi_volume_desc
), GFP_KERNEL
);
162 if (!try_module_get(THIS_MODULE
))
165 spin_lock(&ubi
->volumes_lock
);
166 vol
= ubi
->volumes
[vol_id
];
179 if (vol
->exclusive
|| vol
->writers
> 0)
185 if (vol
->exclusive
|| vol
->writers
|| vol
->readers
||
192 if (vol
->metaonly
|| vol
->exclusive
)
197 get_device(&vol
->dev
);
199 spin_unlock(&ubi
->volumes_lock
);
204 mutex_lock(&ubi
->ckvol_mutex
);
205 if (!vol
->checked
&& !vol
->skip_check
) {
206 /* This is the first open - check the volume */
207 err
= ubi_check_volume(ubi
, vol_id
);
209 mutex_unlock(&ubi
->ckvol_mutex
);
210 ubi_close_volume(desc
);
214 ubi_warn(ubi
, "volume %d on UBI device %d is corrupted",
215 vol_id
, ubi
->ubi_num
);
220 mutex_unlock(&ubi
->ckvol_mutex
);
225 spin_unlock(&ubi
->volumes_lock
);
226 module_put(THIS_MODULE
);
231 ubi_err(ubi
, "cannot open device %d, volume %d, error %d",
232 ubi_num
, vol_id
, err
);
235 EXPORT_SYMBOL_GPL(ubi_open_volume
);
238 * ubi_open_volume_nm - open UBI volume by name.
239 * @ubi_num: UBI device number
243 * This function is similar to 'ubi_open_volume()', but opens a volume by name.
245 struct ubi_volume_desc
*ubi_open_volume_nm(int ubi_num
, const char *name
,
248 int i
, vol_id
= -1, len
;
249 struct ubi_device
*ubi
;
250 struct ubi_volume_desc
*ret
;
252 dbg_gen("open device %d, volume %s, mode %d", ubi_num
, name
, mode
);
255 return ERR_PTR(-EINVAL
);
257 len
= strnlen(name
, UBI_VOL_NAME_MAX
+ 1);
258 if (len
> UBI_VOL_NAME_MAX
)
259 return ERR_PTR(-EINVAL
);
261 if (ubi_num
< 0 || ubi_num
>= UBI_MAX_DEVICES
)
262 return ERR_PTR(-EINVAL
);
264 ubi
= ubi_get_device(ubi_num
);
266 return ERR_PTR(-ENODEV
);
268 spin_lock(&ubi
->volumes_lock
);
269 /* Walk all volumes of this UBI device */
270 for (i
= 0; i
< ubi
->vtbl_slots
; i
++) {
271 struct ubi_volume
*vol
= ubi
->volumes
[i
];
273 if (vol
&& len
== vol
->name_len
&& !strcmp(name
, vol
->name
)) {
278 spin_unlock(&ubi
->volumes_lock
);
281 ret
= ubi_open_volume(ubi_num
, vol_id
, mode
);
283 ret
= ERR_PTR(-ENODEV
);
286 * We should put the UBI device even in case of success, because
287 * 'ubi_open_volume()' took a reference as well.
292 EXPORT_SYMBOL_GPL(ubi_open_volume_nm
);
295 * ubi_open_volume_path - open UBI volume by its character device node path.
296 * @pathname: volume character device node path
299 * This function is similar to 'ubi_open_volume()', but opens a volume the path
300 * to its character device node.
302 struct ubi_volume_desc
*ubi_open_volume_path(const char *pathname
, int mode
)
304 int error
, ubi_num
, vol_id
;
308 dbg_gen("open volume %s, mode %d", pathname
, mode
);
310 if (!pathname
|| !*pathname
)
311 return ERR_PTR(-EINVAL
);
313 error
= kern_path(pathname
, LOOKUP_FOLLOW
, &path
);
315 return ERR_PTR(error
);
317 error
= vfs_getattr(&path
, &stat
, STATX_TYPE
, AT_STATX_SYNC_AS_STAT
);
320 return ERR_PTR(error
);
322 if (!S_ISCHR(stat
.mode
))
323 return ERR_PTR(-EINVAL
);
325 ubi_num
= ubi_major2num(MAJOR(stat
.rdev
));
326 vol_id
= MINOR(stat
.rdev
) - 1;
328 if (vol_id
>= 0 && ubi_num
>= 0)
329 return ubi_open_volume(ubi_num
, vol_id
, mode
);
330 return ERR_PTR(-ENODEV
);
332 EXPORT_SYMBOL_GPL(ubi_open_volume_path
);
335 * ubi_close_volume - close UBI volume.
336 * @desc: volume descriptor
338 void ubi_close_volume(struct ubi_volume_desc
*desc
)
340 struct ubi_volume
*vol
= desc
->vol
;
341 struct ubi_device
*ubi
= vol
->ubi
;
343 dbg_gen("close device %d, volume %d, mode %d",
344 ubi
->ubi_num
, vol
->vol_id
, desc
->mode
);
346 spin_lock(&ubi
->volumes_lock
);
347 switch (desc
->mode
) {
362 spin_unlock(&ubi
->volumes_lock
);
365 put_device(&vol
->dev
);
367 module_put(THIS_MODULE
);
369 EXPORT_SYMBOL_GPL(ubi_close_volume
);
372 * leb_read_sanity_check - does sanity checks on read requests.
373 * @desc: volume descriptor
374 * @lnum: logical eraseblock number to read from
375 * @offset: offset within the logical eraseblock to read from
376 * @len: how many bytes to read
378 * This function is used by ubi_leb_read() and ubi_leb_read_sg()
379 * to perform sanity checks.
381 static int leb_read_sanity_check(struct ubi_volume_desc
*desc
, int lnum
,
384 struct ubi_volume
*vol
= desc
->vol
;
385 struct ubi_device
*ubi
= vol
->ubi
;
386 int vol_id
= vol
->vol_id
;
388 if (vol_id
< 0 || vol_id
>= ubi
->vtbl_slots
|| lnum
< 0 ||
389 lnum
>= vol
->used_ebs
|| offset
< 0 || len
< 0 ||
390 offset
+ len
> vol
->usable_leb_size
)
393 if (vol
->vol_type
== UBI_STATIC_VOLUME
) {
394 if (vol
->used_ebs
== 0)
395 /* Empty static UBI volume */
397 if (lnum
== vol
->used_ebs
- 1 &&
398 offset
+ len
> vol
->last_eb_bytes
)
409 * ubi_leb_read - read data.
410 * @desc: volume descriptor
411 * @lnum: logical eraseblock number to read from
412 * @buf: buffer where to store the read data
413 * @offset: offset within the logical eraseblock to read from
414 * @len: how many bytes to read
415 * @check: whether UBI has to check the read data's CRC or not.
417 * This function reads data from offset @offset of logical eraseblock @lnum and
418 * stores the data at @buf. When reading from static volumes, @check specifies
419 * whether the data has to be checked or not. If yes, the whole logical
420 * eraseblock will be read and its CRC checksum will be checked (i.e., the CRC
421 * checksum is per-eraseblock). So checking may substantially slow down the
422 * read speed. The @check argument is ignored for dynamic volumes.
424 * In case of success, this function returns zero. In case of failure, this
425 * function returns a negative error code.
427 * %-EBADMSG error code is returned:
428 * o for both static and dynamic volumes if MTD driver has detected a data
429 * integrity problem (unrecoverable ECC checksum mismatch in case of NAND);
430 * o for static volumes in case of data CRC mismatch.
432 * If the volume is damaged because of an interrupted update this function just
433 * returns immediately with %-EBADF error code.
435 int ubi_leb_read(struct ubi_volume_desc
*desc
, int lnum
, char *buf
, int offset
,
438 struct ubi_volume
*vol
= desc
->vol
;
439 struct ubi_device
*ubi
= vol
->ubi
;
440 int err
, vol_id
= vol
->vol_id
;
442 dbg_gen("read %d bytes from LEB %d:%d:%d", len
, vol_id
, lnum
, offset
);
444 err
= leb_read_sanity_check(desc
, lnum
, offset
, len
);
451 err
= ubi_eba_read_leb(ubi
, vol
, lnum
, buf
, offset
, len
, check
);
452 if (err
&& mtd_is_eccerr(err
) && vol
->vol_type
== UBI_STATIC_VOLUME
) {
453 ubi_warn(ubi
, "mark volume %d as corrupted", vol_id
);
459 EXPORT_SYMBOL_GPL(ubi_leb_read
);
463 * ubi_leb_read_sg - read data into a scatter gather list.
464 * @desc: volume descriptor
465 * @lnum: logical eraseblock number to read from
466 * @buf: buffer where to store the read data
467 * @offset: offset within the logical eraseblock to read from
468 * @len: how many bytes to read
469 * @check: whether UBI has to check the read data's CRC or not.
471 * This function works exactly like ubi_leb_read_sg(). But instead of
472 * storing the read data into a buffer it writes to an UBI scatter gather
475 int ubi_leb_read_sg(struct ubi_volume_desc
*desc
, int lnum
, struct ubi_sgl
*sgl
,
476 int offset
, int len
, int check
)
478 struct ubi_volume
*vol
= desc
->vol
;
479 struct ubi_device
*ubi
= vol
->ubi
;
480 int err
, vol_id
= vol
->vol_id
;
482 dbg_gen("read %d bytes from LEB %d:%d:%d", len
, vol_id
, lnum
, offset
);
484 err
= leb_read_sanity_check(desc
, lnum
, offset
, len
);
491 err
= ubi_eba_read_leb_sg(ubi
, vol
, sgl
, lnum
, offset
, len
, check
);
492 if (err
&& mtd_is_eccerr(err
) && vol
->vol_type
== UBI_STATIC_VOLUME
) {
493 ubi_warn(ubi
, "mark volume %d as corrupted", vol_id
);
499 EXPORT_SYMBOL_GPL(ubi_leb_read_sg
);
502 * ubi_leb_write - write data.
503 * @desc: volume descriptor
504 * @lnum: logical eraseblock number to write to
505 * @buf: data to write
506 * @offset: offset within the logical eraseblock where to write
507 * @len: how many bytes to write
509 * This function writes @len bytes of data from @buf to offset @offset of
510 * logical eraseblock @lnum.
512 * This function takes care of physical eraseblock write failures. If write to
513 * the physical eraseblock write operation fails, the logical eraseblock is
514 * re-mapped to another physical eraseblock, the data is recovered, and the
515 * write finishes. UBI has a pool of reserved physical eraseblocks for this.
517 * If all the data were successfully written, zero is returned. If an error
518 * occurred and UBI has not been able to recover from it, this function returns
519 * a negative error code. Note, in case of an error, it is possible that
520 * something was still written to the flash media, but that may be some
523 * If the volume is damaged because of an interrupted update this function just
524 * returns immediately with %-EBADF code.
526 int ubi_leb_write(struct ubi_volume_desc
*desc
, int lnum
, const void *buf
,
529 struct ubi_volume
*vol
= desc
->vol
;
530 struct ubi_device
*ubi
= vol
->ubi
;
531 int vol_id
= vol
->vol_id
;
533 dbg_gen("write %d bytes to LEB %d:%d:%d", len
, vol_id
, lnum
, offset
);
535 if (vol_id
< 0 || vol_id
>= ubi
->vtbl_slots
)
538 if (desc
->mode
== UBI_READONLY
|| vol
->vol_type
== UBI_STATIC_VOLUME
)
541 if (!ubi_leb_valid(vol
, lnum
) || offset
< 0 || len
< 0 ||
542 offset
+ len
> vol
->usable_leb_size
||
543 offset
& (ubi
->min_io_size
- 1) || len
& (ubi
->min_io_size
- 1))
552 return ubi_eba_write_leb(ubi
, vol
, lnum
, buf
, offset
, len
);
554 EXPORT_SYMBOL_GPL(ubi_leb_write
);
557 * ubi_leb_change - change logical eraseblock atomically.
558 * @desc: volume descriptor
559 * @lnum: logical eraseblock number to change
560 * @buf: data to write
561 * @len: how many bytes to write
563 * This function changes the contents of a logical eraseblock atomically. @buf
564 * has to contain new logical eraseblock data, and @len - the length of the
565 * data, which has to be aligned. The length may be shorter than the logical
566 * eraseblock size, ant the logical eraseblock may be appended to more times
567 * later on. This function guarantees that in case of an unclean reboot the old
568 * contents is preserved. Returns zero in case of success and a negative error
569 * code in case of failure.
571 int ubi_leb_change(struct ubi_volume_desc
*desc
, int lnum
, const void *buf
,
574 struct ubi_volume
*vol
= desc
->vol
;
575 struct ubi_device
*ubi
= vol
->ubi
;
576 int vol_id
= vol
->vol_id
;
578 dbg_gen("atomically write %d bytes to LEB %d:%d", len
, vol_id
, lnum
);
580 if (vol_id
< 0 || vol_id
>= ubi
->vtbl_slots
)
583 if (desc
->mode
== UBI_READONLY
|| vol
->vol_type
== UBI_STATIC_VOLUME
)
586 if (!ubi_leb_valid(vol
, lnum
) || len
< 0 ||
587 len
> vol
->usable_leb_size
|| len
& (ubi
->min_io_size
- 1))
596 return ubi_eba_atomic_leb_change(ubi
, vol
, lnum
, buf
, len
);
598 EXPORT_SYMBOL_GPL(ubi_leb_change
);
601 * ubi_leb_erase - erase logical eraseblock.
602 * @desc: volume descriptor
603 * @lnum: logical eraseblock number
605 * This function un-maps logical eraseblock @lnum and synchronously erases the
606 * correspondent physical eraseblock. Returns zero in case of success and a
607 * negative error code in case of failure.
609 * If the volume is damaged because of an interrupted update this function just
610 * returns immediately with %-EBADF code.
612 int ubi_leb_erase(struct ubi_volume_desc
*desc
, int lnum
)
614 struct ubi_volume
*vol
= desc
->vol
;
615 struct ubi_device
*ubi
= vol
->ubi
;
618 dbg_gen("erase LEB %d:%d", vol
->vol_id
, lnum
);
620 if (desc
->mode
== UBI_READONLY
|| vol
->vol_type
== UBI_STATIC_VOLUME
)
623 if (!ubi_leb_valid(vol
, lnum
))
629 err
= ubi_eba_unmap_leb(ubi
, vol
, lnum
);
633 return ubi_wl_flush(ubi
, vol
->vol_id
, lnum
);
635 EXPORT_SYMBOL_GPL(ubi_leb_erase
);
638 * ubi_leb_unmap - un-map logical eraseblock.
639 * @desc: volume descriptor
640 * @lnum: logical eraseblock number
642 * This function un-maps logical eraseblock @lnum and schedules the
643 * corresponding physical eraseblock for erasure, so that it will eventually be
644 * physically erased in background. This operation is much faster than the
647 * Unlike erase, the un-map operation does not guarantee that the logical
648 * eraseblock will contain all 0xFF bytes when UBI is initialized again. For
649 * example, if several logical eraseblocks are un-mapped, and an unclean reboot
650 * happens after this, the logical eraseblocks will not necessarily be
651 * un-mapped again when this MTD device is attached. They may actually be
652 * mapped to the same physical eraseblocks again. So, this function has to be
655 * In other words, when un-mapping a logical eraseblock, UBI does not store
656 * any information about this on the flash media, it just marks the logical
657 * eraseblock as "un-mapped" in RAM. If UBI is detached before the physical
658 * eraseblock is physically erased, it will be mapped again to the same logical
659 * eraseblock when the MTD device is attached again.
661 * The main and obvious use-case of this function is when the contents of a
662 * logical eraseblock has to be re-written. Then it is much more efficient to
663 * first un-map it, then write new data, rather than first erase it, then write
664 * new data. Note, once new data has been written to the logical eraseblock,
665 * UBI guarantees that the old contents has gone forever. In other words, if an
666 * unclean reboot happens after the logical eraseblock has been un-mapped and
667 * then written to, it will contain the last written data.
669 * This function returns zero in case of success and a negative error code in
670 * case of failure. If the volume is damaged because of an interrupted update
671 * this function just returns immediately with %-EBADF code.
673 int ubi_leb_unmap(struct ubi_volume_desc
*desc
, int lnum
)
675 struct ubi_volume
*vol
= desc
->vol
;
676 struct ubi_device
*ubi
= vol
->ubi
;
678 dbg_gen("unmap LEB %d:%d", vol
->vol_id
, lnum
);
680 if (desc
->mode
== UBI_READONLY
|| vol
->vol_type
== UBI_STATIC_VOLUME
)
683 if (!ubi_leb_valid(vol
, lnum
))
689 return ubi_eba_unmap_leb(ubi
, vol
, lnum
);
691 EXPORT_SYMBOL_GPL(ubi_leb_unmap
);
694 * ubi_leb_map - map logical eraseblock to a physical eraseblock.
695 * @desc: volume descriptor
696 * @lnum: logical eraseblock number
698 * This function maps an un-mapped logical eraseblock @lnum to a physical
699 * eraseblock. This means, that after a successful invocation of this
700 * function the logical eraseblock @lnum will be empty (contain only %0xFF
701 * bytes) and be mapped to a physical eraseblock, even if an unclean reboot
704 * This function returns zero in case of success, %-EBADF if the volume is
705 * damaged because of an interrupted update, %-EBADMSG if the logical
706 * eraseblock is already mapped, and other negative error codes in case of
709 int ubi_leb_map(struct ubi_volume_desc
*desc
, int lnum
)
711 struct ubi_volume
*vol
= desc
->vol
;
712 struct ubi_device
*ubi
= vol
->ubi
;
714 dbg_gen("map LEB %d:%d", vol
->vol_id
, lnum
);
716 if (desc
->mode
== UBI_READONLY
|| vol
->vol_type
== UBI_STATIC_VOLUME
)
719 if (!ubi_leb_valid(vol
, lnum
))
725 if (ubi_eba_is_mapped(vol
, lnum
))
728 return ubi_eba_write_leb(ubi
, vol
, lnum
, NULL
, 0, 0);
730 EXPORT_SYMBOL_GPL(ubi_leb_map
);
733 * ubi_is_mapped - check if logical eraseblock is mapped.
734 * @desc: volume descriptor
735 * @lnum: logical eraseblock number
737 * This function checks if logical eraseblock @lnum is mapped to a physical
738 * eraseblock. If a logical eraseblock is un-mapped, this does not necessarily
739 * mean it will still be un-mapped after the UBI device is re-attached. The
740 * logical eraseblock may become mapped to the physical eraseblock it was last
743 * This function returns %1 if the LEB is mapped, %0 if not, and a negative
744 * error code in case of failure. If the volume is damaged because of an
745 * interrupted update this function just returns immediately with %-EBADF error
748 int ubi_is_mapped(struct ubi_volume_desc
*desc
, int lnum
)
750 struct ubi_volume
*vol
= desc
->vol
;
752 dbg_gen("test LEB %d:%d", vol
->vol_id
, lnum
);
754 if (!ubi_leb_valid(vol
, lnum
))
760 return ubi_eba_is_mapped(vol
, lnum
);
762 EXPORT_SYMBOL_GPL(ubi_is_mapped
);
765 * ubi_sync - synchronize UBI device buffers.
766 * @ubi_num: UBI device to synchronize
768 * The underlying MTD device may cache data in hardware or in software. This
769 * function ensures the caches are flushed. Returns zero in case of success and
770 * a negative error code in case of failure.
772 int ubi_sync(int ubi_num
)
774 struct ubi_device
*ubi
;
776 ubi
= ubi_get_device(ubi_num
);
784 EXPORT_SYMBOL_GPL(ubi_sync
);
787 * ubi_flush - flush UBI work queue.
788 * @ubi_num: UBI device to flush work queue
789 * @vol_id: volume id to flush for
790 * @lnum: logical eraseblock number to flush for
792 * This function executes all pending works for a particular volume id / logical
793 * eraseblock number pair. If either value is set to %UBI_ALL, then it acts as
794 * a wildcard for all of the corresponding volume numbers or logical
795 * eraseblock numbers. It returns zero in case of success and a negative error
796 * code in case of failure.
798 int ubi_flush(int ubi_num
, int vol_id
, int lnum
)
800 struct ubi_device
*ubi
;
803 ubi
= ubi_get_device(ubi_num
);
807 err
= ubi_wl_flush(ubi
, vol_id
, lnum
);
811 EXPORT_SYMBOL_GPL(ubi_flush
);
813 BLOCKING_NOTIFIER_HEAD(ubi_notifiers
);
816 * ubi_register_volume_notifier - register a volume notifier.
817 * @nb: the notifier description object
818 * @ignore_existing: if non-zero, do not send "added" notification for all
819 * already existing volumes
821 * This function registers a volume notifier, which means that
822 * 'nb->notifier_call()' will be invoked when an UBI volume is created,
823 * removed, re-sized, re-named, or updated. The first argument of the function
824 * is the notification type. The second argument is pointer to a
825 * &struct ubi_notification object which describes the notification event.
826 * Using UBI API from the volume notifier is prohibited.
828 * This function returns zero in case of success and a negative error code
829 * in case of failure.
831 int ubi_register_volume_notifier(struct notifier_block
*nb
,
836 err
= blocking_notifier_chain_register(&ubi_notifiers
, nb
);
843 * We are going to walk all UBI devices and all volumes, and
844 * notify the user about existing volumes by the %UBI_VOLUME_ADDED
845 * event. We have to lock the @ubi_devices_mutex to make sure UBI
846 * devices do not disappear.
848 mutex_lock(&ubi_devices_mutex
);
849 ubi_enumerate_volumes(nb
);
850 mutex_unlock(&ubi_devices_mutex
);
854 EXPORT_SYMBOL_GPL(ubi_register_volume_notifier
);
857 * ubi_unregister_volume_notifier - unregister the volume notifier.
858 * @nb: the notifier description object
860 * This function unregisters volume notifier @nm and returns zero in case of
861 * success and a negative error code in case of failure.
863 int ubi_unregister_volume_notifier(struct notifier_block
*nb
)
865 return blocking_notifier_chain_unregister(&ubi_notifiers
, nb
);
867 EXPORT_SYMBOL_GPL(ubi_unregister_volume_notifier
);